[PATCH v3 03/10] qemu: Refactor hub alias assignment for hotplug

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

 



Make qemuAssignDeviceHubAlias global and allow alias
generating for reuse on hotplug.

Signed-off-by: Han Han <hhan@xxxxxxxxxx>
---
 src/qemu/qemu_alias.c | 22 ++++++++++++++++++----
 src/qemu/qemu_alias.h |  4 ++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 815caec465..116480eaee 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -364,14 +364,28 @@ qemuAssignDeviceVideoAlias(virDomainVideoDefPtr video,
 }
 
 
-static int
-qemuAssignDeviceHubAlias(virDomainHubDefPtr hub,
+int
+qemuAssignDeviceHubAlias(virDomainDefPtr def,
+                         virDomainHubDefPtr hub,
                          int idx)
 {
     if (hub->info.alias)
         return 0;
 
-    return virAsprintf(&hub->info.alias, "hub%d", idx);
+    if (idx == -1) {
+        int thisidx;
+        size_t i;
+
+        for (i = 0; i < def->nhubs; i++) {
+            if ((thisidx = qemuDomainDeviceAliasIndex(&def->hubs[i]->info, "hub")) >= idx)
+                idx = thisidx + 1;
+        }
+    }
+
+    if (virAsprintf(&hub->info.alias, "hub%d", idx) < 0)
+        return -1;
+
+    return 0;
 }
 
 
@@ -647,7 +661,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
             return -1;
     }
     for (i = 0; i < def->nhubs; i++) {
-        if (qemuAssignDeviceHubAlias(def->hubs[i], i) < 0)
+        if (qemuAssignDeviceHubAlias(def, def->hubs[i], i) < 0)
             return -1;
     }
     for (i = 0; i < def->nshmems; i++) {
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 33b9937ea4..ea30c1c8a3 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -71,6 +71,10 @@ int qemuAssignDeviceInputAlias(virDomainDefPtr def,
                                virDomainInputDefPtr input,
                                int idx);
 
+int qemuAssignDeviceHubAlias(virDomainDefPtr def,
+                             virDomainHubDefPtr hub,
+                             int idx);
+
 int qemuAssignDeviceVsockAlias(virDomainVsockDefPtr vsock);
 
 int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
-- 
2.19.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]

  Powered by Linux