chiark / gitweb /
netif rename: optimistic loop for the name to become free
authorKay Sievers <kay.sievers@suse.de>
Sun, 2 Jul 2006 22:58:35 +0000 (00:58 +0200)
committerKay Sievers <kay.sievers@suse.de>
Sun, 2 Jul 2006 22:58:35 +0000 (00:58 +0200)
Parts from Ubuntu's 70-ifrename.patch.

extras/volume_id/lib/reiserfs.c
udev_device.c
udevd.h

index abeb06b..770f726 100644 (file)
@@ -66,7 +66,7 @@ int volume_id_probe_reiserfs(struct volume_id *id, uint64_t off)
        if (buf == NULL)
                return -1;
 
-       rs = (struct reiserfs_super_block *) buf;;
+       rs = (struct reiserfs_super_block *) buf;
        if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
                strcpy(id->type_version, "3.5");
                id->type = "reiserfs";
index ab4965c..3c4ac91 100644 (file)
@@ -81,7 +81,7 @@ dev_t udev_device_get_devt(struct udevice *udev)
        return makedev(0, 0);
 }
 
-static int rename_net_if(struct udevice *udev)
+static int rename_netif(struct udevice *udev)
 {
        int sk;
        struct ifreq ifr;
@@ -100,12 +100,44 @@ static int rename_net_if(struct udevice *udev)
        memset(&ifr, 0x00, sizeof(struct ifreq));
        strlcpy(ifr.ifr_name, udev->dev->kernel_name, IFNAMSIZ);
        strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
-
        retval = ioctl(sk, SIOCSIFNAME, &ifr);
-       if (retval != 0)
-               err("error changing net interface name: %s", strerror(errno));
-       close(sk);
+       if (retval != 0) {
+               int loop;
+
+               /* 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;
 }
 
@@ -181,7 +213,7 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
                if (strcmp(udev->name, udev->dev->kernel_name) != 0) {
                        char *pos;
 
-                       retval = rename_net_if(udev);
+                       retval = rename_netif(udev);
                        if (retval != 0)
                                goto exit;
                        info("renamed netif to '%s'", udev->name);
diff --git a/udevd.h b/udevd.h
index 1e9c702..20dde8e 100644 (file)
--- a/udevd.h
+++ b/udevd.h
@@ -32,7 +32,7 @@
 #define EVENT_SEQNUM                   ".udev/uevent_seqnum"
 
 /* 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 */
 #define UDEVD_MAX_CHILDS_RUNNING       16