mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-28 11:21:44 +03:00
qemuInterfacePrepareSlirp: Directly populate the 'slirp' variable in network private data
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@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
13ae2e2e30
commit
50d2489b7f
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user