ia64/xen-unstable

changeset 1738:5e62083d519d

bitkeeper revision 1.1062.1.5 (40f072a1UFyXtMJ6B61Hidr8z_FNGw)

Fix block device name parsing to enable use of LVM/loopback devices.
Also enable naming of devices by major minor e.g. 0x0306
author iap10@labyrinth.cl.cam.ac.uk
date Sat Jul 10 22:50:09 2004 +0000 (2004-07-10)
parents d10bc5ceda22
children a503a822a023
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sat Jul 10 22:46:05 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sat Jul 10 22:50:09 2004 +0000
     1.3 @@ -72,12 +72,12 @@ def blkdev_name_to_number(name):
     1.4      """Take the given textual block-device name (e.g., '/dev/sda1',
     1.5      'hda') and return the device number used by the OS. """
     1.6  
     1.7 -    if not re.match( '/dev/', name ):
     1.8 +    if not re.match( '^/dev/', name ):
     1.9          name = '/dev/' + name
    1.10          
    1.11      return os.stat(name).st_rdev
    1.12  
    1.13 -def lookup_raw_partn(partition):
    1.14 +def lookup_raw_partn(name):
    1.15      """Take the given block-device name (e.g., '/dev/sda1', 'hda')
    1.16      and return a dictionary { device, start_sector,
    1.17      nr_sectors, type }
    1.18 @@ -87,40 +87,26 @@ def lookup_raw_partn(partition):
    1.19          type:         'Disk' or identifying name for partition type
    1.20      """
    1.21  
    1.22 -    if not re.match( '/dev/', partition ):
    1.23 -        partition = '/dev/' + partition
    1.24 -        
    1.25 -    """Try and match non-standard scsi raid arraysa
    1.26 -    """
    1.27 -    if re.match( '/dev/cciss/c[0-9]+d[0-9]+p[0-9]+', partition ):
    1.28 -        drive = re.split( 'p[0-9]+', partition )[0]
    1.29 -    else:
    1.30 -        drive = re.split( '[0-9]', partition )[0]
    1.31 +    p = name
    1.32  
    1.33 -    if drive == partition:
    1.34 -        fd = os.popen( '/sbin/sfdisk -s ' + drive + ' 2>/dev/null' )
    1.35 -        line = _readline(fd)
    1.36 -        if line:
    1.37 -            return [ { 'device' : blkdev_name_to_number(drive),
    1.38 -                       'start_sector' : long(0),
    1.39 -                       'nr_sectors' : long(line) * 2,
    1.40 -                       'type' : 'Disk' } ]
    1.41 -        return None
    1.42 -
    1.43 -    # determine position on disk
    1.44 -    fd = os.popen( '/sbin/sfdisk -d ' + drive + ' 2>/dev/null' )
    1.45 -
    1.46 -    #['/dev/sda3 : start= 16948575, size=16836120, Id=83, bootable\012']
    1.47 -    lines = _readlines(fd)
    1.48 -    for line in lines:
    1.49 -        m = re.search( '^' + partition + '\s*: start=\s*([0-9]+), ' +
    1.50 -                       'size=\s*([0-9]+), Id=\s*(\S+).*$', line)
    1.51 -        if m:
    1.52 -            return [ { 'device' : blkdev_name_to_number(drive),
    1.53 -                       'start_sector' : long(m.group(1)),
    1.54 -                       'nr_sectors' : long(m.group(2)),
    1.55 -                       'type' : m.group(3) } ]
    1.56 -    
    1.57 +    if not re.match( '^/dev/', name ):
    1.58 +        p = '/dev/' + name
    1.59 +	        
    1.60 +    fd = os.popen( '/sbin/sfdisk -s ' + p + ' 2>/dev/null' )
    1.61 +    line = _readline(fd)
    1.62 +    if line:
    1.63 +	return [ { 'device' : blkdev_name_to_number(p),
    1.64 +		   'start_sector' : long(0),
    1.65 +		   'nr_sectors' : long(line) * 2,
    1.66 +		   'type' : 'Disk' } ]
    1.67 +    else:
    1.68 +	# see if this is a hex device number
    1.69 +	if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
    1.70 +	    return [ { 'device' : string.atoi(name,16),
    1.71 +		   'start_sector' : long(0),
    1.72 +		   'nr_sectors' : long(1L<<63),
    1.73 +		   'type' : 'Disk' } ]
    1.74 +	
    1.75      return None
    1.76  
    1.77  def lookup_disk_uname(uname):
    1.78 @@ -143,7 +129,7 @@ def make_disk(dom, uname, dev, mode, rec
    1.79      """
    1.80      segments = lookup_disk_uname(uname)
    1.81      if not segments:
    1.82 -        raise VmError("vbd: Segments not found: uname=%s" % uname)
    1.83 +        raise VmError("vbd: Segments not foundXXXXXX: uname=%s" % uname)
    1.84      if len(segments) > 1:
    1.85          raise VmError("vbd: Multi-segment vdisk: uname=%s" % uname)
    1.86      segment = segments[0]