Skip to contentSkip to conversation

Fix xm block/network-detach command (take2)

PATCH In review Masaki Kanno 2 participants 6 messages Aug 9, 2007 – Aug 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix xm block/network-detach command (take2)

Hi,

I updated the patch for latest xen-unstable.

Please look at the following for the last patch.
http://lists.xensource.com/archives/html/xen-devel/2007-08/msg00043.html

Best regards,
Kan

tools/python/xen/xend/XendDomainInfo.py +79 -3
diff -r 7953164cebb6 tools/python/xen/xend/XendDomainInfo.py
@@ -558,9 +558,64 @@ class XendDomainInfo:
         for devclass in XendDevices.valid_devices():
             self.getDeviceController(devclass).waitForDevices()
 
-    def destroyDevice(self, deviceClass, devid, force = False):
-        log.debug("dev = %s", devid)
-        return self.getDeviceController(deviceClass).destroyDevice(devid, force)
+    def destroyDevice(self, deviceClass, devid, force = False, rm_cfg = False):
+        log.debug("XendDomainInfo.destroyDevice: deviceClass = %s, device = %s",
+                  deviceClass, devid)
+
+        if rm_cfg:
+            # Convert devid to device number.  A device number is
+            # needed to remove its configuration.
+            dev = self.getDeviceController(deviceClass).convertToDeviceNumber(devid)
+            
+            # Save current sxprs.  A device number and a backend
+            # path are needed to remove its configuration but sxprs
+            # do not have those after calling destroyDevice.
+            sxprs = self.getDeviceSxprs(deviceClass)
+
+        rc = None
+        if self.domid is not None:
+            rc = self.getDeviceController(deviceClass).destroyDevice(devid, force)
+            if not force and rm_cfg:
+                # The backend path, other than the device itself,
+                # has to be passed because its accompanied frontend
+                # path may be void until its removal is actually
+                # issued.  It is probable because destroyDevice is
+                # issued first.
+                for dev_num, dev_info in sxprs:
+                    dev_num = int(dev_num)
+                    if dev_num == dev:
+                        for x in dev_info:
+                            if x[0] == 'backend':
+                                backend = x[1]
+                                break
+                        break
+                self._waitForDevice_destroy(deviceClass, devid, backend)
+
+        if rm_cfg:
+            if deviceClass == 'vif':
+                if self.domid is not None:
+                    for dev_num, dev_info in sxprs:
+                        dev_num = int(dev_num)
+                        if dev_num == dev:
+                            for x in dev_info:
+                                if x[0] == 'mac':
+                                    mac = x[1]
+                                    break
+                            break
+                    dev_info = self.getDeviceInfo_vif(mac)
+                else:
+                    _, dev_info = sxprs[dev]
+            else:  # 'vbd' or 'tap'
+                dev_info = self.getDeviceInfo_vbd(dev)
+            if dev_info is None:
+                return rc
+
+            dev_uuid = sxp.child_value(dev_info, 'uuid')
+            del self.info['devices'][dev_uuid]
+            self.info['%s_refs' % deviceClass].remove(dev_uuid)
+            xen.xend.XendDomain.instance().managed_config_save(self)
+
+        return rc
 
     def getDeviceSxprs(self, deviceClass):
         if self._stateGet() in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
@@ -573,6 +628,23 @@ class XendDomainInfo:
                     sxprs.append([dev_num, dev_info])
                     dev_num += 1
             return sxprs
+
+    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):
+        for dev_type, dev_info in self.info.all_devices_sxpr():
+            if dev_type != 'vbd' and dev_type != 'tap':
+                continue
+            dev = sxp.child_value(dev_info, 'dev')
+            dev = dev.split(':')[0]
+            dev = self.getDeviceController(dev_type).convertToDeviceNumber(dev)
+            if devid == dev:
+                return dev_info
 
 
     def setMemoryTarget(self, target):
@@ -1321,6 +1393,10 @@ class XendDomainInfo:
         deviceClass, config = self.info['devices'].get(dev_uuid)
         self._waitForDevice(deviceClass, config['devid'])
 
+    def _waitForDevice_destroy(self, deviceClass, devid, backpath):
+        return self.getDeviceController(deviceClass).waitForDevice_destroy(
+            devid, backpath)
+
     def _reconfigureDevice(self, deviceClass, devid, devconfig):
         return self.getDeviceController(deviceClass).reconfigureDevice(
             devid, devconfig)
tools/python/xen/xend/server/DevController.py +59 -12

109 lines not on this page · raw message

tools/python/xen/xend/server/blkif.py +15 -3
diff -r 7953164cebb6 tools/python/xen/xend/server/blkif.py
@@ -165,11 +165,23 @@ class BlkifController(DevController):
         try:
             DevController.destroyDevice(self, devid, force)
         except ValueError:
-            devid_end = type(devid) is str and devid.split('/')[-1] or None
+            dev = self.convertToDeviceNumber(devid)
 
             for i in self.deviceIDs():
