diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 9737158488..8521a44ff8 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -332,17 +332,34 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def, } +/** + * qemuAssignDeviceMemoryAlias: + * @def: domain definition. Necessary only if @oldAlias is true. + * @mem: memory device definition + * @oldAlias: Generate the alias according to the order of the device in @def + * rather than according to the slot number for legacy reasons. + * + * Generates alias for a memory device according to slot number if @oldAlias is + * false or according to order in @def->mems otherwise. + * + * Returns 0 on success, -1 on error. + */ int qemuAssignDeviceMemoryAlias(virDomainDefPtr def, - virDomainMemoryDefPtr mem) + virDomainMemoryDefPtr mem, + bool oldAlias) { size_t i; int maxidx = 0; int idx; - for (i = 0; i < def->nmems; i++) { - if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= maxidx) - maxidx = idx + 1; + if (oldAlias) { + for (i = 0; i < def->nmems; i++) { + if ((idx = qemuDomainDeviceAliasIndex(&def->mems[i]->info, "dimm")) >= maxidx) + maxidx = idx + 1; + } + } else { + maxidx = mem->info.addr.dimm.slot; } if (virAsprintf(&mem->info.alias, "dimm%d", maxidx) < 0) @@ -475,7 +492,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) return -1; } for (i = 0; i < def->nmems; i++) { - if (virAsprintf(&def->mems[i]->info.alias, "dimm%zu", i) < 0) + if (qemuAssignDeviceMemoryAlias(NULL, def->mems[i], false) < 0) return -1; } diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h index d298a4dab2..dea05cf992 100644 --- a/src/qemu/qemu_alias.h +++ b/src/qemu/qemu_alias.h @@ -58,7 +58,8 @@ int qemuAssignDeviceRNGAlias(virDomainDefPtr def, virDomainRNGDefPtr rng); int qemuAssignDeviceMemoryAlias(virDomainDefPtr def, - virDomainMemoryDefPtr mems); + virDomainMemoryDefPtr mems, + bool oldAlias); int qemuAssignDeviceShmemAlias(virDomainDefPtr def, virDomainShmemDefPtr shmem, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7a023d2974..1bc27068bb 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2135,7 +2135,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (qemuDomainAssignMemoryDeviceSlot(vm->def, mem) < 0) goto cleanup; - if (qemuAssignDeviceMemoryAlias(vm->def, mem) < 0) + /* in cases where we are using a VM with aliases generated according to the + * index of the memory device we need to keep continue using that scheme */ + if (qemuAssignDeviceMemoryAlias(vm->def, mem, priv->memAliasOrderMismatch) < 0) goto cleanup; if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0) diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm-addr.args b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm-addr.args index 23403df5eb..fdbb4c3299 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm-addr.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-dimm-addr.args @@ -15,8 +15,8 @@ QEMU_AUDIO_DRV=none \ mem-path=/dev/hugepages2M/libvirt/qemu,size=536870912,host-nodes=1-3,\ policy=bind \ -device pc-dimm,node=0,memdev=memdimm0,id=dimm0,slot=0,addr=4294967296 \ --object memory-backend-ram,id=memdimm1,size=536870912 \ --device pc-dimm,node=0,memdev=memdimm1,id=dimm1,slot=2 \ +-object memory-backend-ram,id=memdimm2,size=536870912 \ +-device pc-dimm,node=0,memdev=memdimm2,id=dimm2,slot=2 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -nographic \ -nodefaults \