mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-24 21:34:08 +03:00
netif rename: optimistic loop for the name to become free
Parts from Ubuntu's 70-ifrename.patch.
This commit is contained in:
parent
e0595b53b5
commit
b879c303a7
@ -66,7 +66,7 @@ int volume_id_probe_reiserfs(struct volume_id *id, uint64_t off)
|
|||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
rs = (struct reiserfs_super_block *) buf;;
|
rs = (struct reiserfs_super_block *) buf;
|
||||||
if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
|
if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
|
||||||
strcpy(id->type_version, "3.5");
|
strcpy(id->type_version, "3.5");
|
||||||
id->type = "reiserfs";
|
id->type = "reiserfs";
|
||||||
|
@ -81,7 +81,7 @@ dev_t udev_device_get_devt(struct udevice *udev)
|
|||||||
return makedev(0, 0);
|
return makedev(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rename_net_if(struct udevice *udev)
|
static int rename_netif(struct udevice *udev)
|
||||||
{
|
{
|
||||||
int sk;
|
int sk;
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
@ -100,12 +100,44 @@ static int rename_net_if(struct udevice *udev)
|
|||||||
memset(&ifr, 0x00, sizeof(struct ifreq));
|
memset(&ifr, 0x00, sizeof(struct ifreq));
|
||||||
strlcpy(ifr.ifr_name, udev->dev->kernel_name, IFNAMSIZ);
|
strlcpy(ifr.ifr_name, udev->dev->kernel_name, IFNAMSIZ);
|
||||||
strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
|
strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
|
||||||
|
|
||||||
retval = ioctl(sk, SIOCSIFNAME, &ifr);
|
retval = ioctl(sk, SIOCSIFNAME, &ifr);
|
||||||
if (retval != 0)
|
if (retval != 0) {
|
||||||
err("error changing net interface name: %s", strerror(errno));
|
int loop;
|
||||||
close(sk);
|
|
||||||
|
|
||||||
|
/* see if the destination interface name already exists */
|
||||||
|
if (errno != EEXIST) {
|
||||||
|
err("error changing netif name: %s", strerror(errno));
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free our own name, another process may wait for us */
|
||||||
|
strlcpy(ifr.ifr_newname, udev->dev->kernel_name, IFNAMSIZ);
|
||||||
|
strlcat(ifr.ifr_newname, "_rename", IFNAMSIZ);
|
||||||
|
retval = ioctl(sk, SIOCSIFNAME, &ifr);
|
||||||
|
if (retval != 0) {
|
||||||
|
err("error changing netif name: %s", strerror(errno));
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wait 30 seconds for our target to become available */
|
||||||
|
strlcpy(ifr.ifr_name, ifr.ifr_newname, IFNAMSIZ);
|
||||||
|
strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
|
||||||
|
loop = 30 * 20;
|
||||||
|
while (loop--) {
|
||||||
|
retval = ioctl(sk, SIOCSIFNAME, &ifr);
|
||||||
|
if (retval != 0) {
|
||||||
|
if (errno != EEXIST) {
|
||||||
|
err("error changing net interface name: %s", strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dbg("wait for netif '%s' to become free, loop=%i", udev->name, (30 * 20) - loop);
|
||||||
|
usleep(1000 * 1000 / 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
close(sk);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +213,7 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
|
|||||||
if (strcmp(udev->name, udev->dev->kernel_name) != 0) {
|
if (strcmp(udev->name, udev->dev->kernel_name) != 0) {
|
||||||
char *pos;
|
char *pos;
|
||||||
|
|
||||||
retval = rename_net_if(udev);
|
retval = rename_netif(udev);
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
info("renamed netif to '%s'", udev->name);
|
info("renamed netif to '%s'", udev->name);
|
||||||
|
2
udevd.h
2
udevd.h
@ -32,7 +32,7 @@
|
|||||||
#define EVENT_SEQNUM ".udev/uevent_seqnum"
|
#define EVENT_SEQNUM ".udev/uevent_seqnum"
|
||||||
|
|
||||||
/* maximum limit of forked childs */
|
/* maximum limit of forked childs */
|
||||||
#define UDEVD_MAX_CHILDS 64
|
#define UDEVD_MAX_CHILDS 256
|
||||||
/* start to throttle forking if maximum number of running childs in our session is reached */
|
/* start to throttle forking if maximum number of running childs in our session is reached */
|
||||||
#define UDEVD_MAX_CHILDS_RUNNING 16
|
#define UDEVD_MAX_CHILDS_RUNNING 16
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user