-                d = self.readBackend(i, 'dev')
-                if d == devid or (devid_end and d == devid_end):
+                if i == dev:
                     DevController.destroyDevice(self, i, force)
                     return
             raise VmError("Device %s not connected" % devid)
+
+    def convertToDeviceNumber(self, devid):
+        try:
+            dev = int(devid)
+        except ValueError:
+            if type(devid) is not str:
+                raise VmError("devid %s is wrong type" % str(devid))
+            try:
+                dev = devid.split('/')[-1]
+                dev = int(dev)
+            except ValueError:
+                dev = blkif.blkdev_name_to_number(dev)
+        return dev
tools/python/xen/xm/main.py +2 -1
diff -r 7953164cebb6 tools/python/xen/xm/main.py
@@ -2186,6 +2186,7 @@ def xm_network_attach(args):
 
 
 def detach(args, deviceClass):
+    rm_cfg = True
     dom = args[0]
     dev = args[1]
     try:
@@ -2196,7 +2197,7 @@ def detach(args, deviceClass):
     except IndexError:
         force = None
 
-    server.xend.domain.destroyDevice(dom, deviceClass, dev, force)
+    server.xend.domain.destroyDevice(dom, deviceClass, dev, force, rm_cfg)
 
 
 def xm_block_detach(args):

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

#1 lore raw
Quoted 7 lines · Masaki Kanno

Hi,

I updated the patch for latest xen-unstable.

Please look at the following for the last patch.
http://lists.xensource.com/archives/html/xen-devel/2007-08/msg00043.html

Hi Masaki,

I tested your patch briefly on c/s 15672.

klutina:/usr/lib64/python/xen/xend # xm li
Name ID Mem VCPUs State Time(s)
Domain-0 0 1343 2 r----- 5760.4
sles10 9 512 1 r----- 0.9

klutina:/usr/lib64/python/xen/xend # xm block-list 9 Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 9 522 /local/domain/0/backend/vbd/9/51712

klutina:/usr/lib64/python/xen/xend # xm block-attach 9 tap:aoi:/tests/images/sles10_graphics/disk1 xvdb r

klutina:/usr/lib64/python/xen/xend # xm block-list 9 Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 9 522 /local/domain/0/backend/vbd/9/51712 51728 0 0 3 10 676 /local/domain/0/backend/tap/9/51728

51728 0 0 3 10 676 /local/domain/0/backend/tap/9/51728

klutina:/usr/lib64/python/xen/xend # xm block-detach 9 xvdb
Error: 'tap_refs'
Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.

klutina:/usr/lib64/python/xen/xend # xm block-list 9 Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 9 522 /local/domain/0/backend/vbd/9/51712

The device was unplugged but its config not removed. From xend.log:

File "/usr/lib64/python2.4/xen/xend/XendDomainInfo.py", line 615, in destroyDevice
self.info['%s_refs' % deviceClass].remove(dev_uuid)
KeyError: 'tap_refs'

I think refs for the various disk types all fall under 'vbd_refs'.

Also, when trying to detach a disk that a pv domU has mounted, I get this error (after 100 second timeout):

klutina:/usr/lib64/python/xen/xend # xm block-list 10 Vdev BE handle state evt-ch ring-ref BE-path 51712 0 0 4 12 522 /local/domain/0/backend/vbd/10/51712 51728 0 0 4 13 523 /local/domain/0/backend/vbd/10/51728

klutina:/usr/lib64/python/xen/xend # xm block-detach 10 xvdb (...... wait 100 seconds .......)
Error: Device xvdb not connected
Usage: xm block-detach <Domain> <DevId> [-f|--force]

Destroy a domain's virtual block device.

The behavior is fine (i.e. the disk is still attached and remains in stored config) but the error message is misleading. xvbd is connected, its just the front-end won't let go AFAIK.

Regards,
Jim

#2 lore raw

Hi Jim,

Thanks for your tests.

Quoted 1 line

I tested your patch briefly on c/s 15672.

<snip>

Quoted 8 lines

The device was unplugged but its config not removed. From xend.log:

File "/usr/lib64/python2.4/xen/xend/XendDomainInfo.py", line 615, in destroyDevice
self.info['%s_refs' % deviceClass].remove(dev_uuid)
KeyError: 'tap_refs'

I think refs for the various disk types all fall under 'vbd_refs'.

I tested blktap with the same way as your operation. But I did not encounter the command error as follows.
But your thinking is right, so I wrote a small patch to remove the error message. Could you test the patch again?

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   747     2     r-----     89.9
vm1                                          1   256     1     -b----      0.7
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
# xm block-attach vm1 tap:aio:/xen/second.img xvdb r
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
51728    0    0     4      8      836   /local/domain/0/backend/tap/1/51728  
# xm block-detach vm1 xvdb
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
Quoted 2 lines

Also, when trying to detach a disk that a pv domU has mounted, I get this error (after 100 second timeout):

<snip>

Quoted 3 lines

The behavior is fine (i.e. the disk is still attached and remains in stored config) but the error message is misleading. xvbd is connected, its just the front-end won't let go AFAIK.

I'd like to improve the error message. Could you give me thinking time about 2 weeks?

