From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
If a slirp-helper is associated with a network interface,
prepare/start/stop the process via qemu-extdevice.
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
src/qemu/qemu_extdevice.c | 46 ++++++++++++++++++++++++++++++++++-----
src/qemu/qemu_extdevice.h | 8 ++++---
src/qemu/qemu_process.c | 4 ++--
3 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 79d5d64951..2a6cb12215 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -23,6 +23,7 @@
#include "qemu_extdevice.h"
#include "qemu_domain.h"
#include "qemu_tpm.h"
+#include "qemu_slirp.h"
#include "viralloc.h"
#include "virlog.h"
@@ -87,14 +88,24 @@ qemuExtDevicesInitPaths(virQEMUDriverPtr driver,
*/
int
qemuExtDevicesPrepareHost(virQEMUDriverPtr driver,
- virDomainDefPtr def)
+ virDomainObjPtr vm)
{
- int ret = 0;
+ virDomainDefPtr def = vm->def;
+ size_t i;
- if (def->tpm)
- ret = qemuExtTPMPrepareHost(driver, def);
+ if (def->tpm &&
+ qemuExtTPMPrepareHost(driver, def) < 0)
+ return -1;
- return ret;
+ for (i = 0; i < def->nnets; i++) {
+ virDomainNetDefPtr net = def->nets[i];
+ qemuSlirpPtr slirp = QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp;
+
+ if (slirp && qemuSlirpOpen(slirp, driver, def) < 0)
+ return -1;
+ }
+
+ return 0;
}
@@ -112,9 +123,12 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver,
int
qemuExtDevicesStart(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+ virDomainObjPtr vm,
+ qemuProcessIncomingDefPtr incoming)
{
+ virDomainDefPtr def = vm->def;
int ret = 0;
+ size_t i;
if (qemuExtDevicesInitPaths(driver, vm->def) < 0)
return -1;
@@ -122,6 +136,15 @@ qemuExtDevicesStart(virQEMUDriverPtr driver,
if (vm->def->tpm)
ret = qemuExtTPMStart(driver, vm);
+ for (i = 0; i < def->nnets; i++) {
+ virDomainNetDefPtr net = def->nets[i];
+ qemuSlirpPtr slirp = QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp;
+
+ if (slirp &&
+ qemuSlirpStart(slirp, vm, driver, net, incoming) < 0)
+ return -1;
+ }
+
return ret;
}
@@ -130,11 +153,22 @@ void
qemuExtDevicesStop(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
+ virDomainDefPtr def = vm->def;
+ size_t i;
+
if (qemuExtDevicesInitPaths(driver, vm->def) < 0)
return;
if (vm->def->tpm)
qemuExtTPMStop(driver, vm);
+
+ for (i = 0; i < def->nnets; i++) {
+ virDomainNetDefPtr net = def->nets[i];
+ qemuSlirpPtr slirp = QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp;
+
+ if (slirp)
+ qemuSlirpStop(slirp, vm, driver, net);
+ }
}
diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h
index c9a3109fb6..39502b57a6 100644
--- a/src/qemu/qemu_extdevice.h
+++ b/src/qemu/qemu_extdevice.h
@@ -22,6 +22,7 @@
#include "qemu_conf.h"
#include "qemu_domain.h"
+#include "qemu_process.h"
int qemuExtDeviceLogCommand(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -31,7 +32,7 @@ int qemuExtDeviceLogCommand(virQEMUDriverPtr driver,
ATTRIBUTE_RETURN_CHECK;
int qemuExtDevicesPrepareHost(virQEMUDriverPtr driver,
- virDomainDefPtr def)
+ virDomainObjPtr vm)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_RETURN_CHECK;
@@ -40,8 +41,9 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuExtDevicesStart(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+ virDomainObjPtr vm,
+ qemuProcessIncomingDefPtr incoming)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK;
void qemuExtDevicesStop(virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 93e06104f4..d067223a0e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6535,7 +6535,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
goto cleanup;
VIR_DEBUG("Preparing external devices");
- if (qemuExtDevicesPrepareHost(driver, vm->def) < 0)
+ if (qemuExtDevicesPrepareHost(driver, vm) < 0)
goto cleanup;
if (qemuProcessPrepareSEVGuestInput(vm) < 0)
@@ -6710,7 +6710,7 @@ qemuProcessLaunch(virConnectPtr conn,
if (qemuProcessGenID(vm, flags) < 0)
goto cleanup;
- if (qemuExtDevicesStart(driver, vm) < 0)
+ if (qemuExtDevicesStart(driver, vm, incoming) < 0)
goto cleanup;
VIR_DEBUG("Building emulator command line");
--
2.22.0.214.g8dca754b1e