[PATCH 13/20] snapshot: qemu: Add flag VIR_DOMAIN_SNAPSHOT_REVERT_STOPPED

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

 



The current snapshot reverting api supported changing the state of the
machine after the snapshot was reverted to either started or paused.

This patch adds the ability to revert the state but to stopped state.
---
 include/libvirt/libvirt.h.in | 1 +
 src/libvirt.c                | 9 +++++----
 tools/virsh-snapshot.c       | 3 +++
 tools/virsh.pod              | 9 +++++----
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 815a491..ec03e4f 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3775,6 +3775,7 @@ 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_STOPPED = 1 << 3, /* Revert into stopped state */
 } virDomainSnapshotRevertFlags;

 /* Revert the domain to a point-in-time snapshot.  The
diff --git a/src/libvirt.c b/src/libvirt.c
index 33cf7cb..2d09eb0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -18691,11 +18691,12 @@ virDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
         goto error;
     }

-    if ((flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) &&
-        (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
+    if ((!!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) +
+         !!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)  +
+         !!(flags & VIR_DOMAIN_SNAPSHOT_REVERT_STOPPED)) > 1) {
         virReportInvalidArg(flags,
-                            _("running and paused flags in %s are mutually exclusive"),
-                            __FUNCTION__);
+                            _("running, paused and stopped flags in %s are "
+                              "mutually exclusive"), __FUNCTION__);
         goto error;
     }

diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 895cd42..b48faa3 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1467,6 +1467,7 @@ static const vshCmdOptDef opts_snapshot_revert[] = {
     {"current", VSH_OT_BOOL, 0, N_("revert to current snapshot")},
     {"running", VSH_OT_BOOL, 0, N_("after reverting, change state to running")},
     {"paused", VSH_OT_BOOL, 0, N_("after reverting, change state to paused")},
+    {"stopped", VSH_OT_BOOL, 0, N_("after reverting, change state to stopped")},
     {"force", VSH_OT_BOOL, 0, N_("try harder on risky reverts")},
     {NULL, 0, 0, NULL}
 };
@@ -1486,6 +1487,8 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING;
     if (vshCommandOptBool(cmd, "paused"))
         flags |= VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED;
+    if (vshCommandOptBool(cmd, "stopped"))
+        flags |= VIR_DOMAIN_SNAPSHOT_REVERT_STOPPED;
     /* We want virsh snapshot-revert --force to work even when talking
      * to older servers that did the unsafe revert by default but
      * reject the flag, so we probe without the flag, and only use it
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 09ad8c1..430b36e 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2796,7 +2796,7 @@ Output the name of the parent snapshot, if any, for the given
 I<snapshot>, or for the current snapshot with I<--current>.

 =item B<snapshot-revert> I<domain> {I<snapshot> | I<--current>}
-[{I<--running> | I<--paused>}] [I<--force>]
+[{I<--running> | I<--paused>} | I<--stopped>] [I<--force>]

 Revert the given domain to the snapshot specified by I<snapshot>, or to
 the current snapshot with I<--current>.  Be aware
@@ -2807,9 +2807,10 @@ the original snapshot was taken.

 Normally, reverting to a snapshot leaves the domain in the state it was
 at the time the snapshot was created, except that a disk snapshot with
-no vm state leaves the domain in an inactive state.  Passing either the
-I<--running> or I<--paused> flag will perform additional state changes
-(such as booting an inactive domain, or pausing a running domain).  Since
+no vm state leaves the domain in an inactive state.  Passing one of the
+I<--running>, I<--paused> or I<--stopped> flag will perform additional
+state changes such as booting an inactive domain, pausing a running domain
+or shutting the domain down after the snapshot is reverted.  Since
 transient domains cannot be inactive, it is required to use one of these
 flags when reverting to a disk snapshot of a transient domain.

-- 
1.7.12.4

--
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]