diff -r ec03b24a2d83 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Sun Aug 20 21:12:15 2006 +0900 @@ -699,6 +699,9 @@ class XendDomainInfo: if security[idx][0] == 'ssidref': to_store['security/ssidref'] = str(security[idx][1]) + if not self.readVm('xend/restart_count'): + to_store['xend/restart_count'] = str(0) + log.debug("Storing VM details: %s", to_store) self.writeVm(to_store) @@ -819,6 +822,9 @@ class XendDomainInfo: def setResume(self, state): self.info['resume'] = state + + def getRestartCount(self): + return self.readVm('xend/restart_count') def refreshShutdown(self, xeninfo = None): # If set at the end of this method, a restart is required, with the @@ -1601,6 +1607,9 @@ class XendDomainInfo: try: new_dom = XendDomain.instance().domain_create(config) new_dom.unpause() + rst_cnt = self.readVm('xend/restart_count') + rst_cnt = int(rst_cnt) + 1 + self.writeVm('xend/restart_count', str(rst_cnt)) new_dom.removeVm(RESTART_IN_PROGRESS) except: if new_dom: diff -r ec03b24a2d83 tools/python/xen/xend/server/XMLRPCServer.py --- a/tools/python/xen/xend/server/XMLRPCServer.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xend/server/XMLRPCServer.py Sun Aug 20 21:12:15 2006 +0900 @@ -76,7 +76,8 @@ def get_log(): methods = ['device_create', 'destroyDevice', 'getDeviceSxprs', 'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown', - 'send_sysrq', 'getVCPUInfo', 'waitForDevices'] + 'send_sysrq', 'getVCPUInfo', 'waitForDevices', + 'getRestartCount'] exclude = ['domain_create', 'domain_restore'] diff -r ec03b24a2d83 tools/python/xen/xm/shutdown.py --- a/tools/python/xen/xm/shutdown.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xm/shutdown.py Sun Aug 20 21:12:15 2006 +0900 @@ -48,21 +48,48 @@ gopts.opt('reboot', short='R', fn=set_true, default=0, use='Shutdown and reboot.') +def wait_reboot(opts, doms, rcs): + while doms: + alive = server.xend.domains(0) + reboot = [] + for d in doms: + if d in alive: + rc = server.xend.domain.getRestartCount(d) + if rc == rcs[d]: continue + reboot.append(d) + else: + opts.info("Domain %s destroyed for failed in rebooting" % d) + doms.remove(d) + for d in reboot: + opts.info("Domain %s rebooted" % d) + doms.remove(d) + time.sleep(1) + opts.info("All domains rebooted") + +def wait_shutdown(opts, doms): + while doms: + alive = server.xend.domains(0) + dead = [] + for d in doms: + if d in alive: continue + dead.append(d) + for d in dead: + opts.info("Domain %s terminated" % d) + doms.remove(d) + time.sleep(1) + opts.info("All domains terminated") + def shutdown(opts, doms, mode, wait): + rcs = {} for d in doms: + rcs[d] = server.xend.domain.getRestartCount(d) server.xend.domain.shutdown(d, mode) + if wait: - while doms: - alive = server.xend.domains(0) - dead = [] - for d in doms: - if d in alive: continue - dead.append(d) - for d in dead: - opts.info("Domain %s terminated" % d) - doms.remove(d) - time.sleep(1) - opts.info("All domains terminated") + if mode == 'reboot': + wait_reboot(opts, doms, rcs) + else: + wait_shutdown(opts, doms) def shutdown_mode(opts): if opts.vals.halt and opts.vals.reboot: