[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Move blkif utility functions into xen.util.



ChangeSet 1.1327.2.15, 2005/04/28 14:28:15+01:00, mjw@xxxxxxxxxxxxxxxxxxx

        Move blkif utility functions into xen.util.
        Importing xen.xend.server.blkif from xm create caused
        errors.
        
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>



 util/blkif.py          |   84 ++++++++++++++++++++++++++++++++++++++++++++
 xend/XendDomainInfo.py |    2 -
 xend/server/blkif.py   |   92 ++-----------------------------------------------
 xm/create.py           |    2 -
 4 files changed, 91 insertions(+), 89 deletions(-)


diff -Nru a/tools/python/xen/util/blkif.py b/tools/python/xen/util/blkif.py
--- /dev/null   Wed Dec 31 16:00:00 196900
+++ b/tools/python/xen/util/blkif.py    2005-05-13 16:05:11 -04:00
@@ -0,0 +1,84 @@
+import os
+import re
+import string
+
+from xen.util.ip import _readline, _readlines
+
+def expand_dev_name(name):
+    if not name:
+        return name
+    if re.match( '^/dev/', name ):
+        return name
+    else:
+        return '/dev/' + name
+
+def blkdev_name_to_number(name):
+    """Take the given textual block-device name (e.g., '/dev/sda1',
+    'hda') and return the device number used by the OS. """
+
+    n = expand_dev_name(name)
+
+    try:
+        return os.stat(n).st_rdev
+    except Exception, ex:
+        log.debug("exception looking up device number for %s: %s", name, ex)
+        pass
+
+    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
+        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
+
+    if 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
+
+    # see if this is a hex device number
+    if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
+        return string.atoi(name,16)
+        
+    return None
+
+def blkdev_segment(name):
+    """Take the given block-device name (e.g. '/dev/sda1', 'hda')
+    and return a dictionary { device, start_sector,
+    nr_sectors, type }
+        device:       Device number of the given partition
+        start_sector: Index of first sector of the partition
+        nr_sectors:   Number of sectors comprising this partition
+        type:         'Disk' or identifying name for partition type
+    """
+    val = None
+    n = blkdev_name_to_number(name)
+    if n:
+        val = { 'device'       : n,
+                'start_sector' : long(0),
+                'nr_sectors'   : long(1L<<63),
+                'type'         : 'Disk' }
+    return val
+
+def blkdev_uname_to_file(uname):
+    """Take a blkdev uname and return the corresponding filename."""
+    fn = None
+    if uname.find(":") != -1:
+        (typ, fn) = uname.split(":")
+        if typ == "phy" and not fn.startswith("/dev/"):
+            fn = "/dev/%s" %(fn,)
+    return fn
+
+def mount_mode(name):
+    mode = None
+    name = expand_dev_name(name)
+    lines = _readlines(os.popen('mount 2>/dev/null'))
+    exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
+    for line in lines:
+        pm = exp.match(line)
+        if not pm: continue
+        mode = pm.group('mode')
+        break
+    if mode == 'w':
+        return mode
+    if mode == 'o':
+        mode = 'r'
+    return mode
+    
diff -Nru a/tools/python/xen/xend/XendDomainInfo.py 
b/tools/python/xen/xend/XendDomainInfo.py
--- a/tools/python/xen/xend/XendDomainInfo.py   2005-05-13 16:05:11 -04:00
+++ b/tools/python/xen/xend/XendDomainInfo.py   2005-05-13 16:05:11 -04:00
@@ -16,7 +16,7 @@
 import xen.util.ip
 from xen.util.ip import _readline, _readlines
 from xen.xend.server import channel, controller
-from xen.xend.server.blkif import blkdev_uname_to_file
+from xen.util.blkif import blkdev_uname_to_file
 
 from server.channel import channelFactory
 import server.SrvDaemon; xend = server.SrvDaemon.instance()
diff -Nru a/tools/python/xen/xend/server/blkif.py 
b/tools/python/xen/xend/server/blkif.py
--- a/tools/python/xen/xend/server/blkif.py     2005-05-13 16:05:11 -04:00
+++ b/tools/python/xen/xend/server/blkif.py     2005-05-13 16:05:11 -04:00
@@ -1,11 +1,9 @@
 # Copyright (C) 2004 Mike Wray <mike.wray@xxxxxx>
 """Support for virtual block devices.
 """
-
-import os
-import re
 import string
 
+from xen.util import blkif
 from xen.xend.XendError import XendError, VmError
 from xen.xend import XendRoot
 from xen.xend.XendLogging import log
@@ -16,86 +14,6 @@
 from controller import CtrlMsgRcvr, Dev, DevController
 from messages import *
 
-from xen.util.ip import _readline, _readlines
-
-def expand_dev_name(name):
-    if not name:
-        return name
-    if re.match( '^/dev/', name ):
-        return name
-    else:
-        return '/dev/' + name
-
-def blkdev_name_to_number(name):
-    """Take the given textual block-device name (e.g., '/dev/sda1',
-    'hda') and return the device number used by the OS. """
-
-    n = expand_dev_name(name)
-
-    try:
-        return os.stat(n).st_rdev
-    except Exception, ex:
-        log.debug("exception looking up device number for %s: %s", name, ex)
-        pass
-
-    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
-        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
-
-    if 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
-
-    # see if this is a hex device number
-    if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
-        return string.atoi(name,16)
-        
-    return None
-
-def blkdev_segment(name):
-    """Take the given block-device name (e.g. '/dev/sda1', 'hda')
-    and return a dictionary { device, start_sector,
-    nr_sectors, type }
-        device:       Device number of the given partition
-        start_sector: Index of first sector of the partition
-        nr_sectors:   Number of sectors comprising this partition
-        type:         'Disk' or identifying name for partition type
-    """
-    val = None
-    n = blkdev_name_to_number(name)
-    if n:
-        val = { 'device'       : n,
-                'start_sector' : long(0),
-                'nr_sectors'   : long(1L<<63),
-                'type'         : 'Disk' }
-    return val
-
-def blkdev_uname_to_file(uname):
-    """Take a blkdev uname and return the corresponding filename."""
-    fn = None
-    if uname.find(":") != -1:
-        (typ, fn) = uname.split(":")
-        if typ == "phy" and not fn.startswith("/dev/"):
-            fn = "/dev/%s" %(fn,)
-    return fn
-
-def mount_mode(name):
-    mode = None
-    name = expand_dev_name(name)
-    lines = _readlines(os.popen('mount 2>/dev/null'))
-    exp = re.compile('^' + name + ' .*[\(,]r(?P<mode>[ow])[,\)]')
-    for line in lines:
-        pm = exp.match(line)
-        if not pm: continue
-        mode = pm.group('mode')
-        break
-    if mode == 'w':
-        return mode
-    if mode == 'o':
-        mode = 'r'
-    return mode
-    
 class BlkifBackend:
     """ Handler for the 'back-end' channel to a block device driver domain
     on behalf of a front-end domain.
@@ -280,7 +198,7 @@
             raise VmError('vbd: Missing dev')
         self.mode = sxp.child_value(config, 'mode', 'r')
         
-        self.vdev = blkdev_name_to_number(self.dev)
+        self.vdev = blkif.blkdev_name_to_number(self.dev)
         if not self.vdev:
             raise VmError('vbd: Device not found: %s' % self.dev)
         
@@ -333,7 +251,7 @@
                 raise VmError("vbd: Segment %s is in read-only use" %
                               self.uname)
             
-        segment = blkdev_segment(node)
+        segment = blkif.blkdev_segment(node)
         if not segment:
             raise VmError("vbd: Segment not found: uname=%s" % self.uname)
         self.node = node
@@ -342,14 +260,14 @@
         self.nr_sectors = segment['nr_sectors']
 
     def check_mounted(self, name):
-        mode = mount_mode(name)
+        mode = blkif.mount_mode(name)
         xd = XendRoot.get_component('xen.xend.XendDomain')
         for vm in xd.domains():
             ctrl = vm.getDeviceController(self.getType(), error=False)
             if (not ctrl): continue
             for dev in ctrl.getDevices():
                 if dev is self: continue
-                if dev.type == 'phy' and name == expand_dev_name(dev.params):
+                if dev.type == 'phy' and name == 
blkif.expand_dev_name(dev.params):
                     mode = dev.mode
                     if 'w' in mode:
                         return 'w'
diff -Nru a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py     2005-05-13 16:05:11 -04:00
+++ b/tools/python/xen/xm/create.py     2005-05-13 16:05:11 -04:00
@@ -11,7 +11,7 @@
 from xen.xend import PrettyPrint
 from xen.xend.XendClient import server, XendError
 from xen.xend.XendBootloader import bootloader
-from xen.xend.server import blkif
+from xen.util import blkif
 
 from xen.util import console_client
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.