]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: make vdpa connect function more generic
authorJonathon Jongsma <jjongsma@redhat.com>
Tue, 30 May 2023 20:33:46 +0000 (15:33 -0500)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 12 Sep 2023 16:06:41 +0000 (11:06 -0500)
qemuInterfaceVDPAConnect() was a helper function for connecting to the
vdpa device file. But in order to support other vdpa devices besides
network interfaces (e.g. vdpa block devices) make this function a bit
more generic.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_interface.c
src/qemu/qemu_interface.h
tests/qemuhotplugmock.c
tests/qemuxml2argvmock.c

index 778958700ba26acd4c7b925bc79b4a37867332b6..e84374b4cfd57f9c335e9a8df1776863c0fe8593 100644 (file)
@@ -8533,7 +8533,7 @@ qemuBuildInterfaceConnect(virDomainObj *vm,
         break;
 
     case VIR_DOMAIN_NET_TYPE_VDPA:
-        if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0)
+        if ((vdpafd = qemuVDPAConnect(net->data.vdpa.devicepath)) < 0)
             return -1;
 
         netpriv->vdpafd = qemuFDPassNew(net->info.alias, priv);
@@ -10993,3 +10993,24 @@ qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSource *top,
 
     return g_steal_pointer(&data);
 }
+
+
+/* qemuVDPAConnect:
+ * @devicepath: the path to the vdpa device
+ *
+ * returns: file descriptor of the vdpa device
+ */
+int
+qemuVDPAConnect(const char *devicepath)
+{
+    int fd;
+
+    if ((fd = open(devicepath, O_RDWR)) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to open '%1$s' for vdpa device"),
+                             devicepath);
+        return -1;
+    }
+
+    return fd;
+}
index 55efa4560181dcae446e17b25d3198079f6d4c1a..341ec43f9a25250f9ad90f7169966a0fa7122e64 100644 (file)
@@ -248,3 +248,4 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,
 
 const char * qemuAudioDriverTypeToString(virDomainAudioType type);
 virDomainAudioType qemuAudioDriverTypeFromString(const char *str);
+int qemuVDPAConnect(const char *devicepath) G_NO_INLINE;
index e875de48eeccb18bc5122b769a3736efa36e0252..8856bb95a8fc6298848baffea0558d8073343994 100644 (file)
@@ -648,29 +648,6 @@ qemuInterfaceBridgeConnect(virDomainDef *def,
 }
 
 
-/* qemuInterfaceVDPAConnect:
- * @net: pointer to the VM's interface description
- *
- * returns: file descriptor of the vdpa device
- *
- * Called *only* called if actualType is VIR_DOMAIN_NET_TYPE_VDPA
- */
-int
-qemuInterfaceVDPAConnect(virDomainNetDef *net)
-{
-    int fd;
-
-    if ((fd = open(net->data.vdpa.devicepath, O_RDWR)) < 0) {
-        virReportSystemError(errno,
-                             _("Unable to open '%1$s' for vdpa device"),
-                             net->data.vdpa.devicepath);
-        return -1;
-    }
-
-    return fd;
-}
-
-
 /*
  * Returns: -1 on error, 0 on success. Populates net->privateData->slirp if
  * the slirp helper is needed.
index d866beb184cb8556d18b2bcba2ae032ef21b1e4b..6eed3e6bd75ee28d634624c13030852b2bbdc70e 100644 (file)
@@ -55,5 +55,3 @@ int qemuInterfaceOpenVhostNet(virDomainObj *def,
 
 int qemuInterfacePrepareSlirp(virQEMUDriver *driver,
                               virDomainNetDef *net);
-
-int qemuInterfaceVDPAConnect(virDomainNetDef *net) G_NO_INLINE;
index 89d287945aaba82b5146138f409cfa39e67b4cce..dd7e2c67e07b250378c035c6b160fdf956ebb982 100644 (file)
@@ -18,8 +18,8 @@
 
 #include <config.h>
 
+#include "qemu/qemu_command.h"
 #include "qemu/qemu_hotplug.h"
-#include "qemu/qemu_interface.h"
 #include "qemu/qemu_process.h"
 #include "testutilsqemu.h"
 #include "conf/domain_conf.h"
@@ -94,7 +94,7 @@ qemuProcessKillManagedPRDaemon(virDomainObj *vm G_GNUC_UNUSED)
 }
 
 int
-qemuInterfaceVDPAConnect(virDomainNetDef *net G_GNUC_UNUSED)
+qemuVDPAConnect(const char *devicepath G_GNUC_UNUSED)
 {
     /* need a valid fd or sendmsg won't work. Just open /dev/null */
     return open("/dev/null", O_RDONLY);
index 400dd5c020309c5738306456f138e90237806edd..52c44b2ed0281940f8a66a8b2aafc6ca6a94b871 100644 (file)
@@ -255,7 +255,7 @@ virNetDevBandwidthSetRootQDisc(const char *ifname G_GNUC_UNUSED,
 
 
 int
-qemuInterfaceVDPAConnect(virDomainNetDef *net G_GNUC_UNUSED)
+qemuVDPAConnect(const char *devicepath G_GNUC_UNUSED)
 {
     if (fcntl(1732, F_GETFD) != -1)
         abort();