Best regards,
Kan

tools/python/xen/xend/XendDomainInfo.py +3 -0
diff -r 95f90f24f3b1 tools/python/xen/xend/XendDomainInfo.py
@@ -607,6 +607,9 @@ class XendDomainInfo:
                     _, dev_info = sxprs[dev]
             else:  # 'vbd' or 'tap'
                 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
 

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

#3 lore raw

Hi Keir,

I send a patch. It resolves the problem that Jim found. Could you apply it?

Best regards,
Kan

Quoted 58 lines · Masaki Kanno

Hi Jim,

Thanks for your tests.

Quoted 1 line

I tested your patch briefly on c/s 15672.

<snip>

Quoted 8 lines

The device was unplugged but its config not removed. From xend.log:

File "/usr/lib64/python2.4/xen/xend/XendDomainInfo.py", line 615, in destroyDevice
self.info['%s_refs' % deviceClass].remove(dev_uuid)
KeyError: 'tap_refs'

I think refs for the various disk types all fall under 'vbd_refs'.

I tested blktap with the same way as your operation. But I did not encounter the command error as follows.
But your thinking is right, so I wrote a small patch to remove the error message. Could you test the patch again?

# xm list
Name                                        ID   Mem VCPUs      State   
Time(s)
Domain-0                                     0   747     2     r-----     
89.9
vm1                                          1   256     1     -b----      
0.7
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
# xm block-attach vm1 tap:aio:/xen/second.img xvdb r
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
51728    0    0     4      8      836   /local/domain/0/backend/tap/1/51728  
# xm block-detach vm1 xvdb
# xm block-list vm1
Vdev  BE handle state evt-ch ring-ref BE-path
769    0    0     4      6      8     /local/domain/0/backend/vbd/1/769  
Quoted 2 lines

Also, when trying to detach a disk that a pv domU has mounted, I get this error (after 100 second timeout):

<snip>

Quoted 3 lines

The behavior is fine (i.e. the disk is still attached and remains in stored config) but the error message is misleading. xvbd is connected, its just the front-end won't let go AFAIK.

I'd like to improve the error message. Could you give me thinking time about 2 weeks?

Best regards,
Kan

Quoted 5 lines

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

tools/python/xen/xend/XendDomainInfo.py +3 -0
diff -r cd511c380e03 tools/python/xen/xend/XendDomainInfo.py
@@ -607,6 +607,9 @@ class XendDomainInfo:
                     _, dev_info = sxprs[dev]
             else:  # 'vbd' or 'tap'
                 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
 

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

#4 lore raw
In reply to Jim Fehlig
Quoted 16 lines · Masaki Kanno

Hi Jim,

Thanks for your tests.

Quoted 2 lines

I tested your patch briefly on c/s 15672.

<snip>

Quoted 7 lines

The device was unplugged but its config not removed. From xend.log:

File "/usr/lib64/python2.4/xen/xend/XendDomainInfo.py", line 615, in destroyDevice
self.info['%s_refs' % deviceClass].remove(dev_uuid)
KeyError: 'tap_refs'

Quoted 8 lines
Quoted 2 lines

I think refs for the various disk types all fall under 'vbd_refs'.

I tested blktap with the same way as your operation. But I did not encounter the command error as follows.
But your thinking is right, so I wrote a small patch to remove the error message. Could you test the patch again?

Looks good with your additional patch. Thanks.

<snip>

Quoted 8 lines
Quoted 4 lines

The behavior is fine (i.e. the disk is still attached and remains in stored config) but the error message is misleading. xvbd is connected, its just the front-end won't let go AFAIK.

I'd like to improve the error message. Could you give me thinking time about 2 weeks?

Sure. I just noticed it while testing but spent no time investigating.

Regards,
Jim

#5 lore raw

Hi Jim,

Thanks for your review.

Best regards,
Kan

Quoted 48 lines · Jim Fehlig
Quoted 16 lines · Masaki Kanno

Hi Jim,

Thanks for your tests.

Quoted 2 lines

I tested your patch briefly on c/s 15672.

<snip>

Quoted 7 lines

The device was unplugged but its config not removed. From xend.log:

File "/usr/lib64/python2.4/xen/xend/XendDomainInfo.py", line 615, in destroyDevice
self.info['%s_refs' % deviceClass].remove(dev_uuid)
KeyError: 'tap_refs'

Quoted 8 lines
Quoted 2 lines

I think refs for the various disk types all fall under 'vbd_refs'.

I tested blktap with the same way as your operation. But I did not encounter the command error as follows.
But your thinking is right, so I wrote a small patch to remove the error message. Could you test the patch again?

Looks good with your additional patch. Thanks.

<snip>

Quoted 8 lines
Quoted 4 lines

The behavior is fine (i.e. the disk is still attached and remains in stored config) but the error message is misleading. xvbd is connected, its just the front-end won't let go AFAIK.

I'd like to improve the error message. Could you give me thinking time about 2 weeks?

Sure. I just noticed it while testing but spent no time investigating.

Regards,
Jim

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