]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Add monitor support for CPU halted state
authorViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Thu, 13 Oct 2016 11:42:44 +0000 (13:42 +0200)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 24 Oct 2016 22:52:36 +0000 (18:52 -0400)
Extended the qemuMonitorCPUInfo with a halted flag. Extract the halted
flag for both text and JSON monitor.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_text.c
tests/qemumonitorjsontest.c

index 5175f4eaa890dab39b9694d1d77eeb1702c2624a..d9f66a2bfc08d0506bdcc46d110d127c0746c0c3 100644 (file)
@@ -1677,6 +1677,7 @@ qemuMonitorCPUInfoClear(qemuMonitorCPUInfoPtr cpus,
         cpus[i].thread_id = -1;
         cpus[i].vcpus = 0;
         cpus[i].tid = 0;
+        cpus[i].halted = false;
 
         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;
index 7d78e5b0fb2bb02785e3a52d4b75834ab5d6d147..cb27412b6d442aacd23268ae32b33e7199eed7eb 100644 (file)
@@ -394,6 +394,7 @@ int qemuMonitorSystemPowerdown(qemuMonitorPtr mon);
 struct qemuMonitorQueryCpusEntry {
     pid_t tid;
     char *qom_path;
+    bool halted;
 };
 void qemuMonitorQueryCpusFree(struct qemuMonitorQueryCpusEntry *entries,
                               size_t nentries);
@@ -441,6 +442,8 @@ struct _qemuMonitorCPUInfo {
 
     /* internal for use in the matching code */
     char *qom_path;
+
+    bool halted;
 };
 typedef struct _qemuMonitorCPUInfo qemuMonitorCPUInfo;
 typedef qemuMonitorCPUInfo *qemuMonitorCPUInfoPtr;
index b93220b981740865f547a7060192f98eb1925644..dff6d42cfca033298b42ad569a55bd914bfe9d9e 100644 (file)
@@ -1349,6 +1349,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
     for (i = 0; i < ncpus; i++) {
         virJSONValuePtr entry = virJSONValueArrayGet(data, i);
         int thread = 0;
+        bool halted = false;
         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;
     }
index ff7cc79fda4bcdbc654410da21b82fc8a016f644..f9753476b0af14adcf9b7fceafe96f6118feed3c 100644 (file)
@@ -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;
index 993a373c31cb3c81b53d42e091e2d1a5a57aa6ad..5e72a0f6be1ba2326ce7f07e1c5cc539d8e43957 100644 (file)
@@ -1332,10 +1332,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;