[libvirt] [PATCH 3/7] snapshot: Add flag to enable creating checkpoints in paused state

Peter Krempa pkrempa at redhat.com
Tue Oct 9 13:39:33 UTC 2012


The default behavior while creating external checkpoints is to let the
guest run while the memory state is caputred. This leads to a larger
save file but minimizes the time needed to take the checkpoint.

This patch adds a flag that causes the guest to be paused before taking
the snapshot.
 *include/libvirt/libvirt.h.in:
    - add new paused reason: VIR_DOMAIN_PAUSED_SNAPSHOT
    - add new flag for takin snapshot: VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE
 *tools/virsh-domain-monitor.c:
    - add string representation for VIR_DOMAIN_PAUSED_SNAPSHOT
 *tools/virsh-snapshot.c:
    - add support for VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE
 *tools/virsh.pod:
    - add docs for --pause option added to use
    VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE flag
---
 include/libvirt/libvirt.h.in |  4 ++++
 tools/virsh-domain-monitor.c |  2 ++
 tools/virsh-snapshot.c       |  6 ++++++
 tools/virsh.pod              | 12 ++++++++++--
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 81f12a4..376d6d5 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -179,6 +179,7 @@ typedef enum {
     VIR_DOMAIN_PAUSED_WATCHDOG = 6,     /* paused due to a watchdog event */
     VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* paused after restoring from snapshot */
     VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
+    VIR_DOMAIN_PAUSED_SNAPSHOT = 9,      /* paused while creating a snaphot */

 #ifdef VIR_ENUM_SENTINELS
     VIR_DOMAIN_PAUSED_LAST
@@ -3663,6 +3664,9 @@ typedef enum {
                                                           the domain */
     VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC      = (1 << 7), /* atomically avoid
                                                           partial changes */
+    VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE       = (1 << 8), /* pause the guest
+                                                          before taking
+                                                          checkpoint */
 } virDomainSnapshotCreateFlags;

 /* Take a snapshot of the current VM state */
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index b264f15..faf23fe 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -223,6 +223,8 @@ vshDomainStateReasonToString(int state, int reason)
             return N_("from snapshot");
         case VIR_DOMAIN_PAUSED_SHUTTING_DOWN:
             return N_("shutting down");
+        case VIR_DOMAIN_PAUSED_SNAPSHOT:
+            return N_("creating snapshot");
         case VIR_DOMAIN_PAUSED_UNKNOWN:
         case VIR_DOMAIN_PAUSED_LAST:
             ;
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index b828371..05ee7bd 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -127,6 +127,7 @@ static const vshCmdOptDef opts_snapshot_create[] = {
     {"reuse-external", VSH_OT_BOOL, 0, N_("reuse any existing external files")},
     {"quiesce", VSH_OT_BOOL, 0, N_("quiesce guest's file systems")},
     {"atomic", VSH_OT_BOOL, 0, N_("require atomic operation")},
+    {"pause", VSH_OT_BOOL, 0, N_("pause guest before taking snapshot")},
     {NULL, 0, 0, NULL}
 };

@@ -155,6 +156,8 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE;
     if (vshCommandOptBool(cmd, "atomic"))
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC;
+    if (vshCommandOptBool(cmd, "pause"))
+        flags |= VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE;

     dom = vshCommandOptDomain(ctl, cmd, NULL);
     if (dom == NULL)
@@ -263,6 +266,7 @@ static const vshCmdOptDef opts_snapshot_create_as[] = {
     {"reuse-external", VSH_OT_BOOL, 0, N_("reuse any existing external files")},
     {"quiesce", VSH_OT_BOOL, 0, N_("quiesce guest's file systems")},
     {"atomic", VSH_OT_BOOL, 0, N_("require atomic operation")},
+    {"pause", VSH_OT_BOOL, 0, N_("pause guest before taking snapshot")},
     {"diskspec", VSH_OT_ARGV, 0,
      N_("disk attributes: disk[,snapshot=type][,driver=type][,file=name]")},
     {NULL, 0, 0, NULL}
@@ -292,6 +296,8 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE;
     if (vshCommandOptBool(cmd, "atomic"))
         flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC;
+    if (vshCommandOptBool(cmd, "pause"))
+        flags |= VIR_DOMAIN_SNAPSHOT_CREATE_PAUSE;

     dom = vshCommandOptDomain(ctl, cmd, NULL);
     if (dom == NULL)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index ac8a00f..b02ca45 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2575,7 +2575,7 @@ used to represent properties of snapshots.

 =item B<snapshot-create> I<domain> [I<xmlfile>] {[I<--redefine> [I<--current>]]
 | [I<--no-metadata>] [I<--halt>] [I<--disk-only>] [I<--reuse-external>]
-[I<--quiesce>] [I<--atomic>]}
+[I<--quiesce>] [I<--atomic>] [I<--pause>]}

 Create a snapshot for domain I<domain> with the properties specified in
 I<xmlfile>.  Normally, the only properties settable for a domain snapshot
@@ -2628,6 +2628,10 @@ this.  If this flag is not specified, then some hypervisors may fail
 after partially performing the action, and B<dumpxml> must be used to
 see whether any partial changes occurred.

+If I<--pause> is specified, libvirt pauses the guest before taking the
+snapshot to decrease size of the memory image in case of external
+checkpoints. Afterwards the guest is resumed.
+
 Existence of snapshot metadata will prevent attempts to B<undefine>
 a persistent domain.  However, for transient domains, snapshot
 metadata is silently lost when the domain quits running (whether
@@ -2636,7 +2640,7 @@ by command such as B<destroy> or by internal guest action).
 =item B<snapshot-create-as> I<domain> {[I<--print-xml>]
 | [I<--no-metadata>] [I<--halt>] [I<--reuse-external>]} [I<name>]
 [I<description>] [I<--disk-only> [I<--quiesce>] [I<--atomic>]
-[[I<--diskspec>] B<diskspec>]...]
+[I<--pause>] [[I<--diskspec>] B<diskspec>]...]

 Create a snapshot for domain I<domain> with the given <name> and
 <description>; if either value is omitted, libvirt will choose a
@@ -2681,6 +2685,10 @@ this.  If this flag is not specified, then some hypervisors may fail
 after partially performing the action, and B<dumpxml> must be used to
 see whether any partial changes occurred.

+If I<--pause> is specified, libvirt pauses the guest before taking the
+snapshot to decrease size of the memory image in case of external
+checkpoints. Afterwards the guest is resumed.
+
 =item B<snapshot-current> I<domain> {[I<--name>] | [I<--security-info>]
 | [I<snapshotname>]}

-- 
1.7.12




More information about the libvir-list mailing list