提交 35ae18f3 编写于 作者: E Eric Blake

snapshot: expose new flags in virsh

Previously, to get the name of all snapshots with children, it was
necessary to get the name of all snapshots and then remove the
name of leaf snapshots.  This is racy, and somewhat inefficient
compared to planned API additions.  We can emulate --no-metadata on
0.9.5-0.9.12, but for now, there is no emulation of --no-leaves.

* tools/virsh.c (cmdSnapshotList): Add new options --no-leaves and
--no-metadata.
(vshSnapshotList): Emulate where possible.
* tools/virsh.pod (snapshot-list): Document them.
上级 5873f2e2
...@@ -16794,6 +16794,30 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, ...@@ -16794,6 +16794,30 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
/* 0.9.13 will be adding a new listing API. */ /* 0.9.13 will be adding a new listing API. */
/* Assume that if we got this far, then the --no-leaves and
* --no-metadata flags were not supported. Disable groups that
* have no impact. */
/* XXX should we emulate --no-leaves? */
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES &&
flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES)
flags &= ~(VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES |
VIR_DOMAIN_SNAPSHOT_LIST_LEAVES);
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA &&
flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA)
flags &= ~(VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA |
VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA) {
/* We can emulate --no-metadata if --metadata was supported,
* since it was an all-or-none attribute on old servers. */
count = virDomainSnapshotNum(dom,
VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
if (count < 0)
goto cleanup;
if (count > 0)
return snaplist;
flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA;
}
/* This uses the interfaces available in 0.8.0-0.9.6 /* This uses the interfaces available in 0.8.0-0.9.6
* (virDomainSnapshotListNames, global list only) and in * (virDomainSnapshotListNames, global list only) and in
* 0.9.7-0.9.12 (addition of virDomainSnapshotListChildrenNames * 0.9.7-0.9.12 (addition of virDomainSnapshotListChildrenNames
...@@ -17028,8 +17052,12 @@ static const vshCmdOptDef opts_snapshot_list[] = { ...@@ -17028,8 +17052,12 @@ static const vshCmdOptDef opts_snapshot_list[] = {
{"parent", VSH_OT_BOOL, 0, N_("add a column showing parent snapshot")}, {"parent", VSH_OT_BOOL, 0, N_("add a column showing parent snapshot")},
{"roots", VSH_OT_BOOL, 0, N_("list only snapshots without parents")}, {"roots", VSH_OT_BOOL, 0, N_("list only snapshots without parents")},
{"leaves", VSH_OT_BOOL, 0, N_("list only snapshots without children")}, {"leaves", VSH_OT_BOOL, 0, N_("list only snapshots without children")},
{"no-leaves", VSH_OT_BOOL, 0,
N_("list only snapshots that are not leaves (with children)")},
{"metadata", VSH_OT_BOOL, 0, {"metadata", VSH_OT_BOOL, 0,
N_("list only snapshots that have metadata that would prevent undefine")}, N_("list only snapshots that have metadata that would prevent undefine")},
{"no-metadata", VSH_OT_BOOL, 0,
N_("list only snapshots that have no metadata managed by libvirt")},
{"tree", VSH_OT_BOOL, 0, N_("list snapshots in a tree")}, {"tree", VSH_OT_BOOL, 0, N_("list snapshots in a tree")},
{"from", VSH_OT_DATA, 0, N_("limit list to children of given snapshot")}, {"from", VSH_OT_DATA, 0, N_("limit list to children of given snapshot")},
{"current", VSH_OT_BOOL, 0, {"current", VSH_OT_BOOL, 0,
...@@ -17058,6 +17086,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -17058,6 +17086,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
struct tm time_info; struct tm time_info;
bool tree = vshCommandOptBool(cmd, "tree"); bool tree = vshCommandOptBool(cmd, "tree");
bool leaves = vshCommandOptBool(cmd, "leaves"); bool leaves = vshCommandOptBool(cmd, "leaves");
bool no_leaves = vshCommandOptBool(cmd, "no-leaves");
const char *from = NULL; const char *from = NULL;
virDomainSnapshotPtr start = NULL; virDomainSnapshotPtr start = NULL;
vshSnapshotListPtr snaplist = NULL; vshSnapshotListPtr snaplist = NULL;
...@@ -17107,10 +17136,21 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) ...@@ -17107,10 +17136,21 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
} }
flags |= VIR_DOMAIN_SNAPSHOT_LIST_LEAVES; flags |= VIR_DOMAIN_SNAPSHOT_LIST_LEAVES;
} }
if (no_leaves) {
if (tree) {
vshError(ctl, "%s",
_("--no-leaves and --tree are mutually exclusive"));
goto cleanup;
}
flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES;
}
if (vshCommandOptBool(cmd, "metadata")) { if (vshCommandOptBool(cmd, "metadata")) {
flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA;
} }
if (vshCommandOptBool(cmd, "no-metadata")) {
flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA;
}
if (vshCommandOptBool(cmd, "descendants")) { if (vshCommandOptBool(cmd, "descendants")) {
if (!from) { if (!from) {
......
...@@ -2518,7 +2518,7 @@ with I<--current>. ...@@ -2518,7 +2518,7 @@ with I<--current>.
=item B<snapshot-list> I<domain> [{I<--parent> | I<--roots> | I<--tree>}] =item B<snapshot-list> I<domain> [{I<--parent> | I<--roots> | I<--tree>}]
[{[I<--from>] B<snapshot> | I<--current>} [I<--descendants>]] [{[I<--from>] B<snapshot> | I<--current>} [I<--descendants>]]
[I<--metadata>] [I<--leaves>] [I<--metadata>] [I<--no-metadata>] [I<--leaves>] [I<--no-leaves>]
List all of the available snapshots for the given domain, defaulting List all of the available snapshots for the given domain, defaulting
to show columns for the snapshot name, creation time, and domain state. to show columns for the snapshot name, creation time, and domain state.
...@@ -2538,13 +2538,19 @@ use of I<--descendants> is implied. This option is not compatible ...@@ -2538,13 +2538,19 @@ use of I<--descendants> is implied. This option is not compatible
with I<--roots>. with I<--roots>.
If I<--leaves> is specified, the list will be filtered to just If I<--leaves> is specified, the list will be filtered to just
snapshots that have no children. This option is not compatible snapshots that have no children. Likewise, if I<--no-leaves> is
with I<--tree>. specified, the list will be filtered to just snapshots with
children. (Note that omitting both options does no filtering,
while providing both options will either produce the same list
or error out depending on whether the server recognizes the flags).
These options are not compatible with I<--tree>.
If I<--metadata> is specified, the list will be filtered to just If I<--metadata> is specified, the list will be filtered to just
snapshots that involve libvirt metadata, and thus would prevent snapshots that involve libvirt metadata, and thus would prevent
B<undefine> of a persistent domain, or be lost on B<destroy> of B<undefine> of a persistent domain, or be lost on B<destroy> of
a transient domain. a transient domain. Likewise, if I<--no-metadata> is specified,
the list will be filtered to just snapshots that exist without
the need for libvirt metadata.
=item B<snapshot-dumpxml> I<domain> I<snapshot> [I<--security-info>] =item B<snapshot-dumpxml> I<domain> I<snapshot> [I<--security-info>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册