[PATCH v2 12/22] hypervisor: wire up support for auto restore of running domains

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/hypervisor/domain_driver.c | 19 +++++++++++++++++--
 src/hypervisor/domain_driver.h |  1 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index bfba435ee0..1105d36388 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -738,12 +738,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
@@ -788,6 +788,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) {
diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h
index fae316ee2d..d90466b942 100644
--- a/src/hypervisor/domain_driver.h
+++ b/src/hypervisor/domain_driver.h
@@ -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);
-- 
2.48.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux