[PATCH 1/2] qemu: alias: Fix calculation of RNG device aliases

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

 



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
---
 src/qemu/qemu_alias.c   | 20 ++++++++++++++++++--
 src/qemu/qemu_alias.h   |  3 ++-
 src/qemu/qemu_hotplug.c |  2 +-
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 010d6b9..052a829 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -382,9 +382,25 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,


 int
-qemuAssignDeviceRNGAlias(virDomainRNGDefPtr rng,
+qemuAssignDeviceRNGAlias(virDomainDefPtr def,
+                         virDomainRNGDefPtr rng,
                          size_t 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%zu", idx) < 0)
         return -1;

@@ -480,7 +496,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
             return -1;
     }
     for (i = 0; i < def->nrngs; i++) {
-        if (qemuAssignDeviceRNGAlias(def->rngs[i], i) < 0)
+        if (virAsprintf(&def->rngs[i]->info.alias, "rng%zu", i) < 0)
             return -1;
     }
     if (def->tpm) {
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index b915f73..f311583 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -54,7 +54,8 @@ int qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
                                   virDomainRedirdevDefPtr redirdev,
                                   int idx);

-int qemuAssignDeviceRNGAlias(virDomainRNGDefPtr rng,
+int qemuAssignDeviceRNGAlias(virDomainDefPtr def,
+                             virDomainRNGDefPtr rng,
                              size_t idx);

 int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 48bea6a..93cc8e2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1625,7 +1625,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
     const char *type;
     int ret = -1;

-    if (qemuAssignDeviceRNGAlias(rng, vm->def->nrngs) < 0)
+    if (qemuAssignDeviceRNGAlias(vm->def, rng, -1) < 0)
         return -1;

     /* preallocate space for the device definition */
-- 
2.8.0

--
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]