[libvirt] [PATCH] Clarify semantics of virDomainMigrate2

Jiri Denemark jdenemar at redhat.com
Fri Oct 14 19:34:31 UTC 2011


Explicitly disallow conflicts between domain name from dxml and dname.
---
 src/libvirt.c             |    3 +++
 src/qemu/qemu_driver.c    |    4 ++--
 src/qemu/qemu_migration.c |   17 ++++++++++++++---
 src/qemu/qemu_migration.h |    1 +
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index f1e6a6b..69cffc5 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -4854,6 +4854,9 @@ error:
  * in accessing the underlying storage.  The migration will fail
  * if @dxml would cause any guest-visible changes.  Pass NULL
  * if no changes are needed to the XML between source and destination.
+ * @dxml cannot be used to rename the domain during migration (use
+ * @dname for that purpose).  Domain name in @dxml must either match the
+ * original domain name or @dname if it was specified.
  *
  * Returns the new domain object if the migration was successful,
  *   or NULL in case of error.  Note that the new domain object
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 98f4d7f..f833655 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8043,7 +8043,7 @@ qemuDomainMigrateBegin3(virDomainPtr domain,
                         char **cookieout,
                         int *cookieoutlen,
                         unsigned long flags,
-                        const char *dname ATTRIBUTE_UNUSED,
+                        const char *dname,
                         unsigned long resource ATTRIBUTE_UNUSED)
 {
     struct qemud_driver *driver = domain->conn->privateData;
@@ -8083,7 +8083,7 @@ qemuDomainMigrateBegin3(virDomainPtr domain,
     if (qemuDomainCheckEjectableMedia(driver, vm) < 0)
         goto endjob;
 
-    if (!(xml = qemuMigrationBegin(driver, vm, xmlin,
+    if (!(xml = qemuMigrationBegin(driver, vm, xmlin, dname,
                                    cookieout, cookieoutlen)))
         goto endjob;
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f0a0e49..3770bb6 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -993,6 +993,7 @@ qemuDomainMigrateGraphicsRelocate(struct qemud_driver *driver,
 char *qemuMigrationBegin(struct qemud_driver *driver,
                          virDomainObjPtr vm,
                          const char *xmlin,
+                         const char *dname,
                          char **cookieout,
                          int *cookieoutlen)
 {
@@ -1001,8 +1002,10 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
     virDomainDefPtr def = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
-    VIR_DEBUG("driver=%p, vm=%p, xmlin=%s, cookieout=%p, cookieoutlen=%p",
-              driver, vm, NULLSTR(xmlin), cookieout, cookieoutlen);
+    VIR_DEBUG("driver=%p, vm=%p, xmlin=%s, dname=%s,"
+              " cookieout=%p, cookieoutlen=%p",
+              driver, vm, NULLSTR(xmlin), NULLSTR(dname),
+              cookieout, cookieoutlen);
 
     /* Only set the phase if we are inside QEMU_ASYNC_JOB_MIGRATION_OUT.
      * Otherwise we will start the async job later in the perform phase losing
@@ -1028,6 +1031,14 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
                                             VIR_DOMAIN_XML_INACTIVE)))
             goto cleanup;
 
+        if (STRNEQ(def->name, vm->def->name) &&
+            (!dname || STRNEQ(def->name, dname))) {
+            qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                            "target domain name doesn't match source name"
+                            " nor destination name");
+            goto cleanup;
+        }
+
         if (!virDomainDefCheckABIStability(vm->def, def))
             goto cleanup;
 
@@ -2012,7 +2023,7 @@ static int doPeer2PeerMigrate3(struct qemud_driver *driver,
      * bit here, because we are already running inside the context of
      * a single job.  */
 
-    dom_xml = qemuMigrationBegin(driver, vm, xmlin,
+    dom_xml = qemuMigrationBegin(driver, vm, xmlin, dname,
                                  &cookieout, &cookieoutlen);
     if (!dom_xml)
         goto cleanup;
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index ec70422..f806ca1 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -79,6 +79,7 @@ int qemuMigrationSetOffline(struct qemud_driver *driver,
 char *qemuMigrationBegin(struct qemud_driver *driver,
                          virDomainObjPtr vm,
                          const char *xmlin,
+                         const char *dname,
                          char **cookieout,
                          int *cookieoutlen);
 
-- 
1.7.7




More information about the libvir-list mailing list