Skip to contentSkip to conversation

Fix error message and wait time for xm block-detach command

PATCH New Masaki Kanno 1 participant 1 message Sep 4, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix error message and wait time for xm block-detach command

Hi,

I tested xm block-detach command with latest xen-unstable and changeset:15736 in the staging tree. Test cases are as follows. I found some problems in the following test case 1, 3 and 8.

+--+----------+----------+----------+----------+
|  |A         |B         |C         |D         |
|  +----------+----------+----------+----------+
|  |Domain    |Already   |Disk Type |Disk      |
|  |    Status| Attached?|          |  on Guest|
+--+----------+----------+----------+----------+
| 1|Active    |Yes       |VBD       |Mounted   |
+--+----------+----------+----------+----------+
| 2|Inactive  |No        |TAP       |Unmounted |
|  |(Managed) |          |          |          |
+--+----------+----------+----------+----------+

Test case 1:A1+B1+C1+D1

  # xm block-detach vm1 hda1
  << Wait 200 seconds >>
  Error: Device hda1 (tap) could not be disconnected. 
  Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.
#

** The keyword "(tap)" in the error message is misleading. ** The wait time is 200 seconds. It's long, isn't it?

Test case 2:A1+B1+C1+D2

  # xm block-detach vm1 hdb1
  #

** Good

Test case 3:A1+B1+C2+D1

  # xm block-detach vm2 hda1
  << Wait 200 seconds >>
  Error: Device hda1 (tap) could not be disconnected. 
  Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.

** The wait time is 200 seconds. It's long, isn't it?

Test case 4:A1+B1+C2+D2

  # xm block-detach vm2 hdb1
  #

** Good

Test case 5:A1+B2

  # xm block-detach vm2 hdb2
  Error: Device 834 not connected
  Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.

** Good

Test case 6:A2+B1+C1

  # xm block-detach vm1 hda1
  #

** Good

Test case 7:A2+B1+C2

  # xm block-detach vm2 hda1
  #

** Good

Test case 8:A2+B2

  # xm block-detach vm2 hdb2
  #

** Error message is not shown.

About the problem of test case 1 and 3:
- Wait time
There is a cause in xm. When xm requires a block device detaching to xend, xm requires the block device detaching two times.
At first, xm requires the block device detaching by device class 'vbd'.
Next, xm requires the block device detaching by device class 'tap'.
As the result, the wait time is 200 seconds because each of the block device detaching requests causes time-out.
- Misleading error message
Because the last request is by device class 'tap' to xend, the keyword "(tap)" is included in the error message of test case 1.

This patch fixes the number of times of the block device detaching request to one time. At first, xm makes inquiries about device class of a detaching target device to xend. Then xm requires the block device detaching by xend returned device class. The wait time becomes 100 seconds because the block device detaching request is one time. And the error message is also fixed.

About the problem of test case 8:
There is a cause in xend. In the test case, xend does not show error message.

This patch fixes to show the following error message in test case.

  # xm block-detach vm2 hdb2
  Error: Device hdb2 is not defined
  Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.

Best regards,
Kan

tools/python/xen/xend/XendDomainInfo.py +13 -5
diff -r e8b71d5e584d tools/python/xen/xend/XendDomainInfo.py
@@ -602,16 +602,16 @@ class XendDomainInfo:
                                     mac = x[1]
                                     break
                             break
-                    dev_info = self.getDeviceInfo_vif(mac)
+                    dev_info = self._getDeviceInfo_vif(mac)
                 else:
                     _, dev_info = sxprs[dev]
             else:  # 'vbd' or 'tap'
-                dev_info = self.getDeviceInfo_vbd(dev)
+                dev_info = self._getDeviceInfo_vbd(dev)
                 # To remove the UUID of the device from refs,
                 # deviceClass must be always 'vbd'.
                 deviceClass = 'vbd'
             if dev_info is None:
-                return rc
+                raise XendError("Device %s is not defined" % devid)
 
             dev_uuid = sxp.child_value(dev_info, 'uuid')
             del self.info['devices'][dev_uuid]
@@ -632,14 +632,22 @@ class XendDomainInfo:
                     dev_num += 1
             return sxprs
 
-    def getDeviceInfo_vif(self, mac):
+    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 _getDeviceInfo_vif(self, mac):
         for dev_type, dev_info in self.info.all_devices_sxpr():
             if dev_type != 'vif':
                 continue
             if mac == sxp.child_value(dev_info, 'mac'):
                 return dev_info
 
-    def getDeviceInfo_vbd(self, devid):
+    def _getDeviceInfo_vbd(self, devid):
         for dev_type, dev_info in self.info.all_devices_sxpr():
             if dev_type != 'vbd' and dev_type != 'tap':
                 continue
tools/python/xen/xend/server/XMLRPCServer.py +1 -1
diff -r e8b71d5e584d tools/python/xen/xend/server/XMLRPCServer.py
@@ -87,7 +87,7 @@ methods = ['device_create', 'device_conf
            'destroyDevice','getDeviceSxprs',
            'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
            'send_sysrq', 'getVCPUInfo', 'waitForDevices',
-           'getRestartCount']
+           'getRestartCount', 'getBlockDeviceClass']
 
 exclude = ['domain_create', 'domain_restore']
 
tools/python/xen/xm/main.py +6 -5
diff -r e8b71d5e584d tools/python/xen/xm/main.py
@@ -2217,12 +2217,13 @@ def xm_block_detach(args):
                               % (dev,dom))
     else:
         arg_check(args, 'block-detach', 2, 3)
-        try:
+        dom = args[0]
+        dev = args[1]
+        dc = server.xend.domain.getBlockDeviceClass(dom, dev)
+        if dc == "tap":
+            detach(args, 'tap')
+        else:
             detach(args, 'vbd')
-            return
-        except:
-            pass
-        detach(args, 'tap')
 
 def xm_network_detach(args):
     if serverType == SERVER_XEN_API:

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