This function used to set a alias name for cpu device.
Signed-off-by: Zhu Guihua <zhugh.fnst(a)cn.fujitsu.com>
---
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 c041ee7..69d0a2a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -946,6 +946,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;
@@ -1015,6 +1043,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 dcc7127..2898876 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -264,6 +264,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