Commit 65e88dc0 authored by Michael Biebl's avatar Michael Biebl

Revert "udev: network device renaming - immediately give up if the target name isn't available"

This reverts commit 97595710.

Since we are keeping the old persistent network interface naming for
now, and make the new naming scheme [1] explictly opt-in [2], re-apply
this old hack to make the renaming less likely to fail.

[1] http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
[2] d5051f76
parent 0bcf5c01
......@@ -750,6 +750,7 @@ static int rename_netif(struct udev_event *event)
struct udev_device *dev = event->dev;
int sk;
struct ifreq ifr;
int loop;
int err;
log_debug("changing net interface name from '%s' to '%s'\n",
......@@ -766,12 +767,49 @@ static int rename_netif(struct udev_event *event)
strscpy(ifr.ifr_name, IFNAMSIZ, udev_device_get_sysname(dev));
strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err >= 0) {
if (err == 0) {
print_kmsg("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname);
} else {
goto out;
}
/* keep trying if the destination interface name already exists */
err = -errno;
if (err != -EEXIST)
goto out;
/* free our own name, another process may wait for us */
snprintf(ifr.ifr_newname, IFNAMSIZ, "rename%u", udev_device_get_ifindex(dev));
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err < 0) {
err = -errno;
log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname);
goto out;
}
/* log temporary name */
print_kmsg("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname);
/* wait a maximum of 90 seconds for our target to become available */
strscpy(ifr.ifr_name, IFNAMSIZ, ifr.ifr_newname);
strscpy(ifr.ifr_newname, IFNAMSIZ, event->name);
loop = 90 * 20;
while (loop--) {
const struct timespec duration = { 0, 1000 * 1000 * 1000 / 20 };
nanosleep(&duration, NULL);
err = ioctl(sk, SIOCSIFNAME, &ifr);
if (err == 0) {
print_kmsg("renamed network interface %s to %s\n", ifr.ifr_name, ifr.ifr_newname);
break;
}
err = -errno;
if (err != -EEXIST)
break;
}
out:
if (err < 0)
log_error("error changing net interface name %s to %s: %m\n", ifr.ifr_name, ifr.ifr_newname);
close(sk);
return err;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment