qemu: alias: Fix calculation of memory device aliases

For device hotplug, the new alias ID needs to be checked in the list
rather than using the count of devices. Unplugging a device that is not
last in the array will make further hotplug impossible due to alias
collision.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1324551
This commit is contained in:
Peter Krempa 2016-04-06 17:32:12 +02:00
parent bd19b4b25b
commit be6e92f541
3 changed files with 24 additions and 1 deletions

View File

@ -401,6 +401,26 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def,
}
int
qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
virDomainMemoryDefPtr mem)
{
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 (virAsprintf(&mem->info.alias, "dimm%d", maxidx) < 0)
return -1;
return 0;
}
int
qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
{

View File

@ -57,6 +57,9 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
int qemuAssignDeviceRNGAlias(virDomainDefPtr def,
virDomainRNGDefPtr rng);
int qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
virDomainMemoryDefPtr mems);
int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info,

View File

@ -1751,7 +1751,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (qemuDomainDefValidateMemoryHotplug(vm->def, priv->qemuCaps, mem) < 0)
goto cleanup;
if (virAsprintf(&mem->info.alias, "dimm%zu", vm->def->nmems) < 0)
if (qemuAssignDeviceMemoryAlias(vm->def, mem) < 0)
goto cleanup;
if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0)