[PATCH 004/103] qemuBuildMemoryCellBackendStr: Return JSON props instead of a buffer

Peter Krempa pkrempa at redhat.com
Thu Oct 7 15:16:52 UTC 2021


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 at redhat.com>
---
 src/qemu/qemu_command.c | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 28bca1519c..dcd6a6e75d 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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);
 }


@@ -7388,7 +7379,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;
@@ -7408,7 +7399,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 */
@@ -7418,8 +7409,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)
@@ -7448,8 +7439,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");
@@ -7507,7 +7504,7 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg,
  cleanup:
     if (nodeBackends) {
         for (i = 0; i < ncells; i++)
-            virBufferFreeAndReset(&nodeBackends[i]);
+            virJSONValueFree(nodeBackends[i]);

         VIR_FREE(nodeBackends);
     }
-- 
2.31.1




More information about the libvir-list mailing list