[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] Re-arrange duplicate name checks
This patch moves duplicate name checking out of XendDomainInfo (the item class), and places it in XendDomain (the container class). For the restore case, I moved the code that extracts the config information from a state image into its own function so that the container class can validate the info before initiating the restore. This was done in an attempt to remove yet another mutual dependency between different levels of abstraction. Additionally, I could not find in the existing code the point at which a domain was added to the XendDomain list after restore. Several attempts to restore would result in positive log messages, but the restored domain would not show up in "xm list". This patch includes a call to _add_domain(), which results in restore working for me. Comments are welcomed, especially related to the last point. Signed-off-by: Dan Smith <danms@xxxxxxxxxx> diff -r d1cbfaf804d9 tools/python/xen/xend/XendCheckpoint.py --- a/tools/python/xen/xend/XendCheckpoint.py Mon Sep 19 17:10:20 2005 +++ b/tools/python/xen/xend/XendCheckpoint.py Mon Sep 19 14:07:40 2005 @@ -87,7 +87,7 @@ xd.domain_destroy(dominfo.domid) return None -def restore(xd, fd): +def getSavedConfig(fd): signature = read_exact(fd, len(SIGNATURE), "not a valid guest state file: signature read") if signature != SIGNATURE: @@ -105,8 +105,9 @@ if not p.ready: raise XendError("not a valid guest state file: config parse") - vmconfig = p.get_val() - dominfo = xd.domain_configure(vmconfig) + return p.get_val() + +def restore(fd, dominfo): l = read_exact(fd, sizeof_unsigned_long, "not a valid guest state file: pfn count read") diff -r d1cbfaf804d9 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Mon Sep 19 17:10:20 2005 +++ b/tools/python/xen/xend/XendDomain.py Mon Sep 19 14:07:40 2005 @@ -275,6 +275,11 @@ @param config: configuration @return: domain """ + + name = sxp.child_value(config, 'name') + if self.domains.get_by_name(name): + raise XendError("Domain %s already exists!" % name) + dominfo = XendDomainInfo.create(self.dbmap, config) self._add_domain(dominfo) return dominfo @@ -322,7 +327,18 @@ try: fd = os.open(src, os.O_RDONLY) - return XendCheckpoint.restore(self, fd) + + config = sxp.child_value(XendCheckpoint.getSavedConfig(fd), + 'config') + name = sxp.child_value(config, 'name') + + if self.domains.get_by_name(name): + raise XendError("Domain %s already exists!" % name) + + dominfo = XendDomainInfo.restore(self.dbmap, config) + dominfo = XendCheckpoint.restore(fd, dominfo) + self._add_domain(dominfo) + return dominfo except OSError, ex: raise XendError("can't read guest state file %s: %s" % (src, ex[1])) diff -r d1cbfaf804d9 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Mon Sep 19 17:10:20 2005 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Sep 19 14:07:40 2005 @@ -98,11 +98,6 @@ xend = SrvDaemon.instance() - -def domain_exists(name): - # See comment in XendDomain constructor. - xd = get_component('xen.xend.XendDomain') - return xd.domain_lookup_by_name(name) def shutdown_reason(code): """Get a shutdown reason from a code. @@ -512,16 +507,6 @@ if c in '_-.:/+': continue if c in string.ascii_letters: continue raise VmError('invalid vm name') - dominfo = domain_exists(name) - # When creating or rebooting, a domain with my name should not exist. - # When restoring, a domain with my name will exist, but it should have - # my domain id. - if not dominfo: - return - if dominfo.is_terminated(): - return - if not self.domid or (dominfo.domid != self.domid): - raise VmError('vm name clash: ' + name) def construct(self, config): """Construct the vm instance from its configuration. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@xxxxxxxxxx _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |