All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Re-arrange duplicate name checks
@ 2005-09-19 21:10 Dan Smith
  0 siblings, 0 replies; only message in thread
From: Dan Smith @ 2005-09-19 21:10 UTC (permalink / raw)
  To: Xen Developers

[-- Attachment #1: Type: text/plain, Size: 887 bytes --]

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@us.ibm.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xend-fixchecks.patch --]
[-- Type: text/x-patch, Size: 3377 bytes --]

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.

[-- Attachment #3: Type: text/plain, Size: 88 bytes --]


-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@us.ibm.com

[-- Attachment #4: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-09-19 21:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-19 21:10 [PATCH] Re-arrange duplicate name checks Dan Smith

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.