linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Tourrilhes <jt@hpl.hp.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] udev+ifrename integration
Date: Sat, 10 Mar 2007 01:50:17 +0000	[thread overview]
Message-ID: <20070310015017.GA28999@bougret.hpl.hp.com> (raw)
In-Reply-To: <20070307194435.GA22264@bougret.hpl.hp.com>

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:
> 
> 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=/sys/class/net/renamed3
>   INTERFACE=renamed3
>   INTERFACE_OLD=eth1
> 
> and whatever information may be useful for the stuff that runs after the
> renaming, I'm sure you will find something more to export. :)
> 
> Integration into udev would happen with the IMPORT= 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=%s'", variable, value);
 			name_list_key_add(&udev->env_list, variable, value);
 			setenv(variable, value, 1);
+			if(!strcmp(variable, "INTERFACE"))
+				udev->update_devpath = 1;
 		}
 	}
 
@@ -903,6 +905,25 @@ int udev_rules_get_name(struct udev_rule
 				udev->ignore_remove = 1;
 				dbg("remove event should be ignored");
 			}
+			if (udev->update_devpath = 1) {
+				char *env;
+				char *pos;
+				env = 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 = strrchr(udev->dev->devpath, '/');
+					if (pos != NULL) {
+						pos[1] = '\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 = 1;
+				}
+			}
 			/* apply all_partitions option only at a main block device */
 			if (rule->partitions &&
 			    strcmp(udev->dev->subsystem, "block") = 0 && udev->dev->kernel_number[0] = '\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=join.php&p=sourceforge&CIDÞVDEV
_______________________________________________
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

  parent reply	other threads:[~2007-03-10  1:50 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-07 19:44 [PATCH] udev+ifrename integration Jean Tourrilhes
2007-03-07 20:35 ` Kay Sievers
2007-03-07 21:11 ` Jean Tourrilhes
2007-03-08 11:24 ` Scott James Remnant
2007-03-08 18:15 ` Jean Tourrilhes
2007-03-09 11:57 ` Scott James Remnant
2007-03-09 13:59 ` Kay Sievers
2007-03-09 17:11 ` Jean Tourrilhes
2007-03-09 17:17 ` Jean Tourrilhes
2007-03-10  1:50 ` Jean Tourrilhes [this message]
2007-03-10 13:28 ` Kay Sievers
2007-03-12 16:07 ` Jean Tourrilhes
2007-03-12 16:51 ` Kay Sievers
2007-03-15 23:27 ` Jean Tourrilhes
2007-03-16  0:14 ` Kay Sievers
2007-03-16  0:24 ` Jean Tourrilhes
2007-04-30 10:02 ` Kay Sievers
2007-04-30 17:00 ` Jean Tourrilhes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070310015017.GA28999@bougret.hpl.hp.com \
    --to=jt@hpl.hp.com \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).