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

[libvirt] [PATCH v1 07/12] qemu: Allow multiple vhost-net openings



With multiqueue network feature, we are advised to pass multiple
vhost-net FDs as well. The ratio should be 1:1. Therefore we must
alter the qemuOpenVhostNet function to allow that.
---
 src/qemu/qemu_command.c | 40 ++++++++++++++++++++++++++--------------
 src/qemu/qemu_command.h |  3 ++-
 src/qemu/qemu_hotplug.c |  6 +++---
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f5d11ad..7337069 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -321,9 +321,13 @@ int
 qemuOpenVhostNet(virDomainDefPtr def,
                  virDomainNetDefPtr net,
                  virQEMUCapsPtr qemuCaps,
-                 int *vhostfd)
+                 int *vhostfd,
+                 int vhostfdSize)
 {
-    *vhostfd = -1;   /* assume we won't use vhost */
+    int i;
+
+    for (i = 0; i < vhostfdSize; i++)
+        vhostfd[i] = -1;   /* assume we won't use vhost */
 
     /* If the config says explicitly to not use vhost, return now */
     if (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_QEMU) {
@@ -356,20 +360,28 @@ qemuOpenVhostNet(virDomainDefPtr def,
         return 0;
     }
 
-    *vhostfd = open("/dev/vhost-net", O_RDWR);
-    virDomainAuditNetDevice(def, net, "/dev/vhost-net", *vhostfd >= 0);
+    for (i = 0; i < vhostfdSize; i++) {
+        vhostfd[i] = open("/dev/vhost-net", O_RDWR);
+        virDomainAuditNetDevice(def, net, "/dev/vhost-net", vhostfd[i] >= 0);
 
-    /* If the config says explicitly to use vhost and we couldn't open it,
-     * report an error.
-     */
-    if ((*vhostfd < 0) &&
-        (net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       "%s", _("vhost-net was requested for an interface, "
-                               "but is unavailable"));
-        return -1;
+        /* If the config says explicitly to use vhost and we couldn't open it,
+         * report an error.
+         */
+        if (vhostfd[i] < 0 &&
+            net->driver.virtio.name == VIR_DOMAIN_NET_BACKEND_TYPE_VHOST) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           "%s", _("vhost-net was requested for an interface, "
+                                   "but is unavailable"));
+            goto error;
+        }
     }
     return 0;
+
+error:
+    for (i = 0; i < vhostfdSize; i++)
+        VIR_FORCE_CLOSE(vhostfd[i]);
+
+    return -1;
 }
 
 
@@ -5876,7 +5888,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
            network device */
         int vhostfd;
 
-        if (qemuOpenVhostNet(def, net, qemuCaps, &vhostfd) < 0)
+        if (qemuOpenVhostNet(def, net, qemuCaps, &vhostfd, 1) < 0)
             goto cleanup;
         if (vhostfd >= 0) {
             virCommandTransferFD(cmd, vhostfd);
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index d1ae325..db14d8f 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -162,7 +162,8 @@ int qemuPhysIfaceConnect(virDomainDefPtr def,
 int qemuOpenVhostNet(virDomainDefPtr def,
                      virDomainNetDefPtr net,
                      virQEMUCapsPtr qemuCaps,
-                     int *vhostfd);
+                     int *vhostfd,
+                     int vhostfdSize);
 
 /*
  * NB: def->name can be NULL upon return and the caller
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 26b91bc..b34160a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -744,7 +744,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
                                                  priv->qemuCaps)) < 0)
                 goto cleanup;
             iface_connected = true;
-            if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
+            if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd, 1) < 0)
                 goto cleanup;
         }
     } else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
@@ -753,10 +753,10 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
                                           VIR_NETDEV_VPORT_PROFILE_OP_CREATE)) < 0)
             goto cleanup;
         iface_connected = true;
-        if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
+        if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd, 1) < 0)
             goto cleanup;
     } else if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
-        if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
+        if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd, 1) < 0)
             goto cleanup;
     }
 
-- 
1.8.1.5


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