[PATCH v2 14/22] qemu: add config to control if auto-shutdown VMs are restored

Daniel P. Berrangé posted 22 patches 11 months ago
[PATCH v2 14/22] qemu: add config to control if auto-shutdown VMs are restored
Posted by Daniel P. Berrangé 11 months ago
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         | 1 +
 src/qemu/qemu.conf.in              | 4 ++++
 src/qemu/qemu_conf.c               | 3 +++
 src/qemu/qemu_conf.h               | 1 +
 src/qemu/qemu_driver.c             | 1 +
 src/qemu/test_libvirtd_qemu.aug.in | 1 +
 6 files changed, 11 insertions(+)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index 9fa6398d8d..ee39da73b9 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -102,6 +102,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 5643e849ad..794b8cf31f 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -689,6 +689,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 6161a3c8d6..fa6a9941b4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -318,6 +318,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);
 }
@@ -732,6 +733,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 06c917ba3e..d064c7bb9c 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -206,6 +206,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 3b74a98685..ccac2a1259 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -952,6 +952,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 65d0c20fe1..922cb35db7 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -80,6 +80,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" }
-- 
2.48.1