* write_net_rules: path-based persistence #2
@ 2006-11-11 21:35 Bryan Kadzban
2006-11-13 6:35 ` Alexander E. Patrakov
0 siblings, 1 reply; 2+ messages in thread
From: Bryan Kadzban @ 2006-11-11 21:35 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1.1.1: Type: text/plain, Size: 2590 bytes --]
OK, I've thought about this a bit more, and have come up with a way to
do location-based persistence for network devices, using a slightly
modified path_id.
Modifications to path_id let it handle /class/net DEVPATHs, and remove
the extra - character from the end of PCI card ID_PATH values. (The
last bit isn't necessary, but IMO it makes it look better. Since it
changes the old output, it may not be acceptable, but that hunk is
independent of the rest of the patch.)
Modifications to 75-persistent-net-generator.rules have it run path_id,
and specify by-mac to write_net_rules by default. To move to path-based
persistence for new devices, "sed -i -e 's/by-mac/by-path/'
75-persistent-net-generator.rules" or something similar. (by-path
ignores all subsequent arguments, so the $attr{address} is still
accepted, though it does nothing.)
Modifications to write_net_rules are in two groups, the all_interfaces
handler and the per-device handler.
all_interfaces handler: Usage is documented in the comments. If
neither by-mac nor by-path is given, assume by-mac (for compatibility).
Import path_id for each device here, and print a warning if the device
isn't supported (I think there are some of those? not sure). Otherwise,
pass by-{mac,path} and the other variables down. Note that by-mac or
by-path is $2 here (all_interfaces is $1), which is different from the
per-device handler.
Per-device handler: Move old MAC_ADDR setup code into the by-mac
handler, and add check for $ID_PATH if by-path is given. Then write the
correct type of match depending on $1 (by-mac or by-path).
The resulting rules work properly for both my PCI card and onboard (PCI)
NICs, when each card is triggered on its own. I don't know how well it
works when both cards are triggered at once, or on SMP, but I don't
think it's any different than the old rule-writing script.
This patch should not require a working sysreadlink, since it uses
path_id. (See the discussion starting about a week ago.)
Issues:
1) I still don't know how cards with multiple ports are represented in
sysfs. If they're multiple /class/net/eth* kobjects, then that's only
going to work if their device symlinks point to two different places (if
they show up as multiple PCI devices), otherwise they'll have the same
ID_PATH. path_id will need to be extended to handle these devices if
that's true.
2) I don't know what other bus types may be used by NICs, and whether
these other bus types are supported by path_id. Some are likely not
going to work with this patch, until support gets into path_id.
3) Others?
[-- Attachment #1.1.2: udev-103-net-by-path.patch --]
[-- Type: text/plain, Size: 4757 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 [ -z "$d" ] ; then
+ d="pci-$pci_id"
+ else
+ d="pci-$pci_id-$d"
+ 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 $attr{address}"
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 #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 258 bytes --]
[-- Attachment #2: Type: text/plain, Size: 373 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 #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] 2+ messages in thread* Re: write_net_rules: path-based persistence #2
2006-11-11 21:35 write_net_rules: path-based persistence #2 Bryan Kadzban
@ 2006-11-13 6:35 ` Alexander E. Patrakov
0 siblings, 0 replies; 2+ messages in thread
From: Alexander E. Patrakov @ 2006-11-13 6:35 UTC (permalink / raw)
To: linux-hotplug
Bryan Kadzban wrote:
> Modifications to 75-persistent-net-generator.rules have it run path_id,
> and specify by-mac to write_net_rules by default. To move to path-based
> persistence for new devices, "sed -i -e 's/by-mac/by-path/'
> 75-persistent-net-generator.rules" or something similar. (by-path
> ignores all subsequent arguments, so the $attr{address} is still
> accepted, though it does nothing.)
>
Maybe it is a good idea to remove $attr{address} from the command line
in 75-persistent-net-generator.rules, because of the code below?
> + if [ "$2" ] ; then
> + MAC_ADDR="$2"
> + else
> + MAC_ADDR=$(sysread address)
> + fi
>
--
Alexander E. Patrakov
-------------------------------------------------------------------------
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\x120709&bid&3057&dat\x121642
_______________________________________________
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] 2+ messages in thread
end of thread, other threads:[~2006-11-13 6:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-11 21:35 write_net_rules: path-based persistence #2 Bryan Kadzban
2006-11-13 6:35 ` Alexander E. Patrakov
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).