ia64/xen-unstable

changeset 17917:0728459b3c8d

tools/python: blkdev_name_to_number fixes

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>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 27 16:09:58 2008 +0100 (2008-06-27)
parents 10e79ad54c91
children 2ac9155a85c1
files tools/python/xen/util/blkif.py tools/python/xen/xend/server/blkif.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/util/blkif.py	Fri Jun 27 16:08:56 2008 +0100
     1.2 +++ b/tools/python/xen/util/blkif.py	Fri Jun 27 16:09:58 2008 +0100
     1.3 @@ -16,6 +16,9 @@ def blkdev_name_to_number(name):
     1.4  
     1.5      n = expand_dev_name(name)
     1.6  
     1.7 +    devname = 'virtual-device'
     1.8 +    devnum = None
     1.9 +
    1.10      try:
    1.11          return os.stat(n).st_rdev
    1.12      except Exception, ex:
    1.13 @@ -25,28 +28,30 @@ def blkdev_name_to_number(name):
    1.14      if re.match( '/dev/sd[a-z]([1-9]|1[0-5])?$', n):
    1.15          major = scsi_major[(ord(n[7:8]) - ord('a')) / 16]
    1.16          minor = ((ord(n[7:8]) - ord('a')) % 16) * 16 + int(n[8:] or 0)
    1.17 -        return major * 256 + minor
    1.18 -    if re.match( '/dev/sd[a-i][a-z]([1-9]|1[0-5])?$', n):
    1.19 +        devnum = major * 256 + minor
    1.20 +    elif re.match( '/dev/sd[a-i][a-z]([1-9]|1[0-5])?$', n):
    1.21          major = scsi_major[((ord(n[7:8]) - ord('a') + 1) * 26 + (ord(n[8:9]) - ord('a'))) / 16 ]
    1.22          minor = (((ord(n[7:8]) - ord('a') + 1 ) * 26 + (ord(n[8:9]) - ord('a'))) % 16) * 16 + int(n[9:] or 0)
    1.23 -        return major * 256 + minor
    1.24 -
    1.25 -    if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
    1.26 +        devnum = major * 256 + minor
    1.27 +    elif re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
    1.28          ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
    1.29          major = ide_majors[(ord(n[7:8]) - ord('a')) / 2]
    1.30          minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
    1.31 -        return major * 256 + minor
    1.32 -
    1.33 -    if re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?', n):
    1.34 -        return 202 * 256 + 16 * (ord(n[8:9]) - ord('a')) + int(n[9:] or 0)
    1.35 +        devnum = major * 256 + minor
    1.36 +    elif re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?$', n):
    1.37 +        devnum = (202 << 8) + ((ord(n[8:9]) - ord('a')) << 4) + int(n[9:] or 0)
    1.38 +    elif re.match('/dev/xvd[q-z]([1-9]|1[0-5])?$', n):
    1.39 +        devname = 'virtual-device-ext'
    1.40 +        devnum = (1 << 28) + ((ord(n[8:9]) - ord('a')) << 8) + int(n[9:] or 0)
    1.41 +    elif re.match('/dev/xvd[a-i][a-z]([1-9]|1[0-5])?$', n):
    1.42 +        devname = 'virtual-device-ext'
    1.43 +        devnum = (1 << 28) + (((ord(n[8:9]) - ord('a') + 1) * 26 + (ord(n[9:10]) - ord('a'))) << 8) + int(n[10:] or 0)
    1.44 +    elif re.match( '^(0x)[0-9a-fA-F]+$', name ):
    1.45 +        devnum = string.atoi(name, 16)
    1.46 +    elif re.match('^[0-9]+$', name):
    1.47 +        devnum = string.atoi(name, 10)
    1.48  
    1.49 -    if re.match( '^(0x)[0-9a-fA-F]+$', name ):
    1.50 -        return string.atoi(name,16)
    1.51 -
    1.52 -    if re.match('^[0-9]+$', name):
    1.53 -        return string.atoi(name, 10)
    1.54 -
    1.55 -    return None
    1.56 +    return (devname, devnum)
    1.57  
    1.58  def blkdev_segment(name):
    1.59      """Take the given block-device name (e.g. '/dev/sda1', 'hda')
     2.1 --- a/tools/python/xen/xend/server/blkif.py	Fri Jun 27 16:08:56 2008 +0100
     2.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Jun 27 16:09:58 2008 +0100
     2.3 @@ -81,11 +81,11 @@ class BlkifController(DevController):
     2.4          if security.on() == xsconstants.XS_POLICY_ACM:
     2.5              self.do_access_control(config, uname)
     2.6  
     2.7 -        devid = blkif.blkdev_name_to_number(dev)
     2.8 +        (device_path, devid) = blkif.blkdev_name_to_number(dev)
     2.9          if devid is None:
    2.10              raise VmError('Unable to find number for device (%s)' % (dev))
    2.11  
    2.12 -        front = { 'virtual-device' : "%i" % devid,
    2.13 +        front = { device_path : "%i" % devid,
    2.14                    'device-type' : dev_type
    2.15                  }
    2.16  
    2.17 @@ -204,5 +204,5 @@ class BlkifController(DevController):
    2.18                  dev = devid.split('/')[-1]
    2.19                  dev = int(dev)
    2.20              except ValueError:
    2.21 -                dev = blkif.blkdev_name_to_number(dev)
    2.22 +                (device_path, dev) = blkif.blkdev_name_to_number(dev)
    2.23          return dev
     3.1 --- a/tools/python/xen/xm/main.py	Fri Jun 27 16:08:56 2008 +0100
     3.2 +++ b/tools/python/xen/xm/main.py	Fri Jun 27 16:09:58 2008 +0100
     3.3 @@ -2022,8 +2022,7 @@ def xm_block_list(args):
     3.4              map(server.xenapi.VBD.get_runtime_properties, vbd_refs)
     3.5          vbd_devs = \
     3.6              map(server.xenapi.VBD.get_device, vbd_refs)
     3.7 -        vbd_devids = \
     3.8 -            map(blkdev_name_to_number, vbd_devs)
     3.9 +        vbd_devids = [blkdev_name_to_number(x)[1] for x in vbd_devs]
    3.10          devs = map(lambda (devid, prop): [devid, map2sxp(prop)],
    3.11                     zip(vbd_devids, vbd_properties))
    3.12      else: