]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildMemoryCellBackendStr: Return JSON props instead of a buffer
authorPeter Krempa <pkrempa@redhat.com>
Fri, 24 Sep 2021 13:37:17 +0000 (15:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Oct 2021 08:25:59 +0000 (10:25 +0200)
Rename the function to 'qemuBuildMemoryCellBackendProps' and return the
properties before conversion to commandline arguments. This requires
changes in the caller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c

index 5b7a3e5bc3ff6ff09a77f573847ba1bff3f2a063..228d159699f542b58bbcb2d776fcfa5987e47df4 100644 (file)
@@ -3188,15 +3188,13 @@ qemuBuildMemoryBackendProps(virJSONValue **backendProps,
 
 
 static int
-qemuBuildMemoryCellBackendStr(virDomainDef *def,
-                              virQEMUDriverConfig *cfg,
-                              size_t cell,
-                              qemuDomainObjPrivate *priv,
-                              virBuffer *buf)
+qemuBuildMemoryCellBackendProps(virDomainDef *def,
+                                virQEMUDriverConfig *cfg,
+                                size_t cell,
+                                qemuDomainObjPrivate *priv,
+                                virJSONValue **props)
 {
-    g_autoptr(virJSONValue) props = NULL;
     g_autofree char *alias = NULL;
-    int rc;
     virDomainMemoryDef mem = { 0 };
     unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa,
                                                                 cell);
@@ -3207,14 +3205,7 @@ qemuBuildMemoryCellBackendStr(virDomainDef *def,
     mem.targetNode = cell;
     mem.info.alias = alias;
 
-    if ((rc = qemuBuildMemoryBackendProps(&props, alias, cfg,
-                                          priv, def, &mem, false, false)) < 0)
-        return -1;
-
-    if (qemuBuildObjectCommandlineFromJSON(buf, props, priv->qemuCaps) < 0)
-        return -1;
-
-    return rc;
+    return qemuBuildMemoryBackendProps(props, alias, cfg, priv, def, &mem, false, false);
 }
 
 
@@ -7407,7 +7398,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
     size_t i, j;
     virQEMUCaps *qemuCaps = priv->qemuCaps;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-    virBuffer *nodeBackends = NULL;
+    virJSONValue **nodeBackends = NULL;
     bool needBackend = false;
     bool hmat = false;
     int ret = -1;
@@ -7427,7 +7418,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
         hmat = true;
     }
 
-    nodeBackends = g_new0(virBuffer, ncells);
+    nodeBackends = g_new0(virJSONValue *, ncells);
 
     /* using of -numa memdev= cannot be combined with -numa mem=, thus we
      * need to check which approach to use */
@@ -7437,8 +7428,8 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
         int rc;
 
         for (i = 0; i < ncells; i++) {
-            if ((rc = qemuBuildMemoryCellBackendStr(def, cfg, i, priv,
-                                                    &nodeBackends[i])) < 0)
+            if ((rc = qemuBuildMemoryCellBackendProps(def, cfg, i, priv,
+                                                      &nodeBackends[i])) < 0)
                 goto cleanup;
 
             if (rc == 0)
@@ -7467,8 +7458,14 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
         ssize_t initiator = virDomainNumaGetNodeInitiator(def->numa, i);
 
         if (needBackend) {
+            g_auto(virBuffer) objbuf = VIR_BUFFER_INITIALIZER;
+
+            if (qemuBuildObjectCommandlineFromJSON(&objbuf, nodeBackends[i],
+                                                   priv->qemuCaps) < 0)
+                goto cleanup;
+
             virCommandAddArg(cmd, "-object");
-            virCommandAddArgBuffer(cmd, &nodeBackends[i]);
+            virCommandAddArgBuffer(cmd, &objbuf);
         }
 
         virCommandAddArg(cmd, "-numa");
@@ -7526,7 +7523,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
  cleanup:
     if (nodeBackends) {
         for (i = 0; i < ncells; i++)
-            virBufferFreeAndReset(&nodeBackends[i]);
+            virJSONValueFree(nodeBackends[i]);
 
         VIR_FREE(nodeBackends);
     }