From: Jean Tourrilhes Date: Wed, 07 Mar 2007 19:44:35 +0000 Subject: [PATCH] udev+ifrename integration Message-Id: <20070307194435.GA22264@bougret.hpl.hp.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org Hi, Integration of ifrename into udev has been a thorn in the side of some major distro (Unbuntu, Debian...). There is a set of users that are hooked to ifrename for renaming interfaces. Ifrename has various power user feature that allow you to shoot yourself in the foot pretty nicely, and those users can't live without that. They are integrating ifrename into udev in various ad-hoc ways and everything "seems" to work. Then, the distro maintainers point out that they can't do that because in reality it breaks udev (and HAL, and NetworkManager, and so on). One of the solution is to migrate all apps using Hotplug events to use 'ifindex' instead of 'ifname'. This is needed anyway to fix the netif remove/add race condition. But this require kernel support (which I just sent to Kay) and won't happen overnight. The other solution is to offer a clean integration of ifrename into udev. This has other benefits as well. The attached patch for udev-105 does just that. The first thing to notice is that the changes are minimal. Also, none of the changes are specific to ifrename, and those could be used by any network renaming program/script and solutions based on 'nameif' of 'iproute2'. Another point is that this integration will mostly work with older version of ifrename but only version 29-pre14 or later will fully work. Finally, the udev rules would look like : ---------------------------------------------------- ENV{UDEVTEST}=3D"yes", SUBSYSTEM=3D"net", PROGRAM=3D"/usr/local/sbin/ifrena= me -D -V -i %k", NAME:=3D"%c", OPTIONS+=3D"skip_netrename", OPTIONS+=3D"las= t_rule" SUBSYSTEM=3D"net", PROGRAM=3D"/usr/local/sbin/ifrename -i %k", NAME:=3D"%c"= , OPTIONS+=3D"skip_netrename", OPTIONS+=3D"last_rule" ---------------------------------------------------- Have fun... Jean P.S. : Marco, bug 363598. Non voglio aggiungere niente a questo bug ;-) ----------------------------------------------------------- diff -u -p udev-105-pristine/udev.7 udev-105/udev.7 --- udev-105-pristine/udev.7 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev.7 2007-02-28 17:48:37.000000000 -0800 @@ -146,7 +146,7 @@ keys can be specified per rule. Dependin .PP \fBPROGRAM\fR .RS 4 -Execute external program. The key is true, if the program returns without = exit code zero. The whole event environment is available to the executed pr= ogram. The program's output printed to stdout is available for the RESULT k= ey. +Execute external program. The key is true, if the program returns with exi= t code zero. The whole event environment is available to the executed progr= am. The program's output printed to stdout is available for the RESULT key. .RE .PP \fBRESULT\fR diff -u -p udev-105-pristine/udev.h udev-105/udev.h --- udev-105-pristine/udev.h 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev.h 2007-02-28 17:26:03.000000000 -0800 @@ -85,6 +85,7 @@ struct udevice { int partitions; int ignore_device; int ignore_remove; + int skip_netrename; char program_result[PATH_SIZE]; int test_run; }; diff -u -p udev-105-pristine/udev_device.c udev-105/udev_device.c --- udev-105-pristine/udev_device.c 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev_device.c 2007-02-28 17:26:54.000000000 -0800 @@ -213,10 +213,12 @@ int udev_device_event(struct udev_rules=20 if (strcmp(udev->name, udev->dev->kernel) !=3D 0) { char *pos; =20 - retval =3D rename_netif(udev); - if (retval !=3D 0) - goto exit; - info("renamed netif to '%s'", udev->name); + if(!udev->skip_netrename) { + retval =3D rename_netif(udev); + if (retval !=3D 0) + goto exit; + info("renamed netif to '%s'", udev->name); + } =20 /* export old name */ setenv("INTERFACE_OLD", udev->dev->kernel, 1); diff -u -p udev-105-pristine/udev_rules.c udev-105/udev_rules.c --- udev-105-pristine/udev_rules.c 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev_rules.c 2007-02-28 17:26:45.000000000 -0800 @@ -901,6 +901,8 @@ int udev_rules_get_name(struct udev_rule udev->ignore_remove =3D 1; dbg("remove event should be ignored"); } + if (rule->skip_netrename) + udev->skip_netrename =3D 1; /* apply all_partitions option only at a main block device */ if (rule->partitions && strcmp(udev->dev->subsystem, "block") =3D 0 && udev->dev->kernel_nu= mber[0] =3D '\0') { diff -u -p udev-105-pristine/udev_rules.h udev-105/udev_rules.h --- udev-105-pristine/udev_rules.h 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev_rules.h 2007-02-28 17:17:36.000000000 -0800 @@ -90,7 +90,8 @@ struct udev_rule { unsigned int partitions; unsigned int last_rule:1, ignore_device:1, - ignore_remove:1; + ignore_remove:1, + skip_netrename:1; =20 size_t bufsize; char buf[]; diff -u -p udev-105-pristine/udev_rules_parse.c udev-105/udev_rules_parse.c --- udev-105-pristine/udev_rules_parse.c 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udev_rules_parse.c 2007-02-28 17:36:10.000000000 -0800 @@ -569,6 +569,10 @@ static int add_to_rules(struct udev_rule dbg("creation of partition nodes requested"); rule->partitions =3D DEFAULT_PARTITIONS_COUNT; } + if (strstr(value, "skip_netrename") !=3D NULL) { + dbg("skipping net rename"); + rule->skip_netrename =3D 1; + } valid =3D 1; continue; } diff -u -p udev-105-pristine/udevtest.c udev-105/udevtest.c --- udev-105-pristine/udevtest.c 2007-02-02 16:24:48.000000000 -0800 +++ udev-105/udevtest.c 2007-02-28 16:53:29.000000000 -0800 @@ -110,6 +110,8 @@ int main(int argc, char *argv[], char *e setenv("DEVPATH", udev->dev->devpath, 1); setenv("SUBSYSTEM", udev->dev->subsystem, 1); setenv("ACTION", "add", 1); + /* Allow rules to know it's debugging time */ + setenv("UDEVTEST", "yes", 1); =20 printf("This program is for debugging only, it does not create any node,\= n" "or run any program specified by a RUN key. It may show incorrect = results,\n" ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=DEVD= EV _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel