[PATCH 09/12] split out qemuAssignDeviceInputAlias

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

 



Move assignment of input device alias into a separate function,
for reuse on hotplug.
---
 src/qemu/qemu_alias.c | 24 +++++++++++++++++++++++-
 src/qemu/qemu_alias.h |  3 +++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 72df1083f..737fc2fda 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -412,6 +412,28 @@ qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog)
 
     if (VIR_STRDUP(watchdog->info.alias, "watchdog0") < 0)
         return -1;
+
+    return 0;
+}
+
+int
+qemuAssignDeviceInputAlias(virDomainDefPtr def,
+                           virDomainInputDefPtr input,
+                           int idx)
+{
+    if (idx == -1) {
+        int thisidx;
+        size_t i;
+
+        for (i = 0; i < def->ninputs; i++) {
+            if ((thisidx = qemuDomainDeviceAliasIndex(&def->inputs[i]->info, "input")) >= idx)
+                idx = thisidx + 1;
+        }
+    }
+
+    if (virAsprintf(&input->info.alias, "input%d", idx) < 0)
+        return -1;
+
     return 0;
 }
 
@@ -461,7 +483,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
             return -1;
     }
     for (i = 0; i < def->ninputs; i++) {
-        if (virAsprintf(&def->inputs[i]->info.alias, "input%zu", i) < 0)
+        if (qemuAssignDeviceInputAlias(def, def->inputs[i], i) < 0)
             return -1;
     }
     for (i = 0; i < def->nparallels; i++) {
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 652ffea0c..35424829f 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -66,6 +66,9 @@ int qemuAssignDeviceShmemAlias(virDomainDefPtr def,
                                int idx);
 
 int qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog);
+int qemuAssignDeviceInputAlias(virDomainDefPtr def,
+                               virDomainInputDefPtr input,
+                               int idx);
 
 int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
 
-- 
2.13.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]
  Powered by Linux