[PATCH v3 1/9] qemu: Add helper to assign RNG device aliases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 c041ee7..52741fe 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -910,6 +910,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,
@@ -1036,7 +1059,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 dcc7127..fc5f50a 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -264,6 +264,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]