[PATCH 10/27] qemuBuildInterfaceCommandLine: Use qemuFDPass for the vdpa fd

Peter Krempa pkrempa at redhat.com
Wed Feb 9 16:02:02 UTC 2022


Use the new helpers for passing of the file descriptor needed for 'vdpa'
interfaces.

Apart from the simplification in this case it will allow further changes
to unify all fdset handling.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_command.c                       | 35 ++++++++-----------
 .../net-vdpa.x86_64-latest.args               |  4 +--
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9713467aa8..839cd05e23 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -29,6 +29,7 @@
 #include "qemu_security.h"
 #include "qemu_slirp.h"
 #include "qemu_block.h"
+#include "qemu_fd.h"
 #include "viralloc.h"
 #include "virlog.h"
 #include "virarch.h"
@@ -8732,6 +8733,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
                               size_t *nnicindexes,
                               int **nicindexes)
 {
+    qemuDomainObjPrivate *priv = vm->privateData;
     virDomainDef *def = vm->def;
     int ret = -1;
     g_autoptr(virJSONValue) nicprops = NULL;
@@ -8743,8 +8745,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
     char **tapfdName = NULL;
     char **vhostfdName = NULL;
     g_autofree char *slirpfdName = NULL;
-    g_autofree char *vdpafdName = NULL;
-    int vdpafd = -1;
+    g_autoptr(qemuFDPass) vdpa = NULL;
     virDomainNetType actualType = virDomainNetGetActualType(net);
     const virNetDevBandwidth *actualBandwidth;
     bool requireNicdev = false;
@@ -8823,9 +8824,17 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,

         break;

-    case VIR_DOMAIN_NET_TYPE_VDPA:
+    case VIR_DOMAIN_NET_TYPE_VDPA: {
+        VIR_AUTOCLOSE vdpafd = -1;
+
         if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
             goto cleanup;
+
+        vdpa = qemuFDPassNew(net->data.vdpa.devicepath, priv, true);
+
+        if (qemuFDPassAddFD(vdpa, &vdpafd, NULL) < 0)
+            return -1;
+    }
         break;

     case VIR_DOMAIN_NET_TYPE_USER:
@@ -8958,26 +8967,13 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
         vhostfd[i] = -1;
     }

-    if (vdpafd > 0) {
-        g_autofree char *fdset = NULL;
-        g_autofree char *addfdarg = NULL;
-        size_t idx;
-
-        virCommandPassFDIndex(cmd, vdpafd, VIR_COMMAND_PASS_FD_CLOSE_PARENT, &idx);
-        fdset = qemuBuildFDSet(vdpafd, idx);
-        vdpafdName = g_strdup_printf("/dev/fdset/%zu", idx);
-        /* set opaque to the devicepath so that we can look up the fdset later
-         * if necessary */
-        addfdarg = g_strdup_printf("%s,opaque=%s", fdset,
-                                   net->data.vdpa.devicepath);
-        virCommandAddArgList(cmd, "-add-fd", addfdarg, NULL);
-        vdpafd = -1;
-    }
+    qemuFDPassTransferCommand(vdpa, cmd);

     if (!(hostnetprops = qemuBuildHostNetProps(net,
                                                tapfdName, tapfdSize,
                                                vhostfdName, vhostfdSize,
-                                               slirpfdName, vdpafdName)))
+                                               slirpfdName,
+                                               qemuFDPassGetPath(vdpa))))
         goto cleanup;

     if (qemuBuildNetdevCommandlineFromJSON(cmd, hostnetprops, qemuCaps) < 0)
@@ -9035,7 +9031,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
     VIR_FREE(tapfdName);
     VIR_FREE(vhostfd);
     VIR_FREE(tapfd);
-    VIR_FORCE_CLOSE(vdpafd);
     return ret;
 }

diff --git a/tests/qemuxml2argvdata/net-vdpa.x86_64-latest.args b/tests/qemuxml2argvdata/net-vdpa.x86_64-latest.args
index a56e08a4f1..0300f36314 100644
--- a/tests/qemuxml2argvdata/net-vdpa.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/net-vdpa.x86_64-latest.args
@@ -28,8 +28,8 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
 -no-acpi \
 -boot strict=on \
 -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
--add-fd set=0,fd=1732,opaque=/dev/vhost-vdpa-0 \
--netdev vhost-vdpa,vhostdev=/dev/fdset/0,id=hostnet0 \
+-add-fd set=1,fd=1732,opaque=/dev/vhost-vdpa-0 \
+-netdev vhost-vdpa,vhostdev=/dev/fdset/1,id=hostnet0 \
 -device '{"driver":"virtio-net-pci","netdev":"hostnet0","id":"net0","mac":"52:54:00:95:db:c0","bus":"pci.0","addr":"0x2"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
-- 
2.34.1




More information about the libvir-list mailing list