render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
6ae9ed
From 06dad6304cfc9e14c505f4ea24e8e995776091e2 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <06dad6304cfc9e14c505f4ea24e8e995776091e2@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:22 -0400
6ae9ed
Subject: [PATCH] qemu: monitor: Extract QOM path from query-cpus reply
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
To allow matching up the data returned by query-cpus to entries in the
6ae9ed
query-hotpluggable-cpus reply for CPU hotplug it's necessary to extract
6ae9ed
the QOM path as it's the only link between the two.
6ae9ed
6ae9ed
(cherry picked from commit c91be16b9ff0bfb8f6db400db4ae36c8a47842fc)
6ae9ed
---
6ae9ed
 src/qemu/qemu_monitor.c      |  7 ++++++-
6ae9ed
 src/qemu/qemu_monitor.h      |  1 +
6ae9ed
 src/qemu/qemu_monitor_json.c | 16 ++++++++++++++--
6ae9ed
 tests/qemumonitorjsontest.c  | 14 +++++++++-----
6ae9ed
 4 files changed, 30 insertions(+), 8 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
6ae9ed
index d5af7d1..573c94a 100644
6ae9ed
--- a/src/qemu/qemu_monitor.c
6ae9ed
+++ b/src/qemu/qemu_monitor.c
6ae9ed
@@ -1663,11 +1663,16 @@ qemuMonitorCPUInfoFree(qemuMonitorCPUInfoPtr cpus,
6ae9ed
 
6ae9ed
 void
6ae9ed
 qemuMonitorQueryCpusFree(struct qemuMonitorQueryCpusEntry *entries,
6ae9ed
-                         size_t nentries ATTRIBUTE_UNUSED)
6ae9ed
+                         size_t nentries)
6ae9ed
 {
6ae9ed
+    size_t i;
6ae9ed
+
6ae9ed
     if (!entries)
6ae9ed
         return;
6ae9ed
 
6ae9ed
+    for (i = 0; i < nentries; i++)
6ae9ed
+        VIR_FREE(entries[i].qom_path);
6ae9ed
+
6ae9ed
     VIR_FREE(entries);
6ae9ed
 }
6ae9ed
 
6ae9ed
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
6ae9ed
index 2269d60..83396a4 100644
6ae9ed
--- a/src/qemu/qemu_monitor.h
6ae9ed
+++ b/src/qemu/qemu_monitor.h
6ae9ed
@@ -392,6 +392,7 @@ int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
6ae9ed
 
6ae9ed
 struct qemuMonitorQueryCpusEntry {
6ae9ed
     pid_t tid;
6ae9ed
+    char *qom_path;
6ae9ed
 };
6ae9ed
 void qemuMonitorQueryCpusFree(struct qemuMonitorQueryCpusEntry *entries,
6ae9ed
                               size_t nentries);
6ae9ed
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
6ae9ed
index 8243b52..a59b195 100644
6ae9ed
--- a/src/qemu/qemu_monitor_json.c
6ae9ed
+++ b/src/qemu/qemu_monitor_json.c
6ae9ed
@@ -1325,8 +1325,16 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
6ae9ed
 
6ae9ed
 
6ae9ed
 /*
6ae9ed
- * [ { "CPU": 0, "current": true, "halted": false, "pc": 3227107138 },
6ae9ed
- *   { "CPU": 1, "current": false, "halted": true, "pc": 7108165 } ]
6ae9ed
+ *
6ae9ed
+ * [{ "arch": "x86",
6ae9ed
+ *    "current": true,
6ae9ed
+ *    "CPU": 0,
6ae9ed
+ *    "qom_path": "/machine/unattached/device[0]",
6ae9ed
+ *    "pc": -2130415978,
6ae9ed
+ *    "halted": true,
6ae9ed
+ *    "thread_id": 2631237},
6ae9ed
+ *    {...}
6ae9ed
+ *  ]
6ae9ed
  */
6ae9ed
 static int
6ae9ed
 qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
6ae9ed
@@ -1347,6 +1355,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
6ae9ed
     for (i = 0; i < ncpus; i++) {
6ae9ed
         virJSONValuePtr entry = virJSONValueArrayGet(data, i);
6ae9ed
         int thread = 0;
6ae9ed
+        const char *qom_path;
6ae9ed
         if (!entry) {
6ae9ed
             ret = -2;
6ae9ed
             goto cleanup;
6ae9ed
@@ -1355,8 +1364,11 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
6ae9ed
         /* Some older qemu versions don't report the thread_id so treat this as
6ae9ed
          * non-fatal, simply returning no data */
6ae9ed
         ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id", &thread));
6ae9ed
+        qom_path = virJSONValueObjectGetString(entry, "qom_path");
6ae9ed
 
6ae9ed
         cpus[i].tid = thread;
6ae9ed
+        if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
6ae9ed
+            goto cleanup;
6ae9ed
     }
6ae9ed
 
6ae9ed
     VIR_STEAL_PTR(*entries, cpus);
6ae9ed
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
6ae9ed
index 3fd4eb6..8c31005 100644
6ae9ed
--- a/tests/qemumonitorjsontest.c
6ae9ed
+++ b/tests/qemumonitorjsontest.c
6ae9ed
@@ -1205,7 +1205,8 @@ static bool
6ae9ed
 testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntry *a,
6ae9ed
                                                  struct qemuMonitorQueryCpusEntry *b)
6ae9ed
 {
6ae9ed
-    if (a->tid != b->tid)
6ae9ed
+    if (a->tid != b->tid ||
6ae9ed
+        STRNEQ_NULLABLE(a->qom_path, b->qom_path))
6ae9ed
         return false;
6ae9ed
 
6ae9ed
     return true;
6ae9ed
@@ -1220,10 +1221,10 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
6ae9ed
     int ret = -1;
6ae9ed
     struct qemuMonitorQueryCpusEntry *cpudata = NULL;
6ae9ed
     struct qemuMonitorQueryCpusEntry expect[] = {
6ae9ed
-        {17622},
6ae9ed
-        {17624},
6ae9ed
-        {17626},
6ae9ed
-        {17628},
6ae9ed
+        {17622, (char *) "/machine/unattached/device[0]"},
6ae9ed
+        {17624, (char *) "/machine/unattached/device[1]"},
6ae9ed
+        {17626, (char *) "/machine/unattached/device[2]"},
6ae9ed
+        {17628, NULL},
6ae9ed
     };
6ae9ed
     size_t ncpudata = 0;
6ae9ed
     size_t i;
6ae9ed
@@ -1237,6 +1238,7 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
6ae9ed
                                "        {"
6ae9ed
                                "            \"current\": true,"
6ae9ed
                                "            \"CPU\": 0,"
6ae9ed
+                               "            \"qom_path\": \"/machine/unattached/device[0]\","
6ae9ed
                                "            \"pc\": -2130530478,"
6ae9ed
                                "            \"halted\": true,"
6ae9ed
                                "            \"thread_id\": 17622"
6ae9ed
@@ -1244,6 +1246,7 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
6ae9ed
                                "        {"
6ae9ed
                                "            \"current\": false,"
6ae9ed
                                "            \"CPU\": 1,"
6ae9ed
+                               "            \"qom_path\": \"/machine/unattached/device[1]\","
6ae9ed
                                "            \"pc\": -2130530478,"
6ae9ed
                                "            \"halted\": true,"
6ae9ed
                                "            \"thread_id\": 17624"
6ae9ed
@@ -1251,6 +1254,7 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
6ae9ed
                                "        {"
6ae9ed
                                "            \"current\": false,"
6ae9ed
                                "            \"CPU\": 2,"
6ae9ed
+                               "            \"qom_path\": \"/machine/unattached/device[2]\","
6ae9ed
                                "            \"pc\": -2130530478,"
6ae9ed
                                "            \"halted\": true,"
6ae9ed
                                "            \"thread_id\": 17626"
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed