[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] qemu: Make domain renaming work during migration



https://bugzilla.redhat.com/show_bug.cgi?id=999352

Since commit v1.0.5-56-g449e6b1 (Pull parsing of migration xml up into
QEMU driver APIs) any attempt to rename a domain during migration fails
with the following error message:

    internal error Incoming cookie data had unexpected name DOM vs DOM2

This is because migration cookies always use the original domain name
and the mentioned commit failed to propagate the name back to
qemuMigrationPrepareAny.
---
 src/qemu/qemu_driver.c    | 36 ++++++++++++++++++++++++------------
 src/qemu/qemu_migration.c | 31 +++++++++++++++++++------------
 src/qemu/qemu_migration.h |  5 ++++-
 3 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ed29373..52ca906 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9973,6 +9973,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -9990,7 +9991,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepareTunnelEnsureACL(dconn, def) < 0)
@@ -9998,9 +9999,10 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
     ret = qemuMigrationPrepareTunnel(driver, dconn,
                                      NULL, 0, NULL, NULL, /* No cookies in v2 */
-                                     st, &def, flags);
+                                     st, &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -10022,6 +10024,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -10043,7 +10046,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepare2EnsureACL(dconn, def) < 0)
@@ -10056,9 +10059,10 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
     ret = qemuMigrationPrepareDirect(driver, dconn,
                                      NULL, 0, NULL, NULL, /* No cookies */
                                      uri_in, uri_out,
-                                     &def, flags);
+                                     &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -10235,6 +10239,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -10249,7 +10254,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepare3EnsureACL(dconn, def) < 0)
@@ -10259,9 +10264,10 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
                                      cookiein, cookieinlen,
                                      cookieout, cookieoutlen,
                                      uri_in, uri_out,
-                                     &def, flags);
+                                     &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -10282,6 +10288,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
     const char *dom_xml = NULL;
     const char *dname = NULL;
     const char *uri_in = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -10309,7 +10316,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepare3ParamsEnsureACL(dconn, def) < 0)
@@ -10319,9 +10326,10 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
                                      cookiein, cookieinlen,
                                      cookieout, cookieoutlen,
                                      uri_in, uri_out,
-                                     &def, flags);
+                                     &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -10341,6 +10349,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 {
     virQEMUDriverPtr driver = dconn->privateData;
     virDomainDefPtr def = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -10351,7 +10360,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepareTunnel3EnsureACL(dconn, def) < 0)
@@ -10360,9 +10369,10 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
     ret = qemuMigrationPrepareTunnel(driver, dconn,
                                      cookiein, cookieinlen,
                                      cookieout, cookieoutlen,
-                                     st, &def, flags);
+                                     st, &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
@@ -10382,6 +10392,7 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
     virDomainDefPtr def = NULL;
     const char *dom_xml = NULL;
     const char *dname = NULL;
+    char *origname = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -10402,7 +10413,7 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
         goto cleanup;
 
     if (virDomainMigratePrepareTunnel3ParamsEnsureACL(dconn, def) < 0)
@@ -10411,9 +10422,10 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
     ret = qemuMigrationPrepareTunnel(driver, dconn,
                                      cookiein, cookieinlen,
                                      cookieout, cookieoutlen,
-                                     st, &def, flags);
+                                     st, &def, origname, flags);
 
 cleanup:
+    VIR_FREE(origname);
     virDomainDefFree(def);
     return ret;
 }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index b905459..3177756 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2160,6 +2160,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
                         char **cookieout,
                         int *cookieoutlen,
                         virDomainDefPtr *def,
+                        const char *origname,
                         virStreamPtr st,
                         unsigned int port,
                         unsigned long flags)
@@ -2172,7 +2173,6 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
     unsigned long long now;
     qemuMigrationCookiePtr mig = NULL;
     bool tunnel = !!st;
-    char *origname = NULL;
     char *xmlout = NULL;
     unsigned int cookieFlags;
     virCapsPtr caps = NULL;
@@ -2297,8 +2297,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
 
     *def = NULL;
     priv = vm->privateData;
