[PATCH 31/37] qemuInterfacePrepareSlirp: Directly populate the 'slirp' variable in network private data

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

 



Both callers populate the variable when qemuInterfacePrepareSlirp
returned 1. We can save the hassle in the callers by just doing it right
away.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c   |  8 +++-----
 src/qemu/qemu_interface.c | 10 +++++-----
 src/qemu/qemu_interface.h |  3 +--
 src/qemu/qemu_process.c   |  7 +------
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e126632507..8314d0e546 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1306,14 +1306,12 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
         if (!priv->disableSlirp &&
             virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) {
             qemuSlirp *slirp = NULL;
-            int rv = qemuInterfacePrepareSlirp(driver, net, &slirp);

-            if (rv == -1)
+            if (qemuInterfacePrepareSlirp(driver, net) < 0)
                 goto cleanup;
-            if (rv == 0)
-                break;

-            QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp = slirp;
+            if (!(slirp = QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp))
+                break;

             if (qemuSlirpOpen(slirp, driver, vm->def) < 0 ||
                 qemuSlirpStart(slirp, vm, driver, net, NULL) < 0) {
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index c807be0745..bda96808eb 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -651,12 +651,12 @@ qemuInterfaceVDPAConnect(virDomainNetDef *net)


 /*
- * Returns: -1 on error, 0 if slirp isn't available, 1 on success
+ * Returns: -1 on error, 0 on success. Populates net->privateData->slirp if
+ * the slirp helper is needed.
  */
 int
 qemuInterfacePrepareSlirp(virQEMUDriver *driver,
-                          virDomainNetDef *net,
-                          qemuSlirp **slirpret)
+                          virDomainNetDef *net)
 {
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autoptr(qemuSlirp) slirp = NULL;
@@ -681,8 +681,8 @@ qemuInterfacePrepareSlirp(virQEMUDriver *driver,
             return 0;
     }

-    *slirpret = g_steal_pointer(&slirp);
-    return 1;
+    QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp = g_steal_pointer(&slirp);
+    return 0;
 }


diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h
index a566d877b0..e359d4f520 100644
--- a/src/qemu/qemu_interface.h
+++ b/src/qemu/qemu_interface.h
@@ -55,7 +55,6 @@ int qemuInterfaceOpenVhostNet(virDomainObj *def,
                               virDomainNetDef *net) G_GNUC_NO_INLINE;

 int qemuInterfacePrepareSlirp(virQEMUDriver *driver,
-                              virDomainNetDef *net,
-                              qemuSlirp **slirp);
+                              virDomainNetDef *net);

 int qemuInterfaceVDPAConnect(virDomainNetDef *net) G_GNUC_NO_INLINE;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index be10d2f3ac..392a99a769 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5724,13 +5724,8 @@ qemuProcessNetworkPrepareDevices(virQEMUDriver *driver,
         } else if (actualType == VIR_DOMAIN_NET_TYPE_USER &&
                    !priv->disableSlirp &&
                    virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) {
-            qemuSlirp *slirp = NULL;
-            int rv = qemuInterfacePrepareSlirp(driver, net, &slirp);
-
-            if (rv == -1)
+            if (qemuInterfacePrepareSlirp(driver, net) < 0)
                 return -1;
-            if (rv == 1)
-                QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp = slirp;
          }

     }
-- 
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