diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 49a361ae94994cbf645a7dc8b4e2a5d32ee3078b..84dcde105e8e33b5eeb2e1f8494f590f2413744b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -3818,6 +3818,25 @@ typedef enum { which have metadata */ VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA = (1 << 4), /* Filter by snapshots 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; /* Return the number of snapshots for this domain */ diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index b5c6e259151b4b1edf6d48792aaf1b7ca8af2beb..e291ddd8dcd3d2f890442f4c5a2de468ab4d4f7d 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -145,6 +145,15 @@ void virDomainSnapshotDropParent(virDomainSnapshotObjPtr snapshot); (VIR_DOMAIN_SNAPSHOT_LIST_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 \ (VIR_DOMAIN_SNAPSHOT_FILTERS_METADATA | \ VIR_DOMAIN_SNAPSHOT_FILTERS_LEAVES) diff --git a/src/libvirt.c b/src/libvirt.c index bdb1dc6a053177b3411a6a04ea2c79120b74fbca..4af6089a57fe8de0fb03c9d9fedccbe4c1a45f4c 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -17960,6 +17960,16 @@ error: * whether they have metadata that would prevent the removal of the last * 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. */ int @@ -18024,6 +18034,16 @@ error: * whether they have metadata that would prevent the removal of the last * 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 * define a new snapshot between a call to virDomainSnapshotNum() and * 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 * 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 * 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 @@ -18176,6 +18206,16 @@ error: * whether they have metadata that would prevent the removal of the last * 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. */ int @@ -18242,6 +18282,16 @@ error: * whether they have metadata that would prevent the removal of the last * 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. * Note that this command is inherently racy: another connection can * 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 * 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 * 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 diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 0bd9583a90f0df9b09c4fe78ec005a293ae342e1..62bafd4330d7c5758413de9e8a2c97a49537e388 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1189,6 +1189,13 @@ static const vshCmdOptDef opts_snapshot_list[] = { 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")}, + {"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")}, {"from", VSH_OT_DATA, 0, N_("limit list to children of given snapshot")}, {"current", VSH_OT_BOOL, 0, @@ -1216,8 +1223,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) char timestr[100]; 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; @@ -1258,22 +1263,27 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) } flags |= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; } - if (leaves) { - if (tree) { - vshError(ctl, "%s", - _("--leaves and --tree are mutually exclusive")); - goto cleanup; - } - 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; - } +#define FILTER(option, flag) \ + do { \ + if (vshCommandOptBool(cmd, option)) { \ + if (tree) { \ + vshError(ctl, \ + _("--%s and --tree are mutually exclusive"), \ + option); \ + goto cleanup; \ + } \ + flags |= VIR_DOMAIN_SNAPSHOT_LIST_ ## flag; \ + } \ + } while (0) + + FILTER("leaves", 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")) { flags |= VIR_DOMAIN_SNAPSHOT_LIST_METADATA; diff --git a/tools/virsh.pod b/tools/virsh.pod index 29be39e0b4afee69b6b52fc6f093ffc66ee1542f..c4d505fdbf8f14c2459065a01f17e2b64b7dc1eb 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2763,6 +2763,7 @@ with I<--current>. =item B I [{I<--parent> | I<--roots> | I<--tree>}] [{[I<--from>] B | I<--current>} [I<--descendants>]] [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 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, 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>. +Filtering 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 @@ -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 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 I I [I<--security-info>] Output the snapshot XML for the domain's snapshot named I.