From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> 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@xxxxxxxxxx> --- src/qemu/qemu_extdevice.c | 47 +++++++++++++++++++++++++++++++++------ src/qemu/qemu_extdevice.h | 5 +++-- src/qemu/qemu_process.c | 4 ++-- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index 0aa050cb0a..179552a3ae 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; } @@ -114,15 +125,26 @@ int qemuExtDevicesStart(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt, - bool incomingMigration) + qemuProcessIncomingDefPtr incoming) { + virDomainDefPtr def = vm->def; int ret = 0; + size_t i; if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return -1; if (vm->def->tpm) - ret = qemuExtTPMStart(driver, vm, logCtxt, incomingMigration); + ret = qemuExtTPMStart(driver, vm, logCtxt, incoming != NULL); + + 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, false, incoming) < 0) + return -1; + } return ret; } @@ -132,11 +154,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, false); + } } diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index cdd20c28ef..a526308c51 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; @@ -42,7 +43,7 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, int qemuExtDevicesStart(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt, - bool incomingMigration) + qemuProcessIncomingDefPtr incoming) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f8d740979d..d41ee0f25b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6602,7 +6602,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) @@ -6776,7 +6776,7 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessGenID(vm, flags) < 0) goto cleanup; - if (qemuExtDevicesStart(driver, vm, logCtxt, incoming != NULL) < 0) + if (qemuExtDevicesStart(driver, vm, logCtxt, incoming) < 0) goto cleanup; VIR_DEBUG("Building emulator command line"); -- 2.23.0.rc1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list