[RFC PATCH v2 05/12] qemu_command: introduce a func for cpu device alias assignment

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

 



This function used to set a alias name for cpu device.

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

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 100deed..6201e29 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -948,6 +948,34 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def,
 }
 
 int
+qemuAssignDeviceCPUAlias(virDomainDefPtr def,
+                         virDomainCPUDefPtr cpu,
+                         int idx)
+{
+    if (idx == -1) {
+        size_t i;
+        idx = 0;
+
+        for (i = 0; i < def->ncpus; i++) {
+            int thisidx;
+            if ((thisidx = qemuDomainDeviceAliasIndex(&def->cpus[i]->info, "cpu")) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("unable to determine device index from CPU device"));
+                return -1;
+            }
+
+            if (thisidx >= idx)
+                idx = thisidx + 1;
+        }
+    }
+
+    if (virAsprintf(&cpu->info.alias, "cpu%d", idx) < 0)
+        return -1;
+
+    return 0;
+}
+
+int
 qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
 {
     size_t i;
@@ -1017,6 +1045,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
         if (qemuAssignDeviceChrAlias(def, def->consoles[i], i) < 0)
             return -1;
     }
+    for (i = 0; i< def->ncpus; i++) {
+        if (qemuAssignDeviceCPUAlias(def, def->cpus[i], i) < 0)
+            return -1;
+    }
     for (i = 0; i < def->nhubs; i++) {
         if (virAsprintf(&def->hubs[i]->info.alias, "hub%zu", i) < 0)
             return -1;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 8eaf1e4..c63fd30 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -265,6 +265,9 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, virDomainRedirdevDefPtr r
 int qemuAssignDeviceChrAlias(virDomainDefPtr def,
                              virDomainChrDefPtr chr,
                              ssize_t idx);
+int qemuAssignDeviceCPUAlias(virDomainDefPtr def,
+                             virDomainCPUDefPtr cpu,
+                             int idx);
 
 int
 qemuParseKeywords(const char *str,
-- 
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]