snapshot: Add flag to enable creating checkpoints in live state

The default behavior while creating external checkpoints is to pause the
guest while the memory state is captured. We want the users to sacrifice
space saving for creating the memory save image while the guest is live
to minimize downtime.

This patch adds a flag that causes the guest not to be paused before
taking the snapshot.
 *include/libvirt/libvirt.h.in:
    - add new paused reason: VIR_DOMAIN_PAUSED_SNAPSHOT
    - add new flag for taking snapshot: VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh-domain-monitor.c:
    - add string representation for VIR_DOMAIN_PAUSED_SNAPSHOT
 *tools/virsh-snapshot.c:
    - add support for VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh.pod:
    - add docs for --live option added to use
    VIR_DOMAIN_SNAPSHOT_CREATE_LIVE flag
This commit is contained in:
Peter Krempa 2012-10-09 12:11:56 +02:00
parent 2771f8b74c
commit 5f75bd4bbe
5 changed files with 28 additions and 2 deletions

View File

@ -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 snapshot */
#ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_PAUSED_LAST
@ -3770,6 +3771,9 @@ typedef enum {
the domain */
VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC = (1 << 7), /* atomically avoid
partial changes */
VIR_DOMAIN_SNAPSHOT_CREATE_LIVE = (1 << 8), /* create the snapshot
while the guest is
running */
} virDomainSnapshotCreateFlags;
/* Take a snapshot of the current VM state */

View File

@ -17770,6 +17770,12 @@ virDomainSnapshotGetConnect(virDomainSnapshotPtr snapshot)
* running after the snapshot. This flag is invalid on transient domains,
* and is incompatible with VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE.
*
* If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_LIVE, then the domain
* is not paused while creating the snapshot. This increases the size
* of the memory dump file, but reduces downtime of the guest while
* taking the snapshot. Some hypervisors only support this flag during
* external checkpoints.
*
* If @flags includes VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY, then the
* snapshot will be limited to the disks described in @xmlDesc, and no
* VM state will be saved. For an active guest, the disk image may be

View File

@ -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:
;

View File

@ -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")},
{"live", VSH_OT_BOOL, 0, N_("take a live 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, "live"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
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")},
{"live", VSH_OT_BOOL, 0, N_("take a live 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, "live"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)

View File

@ -2594,7 +2594,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<--live>]}
Create a snapshot for domain I<domain> with the properties specified in
I<xmlfile>. Normally, the only properties settable for a domain snapshot
@ -2647,6 +2647,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<--live> is specified, libvirt takes the snapshot while the guest is
running. This increases the size of the memory image of the external
checkpoint. This is currently supported only for external checkpoints.
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
@ -2655,7 +2659,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<--live>] [[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
@ -2700,6 +2704,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<--live> is specified, libvirt takes the snapshot while the guest is
running. This increases the size of the memory image of the external
checkpoint. This is currently supported only for external checkpoints.
=item B<snapshot-current> I<domain> {[I<--name>] | [I<--security-info>]
| [I<snapshotname>]}