def domain_create(self, config): """Create a domain from a configuration. @param config: configuration @return: domain """ self.domains_lock.acquire() try: dominfo = XendDomainInfo.create(config) self._add_domain(dominfo) return dominfo finally: self.domains_lock.release()
def restore_(self, config): """Create a domain as part of the restore process. This is called only from {@link XendCheckpoint}. A restore request comes into XendDomain through {@link #domain_restore} or {@link #domain_restore_fd}. That request is forwarded immediately to XendCheckpoint which, when it is ready, will call this method. It is necessary to come through here rather than go directly to {@link XendDomainInfo.restore} because we need to serialise the domain creation process, but cannot lock domain_restore_fd as a whole, otherwise we will deadlock waiting for the old domain to die. """ self.domains_lock.acquire() try: dominfo = XendDomainInfo.restore(config) self._add_domain(dominfo) return dominfo finally: self.domains_lock.release()
def init(self): xstransact.Mkdir(VMROOT) xstransact.SetPermissions(VMROOT, { 'dom' : PRIV_DOMAIN }) self.domains_lock.acquire() try: self._add_domain( XendDomainInfo.recreate(self.xen_domains()[PRIV_DOMAIN], True)) self.dom0_setup() # This watch registration needs to be before the refresh call, so # that we're sure that we haven't missed any releases, but inside # the domains_lock, as we don't want the watch to fire until after # the refresh call has completed. xswatch("@introduceDomain", self.onChangeDomain) xswatch("@releaseDomain", self.onChangeDomain) self.refresh(True) finally: self.domains_lock.release()
def refresh(self, initialising = False): """Refresh domain list from Xen. Expects to be protected by the domains_lock. @param initialising True if this is the first refresh after starting Xend. This does not change this method's behaviour, except for logging. """ doms = self.xen_domains() for d in self.domains.values(): info = doms.get(d.getDomid()) if info: d.update(info) else: self._delete_domain(d.getDomid()) for d in doms: if d not in self.domains: if doms[d]['dying']: log.log(initialising and logging.ERROR or logging.DEBUG, 'Cannot recreate information for dying domain %d.' ' Xend will ignore this domain from now on.', doms[d]['dom']) elif d == PRIV_DOMAIN: log.fatal( "No record of privileged domain %d! Terminating.", d) sys.exit(1) else: try: self._add_domain( XendDomainInfo.recreate(doms[d], False)) except: log.exception( "Failed to recreate information for domain " "%d. Destroying it in the hope of " "recovery.", d) try: xc.domain_destroy(d) except: log.exception('Destruction of %d failed.', d)