From 35ae18f3c6f519e65f342d5fc00d2c790833d63d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 8 Jun 2012 16:31:24 -0600 Subject: [PATCH] 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. --- tools/virsh.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 14 ++++++++++---- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 6f8670056a..045decd7e8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -16794,6 +16794,30 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, /* 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 * (virDomainSnapshotListNames, global list only) and in * 0.9.7-0.9.12 (addition of virDomainSnapshotListChildrenNames @@ -17028,8 +17052,12 @@ static const vshCmdOptDef opts_snapshot_list[] = { {"parent", VSH_OT_BOOL, 0, N_("add a column showing parent snapshot")}, {"roots", VSH_OT_BOOL, 0, N_("list only snapshots without parents")}, {"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, 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")}, {"from", VSH_OT_DATA, 0, N_("limit list to children of given snapshot")}, {"current", VSH_OT_BOOL, 0, @@ -17058,6 +17086,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) struct tm time_info; bool tree = vshCommandOptBool(cmd, "tree"); bool leaves = vshCommandOptBool(cmd, "leaves"); + bool no_leaves = vshCommandOptBool(cmd, "no-leaves"); const char *from = NULL; virDomainSnapshotPtr start = NULL; vshSnapshotListPtr snaplist = NULL; @@ -17107,10 +17136,21 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) } 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")) { flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; } + if (vshCommandOptBool(cmd, "no-metadata")) { + flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA; + } if (vshCommandOptBool(cmd, "descendants")) { if (!from) { diff --git a/tools/virsh.pod b/tools/virsh.pod index 23fd68ba73..839c15635c 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2518,7 +2518,7 @@ with I<--current>. =item B I [{I<--parent> | I<--roots> | I<--tree>}] [{[I<--from>] B | 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 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 with I<--roots>. If I<--leaves> is specified, the list will be filtered to just -snapshots that have no children. This option is not compatible -with I<--tree>. +snapshots that have no children. Likewise, if I<--no-leaves> is +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 snapshots that involve libvirt metadata, and thus would prevent B of a persistent domain, or be lost on B 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 I I [I<--security-info>]