Skip to contentSkip to conversation

Fix problems with vbd hotplug on Linux

PATCH New Gary Grebus 1 participant 1 message Nov 2, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix problems with vbd hotplug on Linux

Avoid races between hotplug "add" and "remove" leading to "leaked" loopback devices.

- Don't setup loopback device if xend is no longer waiting for the vbd.
- Use the lock file to avoid add/remove races.

tools/hotplug/Linux/block +11 -0
diff -r 8ca4e32583b6 tools/hotplug/Linux/block
@@ -233,6 +233,15 @@
 
         claim_lock "block"
 
+        # Avoid a race with the remove if the path has been deleted, or
+	# otherwise changed from "InitWait" state e.g. due to a timeout
+        xenbus_state=$(xenstore_read_default "$XENBUS_PATH/state" 'unknown')
+        if [ "$xenbus_state" != '2' ]
+        then
+          release_lock "block"
+          fatal "Path closed or removed during hotplug add: $XENBUS_PATH state: $xenbus_state"
+        fi
+
         if [ "$mode" = 'w' ] && ! stat "$file" -c %A | grep -q w
         then
           release_lock "block"
@@ -363,8 +372,10 @@
 	;;
 
       file)
+        claim_lock "block"
         node=$(xenstore_read "$XENBUS_PATH/node")
 	losetup -d "$node"
+        release_lock "block"
 	exit 0
 	;;