[PATCH v3 11/52] qemu: Flatten qemuMonitorCPUDefs.cpus

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

 



Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in
qemuMonitorCPUDefs rather then using an array of pointers.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>
---

Notes:
    Version 2:
    - trivial rebase
    
    Version 3:
    - minor change caused by g_new0 introduced in v3 of the previous
      patch

 src/qemu/qemu_capabilities.c | 14 +++++++-------
 src/qemu/qemu_monitor.c      |  7 +++----
 src/qemu/qemu_monitor.h      |  2 +-
 src/qemu/qemu_monitor_json.c |  7 +------
 tests/qemumonitorjsontest.c  |  8 ++++----
 5 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e8b857b8cf..af51a701b1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2473,11 +2473,11 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
         for (name = libvirtModels; name && *name; name++) {
             for (i = 0; i < defs->ncpus; i++) {
-                if (STRCASENEQ(defs->cpus[i]->name, *name))
+                if (STRCASENEQ(defs->cpus[i].name, *name))
                     continue;
 
-                VIR_FREE(defs->cpus[i]->name);
-                defs->cpus[i]->name = g_strdup(*name);
+                VIR_FREE(defs->cpus[i].name);
+                defs->cpus[i].name = g_strdup(*name);
             }
         }
     }
@@ -2488,13 +2488,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
     for (i = 0; i < defs->ncpus; i++) {
         virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
 
-        if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
+        if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES)
             usable = VIR_DOMCAPS_CPU_USABLE_YES;
-        else if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
+        else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO)
             usable = VIR_DOMCAPS_CPU_USABLE_NO;
 
-        if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i]->name, usable,
-                                           &defs->cpus[i]->blockers) < 0)
+        if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable,
+                                           &defs->cpus[i].blockers) < 0)
             goto cleanup;
     }
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 44c8ba2adb..f906472cd1 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3572,9 +3572,8 @@ qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs)
         return;
 
     for (i = 0; i < defs->ncpus; i++) {
-        g_strfreev(defs->cpus[i]->blockers);
-        g_free(defs->cpus[i]->name);
-        g_free(defs->cpus[i]);
+        g_strfreev(defs->cpus[i].blockers);
+        g_free(defs->cpus[i].name);
     }
 
     g_free(defs->cpus);
@@ -3588,7 +3587,7 @@ qemuMonitorCPUDefsNew(size_t count)
     g_autoptr(qemuMonitorCPUDefs) defs = NULL;
 
     defs = g_new0(qemuMonitorCPUDefs, 1);
-    defs->cpus = g_new0(qemuMonitorCPUDefInfoPtr, count);
+    defs->cpus = g_new0(qemuMonitorCPUDefInfo, count);
     defs->ncpus = count;
 
     return g_steal_pointer(&defs);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 00f4dd437f..f275e910cf 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1116,7 +1116,7 @@ typedef struct _qemuMonitorCPUDefs qemuMonitorCPUDefs;
 typedef qemuMonitorCPUDefs *qemuMonitorCPUDefsPtr;
 struct _qemuMonitorCPUDefs {
     size_t ncpus;
-    qemuMonitorCPUDefInfoPtr *cpus;
+    qemuMonitorCPUDefInfoPtr cpus;
 };
 
 int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8f04be79c1..a6cf70c70a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5611,12 +5611,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
     for (i = 0; i < defs->ncpus; i++) {
         virJSONValuePtr child = virJSONValueArrayGet(data, i);
         const char *tmp;
-        qemuMonitorCPUDefInfoPtr cpu;
-
-        if (VIR_ALLOC(cpu) < 0)
-            return -1;
-
-        defs->cpus[i] = cpu;
+        qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
 
         if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index c84ff0d6b4..81680d97f8 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -463,16 +463,16 @@ testQemuMonitorJSONGetCPUDefinitions(const void *opaque)
 
 #define CHECK_FULL(i, wantname, Usable) \
     do { \
-        if (STRNEQ(defs->cpus[i]->name, (wantname))) { \
+        if (STRNEQ(defs->cpus[i].name, (wantname))) { \
             virReportError(VIR_ERR_INTERNAL_ERROR, \
                            "name %s is not %s", \
-                           defs->cpus[i]->name, (wantname)); \
+                           defs->cpus[i].name, (wantname)); \
             return -1; \
         } \
-        if (defs->cpus[i]->usable != (Usable)) { \
+        if (defs->cpus[i].usable != (Usable)) { \
             virReportError(VIR_ERR_INTERNAL_ERROR, \
                            "%s: expecting usable flag %d, got %d", \
-                           defs->cpus[i]->name, Usable, defs->cpus[i]->usable); \
+                           defs->cpus[i].name, Usable, defs->cpus[i].usable); \
             return -1; \
         } \
     } while (0)
-- 
2.23.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