Skip to contentSkip to conversation

The Ubuntu Collection: Winter/Spring 2006

PATCH In review Scott James Remnant 2 participants 4 messages Feb 9, 2006 – Feb 10, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 The Ubuntu Collection: Winter/Spring 2006

Further patches added to udev since the last drop to the list; note that we've frozen at 079 for the time being as we're planning on releasing with 2.6.15 so wanted a version "well tested" with that; as such these patches are aimed at that, though should apply to later.

New patches:

70-ifrename-wait-on-eexist.patch
This is an improvement to the rename_net_if() function to allow interface names to be swapped if probed at the same time. Should the ioctl return the EEXIST error, the interface is instead renamed to something temporary (__name) and then goes into a loop trying to rename to the desired interface.

The theory is that another udev process will do the opposite, and both renames will succeed.

80-extras-iftab_helper.patch
Adds an iftab_helper program that parses a tiny subset of the ifrename-style /etc/iftab file and outputs the name the interface should have.

As an improvement, if the kernel-assigned name would be taken by an interface in this file and the selectors don't match, the interface is renamed out of the kernel namespace (_name) so it doesn't clash later.

We use the above patches for the following rule:

	SUBSYSTEM=="net", ACTION=="add", \
		PROGRAM="iftab_helper %k $sysfs{address}", \
		NAME="$result"

Scott

Signature · 2 lines
Scott James Remnant
[email protected]
udev_add.c +23 -2
diff -ruNp udev-079~/udev_add.c udev-079/udev_add.c
@@ -32,6 +32,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <linux/sockios.h>
+#include <errno.h>
 
 #include "libsysfs/sysfs/libsysfs.h"
 #include "udev_libc_wrapper.h"
@@ -262,10 +263,30 @@ static int rename_net_if(struct udevice 
 	strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
 
 	retval = ioctl(sk, SIOCSIFNAME, &ifr);
-	if (retval != 0)
+	if ((retval != 0) && (errno == EEXIST)) {
+		/* Rename to something temporary then keep trying until
+		 * the name we want stops being hogged. */
+		strlcpy(ifr.ifr_newname, "__", IFNAMSIZ);
+		strlcat(ifr.ifr_newname, udev->name, IFNAMSIZ);
+
+		retval = ioctl(sk, SIOCSIFNAME, &ifr);
+		if (retval != 0)
+			err("error changing net interface name: %s", strerror(errno));
+
+		strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
+		while ((retval = ioctl(sk, SIOCSIFNAME, &ifr)) != 0) {
+			if (errno != EEXIST) {
+				err("error changing net interface name: %s", strerror(errno));
+				break;
+			}
+
+			usleep(10000);
+		}
+	} else if (retval != 0) {
 		err("error changing net interface name: %s", strerror(errno));
-	close(sk);
+	}
 
+	close(sk);
 	return retval;
 }
 
extras/iftab/Makefile +68 -0

68 lines not on this page · raw message

extras/iftab/iftab.5 +74 -0

74 lines not on this page · raw message

extras/iftab/iftab_helper.8 +33 -0
diff -ruNp udev-079~/extras/iftab/iftab_helper.8 udev-079/extras/iftab/iftab_helper.8
@@ -0,0 +1,33 @@
+.TH IFTAB_HELPER 8 "February 2006" "" "Linux Administrator's Manual"
+.SH NAME
+iftab_helper \- udev callout to parse /etc/iftab and name network devices
+.SH SYNOPSIS
+.BI iftab_helper
+\fIdevicename\fP \fIaddress\fP
+.SH DESCRIPTION
+.B iftab_helper
+is normally called from a udev rule to provide the name for a detected
+network device.  Udev can use this information to rename devices and thus
+provide consistent names for network devices.
+.SH USAGE
+.B iftab_helper
+looks up the address specified on the command-line in the \fI/etc/iftab\fR
+file and returns the name assigned to it in that file.  If it is not present
+it checks whether the kernel-assigned name is assigned to a different device
+in that file and if so returns a new name for the device.
+
+.B iftab_helper
+is not responsible for performing the actual renaming, that is instead
+eperformed by udev using a NAME rule.  This replaces the functionality
+previously offered by
+.BR ifrename (8)
+though note that
+.B iftab_helper
+does not support as wide a range of selectors for devices and files may
+need to be simplified.
+.SH SEE ALSO
+.BR iftab (5)
+.BR ifrename (8)
+.BR udev (8)
+.SH AUTHORS
+Scott James Remnant <[email protected]>
extras/iftab/iftab_helper.c +205 -0

205 lines not on this page · raw message

#1 lore raw
Quoted 2 lines · Scott James Remnant

The theory is that another udev process will do the opposite, and both renames will succeed.

Did you consider the case of a system with a dozen of interfaces, the exaustion of available udevd child processes and the possible deadlock?

Signature · 2 lines
ciao,
Marco
#2 lore raw
In reply to Scott James Remnant
Quoted 7 lines · Marco d'Itri
Quoted 2 lines · Scott James Remnant

The theory is that another udev process will do the opposite, and both renames will succeed.

Did you consider the case of a system with a dozen of interfaces, the exaustion of available udevd child processes and the possible deadlock?

They'll die off eventually under the three minute rule; if systems with dozens of interfaces are really doing this kind of renaming frenzy, they're probably doomed anyway :-)

Scott

Signature · 2 lines
Scott James Remnant
[email protected]
#3 lore raw
In reply to Scott James Remnant
Quoted 4 lines · Scott James Remnant
Quoted 2 lines · Marco d'Itri

On Feb 09, Scott James Remnant <[email protected]> wrote:

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

The theory is that another udev process will do the opposite, and both renames will succeed.

Did you consider the case of a system with a dozen of interfaces, the exaustion of available udevd child processes and the possible deadlock?

They'll die off eventually under the three minute rule; if systems with dozens of interfaces are really doing this kind of renaming frenzy, they're probably doomed anyway :-)

Uh, missed the following paragraph ...

This is why it renames the interfaces to a temporary name before waiting, so there's never a chain deadlock. You'd need a system with twice the number of interfaces as there were maximum udev processes, with every single one needing renaming and swapping, and be unlucky enough for all the wrong ones to be queued at the same time.

I suspect if a sysadmin really reached that, their box is powerful enough to increase the number of udev children *anyway*.

Scott

Signature · 2 lines
Scott James Remnant
[email protected]