This function used to set a alias name for memory 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 536abc3..68fdab7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -946,6 +946,34 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def,
}
int
+qemuAssignDeviceDimmAlias(virDomainDefPtr def,
+ virDomainDimmDefPtr dimm,
+ int idx)
+{
+ if (idx == -1) {
+ size_t i;
+ idx = 0;
+
+ for (i = 0; i < def->ndimms; i++) {
+ int thisidx;
+ if ((thisidx = qemuDomainDeviceAliasIndex(&def->dimms[i]->info,
"dimm")) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("unable to determine device index from dimm
device"));
+ return -1;
+ }
+
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
+ }
+
+ if (virAsprintf(&dimm->info.alias, "dimm%d", idx) < 0)
+ return -1;
+
+ return 0;
+}
+
+int
qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
{
size_t i;
@@ -1039,6 +1067,10 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr
qemuCaps)
if (virAsprintf(&def->rngs[i]->info.alias, "rng%zu", i) <
0)
return -1;
}
+ for (i = 0; i < def->ndimms; i++) {
+ if (qemuAssignDeviceDimmAlias(def, def->dimms[i], i) < 0)
+ return -1;
+ }
if (def->tpm) {
if (virAsprintf(&def->tpm->info.alias, "tpm%d", 0) < 0)
return -1;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index dcc7127..512d444 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 qemuAssignDeviceDimmAlias(virDomainDefPtr def,
+ virDomainDimmDefPtr dimm,
+ int idx);
int
qemuParseKeywords(const char *str,
--
1.9.3