Skip to contentSkip to conversation

Fix removing /vm/UUID/device paths when device cannot be disconnected

PATCH Jiri Denemark 1 participant 1 message Feb 25, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

Currently if a device cannot be disconnected (for example, when trying to xm block-detach a disk which is mounted in domU), its /vm/UUID/device/CLASS/ID path is still removed. The result is that after a failed detach, the device cannot be detached even when using force...

An example of bad behavior:

xm create guest
xm block-attach guest tap:aio:/var/lib/xen/images/disk.img xvdb w

# mount /dev/xvdb1 in the guest

Than "xm block-detach guest xvdb" fails with something like
Error: Device ID (tap) could not be disconnected.

Examining xenstore, one can find both xvdb's backend and frontend are there, but /vm/UUID/device/tap/ID is not.

Although "xm block-list guest" would still show the xvdb device, "xm block-detach guest xvdb" would fail with
Device ID not connected
And it would show it even when --force is used.

I'd suggest to change deviceDestroy behavior to remove /vm/UUID/device/... path only when force was used (as it already does so for both frontend and backend) and do the removing from xen-hotplug-cleanup script when we are sure the device is really not attached to the guest any more.

Attached is a patch which moves unforced removing to cleanup script.

Cheers.

tools/hotplug/Linux/xen-hotplug-cleanup +10 -0
diff -r f8187a343ad2 tools/hotplug/Linux/xen-hotplug-cleanup
@@ -11,6 +11,13 @@
 # This is pretty horrible, but there's not really a nicer way of solving this.
 claim_lock "block"
 
+# split backend/DEVCLASS/VMID/DEVID on slashes
+path_array=( ${XENBUS_PATH//\// } )
+# get /vm/UUID path
+vm=$(xenstore-read "/local/domain/${path_array[2]}/vm")
+# construct /vm/UUID/device/DEVCLASS/DEVID
+vm_dev="$vm/device/${path_array[1]}/${path_array[3]}"
+
 # remove device frontend store entries
 xenstore-rm -t \
   $(xenstore-read "$XENBUS_PATH/frontend" 2>/dev/null) 2>/dev/null || true
@@ -19,4 +26,7 @@
 xenstore-rm -t "$XENBUS_PATH"        2>/dev/null || true
 xenstore-rm -t "error/$XENBUS_PATH"  2>/dev/null || true
 
+# remove device path from /vm/UUID
+xenstore-rm -t "$vm_dev" 2>/dev/null || true
+
 release_lock "block"
tools/python/xen/xend/server/DevController.py +2 -2
diff -r f8187a343ad2 tools/python/xen/xend/server/DevController.py
@@ -235,8 +235,8 @@
                 xstransact.Remove(backpath)
             xstransact.Remove(frontpath)
 
-        # xstransact.Remove(self.devicePath()) ?? Below is the same ?
-        self.vm._removeVm("device/%s/%d" % (self.deviceClass, dev))
+            # xstransact.Remove(self.devicePath()) ?? Below is the same ?
+            self.vm._removeVm("device/%s/%d" % (self.deviceClass, dev))
 
     def configurations(self, transaction = None):
         return map(lambda x: self.configuration(x, transaction), self.deviceIDs(transaction))

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel