snapshot: add two more filter sets to API

As we enable more modes of snapshot creation, it becomes more important
to be able to quickly filter based on snapshot properties.  This patch
introduces new filter flags; subsequent patches will introduce virsh
back-compat filtering, as well as actual libvirt filtering.

* include/libvirt/libvirt.h.in (virDomainSnapshotListFlags): Add
five new flags in two new groups.
* src/libvirt.c (virDomainSnapshotNum, virDomainSnapshotListNames)
(virDomainListAllSnapshots, virDomainSnapshotNumChildren)
(virDomainSnapshotListChildrenNames)
(virDomainSnapshotListAllChildren): Document them.
* src/conf/snapshot_conf.h (VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS)
(VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION): Add new convenience filter
collection macros.
* tools/virsh-snapshot.c (cmdSnapshotList): Add 5 new flags.
* tools/virsh.pod (snapshot-list): Document them.
This commit is contained in:
Eric Blake 2012-11-12 10:29:14 -07:00
parent 89204fca7f
commit e9028f4b73
5 changed files with 132 additions and 19 deletions

View File

@ -3818,6 +3818,25 @@ typedef enum {
which have metadata */ which have metadata */
VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA = (1 << 4), /* Filter by snapshots VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA = (1 << 4), /* Filter by snapshots
with no metadata */ with no metadata */
VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE = (1 << 5), /* Filter by snapshots
taken while guest was
shut off */
VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE = (1 << 6), /* Filter by snapshots
taken while guest was
active, and with
memory state */
VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY = (1 << 7), /* Filter by snapshots
taken while guest was
active, but without
memory state */
VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL = (1 << 8), /* Filter by snapshots
stored internal to
disk images */
VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL = (1 << 9), /* Filter by snapshots
that use files external
to disk images */
} virDomainSnapshotListFlags; } virDomainSnapshotListFlags;
/* Return the number of snapshots for this domain */ /* Return the number of snapshots for this domain */

View File

