direct-io.hg

changeset 11281:051dc0911547

This patch fixed 'xm reboot' to work as you expected with the wait
option. This patch adds a restart sequence counter to xenstore.
The completion of a VM reboot is detected by observing that
its restart sequence counter changes.


Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Ewan Mellor <ewan@xensource.com>
date Tue Aug 29 22:51:06 2006 +0100 (2006-08-29)
parents b4e9f12df619
children 24258e322e88
files tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/XMLRPCServer.py tools/python/xen/xm/shutdown.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 29 22:51:05 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 29 22:51:06 2006 +0100
     1.3 @@ -703,6 +703,9 @@ class XendDomainInfo:
     1.4                  if security[idx][0] == 'ssidref':
     1.5                      to_store['security/ssidref'] = str(security[idx][1])
     1.6  
     1.7 +        if not self.readVm('xend/restart_count'):
     1.8 +            to_store['xend/restart_count'] = str(0)
     1.9 +
    1.10          log.debug("Storing VM details: %s", to_store)
    1.11  
    1.12          self.writeVm(to_store)
    1.13 @@ -824,6 +827,9 @@ class XendDomainInfo:
    1.14      def setResume(self, state):
    1.15          self.info['resume'] = state
    1.16  
    1.17 +    def getRestartCount(self):
    1.18 +        return self.readVm('xend/restart_count')
    1.19 +
    1.20      def refreshShutdown(self, xeninfo = None):
    1.21          # If set at the end of this method, a restart is required, with the
    1.22          # given reason.  This restart has to be done out of the scope of
    1.23 @@ -1615,6 +1621,9 @@ class XendDomainInfo:
    1.24              try:
    1.25                  new_dom = XendDomain.instance().domain_create(config)
    1.26                  new_dom.unpause()
    1.27 +                rst_cnt = self.readVm('xend/restart_count')
    1.28 +                rst_cnt = int(rst_cnt) + 1
    1.29 +                self.writeVm('xend/restart_count', str(rst_cnt))
    1.30                  new_dom.removeVm(RESTART_IN_PROGRESS)
    1.31              except:
    1.32                  if new_dom:
     2.1 --- a/tools/python/xen/xend/server/XMLRPCServer.py	Tue Aug 29 22:51:05 2006 +0100
     2.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Tue Aug 29 22:51:06 2006 +0100
     2.3 @@ -78,7 +78,8 @@ def get_log():
     2.4  methods = ['device_create', 'device_configure', 'destroyDevice',
     2.5             'getDeviceSxprs',
     2.6             'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown',
     2.7 -           'send_sysrq', 'getVCPUInfo', 'waitForDevices']
     2.8 +           'send_sysrq', 'getVCPUInfo', 'waitForDevices',
     2.9 +           'getRestartCount']
    2.10  
    2.11  exclude = ['domain_create', 'domain_restore']
    2.12  
     3.1 --- a/tools/python/xen/xm/shutdown.py	Tue Aug 29 22:51:05 2006 +0100
     3.2 +++ b/tools/python/xen/xm/shutdown.py	Tue Aug 29 22:51:06 2006 +0100
     3.3 @@ -48,21 +48,48 @@ gopts.opt('reboot', short='R',
     3.4            fn=set_true, default=0,
     3.5            use='Shutdown and reboot.')
     3.6  
     3.7 +def wait_reboot(opts, doms, rcs):
     3.8 +    while doms:
     3.9 +        alive = server.xend.domains(0)
    3.10 +        reboot = []
    3.11 +        for d in doms:
    3.12 +            if d in alive:
    3.13 +                rc = server.xend.domain.getRestartCount(d)
    3.14 +                if rc == rcs[d]: continue
    3.15 +                reboot.append(d)
    3.16 +            else:
    3.17 +                opts.info("Domain %s destroyed for failed in rebooting" % d)
    3.18 +                doms.remove(d)
    3.19 +        for d in reboot:
    3.20 +            opts.info("Domain %s rebooted" % d)
    3.21 +            doms.remove(d)
    3.22 +        time.sleep(1)
    3.23 +    opts.info("All domains rebooted")
    3.24 +
    3.25 +def wait_shutdown(opts, doms):
    3.26 +    while doms:
    3.27 +        alive = server.xend.domains(0)
    3.28 +        dead = []
    3.29 +        for d in doms:
    3.30 +            if d in alive: continue
    3.31 +            dead.append(d)
    3.32 +        for d in dead:
    3.33 +            opts.info("Domain %s terminated" % d)
    3.34 +            doms.remove(d)
    3.35 +        time.sleep(1)
    3.36 +    opts.info("All domains terminated")
    3.37 +
    3.38  def shutdown(opts, doms, mode, wait):
    3.39 +    rcs = {}
    3.40      for d in doms:
    3.41 +        rcs[d] = server.xend.domain.getRestartCount(d)
    3.42          server.xend.domain.shutdown(d, mode)
    3.43 +
    3.44      if wait:
    3.45 -        while doms:
    3.46 -            alive = server.xend.domains(0)
    3.47 -            dead = []
    3.48 -            for d in doms:
    3.49 -                if d in alive: continue
    3.50 -                dead.append(d)
    3.51 -            for d in dead:
    3.52 -                opts.info("Domain %s terminated" % d)
    3.53 -                doms.remove(d)
    3.54 -            time.sleep(1)
    3.55 -        opts.info("All domains terminated")
    3.56 +        if mode == 'reboot':
    3.57 +            wait_reboot(opts, doms, rcs)
    3.58 +        else:
    3.59 +            wait_shutdown(opts, doms)
    3.60  
    3.61  def shutdown_mode(opts):
    3.62      if opts.vals.halt and opts.vals.reboot: