Extended the qemuMonitorCPUInfo with a halted flag. Extract the halted
flag for both text and JSON monitor.
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy(a)linux.vnet.ibm.com>
---
src/qemu/qemu_monitor.c | 6 +++++-
src/qemu/qemu_monitor.h | 5 +++++
src/qemu/qemu_monitor_json.c | 3 +++
src/qemu/qemu_monitor_text.c | 8 +++++++-
tests/qemumonitorjsontest.c | 8 ++++----
5 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index b9e2910..c61fac7 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1677,6 +1677,7 @@ qemuMonitorCPUInfoClear(qemuMonitorCPUInfoPtr cpus,
cpus[i].thread_id = -1;
cpus[i].vcpus = 0;
cpus[i].tid = 0;
+ cpus[i].halted = true;
VIR_FREE(cpus[i].qom_path);
VIR_FREE(cpus[i].alias);
@@ -1725,8 +1726,10 @@ qemuMonitorGetCPUInfoLegacy(struct qemuMonitorQueryCpusEntry
*cpuentries,
size_t i;
for (i = 0; i < maxvcpus; i++) {
- if (i < ncpuentries)
+ if (i < ncpuentries) {
vcpus[i].tid = cpuentries[i].tid;
+ vcpus[i].halted = cpuentries[i].halted;
+ }
/* for legacy hotplug to work we need to fake the vcpu count added by
* enabling a given vcpu */
@@ -1864,6 +1867,7 @@ qemuMonitorGetCPUInfoHotplug(struct
qemuMonitorQueryHotpluggableCpusEntry *hotpl
}
vcpus[anyvcpu].tid = cpuentries[j].tid;
+ vcpus[anyvcpu].halted = cpuentries[j].halted;
}
return 0;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 615ab3e..8d0aa01 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -394,6 +394,8 @@ int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
struct qemuMonitorQueryCpusEntry {
pid_t tid;
char *qom_path;
+ /* halted indicator */
+ bool halted;
};
void qemuMonitorQueryCpusFree(struct qemuMonitorQueryCpusEntry *entries,
size_t nentries);
@@ -441,6 +443,9 @@ struct _qemuMonitorCPUInfo {
/* internal for use in the matching code */
char *qom_path;
+
+ /* halted indicator */
+ bool halted;
};
typedef struct _qemuMonitorCPUInfo qemuMonitorCPUInfo;
typedef qemuMonitorCPUInfo *qemuMonitorCPUInfoPtr;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index de746f1..64f9d01 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1349,6 +1349,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
for (i = 0; i < ncpus; i++) {
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
int thread = 0;
+ bool halted = true;
const char *qom_path;
if (!entry) {
ret = -2;
@@ -1358,9 +1359,11 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
/* Some older qemu versions don't report the thread_id so treat this as
* non-fatal, simply returning no data */
ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id",
&thread));
+ ignore_value(virJSONValueObjectGetBoolean(entry, "halted",
&halted));
qom_path = virJSONValueObjectGetString(entry, "qom_path");
cpus[i].tid = thread;
+ cpus[i].halted = halted;
if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
goto cleanup;
}
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index ff7cc79..f975347 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -521,7 +521,7 @@ qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
* (qemu) info cpus
* * CPU #0: pc=0x00000000000f0c4a thread_id=30019
* CPU #1: pc=0x00000000fffffff0 thread_id=30020
- * CPU #2: pc=0x00000000fffffff0 thread_id=30021
+ * CPU #2: pc=0x00000000fffffff0 (halted) thread_id=30021
*
*/
line = qemucpus;
@@ -541,6 +541,12 @@ qemuMonitorTextQueryCPUs(qemuMonitorPtr mon,
cpu.tid = tid;
+ /* Extract halted indicator */
+ if ((offset = strstr(line, "(halted)")) != NULL)
+ cpu.halted = true;
+ else
+ cpu.halted = false;
+
if (VIR_APPEND_ELEMENT_COPY(cpus, ncpus, cpu) < 0) {
ret = -1;
goto cleanup;
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 9e195d7..8749ea1 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1221,10 +1221,10 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
int ret = -1;
struct qemuMonitorQueryCpusEntry *cpudata = NULL;
struct qemuMonitorQueryCpusEntry expect[] = {
- {17622, (char *) "/machine/unattached/device[0]"},
- {17624, (char *) "/machine/unattached/device[1]"},
- {17626, (char *) "/machine/unattached/device[2]"},
- {17628, NULL},
+ {17622, (char *) "/machine/unattached/device[0]", true},
+ {17624, (char *) "/machine/unattached/device[1]", true},
+ {17626, (char *) "/machine/unattached/device[2]", true},
+ {17628, NULL, true},
};
size_t ncpudata = 0;
size_t i;
--
1.9.1