On Mar 18, Faidon Liambotis <parav...@debian.org> wrote:

> Well, the root cause IMO is that 75-persistent-net-generator.rules is
> inherently susceptible to races. It's my understanding that it's valid
> for events to be triggered multiple times -- there are multiple places
> in d-i that "udevadm trigger" is called, including start-udev (as
> shipped by udev-udeb) which would trigger another set of "add" events
> beyond the original "hotplug" one.
I do not think that this is "valid" in the sense that the kernel could 
generate multiple add events, but removing all misuses of udevadm 
trigger requires some work and may not even be possible at this time.

I see that we have independently devised the same fix, I am attaching 
a test case and a more refined version of your patch.

-- 
ciao,
Marco
#!/bin/sh -e

rm -f /etc/udev/rules.d/70-persistent-net.rules

rmmod e1000e || true
modprobe e1000e
sleep 1

rm -f /etc/udev/rules.d/70-persistent-net.rules

iteration=0

while : ; do
  iteration=$((iteration + 1))
  if ! echo add > /sys/class/net/eth0/uevent; then
    echo "Failed at iteration $iteration!"
    exit
  fi
  # do not send too many events to udev because they will all be queued
  # and eventually processed
  if [ $iteration -eq 2500 ]; then
    echo "Aborting at iteration $iteration!"
    exit
  fi
done

--- /lib/udev/write_net_rules.orig	2015-03-30 05:18:43.228147201 +0200
+++ /lib/udev/write_net_rules	2015-03-30 06:00:39.181085432 +0200
@@ -117,6 +117,18 @@
 basename=${INTERFACE%%[0-9]*}
 match="$match, KERNEL==\"$basename*\""
 
+# build a regular expression that matches the new rule that we want to write
+new_rule_pattern=$(echo "^SUBSYSTEM==\"net\", ACTION==\"add\"$match" | sed -re 's/([\?\*])/\\\1/g')
+
+# Double check if the new rule has already been written. This happens if
+# multiple add events are generated before the script returns and udevd
+# renames the interfaces. See #765577 for details.
+if egrep -q "$new_rule_pattern" \
+    $RO_RULES_FILE $([ -e $RULES_FILE ] && echo $RULES_FILE); then
+  unlock_rules_file
+  exit 0
+fi
+
 if [ "$INTERFACE_NAME" ]; then
 	# external tools may request a custom name
 	COMMENT="$COMMENT (custom name provided by external tool)"

Attachment: pgp099UwXLv9Q.pgp
Description: PGP signature

Reply via email to