ia64/xen-unstable

changeset 2229:decc8ed25d45

bitkeeper revision 1.1159.28.1 (411ce7c8olPyp1mOhZBrwe7zhBtEWg)

Add support for configuring the back-end domain for vbd or vif devices.
author mjw@wray-m-3.hpl.hp.com
date Fri Aug 13 16:09:44 2004 +0000 (2004-08-13)
parents 54c0a4a84934
children 0758c83632e1 c3e3a082384f
files docs/xen_config.html tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/docs/xen_config.html	Fri Aug 13 14:23:49 2004 +0000
     1.2 +++ b/docs/xen_config.html	Fri Aug 13 16:09:44 2004 +0000
     1.3 @@ -62,7 +62,7 @@ The top-level element, a virtual machine
     1.4      <li>memory: int, required. Domain memory in MB.
     1.5      <li>cpu: int, optional. Cpu to run on.
     1.6      <li>image: linux | netbsd | ..., required. Domain image (OS-specific element).
     1.7 -    <li>controller: any device controller type, optional, default none.
     1.8 +    <li>backend: any backend device type, optional, default none.
     1.9      <li>device: any device type, optional, repeats. Device.
    1.10      <li>restart: string, optional, default onreboot. Restart mode, one of
    1.11          <ul><li>onreboot: restart the domain when it exits with code reboot.
    1.12 @@ -99,7 +99,21 @@ block devices.
    1.13  
    1.14  <h2>(backend (netif)) element</h2>
    1.15  The vm is a net device backend.
    1.16 -The domain may not have virtual network interfaces (vifs) configured.
    1.17 +The vm may not have virtual network interfaces (vifs) configured.
    1.18 +
    1.19 +<h2>(backend (vbd) element</h2>
    1.20 +Defines the domain to use as the backend for virtual block devices.
    1.21 +The domain must exist.
    1.22 +<ul>
    1.23 +    <li>domain: string, required. Domain name or id.
    1.24 +</ul>
    1.25 +
    1.26 +<h2>(backend (vif) element</h2>
    1.27 +Defines the domain to use as the backend for virtual network interfaces.
    1.28 +The domain must exist.
    1.29 +<ul>
    1.30 +    <li>dom: string, required. Domain name or id.
    1.31 +</ul>
    1.32  
    1.33  <h2>(device (vif)) element</h2>
    1.34  Defines a virtual network interface.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Aug 13 14:23:49 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Aug 13 16:09:44 2004 +0000
     2.3 @@ -69,6 +69,12 @@ STATE_RESTART_BOOTING = 'booting'
     2.4  STATE_VM_OK         = "ok"
     2.5  STATE_VM_TERMINATED = "terminated"
     2.6  
     2.7 +
     2.8 +def domain_exists(name):
     2.9 +    # See comment in XendDomain constructor.
    2.10 +    xd = get_component('xen.xend.XendDomain')
    2.11 +    return xd.domain_exists(name)
    2.12 +
    2.13  def shutdown_reason(code):
    2.14      """Get a shutdown reason from a code.
    2.15  
    2.16 @@ -131,10 +137,10 @@ def lookup_disk_uname(uname):
    2.17          segments = None
    2.18      return segments
    2.19  
    2.20 -def make_disk(dom, uname, dev, mode, recreate=0):
    2.21 +def make_disk(vm, uname, dev, mode, recreate=0):
    2.22      """Create a virtual disk device for a domain.
    2.23  
    2.24 -    @param dom:      domain id
    2.25 +    @param vm:       vm
    2.26      @param uname:    device to export
    2.27      @param dev:      device name in domain
    2.28      @param mode:     read/write mode
    2.29 @@ -148,10 +154,11 @@ def make_disk(dom, uname, dev, mode, rec
    2.30          raise VmError("vbd: Multi-segment vdisk: uname=%s" % uname)
    2.31      segment = segments[0]
    2.32      vdev = blkdev_name_to_number(dev)
    2.33 -    ctrl = xend.blkif_create(dom, recreate=recreate)
    2.34 +    backend = vm.get_device_backend('vbd')
    2.35 +    ctrl = xend.blkif_create(vm.dom, recreate=recreate, backend=backend)
    2.36      
    2.37      def fn(ctrl):
    2.38 -        return xend.blkif_dev_create(dom, vdev, mode, segment, recreate=recreate)
    2.39 +        return xend.blkif_dev_create(vm.dom, vdev, mode, segment, recreate=recreate)
    2.40      ctrl.addCallback(fn)
    2.41      return ctrl
    2.42          
    2.43 @@ -371,6 +378,7 @@ class XendDomainInfo:
    2.44          self.console = None
    2.45          self.devices = {}
    2.46          self.device_index = {}
    2.47 +        self.device_backends = {}
    2.48          self.configs = []
    2.49          self.info = None
    2.50          self.ipaddrs = []
    2.51 @@ -466,9 +474,7 @@ class XendDomainInfo:
    2.52              if c in '_-.': continue
    2.53              if c in string.ascii_letters: continue
    2.54              raise VmError('invalid vm name')
    2.55 -        # See comment in XendDomain constructor.
    2.56 -        xd = get_component('xen.xend.XendDomain')
    2.57 -        dominfo = xd.domain_exists(name)
    2.58 +        dominfo = domain_exists(name)
    2.59          # When creating or rebooting, a domain with my name should not exist.
    2.60          # When restoring, a domain with my name will exist, but it should have
    2.61          # my domain id.
    2.62 @@ -663,6 +669,7 @@ class XendDomainInfo:
    2.63          
    2.64          self.devices = {}
    2.65          self.device_index = {}
    2.66 +        self.device_backends = {}
    2.67          self.configs = []
    2.68          self.ipaddrs = []
    2.69  
    2.70 @@ -901,15 +908,40 @@ class XendDomainInfo:
    2.71              self.restart_state = None
    2.72          return d
    2.73  
    2.74 +    def configure_device_backend(self, type, sxpr):
    2.75 +        """Configure the backend domain to use for devices of a given type.
    2.76 +
    2.77 +        @param type: device type
    2.78 +        @param sxpr: config
    2.79 +        @raise: VmError if the domain id is missing
    2.80 +        @raise: VmError if the domain does not exist
    2.81 +        """
    2.82 +        dom = sxp.child_value(sxpr, 'domain')
    2.83 +        if dom is None:
    2.84 +            raise VmError('missing backend domain')
    2.85 +        dominfo = domain_exists(dom)
    2.86 +        if dominfo is None:
    2.87 +            raise VmError('invalid backend domain:' + dom)
    2.88 +        self.device_backends[type] = dominfo.dom
    2.89 +
    2.90 +    def get_device_backend(self, type):
    2.91 +        return self.device_backends.get(type, 0)
    2.92 +
    2.93      def configure_backends(self):
    2.94 -        """Set configuration flags if the vm is a backend for netif of blkif.
    2.95 +        """Set configuration flags if the vm is a backend for netif or blkif.
    2.96 +        Configure the backends to use for vbd and vif if specified.
    2.97          """
    2.98          for c in sxp.children(self.config, 'backend'):
    2.99 -            name = sxp.name(sxp.child0(c))
   2.100 +            v = sxp.child0(c)
   2.101 +            name = sxp.name(v)
   2.102              if name == 'blkif':
   2.103                  self.blkif_backend = 1
   2.104              elif name == 'netif':
   2.105                  self.netif_backend = 1
   2.106 +            elif name == 'vbd':
   2.107 +                self.configure_device_backend('vbd', v)
   2.108 +            elif name == 'vif':
   2.109 +                self.configure_device_backend('vif', v)
   2.110              else:
   2.111                  raise VmError('invalid backend type:' + str(name))
   2.112  
   2.113 @@ -1039,7 +1071,8 @@ def vm_dev_vif(vm, val, index):
   2.114          raise VmError('vif: vif in netif backend domain')
   2.115      vif = vm.next_device_index('vif')
   2.116      vmac = sxp.child_value(val, "mac")
   2.117 -    xend.netif_create(vm.dom, recreate=vm.recreate)
   2.118 +    backend = vm.get_device_backend('vif')
   2.119 +    xend.netif_create(vm.dom, recreate=vm.recreate, backend=backend)
   2.120      log.debug("Creating vif dom=%d vif=%d mac=%s", vm.dom, vif, str(vmac))
   2.121      defer = xend.netif_dev_create(vm.dom, vif, val, recreate=vm.recreate)
   2.122      def fn(id):
   2.123 @@ -1068,7 +1101,7 @@ def vm_dev_vbd(vm, val, index):
   2.124          raise VmError('vbd: Missing dev')
   2.125      mode = sxp.child_value(val, 'mode', 'r')
   2.126      log.debug("Creating vbd dom=%d uname=%s dev=%s", vm.dom, uname, dev)
   2.127 -    defer = make_disk(vm.dom, uname, dev, mode, vm.recreate)
   2.128 +    defer = make_disk(vm, uname, dev, mode, vm.recreate)
   2.129      def fn(vbd):
   2.130          vbd.dev = dev
   2.131          vbd.uname = uname
     3.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Fri Aug 13 14:23:49 2004 +0000
     3.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Fri Aug 13 16:09:44 2004 +0000
     3.3 @@ -661,12 +661,12 @@ class Daemon:
     3.4          """
     3.5          return self.blkifCF.getControlDomain()
     3.6      
     3.7 -    def blkif_create(self, dom, recreate=0):
     3.8 +    def blkif_create(self, dom, recreate=0, backend=0):
     3.9          """Create a block device interface controller.
    3.10          
    3.11          Returns Deferred
    3.12          """
    3.13 -        d = self.blkifCF.createInstance(dom, recreate=recreate)
    3.14 +        d = self.blkifCF.createInstance(dom, recreate=recreate, backend=backend)
    3.15          return d
    3.16  
    3.17      def blkifs(self):
    3.18 @@ -699,11 +699,11 @@ class Daemon:
    3.19          """
    3.20          return self.netifCF.getControlDomain()
    3.21      
    3.22 -    def netif_create(self, dom, recreate=0):
    3.23 +    def netif_create(self, dom, recreate=0, backend=0):
    3.24          """Create a network interface controller.
    3.25          
    3.26          """
    3.27 -        return self.netifCF.createInstance(dom, recreate=recreate)
    3.28 +        return self.netifCF.createInstance(dom, recreate=recreate, backend=backend)
    3.29  
    3.30      def netifs(self):
    3.31          return [ x.sxpr() for x in self.netifCF.getInstances() ]
     4.1 --- a/tools/python/xen/xm/create.py	Fri Aug 13 14:23:49 2004 +0000
     4.2 +++ b/tools/python/xen/xm/create.py	Fri Aug 13 16:09:44 2004 +0000
     4.3 @@ -121,6 +121,14 @@ gopts.var('netif', val='no|yes',
     4.4            fn=set_bool, default=0,
     4.5            use="Make the domain a network interface backend.")
     4.6  
     4.7 +gopts.var('vbd_backend', val='DOM',
     4.8 +          fn=set_value, default=None,
     4.9 +          use='Set the domain to use for the vbd backend.')
    4.10 +
    4.11 +gopts.var('vif_backend', val='DOM',
    4.12 +          fn=set_value, default=None,
    4.13 +          use='Set the domain to use for the vif backend.')
    4.14 +
    4.15  gopts.var('disk', val='phy:DEV,VDEV,MODE',
    4.16            fn=append_value, default=[],
    4.17            use="""Add a disk device to a domain. The physical device is DEV,
    4.18 @@ -306,6 +314,10 @@ def make_config(vals):
    4.19          config.append(['backend', ['blkif']])
    4.20      if vals.netif:
    4.21          config.append(['backend', ['netif']])
    4.22 +    if vals.vbd_backend:
    4.23 +        config.append(['backend', ['vbd', ['dom', vals.vbd_backend]]])
    4.24 +    if vals.vif_backend:
    4.25 +        config.append(['backend', ['vif', ['dom', vals.vif_backend]]])
    4.26      if vals.restart:
    4.27          config.append(['restart', vals.restart])
    4.28      if vals.console: