[PATCH 12/37] qemu: domain: Add qemuFDPass helpers into network private data

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

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_command.c |  3 +++
 src/qemu/qemu_domain.c  | 15 +++++++++++++++
 src/qemu/qemu_domain.h  |  8 ++++++++
 src/qemu/qemu_hotplug.c |  3 +++
 4 files changed, 29 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 95632827cb..0d1517a5d6 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8682,6 +8682,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;
@@ -8938,6 +8939,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,

     ret = 0;
  cleanup:
+    qemuDomainNetworkPrivateClearFDs(netpriv);
+
     if (ret < 0) {
         virErrorPtr saved_err;

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2df02943bf..96b0fe56ee 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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);
 }


diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index e13c6be399..85f75ee197 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -398,8 +398,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,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e8e028706b..2923992759 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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)
-- 
2.35.1




[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]

  Powered by Linux