qemu: make vdpa connect function more generic

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>
This commit is contained in:
Jonathon Jongsma 2023-05-30 15:33:46 -05:00
parent 6cf7dbeff8
commit 0ebb416d7e
6 changed files with 26 additions and 29 deletions

View File

@ -8533,7 +8533,7 @@ qemuBuildInterfaceConnect(virDomainObj *vm,
break; break;
case VIR_DOMAIN_NET_TYPE_VDPA: case VIR_DOMAIN_NET_TYPE_VDPA:
if ((vdpafd = qemuInterfaceVDPAConnect(net)) < 0) if ((vdpafd = qemuVDPAConnect(net->data.vdpa.devicepath)) < 0)
return -1; return -1;
netpriv->vdpafd = qemuFDPassNew(net->info.alias, priv); netpriv->vdpafd = qemuFDPassNew(net->info.alias, priv);
@ -10993,3 +10993,24 @@ qemuBuildStorageSourceChainAttachPrepareBlockdevTop(virStorageSource *top,
return g_steal_pointer(&data); 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;
}

View File

@ -248,3 +248,4 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev,
const char * qemuAudioDriverTypeToString(virDomainAudioType type); const char * qemuAudioDriverTypeToString(virDomainAudioType type);
virDomainAudioType qemuAudioDriverTypeFromString(const char *str); virDomainAudioType qemuAudioDriverTypeFromString(const char *str);
int qemuVDPAConnect(const char *devicepath) G_NO_INLINE;

View 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 * Returns: -1 on error, 0 on success. Populates net->privateData->slirp if
* the slirp helper is needed. * the slirp helper is needed.

View File

@ -55,5 +55,3 @@ int qemuInterfaceOpenVhostNet(virDomainObj *def,
int qemuInterfacePrepareSlirp(virQEMUDriver *driver, int qemuInterfacePrepareSlirp(virQEMUDriver *driver,
virDomainNetDef *net); virDomainNetDef *net);
int qemuInterfaceVDPAConnect(virDomainNetDef *net) G_NO_INLINE;

View File

@ -18,8 +18,8 @@
#include <config.h> #include <config.h>
#include "qemu/qemu_command.h"
#include "qemu/qemu_hotplug.h" #include "qemu/qemu_hotplug.h"
#include "qemu/qemu_interface.h"
#include "qemu/qemu_process.h" #include "qemu/qemu_process.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#include "conf/domain_conf.h" #include "conf/domain_conf.h"
@ -94,7 +94,7 @@ qemuProcessKillManagedPRDaemon(virDomainObj *vm G_GNUC_UNUSED)
} }
int 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 */ /* need a valid fd or sendmsg won't work. Just open /dev/null */
return open("/dev/null", O_RDONLY); return open("/dev/null", O_RDONLY);

View File

@ -255,7 +255,7 @@ virNetDevBandwidthSetRootQDisc(const char *ifname G_GNUC_UNUSED,
int int
qemuInterfaceVDPAConnect(virDomainNetDef *net G_GNUC_UNUSED) qemuVDPAConnect(const char *devicepath G_GNUC_UNUSED)
{ {
if (fcntl(1732, F_GETFD) != -1) if (fcntl(1732, F_GETFD) != -1)
abort(); abort();