mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 12:35:20 +00:00
snapshot: expose halt-after-creation in virsh
Easy enough to emulate even with older servers. * tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Add --halt flag. (vshSnapshotCreate): Emulate halt when flag is unsupported. * tools/virsh.pod (snapshot-create, snapshot-create-as): Document it.
This commit is contained in:
parent
6f66423e17
commit
a891ffa446
@ -11996,15 +11996,45 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
|||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
virDomainSnapshotPtr snapshot;
|
virDomainSnapshotPtr snapshot;
|
||||||
|
bool halt = false;
|
||||||
char *doc = NULL;
|
char *doc = NULL;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
|
||||||
snapshot = virDomainSnapshotCreateXML(dom, buffer, flags);
|
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)
|
if (snapshot == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (halt && virDomainDestroy(dom) < 0) {
|
||||||
|
virshReportError(ctl);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
|
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
|
||||||
doc = vshStrdup(ctl, buffer);
|
doc = vshStrdup(ctl, buffer);
|
||||||
else
|
else
|
||||||
@ -12055,6 +12085,7 @@ static const vshCmdOptDef opts_snapshot_create[] = {
|
|||||||
{"redefine", VSH_OT_BOOL, 0, N_("redefine metadata for existing snapshot")},
|
{"redefine", VSH_OT_BOOL, 0, N_("redefine metadata for existing snapshot")},
|
||||||
{"current", VSH_OT_BOOL, 0, N_("with redefine, set current 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")},
|
{"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}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12073,6 +12104,8 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
|
||||||
if (vshCommandOptBool(cmd, "no-metadata"))
|
if (vshCommandOptBool(cmd, "no-metadata"))
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
|
||||||
|
if (vshCommandOptBool(cmd, "halt"))
|
||||||
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -12123,6 +12156,7 @@ static const vshCmdOptDef opts_snapshot_create_as[] = {
|
|||||||
{"description", VSH_OT_DATA, 0, N_("description of snapshot")},
|
{"description", VSH_OT_DATA, 0, N_("description of snapshot")},
|
||||||
{"print-xml", VSH_OT_BOOL, 0, N_("print XML document rather than create")},
|
{"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")},
|
{"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}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12139,6 +12173,8 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (vshCommandOptBool(cmd, "no-metadata"))
|
if (vshCommandOptBool(cmd, "no-metadata"))
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA;
|
||||||
|
if (vshCommandOptBool(cmd, "halt"))
|
||||||
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -12167,6 +12203,11 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "print-xml")) {
|
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);
|
vshPrint(ctl, "%s\n", buffer);
|
||||||
ret = true;
|
ret = true;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1702,7 +1702,7 @@ used to represent properties of snapshots.
|
|||||||
=over 4
|
=over 4
|
||||||
|
|
||||||
=item B<snapshot-create> I<domain> [I<xmlfile>] {[I<--redefine> [I<--current>]]
|
=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
|
Create a snapshot for domain I<domain> with the properties specified in
|
||||||
I<xmlfile>. Normally, the only properties settable for a domain snapshot
|
I<xmlfile>. Normally, the only properties settable for a domain snapshot
|
||||||
@ -1711,6 +1711,9 @@ ignored, and automatically filled in by libvirt. If I<xmlfile> is
|
|||||||
completely omitted, then libvirt will choose a value for all fields.
|
completely omitted, then libvirt will choose a value for all fields.
|
||||||
The new snapshot will become current, as listed by B<snapshot-current>.
|
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
|
If I<--redefine> is specified, then all XML elements produced by
|
||||||
B<snapshot-dumpxml> are valid; this can be used to migrate snapshot
|
B<snapshot-dumpxml> are valid; this can be used to migrate snapshot
|
||||||
hierarchy from one machine to another, to recreate hierarchy for the
|
hierarchy from one machine to another, to recreate hierarchy for the
|
||||||
@ -1732,13 +1735,15 @@ a persistent domain. However, for transient domains, snapshot
|
|||||||
metadata is silently lost when the domain quits running (whether
|
metadata is silently lost when the domain quits running (whether
|
||||||
by command such as B<destroy> or by internal guest action).
|
by command such as B<destroy> or by internal guest action).
|
||||||
|
|
||||||
=item B<snapshot-create-as> I<domain> {[I<--print-xml>] | [I<--no-metadata>]}
|
=item B<snapshot-create-as> I<domain> {[I<--print-xml>]
|
||||||
[I<name>] [I<description>]
|
| [I<--no-metadata>] [I<--halt>]} [I<name>] [I<description>]
|
||||||
|
|
||||||
Create a snapshot for domain I<domain> with the given <name> and
|
Create a snapshot for domain I<domain> with the given <name> and
|
||||||
<description>; if either value is omitted, libvirt will choose a
|
<description>; if either value is omitted, libvirt will choose a
|
||||||
value. If I<--print-xml> is specified, then XML appropriate for
|
value. If I<--print-xml> is specified, then XML appropriate for
|
||||||
I<snapshot-create> is output, rather than actually creating a snapshot.
|
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,
|
If I<--no-metadata> is specified, then the snapshot data is created,
|
||||||
but any metadata is immediately discarded (that is, libvirt does not
|
but any metadata is immediately discarded (that is, libvirt does not
|
||||||
|
Loading…
Reference in New Issue
Block a user