[PATCH v2 08/73] qemu: Allocate struct for migration parameters

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

 



It will get a bit more complicated soon and storing it on a stack with
{0} initializer will no longer work. We need a proper constructor.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c           | 20 +++++++++++------
 src/qemu/qemu_migration.c        | 28 ++++++++++++++---------
 src/qemu/qemu_migration_params.c | 38 +++++++++++++++++++++++---------
 src/qemu/qemu_migration_params.h |  3 +++
 4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bf6c0d0826..c157ff9bb0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12241,7 +12241,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
     int ret = -1;
     const char *dconnuri = NULL;
     qemuMigrationCompressionPtr compression = NULL;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
@@ -12252,6 +12252,9 @@ qemuDomainMigratePerform(virDomainPtr dom,
         goto cleanup;
     }
 
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
     if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
         goto cleanup;
 
@@ -12276,12 +12279,12 @@ qemuDomainMigratePerform(virDomainPtr dom,
      */
     ret = qemuMigrationSrcPerform(driver, dom->conn, vm, NULL,
                                   NULL, dconnuri, uri, NULL, NULL, 0, NULL, 0,
-                                  compression, &migParams, cookie, cookielen,
+                                  compression, migParams, cookie, cookielen,
                                   NULL, NULL, /* No output cookies in v2 */
                                   flags, dname, resource, false);
 
  cleanup:
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
     VIR_FREE(compression);
     return ret;
 }
@@ -12666,13 +12669,16 @@ qemuDomainMigratePerform3(virDomainPtr dom,
     virQEMUDriverPtr driver = dom->conn->privateData;
     virDomainObjPtr vm;
     qemuMigrationCompressionPtr compression = NULL;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
     if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-        return -1;
+        goto cleanup;
 
     if (!(vm = qemuDomObjFromDomain(dom)))
         goto cleanup;
@@ -12684,13 +12690,13 @@ qemuDomainMigratePerform3(virDomainPtr dom,
 
     ret = qemuMigrationSrcPerform(driver, dom->conn, vm, xmlin, NULL,
                                   dconnuri, uri, NULL, NULL, 0, NULL, 0,
-                                  compression, &migParams,
+                                  compression, migParams,
                                   cookiein, cookieinlen,
                                   cookieout, cookieoutlen,
                                   flags, dname, resource, true);
 
  cleanup:
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
     VIR_FREE(compression);
     return ret;
 }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 57903c7b17..a0061c8c83 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2251,7 +2251,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
     int rv;
     char *tlsAlias = NULL;
     char *secAlias = NULL;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
 
     virNWFilterReadLockFilterUpdates();
 
@@ -2301,6 +2301,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
     if (!qemuMigrationSrcIsAllowedHostdev(*def))
         goto cleanup;
 
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
     /* Let migration hook filter domain XML */
     if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
         char *xml;
@@ -2445,7 +2448,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
     }
 
     if (qemuMigrationParamsSetCompression(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
-                                          compression, &migParams) < 0)
+                                          compression, migParams) < 0)
         goto stopjob;
 
     /* Migrations using TLS need to add the "tls-creds-x509" object and
@@ -2458,17 +2461,17 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 
         if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, true,
                                              QEMU_ASYNC_JOB_MIGRATION_IN,
-                                             &tlsAlias, &secAlias, &migParams) < 0)
+                                             &tlsAlias, &secAlias, migParams) < 0)
             goto stopjob;
 
         /* Force reset of 'tls-hostname', it's a source only parameter */
-        if (VIR_STRDUP(migParams.tlsHostname, "") < 0)
+        if (VIR_STRDUP(migParams->tlsHostname, "") < 0)
             goto stopjob;
 
     } else {
         if (qemuMigrationParamsSetEmptyTLS(driver, vm,
                                            QEMU_ASYNC_JOB_MIGRATION_IN,
-                                           &migParams) < 0)
+                                           migParams) < 0)
             goto stopjob;
     }
 
@@ -2489,7 +2492,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
 
     if (qemuMigrationParamsSet(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
-                               &migParams) < 0)
+                               migParams) < 0)
         goto stopjob;
 
     if (mig->nbd &&
@@ -2577,7 +2580,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
         virDomainObjRemoveTransientDef(vm);
         qemuDomainRemoveInactiveJob(driver, vm);
     }
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
     virDomainObjEndAPI(&vm);
     qemuDomainEventQueue(driver, event);
     qemuMigrationCookieFree(mig);
@@ -3881,7 +3884,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
     virStreamPtr st = NULL;
     unsigned long destflags;
     qemuMigrationCompressionPtr compression = NULL;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
 
     VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, dconnuri=%s, "
               "flags=0x%lx, dname=%s, resource=%lu",
