
From: Michal Privoznik <mprivozn@redhat.com> A caller (e.g. chDomainDestroyFlags()) might want to chose whether to kill emulator process forcefully or gracefully (the @force argument of virProcessKillPainfully()). Invent a flag to virCHProcessStop() for this. And to keep consistent behaviour, pass the flag everywhere for now. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/ch/ch_driver.c | 8 ++++++-- src/ch/ch_events.c | 2 +- src/ch/ch_process.c | 22 ++++++++++++++++------ src/ch/ch_process.h | 8 +++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 760fccba82..019994b202 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -686,8 +686,11 @@ chDomainDestroyFlags(virDomainPtr dom, unsigned int flags) if (virDomainObjCheckActive(vm) < 0) goto endjob; - if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED) < 0) + if (virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_DESTROYED, + VIR_CH_PROCESS_STOP_FORCE) < 0) { goto endjob; + } event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, @@ -818,7 +821,8 @@ chDoDomainSave(virCHDriver *driver, goto end; } - if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SAVED) < 0) { + if (virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_SAVED, VIR_CH_PROCESS_STOP_FORCE) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to shutoff after domain save")); goto end; diff --git a/src/ch/ch_events.c b/src/ch/ch_events.c index 3d4e3c41e1..be572dfde3 100644 --- a/src/ch/ch_events.c +++ b/src/ch/ch_events.c @@ -59,7 +59,7 @@ virCHEventStopProcess(virDomainObj *vm, virObjectLock(vm); if (virDomainObjBeginJob(vm, VIR_JOB_DESTROY)) return -1; - virCHProcessStop(driver, vm, reason); + virCHProcessStop(driver, vm, reason, VIR_CH_PROCESS_STOP_FORCE); virDomainObjEndJob(vm); virObjectUnlock(vm); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 6b779285e1..54b21b0baf 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -1003,7 +1003,9 @@ virCHProcessStart(virCHDriver *driver, cleanup: if (ret) - virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); + virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_FAILED, + VIR_CH_PROCESS_STOP_FORCE); return ret; } @@ -1011,7 +1013,8 @@ virCHProcessStart(virCHDriver *driver, int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, - virDomainShutoffReason reason) + virDomainShutoffReason reason, + unsigned int flags) { g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(driver); int ret; @@ -1022,13 +1025,18 @@ virCHProcessStop(virCHDriver *driver, virErrorPtr orig_err = NULL; size_t i; - VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d", - vm->def->name, (int)vm->pid, (int)reason); + VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d flags=0x%x", + vm->def->name, (int)vm->pid, (int)reason, flags); virErrorPreserveLast(&orig_err); if (priv->monitor) { - virProcessKillPainfully(vm->pid, true); + bool force = false; + + if (flags & VIR_CH_PROCESS_STOP_FORCE) + force = true; + + virProcessKillPainfully(vm->pid, force); g_clear_pointer(&priv->monitor, virCHMonitorClose); } @@ -1180,6 +1188,8 @@ virCHProcessStartRestore(virCHDriver *driver, virDomainObj *vm, const char *from if (tapfds) chCloseFDs(tapfds, ntapfds); if (ret) - virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); + virCHProcessStop(driver, vm, + VIR_DOMAIN_SHUTOFF_FAILED, + VIR_CH_PROCESS_STOP_FORCE); return ret; } diff --git a/src/ch/ch_process.h b/src/ch/ch_process.h index 70ae8f700d..a22790bb5c 100644 --- a/src/ch/ch_process.h +++ b/src/ch/ch_process.h @@ -26,9 +26,15 @@ int virCHProcessStart(virCHDriver *driver, virDomainObj *vm, virDomainRunningReason reason); + +typedef enum { + VIR_CH_PROCESS_STOP_FORCE = 1 << 0, +} virCHProcessStopFlags; + int virCHProcessStop(virCHDriver *driver, virDomainObj *vm, - virDomainShutoffReason reason); + virDomainShutoffReason reason, + unsigned int flags); int virCHProcessStartRestore(virCHDriver *driver, virDomainObj *vm, -- 2.49.1