Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 297142 Details for
Bug 436435
NETWORK DEVICE ORDER CHANGES
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
patch file
rename_device_modprobe_check.patch (text/plain), 8.70 KB, created by
Joe.Jin
on 2008-03-07 07:02:28 UTC
(
hide
)
Description:
patch file
Filename:
MIME Type:
Creator:
Joe.Jin
Created:
2008-03-07 07:02:28 UTC
Size:
8.70 KB
patch
obsolete
>--- initscripts-8.45.16.EL/src/rename_device.c.orig 2008-03-05 21:55:34.000000000 +0800 >+++ initscripts-8.45.16.EL/src/rename_device.c 2008-03-05 21:56:07.000000000 +0800 >@@ -39,6 +39,9 @@ > #include <glib.h> > > #define LOCKFILE "/dev/.rename_device.lock" >+#ifndef PATH_MAX >+#define PATH_MAX 4096 >+#endif > > void sighandler(int dummy) { > unlink(LOCKFILE); >@@ -48,6 +51,8 @@ void sighandler(int dummy) { > struct netdev { > char *hwaddr; > char *dev; >+ char *modname; >+ int bind; > struct netdev *next; > }; > >@@ -59,6 +64,7 @@ struct tmp { > > struct netdev *configs = NULL; > struct netdev *devs = NULL; >+struct netdev *modprobe_cfgs = NULL; > struct tmp *tmplist = NULL; > > #if defined(__s390__) || defined(__s390x__) >@@ -107,6 +113,125 @@ char *read_subchannels(char *device) { > > #endif > >+char *get_drv_name(const char *dev) { >+ char *drvname, *path; >+ char link[PATH_MAX]; >+ >+ if (asprintf(&path, "/sys/class/net/%s/device/driver", dev) == -1) >+ return NULL; >+ if (access(path, R_OK)) >+ return NULL; >+ memset(link, 0, PATH_MAX); >+ >+ drvname = NULL; >+ if (readlink(path, link, PATH_MAX) > 0) >+ drvname = strdup(basename(link)); >+ >+ free(path); >+ return drvname; >+} >+ >+int is_bind_hwaddr(char *dev) { >+ struct netdev *config; >+ >+ for (config = configs; config; config = config->next) { >+ if (strcmp(config->dev, dev) == 0) >+ return config->bind; >+ if (strcmp(config->hwaddr, dev) == 0) >+ return config->bind; >+ } >+ return 0; >+} >+ >+struct netdev *get_modprobe_cfgs() { >+ gchar *contents, **lines; >+ struct netdev *ret = NULL, *tmpdev; >+ int i; >+ >+ lines = NULL; >+ >+ g_file_get_contents("/etc/modprobe.conf", &contents, NULL, NULL); >+ if (!contents) >+ return NULL; >+ lines = g_strsplit(contents,"\n", 0); >+ for (i = 0; lines[i]; i++) { >+ gchar **mod_lines = NULL; >+ int fields = 0; >+ >+ mod_lines = g_strsplit(lines[i], " ", 0); >+ for (fields = 0; mod_lines[fields]; fields++) >+ ; >+ if (fields < 2) >+ goto next_line; >+ if (strcmp(mod_lines[0],"alias") != 0) >+ goto next_line; >+ if (strncmp(mod_lines[1], "eth", 3) != 0) >+ goto next_line; >+ /* the device name have bind fixed MAC addr */ >+ if (is_bind_hwaddr(mod_lines[1])) >+ goto next_line; >+ tmpdev = calloc(1, sizeof(struct netdev)); >+ tmpdev->dev = g_strstrip(g_strdup(mod_lines[1])); >+ tmpdev->modname = g_strstrip(g_strdup(mod_lines[2])); >+ tmpdev->next = NULL; >+ if (!ret) { >+ ret = tmpdev; >+ } else { >+ struct netdev *curr, *prev; >+ prev = NULL; >+ for (curr = ret; curr; curr = curr->next) { >+ if (strcmp(curr->dev, tmpdev->dev) > 0) >+ break; >+ prev = curr; >+ } >+ if (prev) { >+ tmpdev->next = prev->next; >+ prev->next = tmpdev; >+ } else { >+ tmpdev->next = ret; >+ ret = tmpdev; >+ } >+ } >+next_line: >+ g_strfreev(mod_lines); >+ } >+ g_free(contents); >+ g_strfreev(lines); >+ >+ return ret; >+} >+ >+char *get_pci_slot_id(char *dev) { >+ char *slot, *path; >+ char link[PATH_MAX]; >+ >+ if (asprintf(&path, "/sys/class/net/%s/device", dev) == -1) >+ return NULL; >+ if (access(path, R_OK)) >+ return NULL; >+ memset(link, 0, PATH_MAX); >+ >+ slot = NULL; >+ if (readlink(path, link, PATH_MAX) > 0) >+ slot = strdup(basename(link)); >+ >+ free(path); >+ return slot; >+} >+ >+int pci_id_cmp(char *dev1, char *dev2) { >+ char *slot1, *slot2; >+ >+ slot1 = slot2 = NULL; >+ slot1 = get_pci_slot_id(dev1); >+ slot2 = get_pci_slot_id(dev2); >+ if (slot1 == NULL) >+ return -1; >+ if (slot2 == NULL) >+ return -1; >+ return strcmp(slot1, slot2); >+} >+ > struct netdev *get_devs() { > DIR *dir; > struct dirent *entry; >@@ -118,6 +243,7 @@ struct netdev *get_devs() { > while ((entry = readdir(dir))) { > char *path; > gchar *contents; >+ char *modname = NULL; > > contents = NULL; > >@@ -146,6 +272,11 @@ struct netdev *get_devs() { > tmpdev = calloc(1, sizeof(struct netdev)); > tmpdev->dev = g_strstrip(g_strdup(entry->d_name)); > tmpdev->hwaddr = g_strstrip(g_strdup(contents)); >+ modname = get_drv_name(entry->d_name); >+ if (modname) >+ tmpdev->modname = strdup(modname); >+ else >+ tmpdev->modname = NULL; > if (ret) > tmpdev->next = ret; > ret = tmpdev; >@@ -222,6 +353,7 @@ struct netdev *get_configs() { > tmpdev = calloc(1, sizeof(struct netdev)); > tmpdev->dev = g_strstrip(g_strdup(devname)); > tmpdev->hwaddr = g_strstrip(g_strdup(hwaddr)); >+ tmpdev->bind = !!strlen(tmpdev->hwaddr); > if (ret) > tmpdev->next = ret; > ret = tmpdev; >@@ -286,7 +418,6 @@ int do_rename(char *src, char *target) { > return ret; > } > >- > void rename_device(char *src, char *target, struct netdev *current) { > int rc; > >@@ -382,6 +513,142 @@ void take_lock() { > return; > } > >+void sort_devs_by_modname(char *modname) { >+ struct netdev *all, *tmpdev; >+ struct netdev *config; >+ >+ if (modname == NULL) return; >+ >+ all = NULL; >+ for (config = devs; config; config = config->next) { >+ if (!config->modname) continue; >+ if (strcmp(config->modname, modname) != 0) continue; >+ if (is_bind_hwaddr(config->hwaddr)) { >+ char *target; >+ struct tmp *ntmp; >+ target = get_config_by_hwaddr(config->hwaddr, config->dev); >+ if (strcmp(target,config->dev) == 0) >+ continue; >+ ntmp = calloc(1, sizeof(struct tmp)); >+ if (ntmp == NULL) return; >+ ntmp->src = strdup(config->dev); >+ ntmp->target = strdup(target); >+ if (tmplist) >+ ntmp->next = tmplist; >+ tmplist = ntmp; >+ continue; >+ >+ } >+ >+ tmpdev = calloc(1, sizeof(struct netdev)); >+ if (tmpdev == NULL) return; >+ memcpy(tmpdev, config, sizeof(struct netdev)); >+ tmpdev->next = NULL; >+ if (!all) { >+ all = tmpdev; >+ } else { >+ struct netdev *curr, *prev; >+ prev = NULL; >+ for (curr = all; curr; curr = curr->next) { >+ if (pci_id_cmp(curr->dev, tmpdev->dev) > 0) >+ break; >+ prev = curr; >+ } >+ if (prev == NULL) { >+ tmpdev->next = all; >+ all = tmpdev; >+ } else { >+ tmpdev->next = prev->next; >+ prev->next = tmpdev; >+ } >+ } >+ } >+ >+ tmpdev = all; >+ for (config = modprobe_cfgs; config && tmpdev; config = config->next) { >+ struct tmp *ntmp; >+ if (strcmp(config->modname, modname)) continue; >+ if (strcmp(tmpdev->dev, config->dev) == 0) { >+ tmpdev = tmpdev->next; >+ continue; >+ } >+ for (ntmp = tmplist; ntmp; ntmp = ntmp->next) >+ if (strcmp(ntmp->src, config->dev) == 0 && >+ strcmp(ntmp->target, tmpdev->dev) == 0) { >+ break; >+ } >+ if (ntmp != NULL) { >+ tmpdev = tmpdev->next; >+ continue; >+ } >+ ntmp = calloc(1, sizeof(struct tmp)); >+ if (ntmp == NULL) >+ return; >+ ntmp->src = strdup(tmpdev->dev); >+ ntmp->target = strdup(config->dev); >+ if (tmplist) >+ ntmp->next = tmplist; >+ tmplist = ntmp; >+ tmpdev = tmpdev->next; >+ } >+ tmpdev = all; >+ while (tmpdev) { >+ struct netdev *curr = tmpdev; >+ tmpdev = tmpdev->next; >+ free(curr); >+ } >+ return; >+} >+ >+char *sort_devs(char *src) { >+ char **modnames = NULL; >+ struct netdev *config; >+ struct tmp *ntmp; >+ int i, n; >+ >+ n = 0; >+ for (config = modprobe_cfgs; config; config = config->next) { >+ int match = 0; >+ if (modnames == NULL) { >+ modnames = calloc(1, sizeof(char *)); >+ if (modnames == NULL) return NULL; >+ modnames[n] = strdup(config->modname); >+ n++; >+ continue; >+ } >+ for (i = 0; i < n; i++) { >+ if (strcmp(modnames[i], config->modname) == 0) { >+ match = 1; >+ break; >+ } >+ } >+ if (match == 0) { >+ n++; >+ modnames = realloc(modnames, n * sizeof(char *)); >+ if (modnames == NULL) return NULL; >+ modnames[n-1] = strdup(config->modname); >+ } >+ } >+ >+ for (i = 0; i < n; i++) { >+ sort_devs_by_modname(modnames[i]); >+ if (modnames[i]) { >+ free(modnames[i]); >+ modnames[i] = NULL; >+ } >+ } >+ if (modnames) { >+ free(modnames); >+ modnames = NULL; >+ } >+ >+ for (ntmp = tmplist; ntmp; ntmp = ntmp->next) { >+ if (strcmp(ntmp->src, src) == 0) >+ return ntmp->target; >+ } >+ return NULL; >+} >+ > int main(int argc, char **argv) { > char *src, *target, *hw; > struct tmp *tmpdev; >@@ -394,7 +661,6 @@ int main(int argc, char **argv) { > signal(SIGSEGV,sighandler); > signal(SIGKILL,sighandler); > signal(SIGTERM,sighandler); >- signal(SIGSEGV,sighandler); > signal(SIGALRM,sighandler); > alarm(10); > >@@ -407,16 +673,25 @@ int main(int argc, char **argv) { > hw = get_hwaddr(src); > if (!hw) > goto out_unlock; >- target = get_config_by_hwaddr(hw, src); >- if (!target || !strcmp(src,target)) >- goto out_unlock; > >- rename_device(src, target, NULL); >+ >+ target = get_config_by_hwaddr(hw, src); >+ if (!target || !strcmp(src,target)) { >+ modprobe_cfgs = get_modprobe_cfgs(); >+ target = sort_devs(src); >+ goto out_sort; >+ } else { >+ rename_device(src, target, NULL); >+ } >+out_sort: > for (tmpdev = tmplist; tmpdev ; tmpdev = tmpdev->next) { > rename_device(tmpdev->src, tmpdev->target, NULL); > } >- printf("INTERFACE=%s\n",target); >- printf("DEVPATH=/class/net/%s\n", target); >+ >+ if (target && strcmp(src,target)) { >+ printf("INTERFACE=%s\n",target); >+ printf("DEVPATH=/class/net/%s\n", target); >+ } > out_unlock: > unlink(LOCKFILE); > exit(0);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 436435
: 297142