ia64/xen-unstable

changeset 8648:018e6dc18f97

This patch make xm reboot/shutdown work for vmx doamin.

xm reboot fails due to two issues:
1. no mechanism to change XendDomainInfo.info to trigger domain reboot
2. ioemu blkif parameter is missing during reboot, thus device model recreation will fail.

This patch fix these issues by
1. introducing a xswatch to monitor the control/shutdown node. once fired, it will change the XendDomainInfo.info to trigger domain reboot
2. saving the ioemu blkif parameter in xen store just like DomU does.

Signed-off-by: Yu Ke <ke.yu@intel.com>
author Ke Yu <ke.yu@intel.com>
date Tue Jan 24 17:58:43 2006 +0100 (2006-01-24)
parents a38c292e8390
children 85dd812ca054
files tools/python/xen/xend/image.py tools/python/xen/xend/server/blkif.py
line diff
     1.1 --- a/tools/python/xen/xend/image.py	Tue Jan 24 17:54:34 2006 +0100
     1.2 +++ b/tools/python/xen/xend/image.py	Tue Jan 24 17:58:43 2006 +0100
     1.3 @@ -25,6 +25,7 @@ from xen.xend import sxp
     1.4  from xen.xend.XendError import VmError
     1.5  from xen.xend.XendLogging import log
     1.6  from xen.xend.server.netif import randomMAC
     1.7 +from xen.xend.xenstore.xswatch import xswatch
     1.8  
     1.9  
    1.10  xc = xen.lowlevel.xc.xc()
    1.11 @@ -229,6 +230,8 @@ class VmxImageHandler(ImageHandler):
    1.12          log.debug("acpi           = %d", self.acpi)
    1.13          log.debug("apic           = %d", self.apic)
    1.14  
    1.15 +        self.register_shutdown_watch()
    1.16 +
    1.17          return xc.vmx_build(dom            = self.vm.getDomid(),
    1.18                              image          = self.kernel,
    1.19                              control_evtchn = self.device_channel,
    1.20 @@ -365,6 +368,7 @@ class VmxImageHandler(ImageHandler):
    1.21          return vncconnect
    1.22  
    1.23      def destroy(self):
    1.24 +        self.unregister_shutdown_watch();
    1.25          import signal
    1.26          if not self.pid:
    1.27              return
    1.28 @@ -398,6 +402,41 @@ class VmxImageHandler(ImageHandler):
    1.29          else:
    1.30              return 1 + ((mem_mb + 3) >> 2)
    1.31  
    1.32 +    def register_shutdown_watch(self):
    1.33 +        """ add xen store watch on control/shutdown """
    1.34 +        self.shutdownWatch = xswatch(self.vm.dompath + "/control/shutdown", \
    1.35 +                                    self.vmx_shutdown)
    1.36 +        log.debug("vmx shutdown watch registered")
    1.37 +
    1.38 +    def unregister_shutdown_watch(self):
    1.39 +        """Remove the watch on the control/shutdown, if any. Nothrow
    1.40 +        guarantee."""
    1.41 +
    1.42 +        try:
    1.43 +            if self.shutdownWatch:
    1.44 +                self.shutdownWatch.unwatch()
    1.45 +        except:
    1.46 +            log.exception("Unwatching vmx shutdown watch failed.")
    1.47 +        self.shutdownWatch = None
    1.48 +        log.debug("vmx shutdown watch unregistered")
    1.49 +
    1.50 +    def vmx_shutdown(self, _):
    1.51 +        """ watch call back on node control/shutdown,
    1.52 +            if node changed, this function will be called
    1.53 +        """
    1.54 +        from xen.xend.XendDomainInfo import shutdown_reasons
    1.55 +        xd = xen.xend.XendDomain.instance()
    1.56 +        vm = xd.domain_lookup( self.vm.getDomid() )
    1.57 +
    1.58 +        reason = vm.readDom('control/shutdown')
    1.59 +        log.debug("vmx_shutdown fired, shutdown reason=%s", reason)
    1.60 +        for x in shutdown_reasons.keys():
    1.61 +            if shutdown_reasons[x] == reason:
    1.62 +                vm.info['shutdown'] = 1
    1.63 +                vm.info['shutdown_reason'] = x
    1.64 +                vm.refreshShutdown(vm.info)
    1.65 +
    1.66 +        return 1 # Keep watching
    1.67  
    1.68  """Table of image handler classes for virtual machine images.  Indexed by
    1.69  image type.
     2.1 --- a/tools/python/xen/xend/server/blkif.py	Tue Jan 24 17:54:34 2006 +0100
     2.2 +++ b/tools/python/xen/xend/server/blkif.py	Tue Jan 24 17:58:43 2006 +0100
     2.3 @@ -42,10 +42,6 @@ class BlkifController(DevController):
     2.4          """@see DevController.getDeviceDetails"""
     2.5  
     2.6          dev = sxp.child_value(config, 'dev')
     2.7 -        if 'ioemu:' in dev:
     2.8 -            return (None,{},{})
     2.9 -
    2.10 -        devid = blkif.blkdev_name_to_number(dev)
    2.11  
    2.12          (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1)
    2.13          back = { 'dev'    : dev,
    2.14 @@ -54,7 +50,13 @@ class BlkifController(DevController):
    2.15                   'mode'   : sxp.child_value(config, 'mode', 'r')
    2.16                   }
    2.17  
    2.18 -        front = { 'virtual-device' : "%i" % devid }
    2.19 +        if 'ioemu:' in dev:
    2.20 +            (dummy, dev1) = string.split(dev, ':', 1)
    2.21 +            devid = blkif.blkdev_name_to_number(dev1)
    2.22 +            front = {}
    2.23 +        else:
    2.24 +            devid = blkif.blkdev_name_to_number(dev)
    2.25 +            front = { 'virtual-device' : "%i" % devid }
    2.26  
    2.27          return (devid, back, front)
    2.28