From 50d2489b7fa968133620a3d027bc304ffc16cb7a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 10 May 2022 16:17:17 +0200 Subject: [PATCH] qemuInterfacePrepareSlirp: Directly populate the 'slirp' variable in network private data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jonathon Jongsma Reviewed-by: Ján Tomko --- 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 a023e6eb4c..07e467d01e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5728,13 +5728,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; } }