[PATCH 18/26] 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.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/hypervisor/domain_driver.c | 27 ++++++++++++++++++++++-----
 src/hypervisor/domain_driver.h |  1 +
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 867ee1ae2a..2f89b8c841 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -677,10 +677,11 @@ virDomainDriverAutoStartOne(virDomainObj *vm,
     virObjectLock(vm);
     virObjectRef(vm);
 
-    VIR_DEBUG("Autostart %s: autostart=%d",
-              vm->def->name, vm->autostart);
+    VIR_DEBUG("Autostart %s: autostart=%d autostartOnce=%d",
+              vm->def->name, vm->autostart, vm->autostartOnce);
 
-    if (vm->autostart && !virDomainObjIsActive(vm)) {
+    if ((vm->autostart || vm->autostartOnce)
+        && !virDomainObjIsActive(vm)) {
         virResetLastError();
         if (state->cfg->delayMS) {
             if (!state->first) {
@@ -691,6 +692,7 @@ virDomainDriverAutoStartOne(virDomainObj *vm,
         }
 
         state->cfg->callback(vm, state->cfg->opaque);
+        vm->autostartOnce = 0;
     }
 
     virDomainObjEndAPI(&vm);
@@ -725,9 +727,9 @@ virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg)
     g_autofree bool *transient = NULL;
 
     VIR_DEBUG("Run autoshutdown uri=%s trySave=%d tryShutdown=%d poweroff=%d"
-              "waitShutdownSecs=%d saveBypassCache=%d",
+              "waitShutdownSecs=%d saveBypassCache=%d autoRestore=%d",
               cfg->uri, cfg->trySave, cfg->tryShutdown, cfg->poweroff,
-              cfg->waitShutdownSecs, cfg->saveBypassCache);
+              cfg->waitShutdownSecs, cfg->saveBypassCache, cfg->autoRestore);
 
     /*
      * Ideally guests will shutdown in a few seconds, but it would
@@ -763,6 +765,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 16832f2449..72152f8054 100644
--- a/src/hypervisor/domain_driver.h
+++ b/src/hypervisor/domain_driver.h
@@ -109,6 +109,7 @@ typedef struct _virDomainDriverAutoShutdownConfig {
     virDomainDriverAutoShutdownScope poweroff;
     int waitShutdownSecs;
     bool saveBypassCache;
+    bool autoRestore;
 } virDomainDriverAutoShutdownConfig;
 
 void virDomainDriverAutoShutdown(virDomainDriverAutoShutdownConfig *cfg);
-- 
2.47.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