{
bool ret = false;
virDomainSnapshotPtr snapshot;
+ bool halt = false;
char *doc = NULL;
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
char *name = NULL;
snapshot = virDomainSnapshotCreateXML(dom, buffer, flags);
+
+ /* Emulate --halt on older servers. */
+ if (!snapshot && last_error->code == VIR_ERR_INVALID_ARG &&
+ (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) {
+ int persistent;
+
+ virFreeError(last_error);
+ last_error = NULL;
+ persistent = virDomainIsPersistent(dom);
+ if (persistent < 0) {
+ virshReportError(ctl);
+ goto cleanup;
+ }
+ if (!persistent) {
+ vshError(ctl, "%s",
+ _("cannot halt after snapshot of transient domain"));
+ goto cleanup;
+ }
+ if (virDomainIsActive(dom) == 1)
+ halt = true;
+ flags &= ~VIR_DOMAIN_SNAPSHOT_CREATE_HALT;
+ snapshot = virDomainSnapshotCreateXML(dom, buffer, flags);
+ }
+
if (snapshot == NULL)
goto cleanup;
+ if (halt && virDomainDestroy(dom) < 0) {
+ virshReportError(ctl);
+ goto cleanup;
+ }
+
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
doc = vshStrdup(ctl, buffer);
else
{"redefine", VSH_OT_BOOL, 0, N_("redefine metadata for existing snapshot")},
{"current", VSH_OT_BOOL, 0, N_("with redefine, set current snapshot")},
{"no-metadata", VSH_OT_BOOL, 0, N_("take snapshot but create no metadata")},
+ {"halt", VSH_OT_BOOL, 0, N_("halt domain after snapshot is created")},
{NULL, 0, 0, NULL}
};
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
if (vshCommandOptBool(cmd, "no-metadata"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
+ if (vshCommandOptBool(cmd, "halt"))
+ flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
{"description", VSH_OT_DATA, 0, N_("description of snapshot")},
{"print-xml", VSH_OT_BOOL, 0, N_("print XML document rather than create")},
{"no-metadata", VSH_OT_BOOL, 0, N_("take snapshot but create no metadata")},
+ {"halt", VSH_OT_BOOL, 0, N_("halt domain after snapshot is created")},
{NULL, 0, 0, NULL}
};
if (vshCommandOptBool(cmd, "no-metadata"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
+ if (vshCommandOptBool(cmd, "halt"))
+ flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
}
if (vshCommandOptBool(cmd, "print-xml")) {
+ if (vshCommandOptBool(cmd, "halt")) {
+ vshError(ctl, "%s",
+ _("--print-xml and --halt are mutually exclusive"));
+ goto cleanup;
+ }
vshPrint(ctl, "%s\n", buffer);
ret = true;
goto cleanup;
=over 4
=item B<snapshot-create> I<domain> [I<xmlfile>] {[I<--redefine> [I<--current>]]
-| [I<--no-metadata>]}
+| [I<--no-metadata>] [I<--halt>]}
Create a snapshot for domain I<domain> with the properties specified in
I<xmlfile>. Normally, the only properties settable for a domain snapshot
completely omitted, then libvirt will choose a value for all fields.
The new snapshot will become current, as listed by B<snapshot-current>.
+If I<--halt> is specified, the domain will be left in an inactive state
+after the snapshot is created.
+
If I<--redefine> is specified, then all XML elements produced by
B<snapshot-dumpxml> are valid; this can be used to migrate snapshot
hierarchy from one machine to another, to recreate hierarchy for the
metadata is silently lost when the domain quits running (whether
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<name>] [I<description>]
+=item B<snapshot-create-as> I<domain> {[I<--print-xml>]
+| [I<--no-metadata>] [I<--halt>]} [I<name>] [I<description>]
Create a snapshot for domain I<domain> with the given <name> and
<description>; if either value is omitted, libvirt will choose a
value. If I<--print-xml> is specified, then XML appropriate for
I<snapshot-create> is output, rather than actually creating a snapshot.
+Otherwise, if I<--halt> is specified, the domain will be left in an
+inactive state after the snapshot is created.
If I<--no-metadata> is specified, then the snapshot data is created,
but any metadata is immediately discarded (that is, libvirt does not