@ -145,6 +145,15 @@ void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot);
(VIR_DOMAIN_SNAPSHOT_LIST_LEAVES | \ (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES | \
VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES) VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
# define VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS \
(VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE | \
VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE | \
VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY)
# define VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION \
(VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL | \
VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)
# define VIR_DOMAIN_SNAPSHOT_FILTERS_ALL \ # define VIR_DOMAIN_SNAPSHOT_FILTERS_ALL \
(VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA | \ (VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA | \
VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES) VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES)

View File

@ -17960,6 +17960,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Returns the number of domain snapshots found or -1 in case of error. * Returns the number of domain snapshots found or -1 in case of error.
*/ */
int int
@ -18024,6 +18034,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Note that this command is inherently racy: another connection can * Note that this command is inherently racy: another connection can
* define a new snapshot between a call to virDomainSnapshotNum() and * define a new snapshot between a call to virDomainSnapshotNum() and
* this call. You are only guaranteed that all currently defined * this call. You are only guaranteed that all currently defined
@ -18106,6 +18126,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Returns the number of domain snapshots found or -1 and sets @snaps to * Returns the number of domain snapshots found or -1 and sets @snaps to
* NULL in case of error. On success, the array stored into @snaps is * NULL in case of error. On success, the array stored into @snaps is
* guaranteed to have an extra allocated element set to NULL but not included * guaranteed to have an extra allocated element set to NULL but not included
@ -18176,6 +18206,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Returns the number of domain snapshots found or -1 in case of error. * Returns the number of domain snapshots found or -1 in case of error.
*/ */
int int
@ -18242,6 +18282,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Returns the number of domain snapshots found or -1 in case of error. * Returns the number of domain snapshots found or -1 in case of error.
* Note that this command is inherently racy: another connection can * Note that this command is inherently racy: another connection can
* define a new snapshot between a call to virDomainSnapshotNumChildren() * define a new snapshot between a call to virDomainSnapshotNumChildren()
@ -18329,6 +18379,16 @@ error:
* whether they have metadata that would prevent the removal of the last * whether they have metadata that would prevent the removal of the last
* reference to a domain. * reference to a domain.
* *
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE,
* VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE, and VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY,
* for filtering snapshots based on what domain state is tracked by the
* snapshot.
*
* The next group of @flags is VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL and
* VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, for filtering snapshots based on
* whether the snapshot is stored inside the disk images or as
* additional files.
*
* Returns the number of domain snapshots found or -1 and sets @snaps to * Returns the number of domain snapshots found or -1 and sets @snaps to
* NULL in case of error. On success, the array stored into @snaps is * NULL in case of error. On success, the array stored into @snaps is
* guaranteed to have an extra allocated element set to NULL but not included * guaranteed to have an extra allocated element set to NULL but not included

View File

@ -1189,6 +1189,13 @@ static const vshCmdOptDef opts_snapshot_list[] = {
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, {"no-metadata", VSH_OT_BOOL, 0,
N_("list only snapshots that have no metadata managed by libvirt")}, N_("list only snapshots that have no metadata managed by libvirt")},
{"inactive", VSH_OT_BOOL, 0,
N_("filter by snapshots taken while inactive")},
{"active", VSH_OT_BOOL, 0,
N_("filter by snapshots taken while active (system checkpoints)")},
{"disk-only", VSH_OT_BOOL, 0, N_("filter by disk-only snapshots")},
{"internal", VSH_OT_BOOL, 0, N_("filter by internal snapshots")},
{"external", VSH_OT_BOOL, 0, N_("filter by external snapshots")},
{"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,
@ -1216,8 +1223,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
char timestr[100]; char timestr[100];
struct tm time_info; struct tm time_info;
bool tree = vshCommandOptBool(cmd, "tree"); bool tree = vshCommandOptBool(cmd, "tree");
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;
@ -1258,22 +1263,27 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
} }
flags |= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; flags |= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
} }
if (leaves) { #define FILTER(option, flag) \
if (tree) { do { \
vshError(ctl, "%s", if (vshCommandOptBool(cmd, option)) { \
_("--leaves and --tree are mutually exclusive")); if (tree) { \
goto cleanup; vshError(ctl, \
} _("--%s and --tree are mutually exclusive"), \
flags |= VIR_DOMAIN_SNAPSHOT_LIST_LEAVES; option); \
} goto cleanup; \
if (no_leaves) { } \
if (tree) { flags |= VIR_DOMAIN_SNAPSHOT_LIST_ ## flag; \
vshError(ctl, "%s", } \
_("--no-leaves and --tree are mutually exclusive")); } while (0)
goto cleanup;
} FILTER("leaves", LEAVES);
flags |= VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES; FILTER("no-leaves", NO_LEAVES);
} FILTER("inactive", INACTIVE);
FILTER("active", ACTIVE);
FILTER("disk-only", DISK_ONLY);
FILTER("internal", INTERNAL);
FILTER("external", EXTERNAL);
#undef FILTER
if (vshCommandOptBool(cmd, "metadata")) { if (vshCommandOptBool(cmd, "metadata")) {
flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA;

View File

@ -2763,6 +2763,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<--no-metadata>] [I<--leaves>] [I<--no-leaves>] [I<--metadata>] [I<--no-metadata>] [I<--leaves>] [I<--no-leaves>]
[I<--inactive>] [I<--active>] [I<--disk-only>] [I<--internal>] [I<--external>]
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.
@ -2789,7 +2790,7 @@ specified, the list will be filtered to just snapshots with
children. (Note that omitting both options does no filtering, children. (Note that omitting both options does no filtering,
while providing both options will either produce the same list while providing both options will either produce the same list
or error out depending on whether the server recognizes the flags). or error out depending on whether the server recognizes the flags).
These options are not compatible with I<--tree>. Filtering 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
@ -2798,6 +2799,20 @@ a transient domain. Likewise, if I<--no-metadata> is specified,
the list will be filtered to just snapshots that exist without the list will be filtered to just snapshots that exist without
the need for libvirt metadata. the need for libvirt metadata.
If I<--inactive> is specified, the list will be filtered to snapshots
that were taken when the domain was shut off. If I<--active> is
specified, the list will be filtered to snapshots that were taken
when the domain was running, and where the snapshot includes the
memory state to revert to that running state. If I<--disk-only> is
specified, the list will be filtered to snapshots that were taken
when the domain was running, but where the snapshot includes only
disk state.
If I<--internal> is specified, the list will be filtered to snapshots
that use internal storage of existing disk images. If I<--external>
is specified, the list will be filtered to snapshots that use external
files for disk images or memory state.
=item B<snapshot-dumpxml> I<domain> I<snapshot> [I<--security-info>] =item B<snapshot-dumpxml> I<domain> I<snapshot> [I<--security-info>]
Output the snapshot XML for the domain's snapshot named I<snapshot>. Output the snapshot XML for the domain's snapshot named I<snapshot>.