mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
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>
This commit is contained in:
1 parent
0da4cefa9f
commit
83a12f2ba6
5 files changed
+92
-89
No files matched your search
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@ import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
|
||||
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()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
|
||||
"""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 @@ import channel
|
||||
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 @@ class BlkDev(Dev):
|
||||
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 @@ class BlkDev(Dev):
|
||||
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 @@ class BlkDev(Dev):
|
||||
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'
|
||||
|
||||
@@ -11,7 +11,7 @@ from xen.xend import sxp
|
||||
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
|
||||
|
||||
|
||||