From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jean Tourrilhes Date: Sat, 10 Mar 2007 01:50:17 +0000 Subject: Re: [PATCH] udev+ifrename integration Message-Id: <20070310015017.GA28999@bougret.hpl.hp.com> List-Id: References: <20070307194435.GA22264@bougret.hpl.hp.com> In-Reply-To: <20070307194435.GA22264@bougret.hpl.hp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: linux-hotplug@vger.kernel.org On Fri, Mar 09, 2007 at 02:59:25PM +0100, Kay Sievers wrote: > On Wed, 2007-03-07 at 13:11 -0800, Jean Tourrilhes wrote: >=20 > Anyway, how about you add a "hotplug" option to ifrename to output all > useful information in env-key format after its work, like: > $ifrename --hotplug-use -i %k > DEVPATH=3D/sys/class/net/renamed3 > INTERFACE=3Drenamed3 > INTERFACE_OLD=3Deth1 >=20 > and whatever information may be useful for the stuff that runs after the > renaming, I'm sure you will find something more to export. :) >=20 > Integration into udev would happen with the IMPORT=3D key. I would change > udev to update all internal variables that carry the name, if DEVPATH is > overwritten from an IMPORT action. How does that sound to you? Ok, I've just looked into doing that. I've implemented the ifrename part in version 29.pre16. The "proof of concept" patch for udev is attached. I've not yet tested that patch, because I'm not sure this is the right implementation and it makes me wonder if this is the right solution. It's definitely more messy than the previous patch I sent. Have fun... Jean -------------------------------------------------------------- diff -u -p udev-106/udev.j1.h udev-106/udev.h --- udev-106/udev.j1.h 2007-03-09 17:26:45.000000000 -0800 +++ udev-106/udev.h 2007-03-09 17:27:30.000000000 -0800 @@ -85,6 +85,7 @@ struct udevice { int partitions; int ignore_device; int ignore_remove; + int update_devpath; char program_result[PATH_SIZE]; int test_run; }; diff -u -p udev-106/udev_rules.j1.c udev-106/udev_rules.c --- udev-106/udev_rules.j1.c 2007-03-09 14:48:19.000000000 -0800 +++ udev-106/udev_rules.c 2007-03-09 17:40:13.000000000 -0800 @@ -188,6 +188,8 @@ static int import_keys_into_env(struct u dbg("import '%s=3D%s'", variable, value); name_list_key_add(&udev->env_list, variable, value); setenv(variable, value, 1); + if(!strcmp(variable, "INTERFACE")) + udev->update_devpath =3D 1; } } =20 @@ -903,6 +905,25 @@ int udev_rules_get_name(struct udev_rule udev->ignore_remove =3D 1; dbg("remove event should be ignored"); } + if (udev->update_devpath =3D 1) { + char *env; + char *pos; + env =3D getenv("INTERFACE"); + if (env && strcmp(env, udev->dev->kernel)) { + /* Update internal variables */ + strcpy(udev->name, env); + strcpy(udev->dev->kernel, env); + /* now fake the devpath, because the kernel name changed silently */ + pos =3D strrchr(udev->dev->devpath, '/'); + if (pos !=3D NULL) { + pos[1] =3D '\0'; + strlcat(udev->dev->devpath, udev->name, sizeof(udev->dev->devpath)); + strlcpy(udev->dev->kernel, udev->name, sizeof(udev->dev->kernel)); + } + /* No more renaming, we are done */ + name_set =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') { ------------------------------------------------------------------------- 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