ia64/xen-unstable
changeset 6913:7cccdb49af75
Cleanup domain reaper and domain destruction functions.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Fri Sep 16 18:06:42 2005 +0000 (2005-09-16) |
parents | aa8943e9b705 |
children | ffbc98d735bd |
files | tools/python/xen/xend/XendDomain.py |
line diff
1.1 --- a/tools/python/xen/xend/XendDomain.py Fri Sep 16 18:05:03 2005 +0000 1.2 +++ b/tools/python/xen/xend/XendDomain.py Fri Sep 16 18:06:42 2005 +0000 1.3 @@ -222,41 +222,30 @@ class XendDomain: 1.4 """Look for domains that have crashed or stopped. 1.5 Tidy them up. 1.6 """ 1.7 - casualties = [] 1.8 doms = self.xen_domains() 1.9 for d in doms.values(): 1.10 - dead = 0 1.11 - dead = dead or (d['crashed'] or d['shutdown']) 1.12 - dead = dead or (d['dying'] and 1.13 - not(d['running'] or d['paused'] or d['blocked'])) 1.14 - if dead: 1.15 - casualties.append(d) 1.16 - for d in casualties: 1.17 - id = d['dom'] 1.18 - dominfo = self.domains.get(id) 1.19 - name = (dominfo and dominfo.name) or '??' 1.20 - if dominfo and dominfo.is_terminated(): 1.21 + dead = d['crashed'] or d['shutdown'] or ( 1.22 + d['dying'] and not(d['running'] or d['paused'] or 1.23 + d['blocked'])) 1.24 + if not dead: 1.25 continue 1.26 - log.debug('XendDomain>reap> domain died name=%s id=%d', name, id) 1.27 + domid = d['dom'] 1.28 + dominfo = self.domains.get(domid) 1.29 + if not dominfo or dominfo.is_terminated(): 1.30 + continue 1.31 + log.debug('domain died name=%s domid=%d', dominfo.name, domid) 1.32 + if d['crashed'] and xroot.get_enable_dump(): 1.33 + self.domain_dumpcore(domid) 1.34 if d['shutdown']: 1.35 reason = shutdown_reason(d['shutdown_reason']) 1.36 - log.debug('XendDomain>reap> shutdown name=%s id=%d reason=%s', name, id, reason) 1.37 - if reason in ['suspend']: 1.38 - if dominfo and dominfo.is_terminated(): 1.39 - log.debug('XendDomain>reap> Suspended domain died id=%d', id) 1.40 - else: 1.41 - eserver.inject('xend.domain.suspended', [name, id]) 1.42 - if dominfo: 1.43 - dominfo.state_set("suspended") 1.44 - continue 1.45 + log.debug('shutdown name=%s id=%d reason=%s', name, domid, 1.46 + reason) 1.47 + if reason == 'suspend': 1.48 + dominfo.state_set("suspended") 1.49 + continue 1.50 if reason in ['poweroff', 'reboot']: 1.51 - eserver.inject('xend.domain.exit', [name, id, reason]) 1.52 - self.domain_restart_schedule(id, reason) 1.53 - else: 1.54 - if xroot.get_enable_dump(): 1.55 - self.domain_dumpcore(id) 1.56 - eserver.inject('xend.domain.exit', [name, id, 'crash']) 1.57 - self.final_domain_destroy(id) 1.58 + self.domain_restart_schedule(domid, reason) 1.59 + dominfo.destroy() 1.60 1.61 def refresh(self, cleanup=False): 1.62 """Refresh domain list from Xen. 1.63 @@ -494,44 +483,31 @@ class XendDomain: 1.64 for dominfo in self.domains.values(): 1.65 if not dominfo.restart_pending(): 1.66 continue 1.67 - print 'domain_restarts>', dominfo.name, dominfo.domid 1.68 info = doms.get(dominfo.domid) 1.69 if info: 1.70 # Don't execute restart for domains still running. 1.71 - print 'domain_restarts> still runnning: ', dominfo.name 1.72 continue 1.73 # Remove it from the restarts. 1.74 - print 'domain_restarts> restarting: ', dominfo.name 1.75 + log.info('restarting: %s' % dominfo.name) 1.76 self.domain_restart(dominfo) 1.77 1.78 - def final_domain_destroy(self, id): 1.79 - """Final destruction of a domain.. 1.80 - 1.81 - @param id: domain id 1.82 - """ 1.83 - try: 1.84 - dominfo = self.domain_lookup(id) 1.85 - log.info('Destroying domain: name=%s', dominfo.name) 1.86 - eserver.inject('xend.domain.destroy', [dominfo.name, dominfo.domid]) 1.87 - val = dominfo.destroy() 1.88 - except: 1.89 - #todo 1.90 - try: 1.91 - val = xc.domain_destroy(dom=id) 1.92 - except Exception, ex: 1.93 - raise XendError(str(ex)) 1.94 - return val 1.95 - 1.96 - def domain_destroy(self, id, reason='halt'): 1.97 + def domain_destroy(self, domid, reason='halt'): 1.98 """Terminate domain immediately. 1.99 - halt: cancel any restart for the domain 1.100 - reboot schedule a restart for the domain 1.101 1.102 - @param id: domain id 1.103 + @param domid: domain id 1.104 """ 1.105 - self.domain_restart_schedule(id, reason, force=True) 1.106 - val = self.final_domain_destroy(id) 1.107 - return val 1.108 + self.domain_restart_schedule(domid, reason, force=True) 1.109 + dominfo = self.domain_lookup(domid) 1.110 + if dominfo: 1.111 + val = dominfo.destroy() 1.112 + else: 1.113 + try: 1.114 + val = xc.domain_destroy(dom=domid) 1.115 + except Exception, ex: 1.116 + raise XendError(str(ex)) 1.117 + return val 1.118 1.119 def domain_migrate(self, id, dst, live=False, resource=0): 1.120 """Start domain migration.