-    priv->origname = origname;
-    origname = NULL;
+    if (VIR_STRDUP(priv->origname, origname) < 0)
+        goto cleanup;
 
     if (!(mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
                                        QEMU_MIGRATION_COOKIE_LOCKSTATE |
@@ -2412,7 +2412,6 @@ done:
 
 cleanup:
     VIR_FREE(migrateFrom);
-    VIR_FREE(origname);
     VIR_FREE(xmlout);
     VIR_FORCE_CLOSE(dataFD[0]);
     VIR_FORCE_CLOSE(dataFD[1]);
@@ -2457,15 +2456,16 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
                            int *cookieoutlen,
                            virStreamPtr st,
                            virDomainDefPtr *def,
+                           const char *origname,
                            unsigned long flags)
 {
     int ret;
 
     VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
               "cookieout=%p, cookieoutlen=%p, st=%p, def=%p, "
-              "flags=%lx",
+              "origname=%s, flags=%lx",
               driver, dconn, NULLSTR(cookiein), cookieinlen,
-              cookieout, cookieoutlen, st, *def, flags);
+              cookieout, cookieoutlen, st, *def, origname, flags);
 
     if (st == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2474,7 +2474,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
     }
 
     ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
-                                  cookieout, cookieoutlen, def,
+                                  cookieout, cookieoutlen, def, origname,
                                   st, 0, flags);
     return ret;
 }
@@ -2490,6 +2490,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
                            const char *uri_in,
                            char **uri_out,
                            virDomainDefPtr *def,
+                           const char *origname,
                            unsigned long flags)
 {
     static int port = 0;
@@ -2502,10 +2503,10 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
 
     VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
               "cookieout=%p, cookieoutlen=%p, uri_in=%s, uri_out=%p, "
-              "def=%p, flags=%lx",
+              "def=%p, origname=%s, flags=%lx",
               driver, dconn, NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
-              *def, flags);
+              *def, origname, flags);
 
     *uri_out = NULL;
 
@@ -2594,7 +2595,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
         VIR_DEBUG("Generated uri_out=%s", *uri_out);
 
     ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
-                                  cookieout, cookieoutlen, def,
+                                  cookieout, cookieoutlen, def, origname,
                                   NULL, this_port, flags);
 cleanup:
     virURIFree(uri);
@@ -2608,10 +2609,12 @@ cleanup:
 virDomainDefPtr
 qemuMigrationPrepareDef(virQEMUDriverPtr driver,
                         const char *dom_xml,
-                        const char *dname)
+                        const char *dname,
+                        char **origname)
 {
     virCapsPtr caps = NULL;
     virDomainDefPtr def;
+    char *name = NULL;
 
     if (!dom_xml) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2628,7 +2631,7 @@ qemuMigrationPrepareDef(virQEMUDriverPtr driver,
         goto cleanup;
 
     if (dname) {
-        VIR_FREE(def->name);
+        name = def->name;
         if (VIR_STRDUP(def->name, dname) < 0) {
             virDomainDefFree(def);
             def = NULL;
@@ -2637,6 +2640,10 @@ qemuMigrationPrepareDef(virQEMUDriverPtr driver,
 
 cleanup:
     virObjectUnref(caps);
+    if (def && origname)
+        *origname = name;
+    else
+        VIR_FREE(name);
     return def;
 }
 
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 0f6c5f7..4af5aed 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -100,7 +100,8 @@ char *qemuMigrationBegin(virConnectPtr conn,
 
 virDomainDefPtr qemuMigrationPrepareDef(virQEMUDriverPtr driver,
                                         const char *dom_xml,
-                                        const char *dname);
+                                        const char *dname,
+                                        char **origname);
 
 int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
                                virConnectPtr dconn,
@@ -110,6 +111,7 @@ int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
                                int *cookieoutlen,
                                virStreamPtr st,
                                virDomainDefPtr *def,
+                               const char *origname,
                                unsigned long flags);
 
 int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
@@ -121,6 +123,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
                                const char *uri_in,
                                char **uri_out,
                                virDomainDefPtr *def,
+                               const char *origname,
                                unsigned long flags);
 
 int qemuMigrationPerform(virQEMUDriverPtr driver,
-- 
1.8.3.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]