[PATCH 08/12] qemuMonitorJSONGetCPUDefinitions: Rework lookup of 'unavailable-features'

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

 



Rather than checking that the object has the correct key and then
fetching it again use fetch the array first and then use
virJSONValueArrayToStringList to directly convert it.

Additionally we can avoid the conversion if there are no members
simplifying the surrounding logic.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_monitor_json.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index a5800e182c..cbd1eb6eec 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4841,6 +4841,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitor *mon,
         virJSONValue *child = virJSONValueArrayGet(data, i);
         const char *tmp;
         qemuMonitorCPUDefInfo *cpu = defs->cpus + i;
+        virJSONValue *feat;

         if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -4853,16 +4854,14 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitor *mon,
         if ((tmp = virJSONValueObjectGetString(child, "typename")) && *tmp)
             cpu->type = g_strdup(tmp);

-        if (virJSONValueObjectHasKey(child, "unavailable-features")) {
-            if (!(cpu->blockers = virJSONValueObjectGetStringArray(child,
-                                                                   "unavailable-features")))
-                return -1;
+        if ((feat = virJSONValueObjectGetArray(child, "unavailable-features"))) {
+            if (virJSONValueArraySize(feat) > 0) {
+                if (!(cpu->blockers = virJSONValueArrayToStringList(feat)))
+                    return -1;

-            if (g_strv_length(cpu->blockers) == 0) {
-                cpu->usable = VIR_DOMCAPS_CPU_USABLE_YES;
-                g_clear_pointer(&cpu->blockers, g_strfreev);
-            } else {
                 cpu->usable = VIR_DOMCAPS_CPU_USABLE_NO;
+            } else {
+                cpu->usable = VIR_DOMCAPS_CPU_USABLE_YES;
             }
         }

-- 
2.38.1




[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