From: Daniel P. Berrangé Date: Tue, 17 Dec 2024 17:45:05 +0000 (+0000) Subject: qemu: support automatic VM managed save in system daemon X-Git-Tag: v11.2.0-rc1~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f48f700f3d5d2783c7201d51f9cb88ceb5dda7df;p=thirdparty%2Flibvirt.git qemu: support automatic VM managed save in system daemon Currently automatic VM managed save is only performed in session daemons, on desktop session close, or host OS shutdown request. With this change it is possible to control shutdown behaviour for all daemons. A recommended setup might be: auto_shutdown_try_save = "persistent" auto_shutdown_try_shutdown = "all" auto_shutdown_poweroff = "all" Each setting accepts 'none', 'persistent', 'transient', and 'all' to control what types of guest it applies to. For historical compatibility, for the system daemon, the settings currently default to: auto_shutdown_try_save = "none" auto_shutdown_try_shutdown = "none" auto_shutdown_poweroff = "none" while for the session daemon they currently default to auto_shutdown_try_save = "persistent" auto_shutdown_try_shutdown = "none" auto_shutdown_poweroff = "none" The system daemon settings should NOT be enabled if the traditional libvirt-guests.service is already enabled. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrangé --- diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 0288c2895b..b2b3616195 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -103,6 +103,9 @@ module Libvirtd_qemu = | bool_entry "auto_dump_bypass_cache" | bool_entry "auto_start_bypass_cache" | int_entry "auto_start_delay" + | str_entry "auto_shutdown_try_save" + | str_entry "auto_shutdown_try_shutdown" + | str_entry "auto_shutdown_poweroff" let process_entry = str_entry "hugetlbfs_mount" | str_entry "bridge_helper" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index 9354e960f1..ea7f905485 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -664,6 +664,48 @@ # #auto_start_delay = 0 +# The settings for auto shutdown actions accept one of +# four possible options: +# +# * "none" - do not try to save any running VMs +# * "persistent" - only try to save persistent running VMs +# * "transient" - only try to save transient running VMs +# * "all" - try to save all running VMs + +# Whether to perform managed save of running VMs if a host OS +# shutdown is requested (system/session daemons), or the desktop +# session terminates (session daemon only). +# +# Defaults to "persistent" for session daemons and "none" +# for system daemons. The values "all" and "transient" are +# not permitted for this setting, since managed save is not +# implemented for transient VMs. +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_try_save = "persistent" + +# As above, but with a graceful shutdown action instead of +# managed save. If managed save is enabled, shutdown will +# be tried only on failure to perform managed save. +# +# Defaults to "none" +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_try_shutdown = "none" + +# As above, but with a forced poweroff instead of managed +# save. If managed save or graceful shutdown are enabled, +# forced poweroff will be tried only on failure of the +# other options. +# +# Defaults to "none" +# +# If 'libvirt-guests.service' is enabled, then this must be +# set to 'none' for system daemons to avoid dueling actions +#auto_shutdown_poweroff = "none" + # If provided by the host and a hugetlbfs mount point is configured, # a guest may request huge page backing. When this mount point is # unspecified here, determination of a host mount point in /proc/mounts diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 79634511db..f0b0749259 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -314,6 +314,21 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->dumpGuestCore = true; #endif + if (privileged) { + /* + * Defer to libvirt-guests.service. + * + * XXX, or query if libvirt-guests.service is enabled perhaps ? + */ + cfg->autoShutdownTrySave = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE; + cfg->autoShutdownTryShutdown = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE; + cfg->autoShutdownPoweroff = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE; + } else { + cfg->autoShutdownTrySave = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_PERSISTENT; + cfg->autoShutdownTryShutdown = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE; + cfg->autoShutdownPoweroff = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE; + } + return g_steal_pointer(&cfg); } @@ -659,6 +674,10 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *cfg, g_autofree char *savestr = NULL; g_autofree char *dumpstr = NULL; g_autofree char *snapstr = NULL; + g_autofree char *autoShutdownTrySave = NULL; + g_autofree char *autoShutdownTryShutdown = NULL; + g_autofree char *autoShutdownPoweroff = NULL; + int autoShutdownVal; if (virConfGetValueString(conf, "save_image_format", &savestr) < 0) return -1; @@ -695,6 +714,54 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *cfg, return -1; if (virConfGetValueUInt(conf, "auto_start_delay", &cfg->autoStartDelayMS) < 0) return -1; + if (virConfGetValueString(conf, "auto_shutdown_try_save", &autoShutdownTrySave) < 0) + return -1; + + if (autoShutdownTrySave != NULL) { + if ((autoShutdownVal = + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownTrySave)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_save '%1$s'"), + autoShutdownTrySave); + return -1; + } + cfg->autoShutdownTrySave = autoShutdownVal; + } + + if (cfg->autoShutdownTrySave == VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_ALL || + cfg->autoShutdownTrySave == VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_TRANSIENT) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("managed save cannot be requested for transient domains")); + return -1; + } + + if (virConfGetValueString(conf, "auto_shutdown_try_shutdown", &autoShutdownTryShutdown) < 0) + return -1; + + if (autoShutdownTryShutdown != NULL) { + if ((autoShutdownVal = + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownTryShutdown)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_try_shutdown '%1$s'"), + autoShutdownTryShutdown); + return -1; + } + cfg->autoShutdownTryShutdown = autoShutdownVal; + } + + if (virConfGetValueString(conf, "auto_shutdown_poweroff", &autoShutdownPoweroff) < 0) + return -1; + + if (autoShutdownPoweroff != NULL) { + if ((autoShutdownVal = + virDomainDriverAutoShutdownScopeTypeFromString(autoShutdownPoweroff)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("unknown auto_shutdown_poweroff '%1$s'"), + autoShutdownPoweroff); + return -1; + } + cfg->autoShutdownPoweroff = autoShutdownVal; + } return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index bbbbd6bf67..5df9f6501e 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -43,6 +43,7 @@ #include "virfilecache.h" #include "virfirmware.h" #include "virinhibitor.h" +#include "domain_driver.h" #define QEMU_DRIVER_NAME "QEMU" @@ -211,6 +212,9 @@ struct _virQEMUDriverConfig { bool autoDumpBypassCache; bool autoStartBypassCache; unsigned int autoStartDelayMS; + virDomainDriverAutoShutdownScope autoShutdownTrySave; + virDomainDriverAutoShutdownScope autoShutdownTryShutdown; + virDomainDriverAutoShutdownScope autoShutdownPoweroff; char *lockManagerName; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9d6523cfbc..8f69d0ec9c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -966,13 +966,12 @@ qemuStateStop(void) g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(qemu_driver); virDomainDriverAutoShutdownConfig ascfg = { .uri = cfg->uri, - .trySave = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_PERSISTENT, - .tryShutdown = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE, - .poweroff = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE + .trySave = cfg->autoShutdownTrySave, + .tryShutdown = cfg->autoShutdownTryShutdown, + .poweroff = cfg->autoShutdownPoweroff, }; - if (!qemu_driver->privileged) - virDomainDriverAutoShutdown(&ascfg); + virDomainDriverAutoShutdown(&ascfg); return 0; } diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index 8ef26a9da1..9dd5fdb1d9 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -80,6 +80,9 @@ module Test_libvirtd_qemu = { "auto_dump_bypass_cache" = "0" } { "auto_start_bypass_cache" = "0" } { "auto_start_delay" = "0" } +{ "auto_shutdown_try_save" = "persistent" } +{ "auto_shutdown_try_shutdown" = "none" } +{ "auto_shutdown_poweroff" = "none" } { "hugetlbfs_mount" = "/dev/hugepages" } { "bridge_helper" = "qemu-bridge-helper" } { "set_process_name" = "1" }