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: [PATCH] udev+ifrename integration
Date: Wed, 07 Mar 2007 19:44:35 +0000	[thread overview]
Message-ID: <20070307194435.GA22264@bougret.hpl.hp.com> (raw)

	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}="yes", SUBSYSTEM="net", PROGRAM="/usr/local/sbin/ifrename -D -V -i %k", NAME:="%c", OPTIONS+="skip_netrename", OPTIONS+="last_rule"
SUBSYSTEM="net", PROGRAM="/usr/local/sbin/ifrename -i %k", NAME:="%c", OPTIONS+="skip_netrename", OPTIONS+="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 program. The program's output printed to stdout is available for the RESULT key.
+Execute external program. The key is true, if the program returns with exit code zero. The whole event environment is available to the executed program. 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 
 		if (strcmp(udev->name, udev->dev->kernel) != 0) {
 			char *pos;
 
-			retval = rename_netif(udev);
-			if (retval != 0)
-				goto exit;
-			info("renamed netif to '%s'", udev->name);
+			if(!udev->skip_netrename) {
+				retval = rename_netif(udev);
+				if (retval != 0)
+					goto exit;
+				info("renamed netif to '%s'", udev->name);
+			}
 
 			/* 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 = 1;
 				dbg("remove event should be ignored");
 			}
+			if (rule->skip_netrename)
+				udev->skip_netrename = 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') {
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;
 
 	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 = DEFAULT_PARTITIONS_COUNT;
 			}
+			if (strstr(value, "skip_netrename") != NULL) {
+				dbg("skipping net rename");
+				rule->skip_netrename = 1;
+			}
 			valid = 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);
 
 	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=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

             reply	other threads:[~2007-03-07 19:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-07 19:44 Jean Tourrilhes [this message]
2007-03-07 20:35 ` [PATCH] udev+ifrename integration 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
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=20070307194435.GA22264@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).