ia64/xen-unstable

changeset 7676:7e3faea076ec

Push the process of waiting for devices to come up right out of DevController,
and drive this process from xm create. Architecturally, this separates the
process of domain creation from the process of waiting for devices, allowing
tools to choose when to perform that wait (if at all). This places the waiting
in the same category as the unpause after domain creation, architecturally.

The main advantage to this approach is that it takes waiting for devices out
of the scope of XendDomain's domains_lock. When restarting a domain, the
watch would fire for @releaseDomain while we were waiting for new domains to
come up. This would deadlock the watch thread, as no more new watches could
be delivered. Closes bug #387.

In the longer term, we expect to be able to wait for devices to come up
completely, not simply to wait for the hotplug scripts to run, and so it is
necessary then to move the waiting procedure right out of the server, so that
it can be performed after the domain unpause. Without unpausing the domain,
the frontends will not come up, and so we cannot detect successful device
completion.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Nov 08 03:34:23 2005 +0100 (2005-11-08)
parents eafd932231ae
children 055efdd6b7c5
files tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xend/XendClient.py	Tue Nov 08 03:07:57 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendClient.py	Tue Nov 08 03:34:23 2005 +0100
     1.3 @@ -220,6 +220,10 @@ class Xend:
     1.4      def xend_domain(self, id):
     1.5          return self.xendGet(self.domainurl(id))
     1.6  
     1.7 +    def xend_domain_wait_for_devices(self, id):
     1.8 +        return self.xendPost(self.domainurl(id),
     1.9 +                             {'op'      : 'wait_for_devices' })
    1.10 +
    1.11      def xend_domain_unpause(self, id):
    1.12          return self.xendPost(self.domainurl(id),
    1.13                               {'op'      : 'unpause' })
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Nov 08 03:07:57 2005 +0100
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Nov 08 03:34:23 2005 +0100
     2.3 @@ -897,6 +897,14 @@ class XendDomainInfo:
     2.4          return self.getDeviceController(deviceClass).createDevice(devconfig)
     2.5  
     2.6  
     2.7 +    def waitForDevices_(self, deviceClass):
     2.8 +        return self.getDeviceController(deviceClass).waitForDevices()
     2.9 +
    2.10 +
    2.11 +    def waitForDevice(self, deviceClass, devid):
    2.12 +        return self.getDeviceController(deviceClass).waitForDevice(devid)
    2.13 +
    2.14 +
    2.15      def reconfigureDevice(self, deviceClass, devid, devconfig):
    2.16          return self.getDeviceController(deviceClass).reconfigureDevice(
    2.17              devid, devconfig)
    2.18 @@ -1232,6 +1240,15 @@ class XendDomainInfo:
    2.19              self.image.createDeviceModel()
    2.20  
    2.21  
    2.22 +    def waitForDevices(self):
    2.23 +        """Wait for this domain's configured devices to connect.
    2.24 +
    2.25 +        @raise: VmError if any device fails to initialise.
    2.26 +        """
    2.27 +        for c in controllerClasses:
    2.28 +            self.waitForDevices_(c)
    2.29 +
    2.30 +
    2.31      def device_create(self, dev_config):
    2.32          """Create a new device.
    2.33  
    2.34 @@ -1239,6 +1256,7 @@ class XendDomainInfo:
    2.35          """
    2.36          dev_type = sxp.name(dev_config)
    2.37          devid = self.createDevice(dev_type, dev_config)
    2.38 +        self.waitForDevice(dev_type, devid)
    2.39  #        self.config.append(['device', dev.getConfig()])
    2.40          return self.getDeviceController(dev_type).sxpr(devid)
    2.41  
     3.1 --- a/tools/python/xen/xend/server/DevController.py	Tue Nov 08 03:07:57 2005 +0100
     3.2 +++ b/tools/python/xen/xend/server/DevController.py	Tue Nov 08 03:34:23 2005 +0100
     3.3 @@ -62,6 +62,18 @@ class DevController:
     3.4  
     3.5          self.writeDetails(config, devid, back, front)
     3.6  
     3.7 +        return devid
     3.8 +
     3.9 +
    3.10 +    def waitForDevices(self):
    3.11 +        log.debug("Waiting for devices %s.", self.deviceClass)
    3.12 +        
    3.13 +        return map(self.waitForDevice, self.deviceIDs())
    3.14 +
    3.15 +
    3.16 +    def waitForDevice(self, devid):
    3.17 +        log.debug("Waiting for %s.", devid)
    3.18 +        
    3.19          status, fn_ret = self.waitForBackend(devid)
    3.20          if status:
    3.21              self.destroyDevice(devid)
    3.22 @@ -74,7 +86,6 @@ class DevController:
    3.23              raise VmError( ("Device %s (%s) could not be connected. "
    3.24                              "Backend device not found!") 
    3.25                              % (devid, self.deviceClass))
    3.26 -        return devid
    3.27  
    3.28  
    3.29      def reconfigureDevice(self, devid, config):
    3.30 @@ -122,10 +133,11 @@ class DevController:
    3.31          specified device.  This would be suitable for giving to {@link
    3.32          #createDevice} in order to recreate that device."""
    3.33  
    3.34 -        backdomid = int(xstransact.Read(self.frontendPath(devid),
    3.35 -                                        "backend-id"))
    3.36 -
    3.37 -        return [self.deviceClass, ['backend', backdomid]]
    3.38 +        backdomid = xstransact.Read(self.frontendPath(devid), "backend-id")
    3.39 +        if backdomid is None:
    3.40 +            raise VmError("Device %s not connected" % devid)
    3.41 +        
    3.42 +        return [self.deviceClass, ['backend', int(backdomid)]]
    3.43  
    3.44  
    3.45      def sxprs(self):
    3.46 @@ -200,7 +212,10 @@ class DevController:
    3.47      def readBackend(self, devid, *args):
    3.48          frontpath = self.frontendPath(devid)
    3.49          backpath = xstransact.Read(frontpath, "backend")
    3.50 -        return xstransact.Read(backpath, *args)
    3.51 +        if backpath:
    3.52 +            return xstransact.Read(backpath, *args)
    3.53 +        else:
    3.54 +            raise VmError("Device %s not connected" % devid)
    3.55  
    3.56  
    3.57      def deviceIDs(self):
    3.58 @@ -242,6 +257,8 @@ class DevController:
    3.59          frontpath = self.frontendPath(devid)
    3.60          backpath  = self.backendPath(backdom, devid)
    3.61          
    3.62 +        xstransact.Remove(backpath, HOTPLUG_STATUS_NODE)
    3.63 +
    3.64          frontDetails.update({
    3.65              'backend' : backpath,
    3.66              'backend-id' : "%i" % backdom.getDomid()
    3.67 @@ -266,7 +283,10 @@ class DevController:
    3.68          ev = Event()
    3.69  
    3.70          def hotplugStatus():
    3.71 -            status = self.readBackend(devid, HOTPLUG_STATUS_NODE)
    3.72 +            try:
    3.73 +                status = self.readBackend(devid, HOTPLUG_STATUS_NODE)
    3.74 +            except VmError:
    3.75 +                status = "died"
    3.76              if status is not None:
    3.77                  watch.xs.unwatch(backpath, watch)
    3.78                  hotplugStatus.value = status
    3.79 @@ -276,14 +296,16 @@ class DevController:
    3.80          frontpath = self.frontendPath(devid)
    3.81          backpath = xstransact.Read(frontpath, "backend")
    3.82  
    3.83 -        watch = xswatch(backpath, hotplugStatus)
    3.84 +        if backpath:
    3.85 +            watch = xswatch(backpath, hotplugStatus)
    3.86  
    3.87 -        ev.wait(DEVICE_CREATE_TIMEOUT)
    3.88 -        if ev.isSet():
    3.89 -            return (0, hotplugStatus.value)
    3.90 +            ev.wait(DEVICE_CREATE_TIMEOUT)
    3.91 +            if ev.isSet():
    3.92 +                return (0, hotplugStatus.value)
    3.93 +            else:
    3.94 +                return (-1, hotplugStatus.value)
    3.95          else:
    3.96 -            return (-1, hotplugStatus.value)
    3.97 -
    3.98 +            return (-1, "missing")
    3.99  
   3.100  
   3.101      def backendPath(self, backdom, devid):
     4.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Tue Nov 08 03:07:57 2005 +0100
     4.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Tue Nov 08 03:34:23 2005 +0100
     4.3 @@ -13,6 +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  #============================================================================
     4.9  
    4.10  from xen.web import http
    4.11 @@ -62,6 +63,10 @@ class SrvDomain(SrvDir):
    4.12          self.acceptCommand(req)
    4.13          return self.dom.send_sysrq(int(req.args['key'][0]))
    4.14  
    4.15 +    def op_wait_for_devices(self, _, req):
    4.16 +        self.acceptCommand(req)
    4.17 +        return self.dom.waitForDevices()
    4.18 +
    4.19      def op_destroy(self, _, req):
    4.20          self.acceptCommand(req)
    4.21          return self.xd.domain_destroy(self.dom.domid)
     5.1 --- a/tools/python/xen/xm/create.py	Tue Nov 08 03:07:57 2005 +0100
     5.2 +++ b/tools/python/xen/xm/create.py	Tue Nov 08 03:34:23 2005 +0100
     5.3 @@ -815,6 +815,10 @@ def make_domain(opts, config):
     5.4  
     5.5      dom = sxp.child_value(dominfo, 'name')
     5.6  
     5.7 +    if server.xend_domain_wait_for_devices(dom) < 0:
     5.8 +        server.xend_domain_destroy(dom)
     5.9 +        err("Device creation failed for domain %s" % dom)
    5.10 +
    5.11      if not opts.vals.paused:
    5.12          if server.xend_domain_unpause(dom) < 0:
    5.13              server.xend_domain_destroy(dom)