]>
Commit | Line | Data |
---|---|---|
d3c9da06 JR |
1 | From: Michael Biebl <biebl@debian.org> |
2 | Date: Thu, 18 Jul 2013 01:04:07 +0200 | |
3 | Subject: Revert "udev: network device renaming - immediately give up if the | |
4 | target name isn't available" | |
5112024c | 5 | |
d3c9da06 | 6 | This reverts commit 97595710b77aa162ca5e20da57d0a1ed7355eaad. |
5112024c | 7 | |
a919bc1d JP |
8 | We need to keep supporting systems with 75-persistent-net-generator.rules |
9 | generated names for a while after switching to net.ifnames. Re-apply this old | |
10 | hack to make the renaming less likely to fail. | |
d3c9da06 | 11 | --- |
7cd4982d JP |
12 | --- systemd-242/src/udev/udev-event.c.orig 2019-04-11 18:28:36.000000000 +0200 |
13 | +++ systemd-242/src/udev/udev-event.c 2019-04-13 14:19:13.346990771 +0200 | |
14 | @@ -698,6 +698,8 @@ | |
15 | sd_device *dev = event->dev; | |
16 | const char *oldname; | |
a919bc1d | 17 | int ifindex, r; |
7cd4982d | 18 | + char name[IFNAMSIZ]; |
5112024c | 19 | + int loop; |
5112024c | 20 | |
a919bc1d JP |
21 | if (!event->name) |
22 | return 0; /* No new name is requested. */ | |
7cd4982d | 23 | @@ -719,22 +720,66 @@ |
a919bc1d | 24 | return log_device_error_errno(dev, r, "Failed to get ifindex: %m"); |
d3c9da06 | 25 | |
7cd4982d | 26 | r = rtnl_set_link_name(&event->rtnl, ifindex, event->name); |
d3c9da06 | 27 | + if (r >= 0) { |
7cd4982d JP |
28 | + /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */ |
29 | + r = device_add_property(dev, "ID_RENAMING", "1"); | |
a919bc1d | 30 | + if (r < 0) |
7cd4982d | 31 | + log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m"); |
a919bc1d | 32 | + |
7cd4982d JP |
33 | + r = device_rename(dev, event->name); |
34 | + if (r < 0) | |
35 | + log_device_warning_errno(dev, r, "Failed to update properties with new name '%s': %m", event->name); | |
a919bc1d | 36 | + |
7cd4982d | 37 | + log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, oldname, event->name); |
a919bc1d | 38 | + return 1; |
5112024c JR |
39 | + } |
40 | + | |
41 | + /* keep trying if the destination interface name already exists */ | |
d3c9da06 | 42 | + if (r != -EEXIST) |
5112024c | 43 | + goto out; |
7cd4982d | 44 | + |
5112024c | 45 | + /* free our own name, another process may wait for us */ |
a919bc1d JP |
46 | + snprintf(name, IFNAMSIZ, "rename%u", ifindex); |
47 | + r = rtnl_set_link_name(&event->rtnl, ifindex, name); | |
d3c9da06 | 48 | if (r < 0) |
7cd4982d JP |
49 | - return log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m", |
50 | - ifindex, oldname, event->name); | |
a919bc1d | 51 | + goto out; |
7cd4982d | 52 | + |
5112024c | 53 | + /* log temporary name */ |
7cd4982d | 54 | + log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, oldname, event->name); |
d3c9da06 | 55 | |
7cd4982d JP |
56 | - /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */ |
57 | - r = device_add_property(dev, "ID_RENAMING", "1"); | |
58 | - if (r < 0) | |
1bbe8306 | 59 | - return log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m"); |
5112024c | 60 | + /* wait a maximum of 90 seconds for our target to become available */ |
d3c9da06 | 61 | + strscpy(name, IFNAMSIZ, event->name); |
5112024c JR |
62 | + loop = 90 * 20; |
63 | + while (loop--) { | |
64 | + const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 }; | |
65 | + | |
66 | + nanosleep(&duration, NULL); | |
67 | + | |
a919bc1d | 68 | + r = rtnl_set_link_name(&event->rtnl, ifindex, name); |
d3c9da06 | 69 | + if (r >= 0) { |
7cd4982d JP |
70 | + /* Set ID_RENAMING boolean property here, and drop it in the corresponding move uevent later. */ |
71 | + r = device_add_property(dev, "ID_RENAMING", "1"); | |
a919bc1d | 72 | + if (r < 0) |
7cd4982d | 73 | + log_device_warning_errno(dev, r, "Failed to add 'ID_RENAMING' property: %m"); |
a919bc1d | 74 | + |
7cd4982d JP |
75 | + r = device_rename(dev, event->name); |
76 | + if (r < 0) | |
77 | + log_device_warning_errno(dev, r, "Failed to update properties with new name '%s': %m", event->name); | |
a919bc1d | 78 | + |
7cd4982d | 79 | + log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, oldname, event->name); |
a919bc1d | 80 | + return 1; |
5112024c | 81 | + } |
d3c9da06 | 82 | + if (r != -EEXIST) |
a919bc1d | 83 | + goto out; |
d3c9da06 | 84 | + } |
7cd4982d JP |
85 | |
86 | - r = device_rename(dev, event->name); | |
5112024c | 87 | +out: |
7cd4982d | 88 | if (r < 0) |
1bbe8306 | 89 | - return log_device_warning_errno(dev, r, "Failed to update properties with new name '%s': %m", event->name); |
7cd4982d JP |
90 | + return log_device_error_errno(dev, r, "Failed to rename network interface %i from '%s' to '%s': %m", |
91 | + ifindex, oldname, event->name); | |
d3c9da06 | 92 | + return r; |
7cd4982d JP |
93 | |
94 | - log_device_debug(dev, "Network interface %i is renamed from '%s' to '%s'", ifindex, oldname, event->name); | |
95 | ||
96 | - return 1; | |
5112024c | 97 | } |
d3c9da06 | 98 | |
a919bc1d | 99 | static int update_devnode(UdevEvent *event) { |