@@ -3903,6 +3906,9 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
     destflags = flags & ~(VIR_MIGRATE_ABORT_ON_ERROR |
                           VIR_MIGRATE_AUTO_CONVERGE);
 
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
     if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
         goto cleanup;
 
@@ -3958,13 +3964,13 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
         ret = qemuMigrationSrcPerformTunnel(driver, vm, st, NULL,
                                             NULL, 0, NULL, NULL,
                                             flags, resource, dconn,
-                                            NULL, 0, NULL, compression, &migParams);
+                                            NULL, 0, NULL, compression, migParams);
     else
         ret = qemuMigrationSrcPerformNative(driver, vm, NULL, uri_out,
                                             cookie, cookielen,
                                             NULL, NULL, /* No out cookie with v2 migration */
                                             flags, resource, dconn, NULL, 0, NULL,
-                                            compression, &migParams);
+                                            compression, migParams);
 
     /* Perform failed. Make sure Finish doesn't overwrite the error */
     if (ret < 0)
@@ -4004,7 +4010,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
         virSetError(orig_err);
         virFreeError(orig_err);
     }
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
     VIR_FREE(uri_out);
     VIR_FREE(cookie);
     VIR_FREE(compression);
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 784b1b9254..95ceed4e14 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -38,6 +38,18 @@ VIR_LOG_INIT("qemu.qemu_migration_params");
 #define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
 
 
+qemuMonitorMigrationParamsPtr
+qemuMigrationParamsNew(void)
+{
+    qemuMonitorMigrationParamsPtr params;
+
+    if (VIR_ALLOC(params) < 0)
+        return NULL;
+
+    return params;
+}
+
+
 void
 qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr migParams)
 {
@@ -67,7 +79,7 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 {
     qemuMonitorMigrationParamsPtr migParams;
 
-    if (VIR_ALLOC(migParams) < 0)
+    if (!(migParams = qemuMigrationParamsNew()))
         return NULL;
 
     if (!params)
@@ -151,16 +163,19 @@ qemuMigrationParamsCheckTLSCreds(virQEMUDriverPtr driver,
 {
     int ret = -1;
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
 
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
         return -1;
 
-    if (qemuMonitorGetMigrationParams(priv->mon, &migParams) < 0)
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
+    if (qemuMonitorGetMigrationParams(priv->mon, migParams) < 0)
         goto cleanup;
 
     /* NB: Could steal NULL pointer too! Let caller decide what to do. */
-    VIR_STEAL_PTR(priv->migTLSAlias, migParams.tlsCreds);
+    VIR_STEAL_PTR(priv->migTLSAlias, migParams->tlsCreds);
 
     ret = 0;
 
@@ -168,7 +183,7 @@ qemuMigrationParamsCheckTLSCreds(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         ret = -1;
 
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
 
     return ret;
 }
@@ -384,7 +399,7 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     char *tlsAlias = NULL;
     char *secAlias = NULL;
-    qemuMonitorMigrationParams migParams = { 0 };
+    qemuMonitorMigrationParamsPtr migParams = NULL;
     int ret = -1;
 
     if (qemuMigrationParamsCheckTLSCreds(driver, vm, asyncJob) < 0)
@@ -395,6 +410,9 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
     if (!priv->migTLSAlias || !*priv->migTLSAlias)
         return 0;
 
+    if (!(migParams = qemuMigrationParamsNew()))
+        goto cleanup;
+
     /* NB: If either or both fail to allocate memory we can still proceed
      *     since the next time we migrate another deletion attempt will be
      *     made after successfully generating the aliases. */
@@ -404,9 +422,9 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
     qemuDomainDelTLSObjects(driver, vm, asyncJob, secAlias, tlsAlias);
     qemuDomainSecretInfoFree(&priv->migSecinfo);
 
-    if (VIR_STRDUP(migParams.tlsCreds, "") < 0 ||
-        VIR_STRDUP(migParams.tlsHostname, "") < 0 ||
-        qemuMigrationParamsSet(driver, vm, asyncJob, &migParams) < 0)
+    if (VIR_STRDUP(migParams->tlsCreds, "") < 0 ||
+        VIR_STRDUP(migParams->tlsHostname, "") < 0 ||
+        qemuMigrationParamsSet(driver, vm, asyncJob, migParams) < 0)
         goto cleanup;
 
     ret = 0;
@@ -414,7 +432,7 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
  cleanup:
     VIR_FREE(tlsAlias);
     VIR_FREE(secAlias);
-    qemuMigrationParamsClear(&migParams);
+    qemuMigrationParamsFree(migParams);
 
     return ret;
 }
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 1f28d8d606..cbc63b9cbf 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -28,6 +28,9 @@
 # include "qemu_conf.h"
 
 
+qemuMonitorMigrationParamsPtr
+qemuMigrationParamsNew(void);
+
 qemuMonitorMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
                              int nparams,
-- 
2.17.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux