1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-28 11:21:44 +03:00

qemu: domain: Add qemuFDPass helpers into network private data

Prepare for the upcoming refactor to use qemuFDPass for all the network
related file descriptors:

    - tapfds
    - vhostfds
    - slirp
    - vdpa

This patch adds the private data variables and a utility function to
clear it. Clearing is useful since we don't really need the data once
the VM is running so we save some memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-05-09 09:50:51 +02:00
parent 686f83e66e
commit ba9e1f629c
4 changed files with 29 additions and 0 deletions

View File

@ -8704,6 +8704,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
qemuSlirp *slirp;
size_t i;
g_autoptr(virJSONValue) hostnetprops = NULL;
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
if (qemuDomainValidateActualNetDef(net, qemuCaps) < 0)
return -1;
@ -8960,6 +8961,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
ret = 0;
cleanup:
qemuDomainNetworkPrivateClearFDs(netpriv);
if (ret < 0) {
virErrorPtr saved_err;

View File

@ -1045,12 +1045,27 @@ qemuDomainNetworkPrivateNew(void)
}
void
qemuDomainNetworkPrivateClearFDs(qemuDomainNetworkPrivate *priv)
{
if (!priv)
return;
g_clear_pointer(&priv->slirpfd, qemuFDPassFree);
g_clear_pointer(&priv->vdpafd, qemuFDPassFree);
g_slist_free_full(g_steal_pointer(&priv->vhostfds), (GDestroyNotify) qemuFDPassFree);
g_slist_free_full(g_steal_pointer(&priv->tapfds), (GDestroyNotify) qemuFDPassFree);
}
static void
qemuDomainNetworkPrivateDispose(void *obj G_GNUC_UNUSED)
{
qemuDomainNetworkPrivate *priv = obj;
qemuSlirpFree(priv->slirp);
qemuDomainNetworkPrivateClearFDs(priv);
}

View File

@ -401,8 +401,16 @@ struct _qemuDomainNetworkPrivate {
virObject parent;
qemuSlirp *slirp;
/* file descriptor transfer helpers */
qemuFDPass *slirpfd;
GSList *tapfds;
GSList *vhostfds;
qemuFDPass *vdpafd;
};
void
qemuDomainNetworkPrivateClearFDs(qemuDomainNetworkPrivate *priv);
typedef enum {
QEMU_PROCESS_EVENT_WATCHDOG = 0,

View File

@ -1181,6 +1181,7 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
{
qemuDomainObjPrivate *priv = vm->privateData;
virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_NET, { .net = net } };
qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
virErrorPtr originalError = NULL;
g_autofree char *slirpfdName = NULL;
int slirpfd = -1;
@ -1541,6 +1542,8 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
ret = 0;
cleanup:
qemuDomainNetworkPrivateClearFDs(netpriv);
if (ret < 0) {
virErrorPreserveLast(&save_err);
if (releaseaddr)