This function is used to assign an alias for a RNG device. It will be
later reused when hotplugging RNGs.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/qemu/qemu_command.c | 25 ++++++++++++++++++++++++-
src/qemu/qemu_command.h | 1 +
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1930abd..97bed1f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -909,6 +909,29 @@ qemuGetNextChrDevIndex(virDomainDefPtr def,
return idx;
}
+int
+qemuAssignDeviceRNGAlias(virDomainDefPtr def, virDomainRNGDefPtr rng, int idx)
+{
+ if (idx == -1) {
+ size_t i;
+ idx = 0;
+ for (i = 0; i < def->nrngs; i++) {
+ int thisidx;
+ if ((thisidx = qemuDomainDeviceAliasIndex(&def->rngs[i]->info,
"rng")) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Unable to determine device index for RNG
device"));
+ return -1;
+ }
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
+ }
+
+ if (virAsprintf(&rng->info.alias, "rng%d", idx) < 0)
+ return -1;
+
+ return 0;
+}
int
qemuAssignDeviceChrAlias(virDomainDefPtr def,
@@ -1035,7 +1058,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_command.h b/src/qemu/qemu_command.h
index f7d3c2d..9f3f249 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -262,6 +262,7 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
virDomainRedirdevDefPtr r
int qemuAssignDeviceChrAlias(virDomainDefPtr def,
virDomainChrDefPtr chr,
ssize_t idx);
+int qemuAssignDeviceRNGAlias(virDomainDefPtr def, virDomainRNGDefPtr rng, int idx);
int
qemuParseKeywords(const char *str,
--
1.8.3.1