All of lore.kernel.org
 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

* Re: [RESEND] [PATCH] by-path persistence for NICs
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Marco d'Itri @ 2007-02-14 10:22 UTC (permalink / raw)
  To: linux-hotplug

On Feb 14, Bryan Kadzban <bryan@kadzban.is-a-geek.net> wrote:

> 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.
USB paths change frequently.
It will not work for removable interfaces and I do not think this is a
great idea generally. Anyway it must not be the default.
I have not reviewed closely the code.

-- 
ciao,
Marco

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

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

* Re: [RESEND] [PATCH] by-path persistence for NICs
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Bryan Kadzban @ 2007-02-14 17:49 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1: Type: text/plain, Size: 1530 bytes --]

On Wed, Feb 14, 2007 at 11:22:45AM +0100, Marco d'Itri wrote:
> On Feb 14, Bryan Kadzban <bryan@kadzban.is-a-geek.net> wrote:
> 
> > 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.
> 
> USB paths change frequently.

You're right, rats.  So would paths for other removable devices.

Well, I'm not sure whether that's a showstopper, but I think it probably
is.  I was only thinking about PCI hardware and what happens when a NIC
dies and is replaced.  With MAC-based persistence, the MAC address in
the generated rules file needs to be changed to the new NIC's MAC before
the new NIC is inserted, otherwise the system's configuration (e.g. the
config files for the distro's network boot script) is invalid.

But that's not as big of a deal as forcing the user to use the same USB
port (or more accurately, the same physical path) all the time.

> Anyway it must not be the default.

It's not the default (in that patch anyway), but from what you said
about it not working for anything removable, it sounds like it's not a
good idea in any case.  I think this kind of persistence would fail more
often than MAC-based persistence does.

So: Retracted, unless someone wants to pick it up even with this issue.
There's no way around the problem either.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
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=DEVDEV

[-- Attachment #3: 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

* Re: [RESEND] [PATCH] by-path persistence for NICs
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Sergey Vlasov @ 2007-02-14 20:55 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1: Type: text/plain, Size: 1895 bytes --]

On Wed, 14 Feb 2007 12:49:36 -0500 Bryan Kadzban wrote:

> On Wed, Feb 14, 2007 at 11:22:45AM +0100, Marco d'Itri wrote:
> > USB paths change frequently.
>
> You're right, rats.  So would paths for other removable devices.
>
> Well, I'm not sure whether that's a showstopper, but I think it probably
> is.  I was only thinking about PCI hardware and what happens when a NIC
> dies and is replaced.  With MAC-based persistence, the MAC address in
> the generated rules file needs to be changed to the new NIC's MAC before
> the new NIC is inserted, otherwise the system's configuration (e.g. the
> config files for the distro's network boot script) is invalid.

Even worse, sometimes you need to change MAC to the value from the old
card, because someone dumb at the other end configured static ARP
entries supposedly to increase security, and it is easier to change
the MAC locally than to make the other end update its config.  Then
you need to have rules both for the new and the old MAC (the latter
for the case when the device is processed by udev again for some
reason).

> But that's not as big of a deal as forcing the user to use the same USB
> port (or more accurately, the same physical path) all the time.
>
> > Anyway it must not be the default.
>
> It's not the default (in that patch anyway), but from what you said
> about it not working for anything removable, it sounds like it's not a
> good idea in any case.  I think this kind of persistence would fail more
> often than MAC-based persistence does.
>
> So: Retracted, unless someone wants to pick it up even with this issue.
> There's no way around the problem either.

It could be possible to detect the device type and use different
persistence methods for different kinds of devices.

And the first part of the patch (path_id change to support network
devices) could be useful by itself at least for manual configuration.

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 345 bytes --]

-------------------------------------------------------------------------
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=DEVDEV

[-- Attachment #3: 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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.