linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND] [PATCH] by-path persistence for NICs
@ 2007-02-14  0:15 Bryan Kadzban
  2007-02-14 10:22 ` Marco d'Itri
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bryan Kadzban @ 2007-02-14  0:15 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1447 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

Resending because discussion died off last time:

http://sourceforge.net/mailarchive/forum.php?thread_id=30958045&forum_id=3157

and I think there are times that by-path persistence makes more sense
than by-MAC persistence.  (E.g., if you expect your NIC to die and get
replaced, and you plan on putting the replacement into the same slot.)

The attached patch adds support for NICs (DEVPATH=/class/net/*) to
path_id, and adds a by-path persistence option to write_net_rules.  The
default (from the rules file) is still by-mac, which is the way current
udev versions work.  The patch was generated against udev-103, but still
applies cleanly against 105.

Caveat: It probably doesn't work with PCMCIA devices, and may not work
with multi-port NICs (I don't have any of that hardware so I don't know
how those devices appear in sysfs).  Both of those may need more support
from path_id.  I suspect USB NICs work, but I can't test them either.

Any comments?  Marco, what do you think (since you got Debian's rules
merged into udev originally)?  Thanks!

And just in case it matters:

Signed-off-by: Bryan Kadzban <bryan@kadzban.is-a-geek.net>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF0lSHS5vET1Wea5wRA6UlAJ9SYNzOT5SkaKGqRKabAHCtIpTWBgCglA9D
KrYS++J/1gf+oagk1YGo1f8=
=nFGD
-----END PGP SIGNATURE-----

[-- Attachment #2: udev-103-net-by-path-2.patch --]
[-- Type: text/plain, Size: 4736 bytes --]

diff -Naur udev-103/extras/path_id/path_id udev-103-patched/extras/path_id/path_id
--- udev-103/extras/path_id/path_id	2006-10-20 08:43:35.000000000 -0400
+++ udev-103-patched/extras/path_id/path_id	2006-11-11 15:44:21.000000000 -0500
@@ -41,7 +41,13 @@
 fi
 
 if [ ! -e $SYSFS$DEVPATH/dev ] ; then
-	exit 1
+	case $DEVPATH in
+		/class/net/*)
+			;;
+		*)
+			exit 1
+			;;
+	esac
 fi
 
 case "$DEVPATH" in
@@ -91,7 +97,11 @@
 				;;
 		esac
 	done
-	d="pci-$pci_id-$d"
+	if [ "$d" ] ; then
+		d="pci-$pci_id-$d"
+	else
+		d="pci-$pci_id"
+	fi
 	D="$host_dev_path"
 	RESULT=0
 }
@@ -554,6 +564,10 @@
 		handle_device
 		echo "ID_PATH=$d"
 		;;
+	net)
+		handle_device
+		echo "ID_PATH=$d"
+		;;
 	*)
 		RESULT=1
 		;;
diff -Naur udev-103/extras/rule_generator/75-persistent-net-generator.rules udev-103-patched/extras/rule_generator/75-persistent-net-generator.rules
--- udev-103/extras/rule_generator/75-persistent-net-generator.rules	2006-10-20 08:43:35.000000000 -0400
+++ udev-103-patched/extras/rule_generator/75-persistent-net-generator.rules	2006-11-11 15:44:21.000000000 -0500
@@ -6,6 +6,8 @@
 GOTO="persistent_net_generator_end"
 LABEL="persistent_net_generator_do"
 
+IMPORT{program}="path_id %p"
+
 # build device description string to add a comment the generated rule
 SUBSYSTEMS=="pci", ENV{COMMENT}="PCI device $attr{vendor}:$attr{device} ($attr{driver})"
 SUBSYSTEMS=="usb", ENV{COMMENT}="USB device 0x$attr{idVendor}:0x$attr{idProduct} ($attr{driver})"
@@ -13,7 +15,7 @@
 SUBSYSTEMS=="xen", ENV{COMMENT}="Xen virtual device"
 ENV{COMMENT}=="", ENV{COMMENT}="$env{SUBSYSTEM} device ($attr{driver})"
 
-IMPORT{program}="write_net_rules $attr{address}"
+IMPORT{program}="write_net_rules by-mac"
 ENV{INTERFACE_NEW}=="?*", NAME="$env{INTERFACE_NEW}"
 
 LABEL="persistent_net_generator_end"
diff -Naur udev-103/extras/rule_generator/write_net_rules udev-103-patched/extras/rule_generator/write_net_rules
--- udev-103/extras/rule_generator/write_net_rules	2006-10-20 08:43:35.000000000 -0400
+++ udev-103-patched/extras/rule_generator/write_net_rules	2006-11-11 15:53:26.000000000 -0500
@@ -73,8 +73,28 @@
 		*) continue ;;
 		esac
 
-		INTERFACE="$INTERFACE" DEVPATH="/class/net/$INTERFACE" \
-			/lib/udev/write_net_rules || true
+		# Old usage (write_net_rules all_interfaces) gives MAC-based
+		# persistence.  New usage (write_net_rules all_interfaces
+		# by-{mac,path}) gives requested persistence type.
+		if [ -z "$2" -o "$2" = "by-mac" ] ; then
+			INTERFACE="$INTERFACE" DEVPATH="/class/net/$INTERFACE" \
+				/lib/udev/write_net_rules by-mac || true
+		elif [ "$2" = "by-path" ] ; then
+			eval $(/lib/udev/path_id "/class/net/$INTERFACE")
+
+			if [ -z "$ID_PATH" ] ; then
+				echo "$INTERFACE: Not supported by path_id." >&2
+				echo "You will need to generate a MAC-based rule." >&2
+			else
+				INTERFACE="$INTERFACE" DEVPATH="/class/net/$INTERFACE" \
+					ID_PATH="$ID_PATH" /lib/udev/write_net_rules by-path || true
+
+				ID_PATH=""
+			fi
+		else
+			echo "Invalid persistence type ($2)." >&2
+			exit 1
+		fi
 	done
 
 	exit 0
@@ -85,20 +105,44 @@
 	exit 1
 fi
 
-if [ "$1" ]; then
-	MAC_ADDR="$1"
-else
-	MAC_ADDR=$(sysread address)
-fi
+# Usage:  write_net_rules by-{mac,path} [mac-address]
+#  If by-path is given, no other arguments are used,
+#   but $ID_PATH must be set.
+#  If by-mac is given, the MAC address can either be
+#   given in $2, or inferred from $DEVPATH using sysread.
+#  One or the other of by-{mac,path} is required.
+
+case "$1" in
+	by-mac)
+		if [ "$2" ]; then
+			MAC_ADDR="$2"
+		else
+			MAC_ADDR=$(sysread address)
+		fi
+
+		if [ -z "$MAC_ADDR" ]; then
+			echo "No MAC address for $INTERFACE." >&2
+			exit 1
+		fi
+		if [ "$MAC_ADDR" = "00:00:00:00:00:00" ]; then
+			echo "NULL MAC address for $INTERFACE." >&2
+			exit 1
+		fi
+
+		;;
+	by-path)
+		if [ -z "$ID_PATH" ]; then
+			echo "No ID_PATH given for by-path rule." >&2
+			exit 1
+		fi
+
+		;;
+	*)
+		echo "First arg must be either by-mac or by-path." >&2
+		exit 1
 
-if [ -z "$MAC_ADDR" ]; then
-	echo "No MAC address for $INTERFACE." >&2
-	exit 1
-fi
-if [ "$MAC_ADDR" = "00:00:00:00:00:00" ]; then
-	echo "NULL MAC address for $INTERFACE." >&2
-	exit 1
-fi
+		;;
+esac
 
 # Prevent concurrent processes from modifying the file at the same time.
 lock_rules_file
@@ -117,7 +161,11 @@
 fi
 
 # the DRIVERS key is needed to not match bridges and VLAN sub-interfaces
-match="DRIVERS==\"?*\", ATTRS{address}==\"$MAC_ADDR\""
+if [ "$1" = "by-mac" ]; then
+	match="DRIVERS==\"?*\", ATTRS{address}==\"$MAC_ADDR\""
+else
+	match="DRIVERS==\"?*\", ENV{ID_PATH}==\"$ID_PATH\""
+fi
 if [ $basename = "ath" -o $basename = "wlan" ]; then
 	match="$match, ATTRS{type}==\"1\"" # do not match the wifi* interfaces
 fi

[-- Attachment #3: Type: text/plain, Size: 374 bytes --]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-02-14 20:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-14  0:15 [RESEND] [PATCH] by-path persistence for NICs Bryan Kadzban
2007-02-14 10:22 ` Marco d'Itri
2007-02-14 17:49 ` Bryan Kadzban
2007-02-14 20:55 ` Sergey Vlasov

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).