ia64/xen-unstable

changeset 4679:10ef5cb210f7

bitkeeper revision 1.1327.2.15 (4270e4efrExxOueWy0PzsA_9yhB0tA)

Move blkif utility functions into xen.util.
Importing xen.xend.server.blkif from xm create caused
errors.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 28 13:28:15 2005 +0000 (2005-04-28)
parents ed1b8fd45247
children f85eb51dc313
files .rootkeys tools/python/xen/util/blkif.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/blkif.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/.rootkeys	Thu Apr 28 13:02:36 2005 +0000
     1.2 +++ b/.rootkeys	Thu Apr 28 13:28:15 2005 +0000
     1.3 @@ -885,6 +885,7 @@ 4107986e6qN1IdvIDdId0AYFmDMkiQ tools/pyt
     1.4  40fcefb4rnaZNjqsBu7A5V2rlLyqRw tools/python/xen/sv/util.py
     1.5  40d8915cyoVA0hJxiBFNymL7YvDaRg tools/python/xen/util/Brctl.py
     1.6  40dfd40aGqGkiopOOgJxSF4iCbHM0Q tools/python/xen/util/__init__.py
     1.7 +4270e4efFg3wHCCxXpA0h6yoMTkeSQ tools/python/xen/util/blkif.py
     1.8  4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/python/xen/util/console_client.py
     1.9  40c9c468IienauFHQ_xJIcqnPJ8giQ tools/python/xen/util/ip.py
    1.10  41dde8b0yuJX-S79w4xJKxBQ-Mhp1A tools/python/xen/util/memmap.py
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/python/xen/util/blkif.py	Thu Apr 28 13:28:15 2005 +0000
     2.3 @@ -0,0 +1,84 @@
     2.4 +import os
     2.5 +import re
     2.6 +import string
     2.7 +
     2.8 +from xen.util.ip import _readline, _readlines
     2.9 +
    2.10 +def expand_dev_name(name):
    2.11 +    if not name:
    2.12 +        return name
    2.13 +    if re.match( '^/dev/', name ):
    2.14 +        return name
    2.15 +    else:
    2.16 +        return '/dev/' + name
    2.17 +
    2.18 +def blkdev_name_to_number(name):
    2.19 +    """Take the given textual block-device name (e.g., '/dev/sda1',
    2.20 +    'hda') and return the device number used by the OS. """
    2.21 +
    2.22 +    n = expand_dev_name(name)
    2.23 +
    2.24 +    try:
    2.25 +        return os.stat(n).st_rdev
    2.26 +    except Exception, ex:
    2.27 +        log.debug("exception looking up device number for %s: %s", name, ex)
    2.28 +        pass
    2.29 +
    2.30 +    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
    2.31 +        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
    2.32 +
    2.33 +    if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
    2.34 +        ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
    2.35 +        major = ide_majors[(ord(n[7:8]) - ord('a')) / 2]
    2.36 +        minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
    2.37 +        return major * 256 + minor
    2.38 +
    2.39 +    # see if this is a hex device number
    2.40 +    if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
    2.41 +        return string.atoi(name,16)
    2.42 +        
    2.43 +    return None
    2.44 +
    2.45 +def blkdev_segment(name):
    2.46 +    """Take the given block-device name (e.g. '/dev/sda1', 'hda')
    2.47 +    and return a dictionary { device, start_sector,
    2.48 +    nr_sectors, type }
    2.49 +        device:       Device number of the given partition
    2.50 +        start_sector: Index of first sector of the partition
    2.51 +        nr_sectors:   Number of sectors comprising this partition
    2.52 +        type:         'Disk' or identifying name for partition type
    2.53 +    """
    2.54 +    val = None
    2.55 +    n = blkdev_name_to_number(name)
    2.56 +    if n:
    2.57 +        val = { 'device'       : n,
    2.58 +                'start_sector' : long(0),
    2.59 +                'nr_sectors'   : long(1L<<63),
    2.60 +                'type'         : 'Disk' }
    2.61 +    return val
    2.62 +
    2.63 +def blkdev_uname_to_file(uname):
    2.64 +    """Take a blkdev uname and return the corresponding filename."""
    2.65 +    fn = None
    2.66 +    if uname.find(":") != -1:
    2.67 +        (typ, fn) = uname.split(":")
    2.68 +        if typ == "phy" and not fn.startswith("/dev/"):
    2.69 +            fn = "/dev/%s" %(fn,)
    2.70 +    return fn
    2.71 +
    2.72 +def mount_mode(name):
    2.73 +    mode = None
    2.74 +    name = expand_dev_name(name)
    2.75 +    lines = _readlines(os.popen('mount 2>/dev/null'))
    2.76 +    exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
    2.77 +    for line in lines:
    2.78 +        pm = exp.match(line)
    2.79 +        if not pm: continue
    2.80 +        mode = pm.group('mode')
    2.81 +        break
    2.82 +    if mode == 'w':
    2.83 +        return mode
    2.84 +    if mode == 'o':
    2.85 +        mode = 'r'
    2.86 +    return mode
    2.87 +    
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Apr 28 13:02:36 2005 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Apr 28 13:28:15 2005 +0000
     3.3 @@ -16,7 +16,7 @@ import xen.lowlevel.xc; xc = xen.lowleve
     3.4  import xen.util.ip
     3.5  from xen.util.ip import _readline, _readlines
     3.6  from xen.xend.server import channel, controller
     3.7 -from xen.xend.server.blkif import blkdev_uname_to_file
     3.8 +from xen.util.blkif import blkdev_uname_to_file
     3.9  
    3.10  from server.channel import channelFactory
    3.11  import server.SrvDaemon; xend = server.SrvDaemon.instance()
     4.1 --- a/tools/python/xen/xend/server/blkif.py	Thu Apr 28 13:02:36 2005 +0000
     4.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Apr 28 13:28:15 2005 +0000
     4.3 @@ -1,11 +1,9 @@
     4.4  # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     4.5  """Support for virtual block devices.
     4.6  """
     4.7 -
     4.8 -import os
     4.9 -import re
    4.10  import string
    4.11  
    4.12 +from xen.util import blkif
    4.13  from xen.xend.XendError import XendError, VmError
    4.14  from xen.xend import XendRoot
    4.15  from xen.xend.XendLogging import log
    4.16 @@ -16,86 +14,6 @@ import channel
    4.17  from controller import CtrlMsgRcvr, Dev, DevController
    4.18  from messages import *
    4.19  
    4.20 -from xen.util.ip import _readline, _readlines
    4.21 -
    4.22 -def expand_dev_name(name):
    4.23 -    if not name:
    4.24 -        return name
    4.25 -    if re.match( '^/dev/', name ):
    4.26 -        return name
    4.27 -    else:
    4.28 -        return '/dev/' + name
    4.29 -
    4.30 -def blkdev_name_to_number(name):
    4.31 -    """Take the given textual block-device name (e.g., '/dev/sda1',
    4.32 -    'hda') and return the device number used by the OS. """
    4.33 -
    4.34 -    n = expand_dev_name(name)
    4.35 -
    4.36 -    try:
    4.37 -        return os.stat(n).st_rdev
    4.38 -    except Exception, ex:
    4.39 -        log.debug("exception looking up device number for %s: %s", name, ex)
    4.40 -        pass
    4.41 -
    4.42 -    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
    4.43 -        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
    4.44 -
    4.45 -    if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
    4.46 -        ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
    4.47 -        major = ide_majors[(ord(n[7:8]) - ord('a')) / 2]
    4.48 -        minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
    4.49 -        return major * 256 + minor
    4.50 -
    4.51 -    # see if this is a hex device number
    4.52 -    if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
    4.53 -        return string.atoi(name,16)
    4.54 -        
    4.55 -    return None
    4.56 -
    4.57 -def blkdev_segment(name):
    4.58 -    """Take the given block-device name (e.g. '/dev/sda1', 'hda')
    4.59 -    and return a dictionary { device, start_sector,
    4.60 -    nr_sectors, type }
    4.61 -        device:       Device number of the given partition
    4.62 -        start_sector: Index of first sector of the partition
    4.63 -        nr_sectors:   Number of sectors comprising this partition
    4.64 -        type:         'Disk' or identifying name for partition type
    4.65 -    """
    4.66 -    val = None
    4.67 -    n = blkdev_name_to_number(name)
    4.68 -    if n:
    4.69 -        val = { 'device'       : n,
    4.70 -                'start_sector' : long(0),
    4.71 -                'nr_sectors'   : long(1L<<63),
    4.72 -                'type'         : 'Disk' }
    4.73 -    return val
    4.74 -
    4.75 -def blkdev_uname_to_file(uname):
    4.76 -    """Take a blkdev uname and return the corresponding filename."""
    4.77 -    fn = None
    4.78 -    if uname.find(":") != -1:
    4.79 -        (typ, fn) = uname.split(":")
    4.80 -        if typ == "phy" and not fn.startswith("/dev/"):
    4.81 -            fn = "/dev/%s" %(fn,)
    4.82 -    return fn
    4.83 -
    4.84 -def mount_mode(name):
    4.85 -    mode = None
    4.86 -    name = expand_dev_name(name)
    4.87 -    lines = _readlines(os.popen('mount 2>/dev/null'))
    4.88 -    exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
    4.89 -    for line in lines:
    4.90 -        pm = exp.match(line)
    4.91 -        if not pm: continue
    4.92 -        mode = pm.group('mode')
    4.93 -        break
    4.94 -    if mode == 'w':
    4.95 -        return mode
    4.96 -    if mode == 'o':
    4.97 -        mode = 'r'
    4.98 -    return mode
    4.99 -    
   4.100  class BlkifBackend:
   4.101      """ Handler for the 'back-end' channel to a block device driver domain
   4.102      on behalf of a front-end domain.
   4.103 @@ -280,7 +198,7 @@ class BlkDev(Dev):
   4.104              raise VmError('vbd: Missing dev')
   4.105          self.mode = sxp.child_value(config, 'mode', 'r')
   4.106          
   4.107 -        self.vdev = blkdev_name_to_number(self.dev)
   4.108 +        self.vdev = blkif.blkdev_name_to_number(self.dev)
   4.109          if not self.vdev:
   4.110              raise VmError('vbd: Device not found: %s' % self.dev)
   4.111          
   4.112 @@ -333,7 +251,7 @@ class BlkDev(Dev):
   4.113                  raise VmError("vbd: Segment %s is in read-only use" %
   4.114                                self.uname)
   4.115              
   4.116 -        segment = blkdev_segment(node)
   4.117 +        segment = blkif.blkdev_segment(node)
   4.118          if not segment:
   4.119              raise VmError("vbd: Segment not found: uname=%s" % self.uname)
   4.120          self.node = node
   4.121 @@ -342,14 +260,14 @@ class BlkDev(Dev):
   4.122          self.nr_sectors = segment['nr_sectors']
   4.123  
   4.124      def check_mounted(self, name):
   4.125 -        mode = mount_mode(name)
   4.126 +        mode = blkif.mount_mode(name)
   4.127          xd = XendRoot.get_component('xen.xend.XendDomain')
   4.128          for vm in xd.domains():
   4.129              ctrl = vm.getDeviceController(self.getType(), error=False)
   4.130              if (not ctrl): continue
   4.131              for dev in ctrl.getDevices():
   4.132                  if dev is self: continue
   4.133 -                if dev.type == 'phy' and name == expand_dev_name(dev.params):
   4.134 +                if dev.type == 'phy' and name == blkif.expand_dev_name(dev.params):
   4.135                      mode = dev.mode
   4.136                      if 'w' in mode:
   4.137                          return 'w'
     5.1 --- a/tools/python/xen/xm/create.py	Thu Apr 28 13:02:36 2005 +0000
     5.2 +++ b/tools/python/xen/xm/create.py	Thu Apr 28 13:28:15 2005 +0000
     5.3 @@ -11,7 +11,7 @@ from xen.xend import sxp
     5.4  from xen.xend import PrettyPrint
     5.5  from xen.xend.XendClient import server, XendError
     5.6  from xen.xend.XendBootloader import bootloader
     5.7 -from xen.xend.server import blkif
     5.8 +from xen.util import blkif
     5.9  
    5.10  from xen.util import console_client
    5.11