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

[libvirt] [PATCHv2 14/20] snapshot: qemu: Add flag VIR_DOMAIN_SNAPSHOT_REVERT_STOPPED



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              | 15 +++++++++------
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index fe58c08..ea57d00 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3872,6 +3872,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 1da3973..4a4518f 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -18698,11 +18698,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 77364e8..818ef56 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1469,6 +1469,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}
 };
@@ -1488,6 +1489,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 a331e56..7c65443 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2803,7 +2803,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
@@ -2814,11 +2814,14 @@ 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
-transient domains cannot be inactive, it is required to use one of these
-flags when reverting to a disk snapshot of a transient domain.
+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
+I<--running> or I<--paused> flags when reverting to a disk snapshot of a
+transient domain. The I<--stopped> flag cannot be used on snapshots
+of transient domains.

 There are two cases where a snapshot revert involves extra risk, which
 requires the use of I<--force> to proceed.  One is the case of a
-- 
1.7.12.4


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