From: Daniel P. Berrangé Date: Fri, 20 Dec 2024 12:55:49 +0000 (+0000) Subject: qemu: add config to control if auto-shutdown VMs are restored X-Git-Tag: v11.2.0-rc1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da1d0f32d0dc83717285bbf30f61e5239a910024;p=thirdparty%2Flibvirt.git qemu: add config to control if auto-shutdown VMs are restored If shutting down running VMs at host shutdown, it can be useful to automatically start them again on next boot. This adds a config parameter 'auto_shutdown_restore', which defaults to enabled, which leverages the autostart once feature. 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 2871c5b128..bd744940d2 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -107,6 +107,7 @@ module Libvirtd_qemu = | str_entry "auto_shutdown_try_shutdown" | str_entry "auto_shutdown_poweroff" | int_entry "auto_shutdown_wait" + | bool_entry "auto_shutdown_restore" | bool_entry "auto_save_bypass_cache" let process_entry = str_entry "hugetlbfs_mount" diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in index e4859f9b59..ed80169348 100644 --- a/src/qemu/qemu.conf.in +++ b/src/qemu/qemu.conf.in @@ -714,6 +714,10 @@ # is currently 30 secs) #auto_shutdown_wait = 30 +# Whether VMs that are automatically powered off or saved during +# host shutdown, should be set to restore on next boot +#auto_shutdown_restore = 1 + # When a domain is configured to be auto-saved on shutdown, enabling # this flag has the same effect as using the VIR_DOMAIN_SAVE_BYPASS_CACHE # flag with the virDomainManagedSave API. That is, the system will diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index a9dde2bcab..8ffbcacaf2 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -328,6 +328,7 @@ virQEMUDriverConfig *virQEMUDriverConfigNew(bool privileged, cfg->autoShutdownTryShutdown = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_ALL; cfg->autoShutdownPoweroff = VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_ALL; } + cfg->autoShutdownRestore = true; return g_steal_pointer(&cfg); } @@ -766,6 +767,8 @@ virQEMUDriverConfigLoadSaveEntry(virQEMUDriverConfig *cfg, if (virConfGetValueUInt(conf, "auto_shutdown_wait", &cfg->autoShutdownWait) < 0) return -1; + if (virConfGetValueBool(conf, "auto_shutdown_restore", &cfg->autoShutdownRestore) < 0) + return -1; if (virConfGetValueBool(conf, "auto_save_bypass_cache", &cfg->autoSaveBypassCache) < 0) return -1; diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 6171b3f5df..f6b13c828d 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -216,6 +216,7 @@ struct _virQEMUDriverConfig { virDomainDriverAutoShutdownScope autoShutdownTryShutdown; virDomainDriverAutoShutdownScope autoShutdownPoweroff; unsigned int autoShutdownWait; + bool autoShutdownRestore; bool autoSaveBypassCache; char *lockManagerName; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 075661c13b..7aa9a09737 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -971,6 +971,7 @@ qemuStateStop(void) .poweroff = cfg->autoShutdownPoweroff, .waitShutdownSecs = cfg->autoShutdownWait, .saveBypassCache = cfg->autoSaveBypassCache, + .autoRestore = cfg->autoShutdownRestore, }; virDomainDriverAutoShutdown(&ascfg); diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in index b242cb5be1..88d1a6aca1 100644 --- a/src/qemu/test_libvirtd_qemu.aug.in +++ b/src/qemu/test_libvirtd_qemu.aug.in @@ -84,6 +84,7 @@ module Test_libvirtd_qemu = { "auto_shutdown_try_shutdown" = "all" } { "auto_shutdown_poweroff" = "all" } { "auto_shutdown_wait" = "30" } +{ "auto_shutdown_restore" = "1" } { "auto_save_bypass_cache" = "0" } { "hugetlbfs_mount" = "/dev/hugepages" } { "bridge_helper" = "qemu-bridge-helper" }