]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hypervisor: wire up support for auto restore of running domains
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 20 Dec 2024 11:38:01 +0000 (11:38 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 20 Mar 2025 14:55:17 +0000 (14:55 +0000)
When performing auto-shutdown of running domains, there is now the
option to mark them as "autostart once",  so that their state is
restored on next boot. This applies on top of the traditional
autostart flag.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/hypervisor/domain_driver.c
src/hypervisor/domain_driver.h

index f9fead5a468f1d05e4e9d61bb5693eed2515e026..4e85417dedc53975f90f1941a24c713aeab30716 100644 (file)
@@ -739,12 +739,12 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
     virDomainPtr *domains = NULL;
     g_autofree bool *transient = NULL;
 
-    VIR_DEBUG("Run autoshutdown uri=%s trySave=%s tryShutdown=%s poweroff=%s waitShutdownSecs=%u saveBypassCache=%d",
+    VIR_DEBUG("Run autoshutdown uri=%s trySave=%s tryShutdown=%s poweroff=%s waitShutdownSecs=%u saveBypassCache=%d autoRestore=%d",
               cfg->uri,
               virDomainDriverAutoShutdownScopeTypeToString(cfg->trySave),
               virDomainDriverAutoShutdownScopeTypeToString(cfg->tryShutdown),
               virDomainDriverAutoShutdownScopeTypeToString(cfg->poweroff),
-              cfg->waitShutdownSecs, cfg->saveBypassCache);
+              cfg->waitShutdownSecs, cfg->saveBypassCache, cfg->autoRestore);
 
     /*
      * Ideally guests will shutdown in a few seconds, but it would
@@ -793,6 +793,21 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
     for (i = 0; i < numDomains; i++) {
         if (virDomainIsPersistent(domains[i]) == 0)
             transient[i] = true;
+
+        if (cfg->autoRestore) {
+            if (transient[i]) {
+                VIR_DEBUG("Cannot auto-restore transient VM %s",
+                          virDomainGetName(domains[i]));
+            } else {
+                VIR_DEBUG("Mark %s for autostart on next boot",
+                          virDomainGetName(domains[i]));
+                if (virDomainSetAutostartOnce(domains[i], 1) < 0) {
+                    VIR_WARN("Unable to mark domain '%s' for auto restore: %s",
+                             virDomainGetName(domains[i]),
+                             virGetLastErrorMessage());
+                }
+            }
+        }
     }
 
     if (cfg->trySave != VIR_DOMAIN_DRIVER_AUTO_SHUTDOWN_SCOPE_NONE) {
index fae316ee2d71565366cff7cefe94a799c82efe29..d90466b9420401a9c1f20160c33872f7b4abf867 100644 (file)
@@ -113,6 +113,7 @@ typedef struct _virDomainDriverAutoShutdownConfig {
                                     * If 0 a default is used (currently 30 secs)
                                     */
     bool saveBypassCache;
+    bool autoRestore;
 } virDomainDriverAutoShutdownConfig;
 
 void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg);