[PATCHv3 03/11] qemu: Make qemuMonitorAddNetdev to pass multiple FDs

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

 



Currently, only one tapfd and one vhostfd could be passed.
However, multiqueue network requires several FDs to be passed to
qemu so we must adapt out monitor handling functions to cope with
that.
---
 src/qemu/qemu_hotplug.c |  7 +++++--
 src/qemu/qemu_monitor.c | 39 +++++++++++++++++++++++----------------
 src/qemu/qemu_monitor.h |  4 ++--
 3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index d037c9d..b04f3bb 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -813,8 +813,11 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
     qemuDomainObjEnterMonitor(driver, vm);
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-        if (qemuMonitorAddNetdev(priv->mon, netstr, tapfd, tapfd_name,
-                                 vhostfd, vhostfd_name) < 0) {
+        if (qemuMonitorAddNetdev(priv->mon, netstr,
+                                 &tapfd, &tapfd_name,
+                                 tapfd_name ? 1 : 0,
+                                 &vhostfd, &vhostfd_name,
+                                 vhostfd_name ? 1 : 0) < 0) {
             qemuDomainObjExitMonitor(driver, vm);
             virDomainAuditNet(vm, NULL, net, "attach", false);
             goto cleanup;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index f6d8ef4..1d65dd8 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2543,14 +2543,16 @@ int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
 
 int qemuMonitorAddNetdev(qemuMonitorPtr mon,
                          const char *netdevstr,
-                         int tapfd, const char *tapfd_name,
-                         int vhostfd, const char *vhostfd_name)
+                         int *tapfd, char **tapfdName, int tapfdSize,
+                         int *vhostfd, char **vhostfdName, int vhostfdSize)
 {
     int ret = -1;
-    VIR_DEBUG("mon=%p netdevstr=%s tapfd=%d tapfd_name=%s "
-              "vhostfd=%d vhostfd_name=%s",
-              mon, netdevstr, tapfd, NULLSTR(tapfd_name),
-              vhostfd, NULLSTR(vhostfd_name));
+    int i = 0, j = 0;
+
+    VIR_DEBUG("mon=%p netdevstr=%s tapfd=%p tapfdName=%p tapfdSize=%d"
+              "vhostfd=%p vhostfdName=%p vhostfdSize=%d",
+              mon, netdevstr, tapfd, tapfdName, tapfdSize,
+              vhostfd, vhostfdName, tapfdSize);
 
     if (!mon) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2558,12 +2560,13 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
         return -1;
     }
 
-    if (tapfd >= 0 && qemuMonitorSendFileHandle(mon, tapfd_name, tapfd) < 0)
-        return -1;
-    if (vhostfd >= 0 &&
-        qemuMonitorSendFileHandle(mon, vhostfd_name, vhostfd) < 0) {
-        vhostfd = -1;
-        goto cleanup;
+    for (i = 0; i < tapfdSize; i++) {
+        if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
+            goto cleanup;
+    }
+    for (j = 0; j < vhostfdSize; j++) {
+        if (qemuMonitorSendFileHandle(mon, vhostfdName[j], vhostfd[j]) < 0)
+            goto cleanup;
     }
 
     if (mon->json)
@@ -2573,10 +2576,14 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
 
 cleanup:
     if (ret < 0) {
-        if (tapfd >= 0 && qemuMonitorCloseFileHandle(mon, tapfd_name) < 0)
-            VIR_WARN("failed to close device handle '%s'", tapfd_name);
-        if (vhostfd >= 0 && qemuMonitorCloseFileHandle(mon, vhostfd_name) < 0)
-            VIR_WARN("failed to close device handle '%s'", vhostfd_name);
+        while (i--) {
+            if (qemuMonitorCloseFileHandle(mon, tapfdName[i]) < 0)
+                VIR_WARN("failed to close device handle '%s'", tapfdName[i]);
+        }
+        while (j--) {
+            if (qemuMonitorCloseFileHandle(mon, vhostfdName[j]) < 0)
+                VIR_WARN("failed to close device handle '%s'", vhostfdName[j]);
+        }
     }
 
     return ret;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 8f9c182..f08e468 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -510,8 +510,8 @@ int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
 
 int qemuMonitorAddNetdev(qemuMonitorPtr mon,
                          const char *netdevstr,
-                         int tapfd, const char *tapfd_name,
-                         int vhostfd, const char *vhostfd_name);
+                         int *tapfd, char **tapfdName, int tapfdSize,
+                         int *vhostfd, char **vhostfdName, int vhostfdSize);
 
 int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
                             const char *alias);
-- 
1.8.2.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]