[RFC PATCH 08/12] qemu: introduce qemuBuildCPUDeviceStr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



qemuBuildCPUDeviceStr being introduced is responsible for creating command
line argument for '-device' for given cpu device.

Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx>
---
 src/qemu/qemu_command.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_command.h |  5 +++++
 2 files changed, 55 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2ee3e10..824ad29 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5956,6 +5956,50 @@ static char *qemuBuildTPMDevStr(const virDomainDef *def,
 }
 
 
+int
+qemuBuildCPUDeviceStr(char **deviceStr,
+                      virDomainCPUDefPtr dev,
+                      virQEMUCapsPtr qemuCaps)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_QEMU64_CPU)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("%s not supported in this QEMU binary"), dev->driver);
+        goto error;
+    }
+
+    virBufferAsprintf(&buf, "%s,id=%s,apic-id=%d",
+                      dev->driver, dev->info.alias,
+                      dev->apic_id);
+
+    if (virBufferCheckError(&buf) < 0)
+        goto error;
+
+    *deviceStr = virBufferContentAndReset(&buf);
+    return 0;
+
+ error:
+    virBufferFreeAndReset(&buf);
+    return -1;
+}
+
+static int
+qemuBuildCPUDeviceCommandLine(virCommandPtr cmd,
+                              virDomainCPUDefPtr dev,
+                              virQEMUCapsPtr qemuCaps)
+{
+    char *devstr = NULL;
+
+    if (qemuBuildCPUDeviceStr(&devstr, dev, qemuCaps) < 0)
+        return -1;
+
+    virCommandAddArgList(cmd, "-device", devstr, NULL);
+    VIR_FREE(devstr);
+    return 0;
+}
+
+
 static char *qemuBuildSmbiosBiosStr(virSysinfoDefPtr def)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -9862,6 +9906,12 @@ qemuBuildCommandLine(virConnectPtr conn,
             goto error;
     }
 
+    /* add cpu devices */
+    for (i = 0; i < def->ncpus; i++) {
+        if (qemuBuildCPUDeviceCommandLine(cmd, def->cpus[i], qemuCaps) < 0)
+            goto error;
+    }
+
     if (def->nvram) {
         if (ARCH_IS_PPC64(def->os.arch) &&
             STRPREFIX(def->os.machine, "pseries")) {
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 2898876..ab161b1 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -92,6 +92,11 @@ qemuBuildChrDeviceStr(char **deviceStr,
                       virDomainChrDefPtr chr,
                       virQEMUCapsPtr qemuCaps);
 
+int
+qemuBuildCPUDeviceStr(char **deviceStr,
+                      virDomainCPUDefPtr cpu,
+                      virQEMUCapsPtr qemuCaps);
+
 /* With vlan == -1, use netdev syntax, else old hostnet */
 char *qemuBuildHostNetStr(virDomainNetDefPtr net,
                           virQEMUDriverPtr driver,
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]