Skip to contentSkip to conversation

Make device detach wait for detach to complete

PATCH New [email protected] 1 participant 1 message Jun 8, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make device detach wait for detach to complete

# HG changeset patch
# User [email protected]
# Date 1181305288 25200
# Node ID b6e22518c35a85e708a62ac526daeb18d16f28a2 # Parent 286d8ec9ccf4082b8db0a17a8ab74ad32a2bf218 Make device detach wait for detach to complete.

*-detach will wait till device is detached or time'ed out. XendConfig will be updated, if detached.

tools/python/xen/xend/XendConfig.py +15 -0
@@ -1274,6 +1274,21 @@ class XendConfig(dict):
 
         return False
 
+    def device_remove(self, dev_uuid):
+        """Remove an existing device referred by dev_uuid.
+        """
+
+        if dev_uuid in self['devices']:
+            dev_config = self['devices'].get(dev_uuid)
+            dev_type = dev_config[0]
+
+            del self['devices'][dev_uuid]
+            # Remove dev references for certain device types (see device_add)
+            if dev_type in ('vif', 'vbd', 'vtpm'):
+                param = '%s_refs' % dev_type
+                if param in self:
+                    if dev_uuid in self[param]:
+                        self[param].remove(dev_uuid)
 
     def device_sxpr(self, dev_uuid = None, dev_type = None, dev_info = None):
         """Get Device SXPR by either giving the device UUID or (type, config).
tools/python/xen/xend/XendDomainInfo.py +18 -2
@@ -569,8 +569,25 @@ class XendDomainInfo:
         if not found:
             log.debug("Could not find the device %s", devid)
             return None
+
         log.debug("devid = %s", devid)
-        return self.getDeviceController(deviceClass).destroyDevice(devid, force)
+
+        dev_control = self.getDeviceController(deviceClass)
+        dev_uuid = dev_control.readBackend(devid, 'uuid')
+
+        ret = None
+
+        try:
+            ret = dev_control.destroyDevice(devid, force)
+        except EnvironmentError:
+            # We failed to detach the device
+            raise VmError("Failed to detach device %d" % devid)
+
+        # update XendConfig
+        if dev_uuid:
+            self.info.device_remove(dev_uuid)
+
+        return ret
 
     def getDeviceSxprs(self, deviceClass):
         if self._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
@@ -583,7 +600,6 @@ class XendDomainInfo:
                     sxprs.append([dev_num, dev_info])
                     dev_num += 1
             return sxprs
-
 
     def setMemoryTarget(self, target):
         """Set the memory target of this domain.
tools/python/xen/xend/server/DevController.py +43 -3

77 lines not on this page · raw message