xend: fix vbd/tapdisk device destruction
PATCH 1/1 xend: fix vbd/tapdisk device destruction
blktap2 devices attach as a regular 'vbd' rather than a 'tap' device. Accordingly, Xend should use 'vbd' as the device class of blktap2 devices. This patch determines the appropriate device class by reading the 'type' field of the backend's xenstore entry.
tools/python/xen/xend/XendDomainInfo.py +28 -8
@@ -1244,13 +1244,33 @@ class XendDomainInfo: dev_num += 1 return sxprs - def getBlockDeviceClass(self, devid): - # To get a device number from the devid, - # we temporarily use the device controller of VBD. - dev = self.getDeviceController('vbd').convertToDeviceNumber(devid) - dev_info = self._getDeviceInfo_vbd(dev) - if dev_info: - return dev_info[0] + def getBlockDeviceClass(self, devid, deviceClass=False): + backendType = 'vbd' + + # For backwards compatability, we may have to get deviceClass ourselves + if not deviceClass: + t = xstransact("%s/device" % self.dompath) + for devclass in XendDevices.valid_devices(): + if devid in t.list(devclass): + deviceClass = devclass + break + t.abort() + + try: + # Note: deviceClass may be incorrect, so we cannot trust readBackend + # or readFrontend from the Device Controller to succeed + backendPath = xstransact.Read("%s/device/%s/%s" + % (self.dompath, deviceClass, devid), + "backend") + backendType = xstransact.Read(backendPath, "type") + except Exception, ex: + # we can probably just assume the block device is a VBD + log.debug("error reading backend for device (%s): %s", devid, str(ex)) + + if backendType == 'tap': + return 'tap' + else: + return 'vbd' def _getDeviceInfo_vif(self, mac): for dev_type, dev_info in self.info.all_devices_sxpr():
@@ -2217,7 +2237,7 @@ class XendDomainInfo: # may possibly be "tap". Just in case, verify # device class. devid = dev.split('/')[-1] - true_devclass = self.getBlockDeviceClass(devid) + true_devclass = self.getBlockDeviceClass(devid, devclass) log.debug("Removing %s", dev); self.destroyDevice(true_devclass, dev, False); except:
Hi Ryan,
I detected problems by testing your patch.
In the case of inactive domains:
xm block-detach failed.
# xm block-list vm2 Vdev BE handle state evt-ch ring-ref BE-path 769 -1 0 -1 -1 -1 ?? 833 -1 0 -1 -1 -1 ?? # xm block-detach vm2 833 Error: (22, 'Invalid argument') Usage: xm block-detach <Domain> <DevId> [-f|--force]
Destroy a domain's virtual block device
In the case of active domains:
xm block-deatch succeeded. But I saw the following message in xend.log.
# xm block-list vm2 Vdev BE handle state evt-ch ring-ref BE-path 769 0 0 4 10 8 /local/domain/0/backend/vbd/3/769 833 0 0 4 11 9 /local/domain/0/backend/vbd/3/833 # xm block-detach vm2 833 # xm block-list vm2 Vdev BE handle state evt-ch ring-ref BE-path 769 0 0 4 10 8 /local/domain/0/backend/vbd/3/769
[2009-06-24 12:49:00 4433] DEBUG (XendDomainInfo:1268) error reading backend for device (833):
To solve all problems, I will send a patch instead of your patch.
Best regards,
Kan
Quoted 72 lines · Ryan O'Connor
blktap2 devices attach as a regular 'vbd' rather than a 'tap' device. Accordingly, Xend should use 'vbd' as the device class of blktap2 devices. This
patch determines the appropriate device class by reading the 'type' field of the
backend's xenstore entry.Signed-off-by Ryan O'Connor <[email protected]>diff -r
3c7536d6b583-r3f100fc620fdtools/python/xen/xend/XendDomainInfo.pytools/python/xen/xend/XendDomainInfo.py +4
-7@@ -1244,13 +1244,33 @@ class XendDomainInfo: dev_num += 1 return sxprs - def getBlockDeviceClass(self, devid): - # To get a device number from the devid, - # we temporarily use the device controller of VBD. - dev = self.getDeviceController('vbd').convertToDeviceNumber(devid) - dev_info = self._getDeviceInfo_vbd(dev) - if dev_info: - return dev_info[0] + def getBlockDeviceClass(self, devid, deviceClass=False): + backendType = 'vbd' + + # For backwards compatability, we may have to get deviceClassourselves
tools/python/xen/xend/XendDomainInfo.py +10
-0+ if not deviceClass: + t = xstransact("%s/device" % self.dompath) + for devclass in XendDevices.valid_devices(): + if devid in t.list(devclass): + deviceClass = devclass + break + t.abort() + + try: + # Note: deviceClass may be incorrect, so we cannot trustreadBackend
tools/python/xen/xend/XendDomainInfo.py +3
-0+ # or readFrontend from the Device Controller to succeed + backendPath = xstransact.Read("%s/device/%s/%s" + % (self.dompath, deviceClass,devid),
tools/python/xen/xend/XendDomainInfo.py +5
-0+ "backend") + backendType = xstransact.Read(backendPath, "type") + except Exception, ex: + # we can probably just assume the block device is a VBD + log.debug("error reading backend for device (%s): %s", devid,str(ex))
tools/python/xen/xend/XendDomainInfo.py +6
-1+ + if backendType == 'tap': + return 'tap' + else: + return 'vbd' def _getDeviceInfo_vif(self, mac): for dev_type, dev_info in self.info.all_devices_sxpr():@@ -2217,7 +2237,7 @@ class XendDomainInfo: # may possibly be "tap". Just in case, verify # device class. devid = dev.split('/')[-1] - true_devclass = self.getBlockDeviceClass(devid) + true_devclass = self.getBlockDeviceClass(devid , devclass) log.debug("Removing %s", dev); self.destroyDevice(true_devclass, dev, False);except:
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel