xend: Perform uuid/name uniqueness check on restore.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 30 Jan 2008 09:35:49 +0000 (09:35 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 30 Jan 2008 09:35:49 +0000 (09:35 +0000)
From: Zhigang Wang <zhigang.x.wang@oracle.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
tools/python/xen/xend/XendCheckpoint.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/server/relocate.py

index d3b409f7deb2ac4dad92e3dd3554ec501574ccf4..a70df6f785360d41a70a7273bf7c493652b4c190 100644 (file)
@@ -151,7 +151,7 @@ def save(fd, dominfo, network, live, dst, checkpoint=False):
         raise exn
 
 
-def restore(xd, fd, dominfo = None, paused = False):
+def restore(xd, fd, dominfo = None, paused = False, relocating = False):
     signature = read_exact(fd, len(SIGNATURE),
         "not a valid guest state file: signature read")
     if signature != SIGNATURE:
@@ -171,6 +171,14 @@ def restore(xd, fd, dominfo = None, paused = False):
 
     vmconfig = p.get_val()
 
+    if not relocating:
+        domconfig = XendConfig(sxp_obj = vmconfig)
+        othervm = xd.domain_lookup_nr(domconfig["name_label"])
+        if othervm is None or othervm.domid is None:
+            othervm = xd.domain_lookup_nr(domconfig["uuid"])
+        if othervm is not None and othervm.domid is not None: 
+            raise VmError("Domain '%s' already exists with ID '%d'" % (domconfig["name_label"], othervm.domid))
+
     if dominfo:
         dominfo.resume()
     else:
index 1dca606ad618c2afcd53dea53d1886da2ad9d5df..087fe57e37edef4d91fe616a57a81b688a19291b 100644 (file)
@@ -1123,7 +1123,7 @@ class XendDomain:
             raise XendError("can't read guest state file %s: %s" %
                             (src, ex[1]))
 
-    def domain_restore_fd(self, fd, paused=False):
+    def domain_restore_fd(self, fd, paused=False, relocating=False):
         """Restore a domain from the given file descriptor.
 
         @param fd: file descriptor of the checkpoint file
@@ -1133,7 +1133,7 @@ class XendDomain:
         """
 
         try:
-            return XendCheckpoint.restore(self, fd, paused=paused)
+            return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating)
         except XendError, e:
             log.exception("Restore failed")
             raise
index 8a28c85c0a51dd5e0a2df858f7d6b0e84c1a1a59..8f6a376bc4a19239254faa798f2e98a126400e72 100644 (file)
@@ -108,7 +108,7 @@ class RelocationProtocol(protocol.Protocol):
             self.send_reply(["ready", name])
             try:
                 XendDomain.instance().domain_restore_fd(
-                    self.transport.sock.fileno())
+                    self.transport.sock.fileno(), relocating=True)
             except:
                 self.send_error()
                 self.close()