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

[libvirt] [PATCH v1 03/12] qemu: Make qemuMonitorAddHostNetwork to pass multiple FDs



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 238d0d7..254ab4a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -820,8 +820,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 1b1d4a1..4ca80f4 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2526,14 +2526,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",
@@ -2541,12 +2543,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)
@@ -2556,10 +2559,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 f39f009..580e42b 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -506,8 +506,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.1.5


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