From: Masayoshi Mizuma Date: Mon, 30 Aug 2021 04:30:42 +0000 (-0400) Subject: qemu: process: Split out logic for setting the 'allowReboot' internal flag X-Git-Tag: v7.8.0-rc1~330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2e6039ccad308adeaa4b3c4155f2ce5d44e03fa;p=thirdparty%2Flibvirt.git qemu: process: Split out logic for setting the 'allowReboot' internal flag Split out the logic which was used to determine whether qemu should allow the guest OS to reboot for QEMU versions which don't support the 'set-action' QMP command. Signed-off-by: Masayoshi Mizuma Signed-off-by: Peter Krempa Reviewed-by: Peter Krempa --- diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3b4af61bf8..207129a556 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6361,6 +6361,24 @@ qemuProcessPrepareHostHostdevs(virDomainObj *vm) } +/** + * qemuProcessRebootAllowed: + * @def: domain definition + * + * This function encapsulates the logic which dictated whether '-no-reboot' was + * used instead of '-no-shutdown' which is used QEMU versions which don't + * support the 'set-action' QMP command. + */ +bool +qemuProcessRebootAllowed(const virDomainDef *def) +{ + return def->onReboot != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || + def->onPoweroff != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || + (def->onCrash != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && + def->onCrash != VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY); +} + + static void qemuProcessPrepareAllowReboot(virDomainObj *vm) { @@ -6375,14 +6393,7 @@ qemuProcessPrepareAllowReboot(virDomainObj *vm) if (priv->allowReboot != VIR_TRISTATE_BOOL_ABSENT) return; - if (def->onReboot == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && - def->onPoweroff == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && - (def->onCrash == VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY || - def->onCrash == VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY)) { - priv->allowReboot = VIR_TRISTATE_BOOL_NO; - } else { - priv->allowReboot = VIR_TRISTATE_BOOL_YES; - } + priv->allowReboot = virTristateBoolFromBool(qemuProcessRebootAllowed(def)); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 93103eb530..f9fa140e6d 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -242,3 +242,5 @@ void qemuProcessQMPFree(qemuProcessQMP *proc); G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuProcessQMP, qemuProcessQMPFree); int qemuProcessQMPStart(qemuProcessQMP *proc); + +bool qemuProcessRebootAllowed(const virDomainDef *def);