tools/python: blkdev_name_to_number fixes
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 27 Jun 2008 15:09:58 +0000 (16:09 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 27 Jun 2008 15:09:58 +0000 (16:09 +0100)
Rework blkdev_name_to_number to allow the tools to attach xvd disks
beyond xvdp.

 1.  Adds the handling for the /dev/xvd[q-z] and /dev/xvd[a-i][a-z]
     extended devices

 2.  Changes blkdev_name_to_number() to return a tuple of (xenbus,
     devnum), and then deals with the resulting fallout.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
tools/python/xen/util/blkif.py
tools/python/xen/xend/server/blkif.py
tools/python/xen/xm/main.py

index beac3dc634de2e6d297c51d30f576055eb36e683..82149bf9df23e5f9a3277a41b3b9421e81407758 100644 (file)
@@ -16,6 +16,9 @@ def blkdev_name_to_number(name):
 
     n = expand_dev_name(name)
 
+    devname = 'virtual-device'
+    devnum = None
+
     try:
         return os.stat(n).st_rdev
     except Exception, ex:
@@ -25,28 +28,30 @@ def blkdev_name_to_number(name):
     if re.match( '/dev/sd[a-z]([1-9]|1[0-5])?$', n):
         major = scsi_major[(ord(n[7:8]) - ord('a')) / 16]
         minor = ((ord(n[7:8]) - ord('a')) % 16) * 16 + int(n[8:] or 0)
-        return major * 256 + minor
-    if re.match( '/dev/sd[a-i][a-z]([1-9]|1[0-5])?$', n):
+        devnum = major * 256 + minor
+    elif re.match( '/dev/sd[a-i][a-z]([1-9]|1[0-5])?$', n):
         major = scsi_major[((ord(n[7:8]) - ord('a') + 1) * 26 + (ord(n[8:9]) - ord('a'))) / 16 ]
         minor = (((ord(n[7:8]) - ord('a') + 1 ) * 26 + (ord(n[8:9]) - ord('a'))) % 16) * 16 + int(n[9:] or 0)
-        return major * 256 + minor
-
-    if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
+        devnum = major * 256 + minor
+    elif re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
         ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
         major = ide_majors[(ord(n[7:8]) - ord('a')) / 2]
         minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
-        return major * 256 + minor
-
-    if re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?', n):
-        return 202 * 256 + 16 * (ord(n[8:9]) - ord('a')) + int(n[9:] or 0)
-
-    if re.match( '^(0x)[0-9a-fA-F]+$', name ):
-        return string.atoi(name,16)
-
-    if re.match('^[0-9]+$', name):
-        return string.atoi(name, 10)
+        devnum = major * 256 + minor
+    elif re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?$', n):
+        devnum = (202 << 8) + ((ord(n[8:9]) - ord('a')) << 4) + int(n[9:] or 0)
+    elif re.match('/dev/xvd[q-z]([1-9]|1[0-5])?$', n):
+        devname = 'virtual-device-ext'
+        devnum = (1 << 28) + ((ord(n[8:9]) - ord('a')) << 8) + int(n[9:] or 0)
+    elif re.match('/dev/xvd[a-i][a-z]([1-9]|1[0-5])?$', n):
+        devname = 'virtual-device-ext'
+        devnum = (1 << 28) + (((ord(n[8:9]) - ord('a') + 1) * 26 + (ord(n[9:10]) - ord('a'))) << 8) + int(n[10:] or 0)
+    elif re.match( '^(0x)[0-9a-fA-F]+$', name ):
+        devnum = string.atoi(name, 16)
+    elif re.match('^[0-9]+$', name):
+        devnum = string.atoi(name, 10)
 
-    return None
+    return (devname, devnum)
 
 def blkdev_segment(name):
     """Take the given block-device name (e.g. '/dev/sda1', 'hda')
index 5238099c22140b7deb6a8194be5342136b5f8e58..87f03d17796e83dc39a65aeb9b25135ec3eac4ed 100644 (file)
@@ -81,11 +81,11 @@ class BlkifController(DevController):
         if security.on() == xsconstants.XS_POLICY_ACM:
             self.do_access_control(config, uname)
 
-        devid = blkif.blkdev_name_to_number(dev)
+        (device_path, devid) = blkif.blkdev_name_to_number(dev)
         if devid is None:
             raise VmError('Unable to find number for device (%s)' % (dev))
 
-        front = { 'virtual-device' : "%i" % devid,
+        front = { device_path : "%i" % devid,
                   'device-type' : dev_type
                 }
 
@@ -204,5 +204,5 @@ class BlkifController(DevController):
                 dev = devid.split('/')[-1]
                 dev = int(dev)
             except ValueError:
-                dev = blkif.blkdev_name_to_number(dev)
+                (device_path, dev) = blkif.blkdev_name_to_number(dev)
         return dev
index 6384ad4322f9326672e12bc5447efa1c0c8c3306..a0c3657f7ac3beecc9142f669c1f6ef831e0d230 100644 (file)
@@ -2022,8 +2022,7 @@ def xm_block_list(args):
             map(server.xenapi.VBD.get_runtime_properties, vbd_refs)
         vbd_devs = \
             map(server.xenapi.VBD.get_device, vbd_refs)
-        vbd_devids = \
-            map(blkdev_name_to_number, vbd_devs)
+        vbd_devids = [blkdev_name_to_number(x)[1] for x in vbd_devs]
         devs = map(lambda (devid, prop): [devid, map2sxp(prop)],
                    zip(vbd_devids, vbd_properties))
     else: