When generating aliases for RNG at the domain startup phase it
make no sense trying to recalculate the next free index every
time. We already know the index - it's the same as the index in
the def->rngs[] array.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_alias.c | 22 +++++++++++++---------
src/qemu/qemu_alias.h | 3 ++-
src/qemu/qemu_hotplug.c | 2 +-
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 914b2b94d..4ac41947c 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -314,18 +314,22 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
int
qemuAssignDeviceRNGAlias(virDomainDefPtr def,
- virDomainRNGDefPtr rng)
+ virDomainRNGDefPtr rng,
+ int idx)
{
- size_t i;
- int maxidx = 0;
- int idx;
+ if (idx == -1) {
+ size_t i;
+ idx = 0;
+ for (i = 0; i < def->nrngs; i++) {
+ int thisidx;
+ thisidx = qemuDomainDeviceAliasIndex(&def->rngs[i]->info,
"rng");
- for (i = 0; i < def->nrngs; i++) {
- if ((idx = qemuDomainDeviceAliasIndex(&def->rngs[i]->info,
"rng")) >= maxidx)
- maxidx = idx + 1;
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
}
- if (virAsprintf(&rng->info.alias, "rng%d", maxidx) < 0)
+ if (virAsprintf(&rng->info.alias, "rng%d", idx) < 0)
return -1;
return 0;
@@ -490,7 +494,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return -1;
}
for (i = 0; i < def->nrngs; i++) {
- if (virAsprintf(&def->rngs[i]->info.alias, "rng%zu", i) <
0)
+ if (qemuAssignDeviceRNGAlias(def, def->rngs[i], i) < 0)
return -1;
}
if (def->tpm) {
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 300fd4de5..860ab6c0c 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -55,7 +55,8 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
int idx);
int qemuAssignDeviceRNGAlias(virDomainDefPtr def,
- virDomainRNGDefPtr rng);
+ virDomainRNGDefPtr rng,
+ int idx);
int qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
virDomainMemoryDefPtr mems,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7dd6e5fd9..816dbd46e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2073,7 +2073,7 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
int ret = -1;
int rv;
- if (qemuAssignDeviceRNGAlias(vm->def, rng) < 0)
+ if (qemuAssignDeviceRNGAlias(vm->def, rng, -1) < 0)
goto cleanup;
/* preallocate space for the device definition */
--
2.13.5