[PATCHv3 05/11] qemu: Adapt command line generation to multiqueue net

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

 



The qemuBuildHostNetStr() function which is responsible for
generating command line for a network interface needs to be aware
of multiqueue network interface as we are required to use:
 - fd=%d   in case of one FD
 - fds=%d:%d:%d:...:%d   in case of multiple FDs

These two approaches can't be mixed. Same applies for vhost FDs.
---
 src/qemu/qemu_command.c | 46 +++++++++++++++++++++++++++++++++++++---------
 src/qemu/qemu_command.h |  6 ++++--
 src/qemu/qemu_hotplug.c | 10 ++++++----
 3 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4c87d70..67baad3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4109,13 +4109,16 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
                     virQEMUDriverPtr driver,
                     char type_sep,
                     int vlan,
-                    const char *tapfd,
-                    const char *vhostfd)
+                    char **tapfd,
+                    int tapfdSize,
+                    char **vhostfd,
+                    int vhostfdSize)
 {
     bool is_tap = false;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     enum virDomainNetType netType = virDomainNetGetActualType(net);
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    int i;
 
     if (net->script && netType != VIR_DOMAIN_NET_TYPE_ETHERNET) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -4134,7 +4137,19 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
     case VIR_DOMAIN_NET_TYPE_NETWORK:
     case VIR_DOMAIN_NET_TYPE_DIRECT:
-        virBufferAsprintf(&buf, "tap%cfd=%s", type_sep, tapfd);
+        virBufferAsprintf(&buf, "tap%c", type_sep);
+        /* for one tapfd 'fd=' shall be used,
+         * for more than one 'fds=' is the right choice */
+        if (tapfdSize == 1) {
+            virBufferAsprintf(&buf, "fd=%s", tapfd[0]);
+        } else {
+            virBufferAddLit(&buf, "fds=");
+            for (i = 0; i < tapfdSize; i++) {
+                if (i)
+                    virBufferAddChar(&buf, ':');
+                virBufferAdd(&buf, tapfd[i], -1);
+            }
+        }
         type_sep = ',';
         is_tap = true;
         break;
@@ -4194,8 +4209,19 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
     }
 
     if (is_tap) {
-        if (vhostfd && *vhostfd)
-            virBufferAsprintf(&buf, ",vhost=on,vhostfd=%s", vhostfd);
+        if (vhostfdSize) {
+            virBufferAddLit(&buf, ",vhost=on,");
+            if (vhostfdSize == 1) {
+                virBufferAsprintf(&buf, "vhostfd=%s", vhostfd[0]);
+            } else {
+                virBufferAddLit(&buf, "vhostfds=");
+                for (i = 0; i < vhostfdSize; i++) {
+                    if (i)
+                        virBufferAddChar(&buf, ':');
+                    virBufferAdd(&buf, vhostfd[i], -1);
+                }
+            }
+        }
         if (net->tune.sndbuf_specified)
             virBufferAsprintf(&buf, ",sndbuf=%lu", net->tune.sndbuf);
     }
@@ -6482,8 +6508,9 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
         if (!(host = qemuBuildHostNetStr(net, driver,
-                                         ',', vlan, tapfdName,
-                                         vhostfdName)))
+                                         ',', vlan,
+                                         &tapfdName, tapfdName ? 1 : 0,
+                                         &vhostfdName, vhostfdName ?  1 : 0)))
             goto cleanup;
         virCommandAddArgList(cmd, "-netdev", host, NULL);
     }
@@ -6499,8 +6526,9 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
     if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
           virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
         if (!(host = qemuBuildHostNetStr(net, driver,
-                                         ',', vlan, tapfdName,
-                                         vhostfdName)))
+                                         ',', vlan,
+                                         &tapfdName, tapfdName ? 1 : 0,
+                                         &vhostfdName, vhostfdName ? 1 : 0)))
             goto cleanup;
         virCommandAddArgList(cmd, "-net", host, NULL);
     }
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 36dfa6b..6765c3a 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -76,8 +76,10 @@ char * qemuBuildHostNetStr(virDomainNetDefPtr net,
                            virQEMUDriverPtr driver,
                            char type_sep,
                            int vlan,
-                           const char *tapfd,
-                           const char *vhostfd);
+                           char **tapfd,
+                           int tapfdSize,
+                           char **vhostfd,
+                           int vhostfdSize);
 
 /* Legacy, pre device support */
 char * qemuBuildNicStr(virDomainNetDefPtr net,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 41431b3..0a1845a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -800,13 +800,15 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) &&
         virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
         if (!(netstr = qemuBuildHostNetStr(net, driver,
-                                           ',', -1, tapfd_name,
-                                           vhostfd_name)))
+                                           ',', -1,
+                                           &tapfd_name, tapfd_name ? 1 : 0,
+                                           &vhostfd_name, vhostfd_name ? 1 : 0)))
             goto cleanup;
     } else {
         if (!(netstr = qemuBuildHostNetStr(net, driver,
-                                           ' ', vlan, tapfd_name,
-                                           vhostfd_name)))
+                                           ' ', vlan,
+                                           &tapfd_name, tapfd_name ? 1 : 0,
+                                           &vhostfd_name, vhostfd_name ? 1 : 0)))
             goto cleanup;
     }
 
-- 
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]