Blob Blame History Raw
From dc796a3d8488292fe7088372a23046681f4d0a11 Mon Sep 17 00:00:00 2001
Message-Id: <dc796a3d8488292fe7088372a23046681f4d0a11@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 24 Aug 2016 16:11:35 -0400
Subject: [PATCH] qemu: command: Add helper to convert vcpu definition to JSON
 props

https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341

For use on the monitor we need to format certain parts of the vcpu
private definition into a JSON object. Add a helper.

(cherry picked from commit 8807f28b8541b59704df4f90ace06b622ab77866)
---
 src/qemu/qemu_command.c | 30 ++++++++++++++++++++++++++++++
 src/qemu/qemu_command.h |  3 +++
 2 files changed, 33 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 57b04ee..95055c4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9823,3 +9823,33 @@ qemuBuildChrDeviceStr(char **deviceStr,
 
     return ret;
 }
+
+
+virJSONValuePtr
+qemuBuildHotpluggableCPUProps(const virDomainVcpuDef *vcpu)
+{
+    qemuDomainVcpuPrivatePtr vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu);
+    virJSONValuePtr ret = NULL;
+
+    if (virJSONValueObjectCreate(&ret, "s:driver", vcpupriv->type,
+                                       "s:id", vcpupriv->alias, NULL) < 0)
+        goto error;
+
+    if (vcpupriv->socket_id != -1 &&
+        virJSONValueObjectAdd(ret, "i:socket-id", vcpupriv->socket_id, NULL) < 0)
+        goto error;
+
+    if (vcpupriv->core_id != -1 &&
+        virJSONValueObjectAdd(ret, "i:core-id", vcpupriv->core_id, NULL) < 0)
+        goto error;
+
+    if (vcpupriv->thread_id != -1 &&
+        virJSONValueObjectAdd(ret, "i:thread-id", vcpupriv->thread_id, NULL) < 0)
+        goto error;
+
+    return ret;
+
+ error:
+    virJSONValueFree(ret);
+    return NULL;
+}
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index c4d0567..36cfc51 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -180,4 +180,7 @@ bool qemuCheckCCWS390AddressSupport(const virDomainDef *def,
                                     virQEMUCapsPtr qemuCaps,
                                     const char *devicename);
 
+virJSONValuePtr qemuBuildHotpluggableCPUProps(const virDomainVcpuDef *vcpu)
+    ATTRIBUTE_NONNULL(1);
+
 #endif /* __QEMU_COMMAND_H__*/
-- 
2.10.0