[PATCH 2/7] qemu: Use active and inactive snapshot configuration on restore

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

 



By default, active and inactive XMl snapshot configurations are
assigned to domain definition. This will make sure that all the
non-persistent configurations of the snapshot are restored back
as it is. This patch will also make sure that user has a choice
to choose of using active XML configuration of snapshot as both
active and inactive XML configurations of the restoring domain.

Signed-off-by: Kothapally Madhu Pavan <kmp@xxxxxxxxxxxxxxxxxx>
---
 include/libvirt/libvirt-domain-snapshot.h | 10 +++++++---
 src/qemu/qemu_driver.c                    | 20 +++++++++++++++++++-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt-domain-snapshot.h b/include/libvirt/libvirt-domain-snapshot.h
index 0f73f24..67ccb59 100644
--- a/include/libvirt/libvirt-domain-snapshot.h
+++ b/include/libvirt/libvirt-domain-snapshot.h
@@ -184,9 +184,13 @@ int virDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
                                  unsigned int flags);
 
 typedef enum {
-    VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING = 1 << 0, /* Run after revert */
-    VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED  = 1 << 1, /* Pause after revert */
-    VIR_DOMAIN_SNAPSHOT_REVERT_FORCE   = 1 << 2, /* Allow risky reverts */
+    VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING       = 1 << 0, /* Run after revert */
+    VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED        = 1 << 1, /* Pause after revert */
+    VIR_DOMAIN_SNAPSHOT_REVERT_FORCE         = 1 << 2, /* Allow risky reverts */
+    VIR_DOMAIN_SNAPSHOT_REVERT_ACTIVE_ONLY   = 1 << 3, /* Use active snapshot
+                                                          configurations as both
+                                                          active and inactive
+                                                          domain configurations*/
 } virDomainSnapshotRevertFlags;
 
 /* Revert the domain to a point-in-time snapshot.  The
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4ffec70..aecfcff 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15577,6 +15577,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
     qemuDomainObjPrivatePtr priv;
     int rc;
     virDomainDefPtr config = NULL;
+    virDomainDefPtr newConfig = NULL;
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
     bool was_running = false;
@@ -15586,7 +15587,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 
     virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
                   VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
-                  VIR_DOMAIN_SNAPSHOT_REVERT_FORCE, -1);
+                  VIR_DOMAIN_SNAPSHOT_REVERT_FORCE |
+                  VIR_DOMAIN_SNAPSHOT_REVERT_ACTIVE_ONLY, -1);
 
     /* We have the following transitions, which create the following events:
      * 1. inactive -> inactive: none
@@ -15688,6 +15690,16 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
             goto endjob;
     }
 
+    /* Prepare to copy snapshot inactive xml as inactive configuration
+     * of this domain unless user exclusively specify not to copy it */
+    if (!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_ACTIVE_ONLY) &&
+        snap->def->newDom) {
+        newConfig = virDomainDefCopy(snap->def->newDom, caps,
+                                     driver->xmlopt, NULL, true);
+        if (!newConfig)
+            goto endjob;
+    }
+
     cookie = (qemuDomainSaveCookiePtr) snap->def->cookie;
 
     switch ((virDomainState) snap->def->state) {
@@ -15785,12 +15797,16 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
                 virCPUDefFree(priv->origCPU);
                 VIR_STEAL_PTR(priv->origCPU, origCPU);
             }
+            if (newConfig)
+                vm->newDef = newConfig;
         } else {
             /* Transitions 2, 3 */
         load:
             was_stopped = true;
             if (config)
                 virDomainObjAssignDef(vm, config, false, NULL);
+            if (newConfig)
+                vm->newDef = newConfig;
 
             /* No cookie means libvirt which saved the domain was too old to
              * mess up the CPU definitions.
@@ -15884,6 +15900,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
         }
         if (config)
             virDomainObjAssignDef(vm, config, false, NULL);
+        if (newConfig)
+            vm->newDef = newConfig;
 
         if (flags & (VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
                      VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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