ia64/xen-unstable

changeset 11160:ff124973a28a

Implement xm block-configure for CD-ROMs.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Wed Aug 16 12:59:30 2006 +0100 (2006-08-16)
parents 716ef8e8bddc
children 4704cd92242e
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/XMLRPCServer.py tools/python/xen/xend/server/blkif.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Aug 16 11:58:48 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Aug 16 12:59:30 2006 +0100
     1.3 @@ -1527,13 +1527,12 @@ class XendDomainInfo:
     1.4          return self.getDeviceController(dev_type).sxpr(devid)
     1.5  
     1.6  
     1.7 -    def device_configure(self, dev_config, devid):
     1.8 +    def device_configure(self, dev_config):
     1.9          """Configure an existing device.
    1.10          @param dev_config: device configuration
    1.11 -        @param devid:      device id
    1.12          """
    1.13          deviceClass = sxp.name(dev_config)
    1.14 -        self.reconfigureDevice(deviceClass, devid, dev_config)
    1.15 +        self.reconfigureDevice(deviceClass, None, dev_config)
    1.16  
    1.17  
    1.18      def pause(self):
     2.1 --- a/tools/python/xen/xend/server/DevController.py	Wed Aug 16 11:58:48 2006 +0100
     2.2 +++ b/tools/python/xen/xend/server/DevController.py	Wed Aug 16 12:59:30 2006 +0100
     2.3 @@ -206,15 +206,9 @@ class DevController:
     2.4          """
     2.5  
     2.6          devid = int(devid)
     2.7 -        
     2.8 -        frontpath = self.frontendPath(devid)
     2.9 -        backpath = xstransact.Read(frontpath, "backend")
    2.10  
    2.11 -        if backpath:
    2.12 -            xstransact.Write(backpath, 'state', str(xenbusState['Closing']))
    2.13 -        else:
    2.14 -            raise VmError("Device %s not connected" % devid)
    2.15 -           
    2.16 +        self.writeBackend(devid, 'state', str(xenbusState['Closing']))
    2.17 +
    2.18  
    2.19      def configurations(self):
    2.20          return map(self.configuration, self.deviceIDs())
    2.21 @@ -355,6 +349,16 @@ class DevController:
    2.22              return map(int, xstransact.List(fe))
    2.23  
    2.24  
    2.25 +    def writeBackend(self, devid, *args):
    2.26 +        frontpath = self.frontendPath(devid)
    2.27 +        backpath = xstransact.Read(frontpath, "backend")
    2.28 +
    2.29 +        if backpath:
    2.30 +            xstransact.Write(backpath, *args)
    2.31 +        else:
    2.32 +            raise VmError("Device %s not connected" % devid)
    2.33 +
    2.34 +
    2.35  ## private:
    2.36  
    2.37      def addStoreEntries(self, config, devid, backDetails, frontDetails):
     3.1 --- a/tools/python/xen/xend/server/XMLRPCServer.py	Wed Aug 16 11:58:48 2006 +0100
     3.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Wed Aug 16 12:59:30 2006 +0100
     3.3 @@ -24,6 +24,7 @@ from xen.util.xmlrpclib2 import UnixXMLR
     3.4  
     3.5  from xen.xend.XendClient import XML_RPC_SOCKET, ERROR_INVALID_DOMAIN
     3.6  from xen.xend.XendError import *
     3.7 +from xen.xend.XendLogging import log
     3.8  from types import ListType
     3.9  
    3.10  def lookup(domid):
    3.11 @@ -74,7 +75,8 @@ def get_log():
    3.12      finally:
    3.13          f.close()
    3.14  
    3.15 -methods = ['device_create', 'destroyDevice', 'getDeviceSxprs',
    3.16 +methods = ['device_create', 'device_configure', 'destroyDevice',
    3.17 +           'getDeviceSxprs',
    3.18             'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
    3.19             'send_sysrq', 'getVCPUInfo', 'waitForDevices']
    3.20  
     4.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Aug 16 11:58:48 2006 +0100
     4.2 +++ b/tools/python/xen/xend/server/blkif.py	Wed Aug 16 12:59:30 2006 +0100
     4.3 @@ -13,7 +13,7 @@
     4.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     4.5  #============================================================================
     4.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
     4.7 -# Copyright (C) 2005 XenSource Ltd
     4.8 +# Copyright (C) 2005, 2006 XenSource Inc.
     4.9  #============================================================================
    4.10  
    4.11  
    4.12 @@ -76,6 +76,23 @@ class BlkifController(DevController):
    4.13          return (devid, back, front)
    4.14  
    4.15  
    4.16 +    def reconfigureDevice(self, _, config):
    4.17 +        """@see DevController.reconfigureDevice"""
    4.18 +        (devid, new_back, new_front) = self.getDeviceDetails(config)
    4.19 +
    4.20 +        (dev, mode) = self.readBackend(devid, 'dev', 'mode')
    4.21 +        dev_type = self.readFrontend(devid, 'device-type')
    4.22 +
    4.23 +        if (dev_type == 'cdrom' and new_front['device-type'] == 'cdrom' and
    4.24 +            dev == new_back['dev'] and mode == 'r'):
    4.25 +            self.writeBackend(devid,
    4.26 +                              'type', new_back['type'],
    4.27 +                              'params', new_back['params'])
    4.28 +        else:
    4.29 +            raise VmError('Refusing to reconfigure device %s:%d to %s' %
    4.30 +                          (self.deviceClass, devid, config))
    4.31 +
    4.32 +
    4.33      def configuration(self, devid):
    4.34          """@see DevController.configuration"""
    4.35  
     5.1 --- a/tools/python/xen/xm/main.py	Wed Aug 16 11:58:48 2006 +0100
     5.2 +++ b/tools/python/xen/xm/main.py	Wed Aug 16 12:59:30 2006 +0100
     5.3 @@ -113,6 +113,8 @@ block_detach_help = """block-detach  <Do
     5.4                                      or the device name as mounted in the guest"""
     5.5  
     5.6  block_list_help = "block-list <DomId> [--long]      List virtual block devices for a domain"
     5.7 +block_configure_help = """block-configure <DomId> <BackDev> <FrontDev> <Mode>
     5.8 +                   [BackDomId] Change block device configuration"""
     5.9  network_attach_help = """network-attach  <DomID> [script=<script>] [ip=<ip>] [mac=<mac>]
    5.10                             [bridge=<bridge>] [backend=<backDomID>]
    5.11                                      Create a new virtual network device """
    5.12 @@ -199,6 +201,7 @@ device_commands = [
    5.13      "block-attach",
    5.14      "block-detach",
    5.15      "block-list",
    5.16 +    "block-configure",
    5.17      "network-attach",
    5.18      "network-detach",
    5.19      "network-list",
    5.20 @@ -1055,9 +1058,8 @@ def xm_vtpm_list(args):
    5.21                     "%(be-path)-30s  "
    5.22                     % ni)
    5.23  
    5.24 -def xm_block_attach(args):
    5.25 -    arg_check(args, 'block-attach', 4, 5)
    5.26  
    5.27 +def parse_block_configuration(args):
    5.28      dom = args[0]
    5.29  
    5.30      if args[1].startswith('tap:'):
    5.31 @@ -1087,9 +1089,23 @@ def xm_block_attach(args):
    5.32          traceback.print_exc(limit=1)
    5.33          sys.exit(1)
    5.34  
    5.35 +    return (dom, vbd)
    5.36 +
    5.37 +
    5.38 +def xm_block_attach(args):
    5.39 +    arg_check(args, 'block-attach', 4, 5)
    5.40 +
    5.41 +    (dom, vbd) = parse_block_configuration(args)
    5.42      server.xend.domain.device_create(dom, vbd)
    5.43  
    5.44  
    5.45 +def xm_block_configure(args):
    5.46 +    arg_check(args, 'block-configure', 4, 5)
    5.47 +
    5.48 +    (dom, vbd) = parse_block_configuration(args)
    5.49 +    server.xend.domain.device_configure(dom, vbd)
    5.50 +
    5.51 +
    5.52  def xm_network_attach(args):
    5.53      arg_check(args, 'network-attach', 1, 10000)
    5.54  
    5.55 @@ -1201,6 +1217,7 @@ commands = {
    5.56      "block-attach": xm_block_attach,
    5.57      "block-detach": xm_block_detach,
    5.58      "block-list": xm_block_list,
    5.59 +    "block-configure": xm_block_configure,
    5.60      # network
    5.61      "network-attach": xm_network_attach,
    5.62      "network-detach": xm_network_detach,