6ae9ed
From b6f5a9033bbed6d3b4567544b7f6556c7b4e1861 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <b6f5a9033bbed6d3b4567544b7f6556c7b4e1861@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:10:51 -0400
6ae9ed
Subject: [PATCH] qemu: Add cpu ID to the vCPU pid list in the status XML
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
Note the vcpu ID so that once we allow non-contiguous vCPU topologies it
6ae9ed
will be possible to pair thread id's with the vcpus.
6ae9ed
6ae9ed
(cherry picked from commit 3f57ce4a7675958c4c0f6aaddfbc2e3c2e8473da)
6ae9ed
---
6ae9ed
 src/qemu/qemu_domain.c  | 13 ++++++++++++-
6ae9ed
 tests/qemuxml2xmltest.c |  3 ++-
6ae9ed
 2 files changed, 14 insertions(+), 2 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
6ae9ed
index 01f0d6a..c27129e 100644
6ae9ed
--- a/src/qemu/qemu_domain.c
6ae9ed
+++ b/src/qemu/qemu_domain.c
6ae9ed
@@ -1368,7 +1368,7 @@ qemuDomainObjPrivateXMLFormatVcpus(virBufferPtr buf,
6ae9ed
     virBufferAdjustIndent(buf, 2);
6ae9ed
 
6ae9ed
     for (i = 0; i < nvcpupids; i++)
6ae9ed
-        virBufferAsprintf(buf, "<vcpu pid='%d'/>\n", vcpupids[i]);
6ae9ed
+        virBufferAsprintf(buf, "<vcpu id='%zu' pid='%d'/>\n", i, vcpupids[i]);
6ae9ed
 
6ae9ed
     virBufferAdjustIndent(buf, -2);
6ae9ed
     virBufferAddLit(buf, "</vcpus>\n");
6ae9ed
@@ -1497,9 +1497,19 @@ qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node,
6ae9ed
                                  unsigned int idx,
6ae9ed
                                  qemuDomainObjPrivatePtr priv)
6ae9ed
 {
6ae9ed
+    char *idstr;
6ae9ed
     char *pidstr;
6ae9ed
     int ret = -1;
6ae9ed
 
6ae9ed
+    if ((idstr = virXMLPropString(node, "id"))) {
6ae9ed
+        if (virStrToLong_uip(idstr, NULL, 10, &idx) < 0 ||
6ae9ed
+            idx >= priv->nvcpupids) {
6ae9ed
+            virReportError(VIR_ERR_INTERNAL_ERROR,
6ae9ed
+                           _("invalid vcpu index '%s'"), idstr);
6ae9ed
+            goto cleanup;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
     if (!(pidstr = virXMLPropString(node, "pid")))
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
@@ -1509,6 +1519,7 @@ qemuDomainObjPrivateXMLParseVcpu(xmlNodePtr node,
6ae9ed
     ret = 0;
6ae9ed
 
6ae9ed
  cleanup:
6ae9ed
+    VIR_FREE(idstr);
6ae9ed
     VIR_FREE(pidstr);
6ae9ed
     return ret;
6ae9ed
 }
6ae9ed
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
6ae9ed
index 573899f..639494b 100644
6ae9ed
--- a/tests/qemuxml2xmltest.c
6ae9ed
+++ b/tests/qemuxml2xmltest.c
6ae9ed
@@ -113,7 +113,8 @@ testGetStatuXMLPrefixVcpus(virBufferPtr buf,
6ae9ed
     virBufferAdjustIndent(buf, 2);
6ae9ed
 
6ae9ed
     while ((vcpuid = virBitmapNextSetBit(data->activeVcpus, vcpuid)) >= 0)
6ae9ed
-        virBufferAsprintf(buf, "<vcpu pid='%zd'/>\n", vcpuid + 3803519);
6ae9ed
+        virBufferAsprintf(buf, "<vcpu id='%zd' pid='%zd'/>\n",
6ae9ed
+                          vcpuid, vcpuid + 3803519);
6ae9ed
 
6ae9ed
     virBufferAdjustIndent(buf, -2);
6ae9ed
     virBufferAddLit(buf, "</vcpus>\n");
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed