]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: add config to control if auto-shutdown VMs are restored
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 20 Dec 2024 12:55:49 +0000 (12:55 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 20 Mar 2025 14:55:17 +0000 (14:55 +0000)
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 <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/libvirtd_qemu.aug
src/qemu/qemu.conf.in
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_driver.c
src/qemu/test_libvirtd_qemu.aug.in

index 2871c5b1285dd33dc0d528a71acf8ab26d8541d2..bd744940d2b87e03bb85db9839cc4947f3eb5d8e 100644 (file)
@@ -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"
index e4859f9b5937f2a882de3ecaf4addbafc6f7c00a..ed8016934884326fc85be261d72ae4d6fee03819 100644 (file)
 # 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
index a9dde2bcabbdf34845e3a2d73e11b7c849a111ff..8ffbcacaf2942d76f1211792678c99554a58f302 100644 (file)
@@ -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;
index 6171b3f5df0dac6264bd4fdcd079a04bb129a9e0..f6b13c828da64698ae9ea10763855526c6a75d91 100644 (file)
@@ -216,6 +216,7 @@ struct _virQEMUDriverConfig {
     virDomainDriverAutoShutdownScope autoShutdownTryShutdown;
     virDomainDriverAutoShutdownScope autoShutdownPoweroff;
     unsigned int autoShutdownWait;
+    bool autoShutdownRestore;
     bool autoSaveBypassCache;
 
     char *lockManagerName;
index 075661c13b15a676d720872bd2128f407ae60b45..7aa9a09737daf540290dfb29a80c4dabf0dc0c68 100644 (file)
@@ -971,6 +971,7 @@ qemuStateStop(void)
         .poweroff = cfg->autoShutdownPoweroff,
         .waitShutdownSecs = cfg->autoShutdownWait,
         .saveBypassCache = cfg->autoSaveBypassCache,
+        .autoRestore = cfg->autoShutdownRestore,
     };
 
     virDomainDriverAutoShutdown(&ascfg);
index b242cb5be175cefc29241701f5a5c9d563484936..88d1a6aca1f921fbfd6720f392e40cb36af90841 100644 (file)
@@ -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" }