[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 1/4] 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.
---
 include/libvirt/libvirt.h.in | 19 ++++++++++++++
 src/conf/snapshot_conf.h     |  9 +++++++
 src/libvirt.c                | 60 ++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh-snapshot.c       | 46 ++++++++++++++++++++-------------
 tools/virsh.pod              | 17 ++++++++++++-
 5 files changed, 132 insertions(+), 19 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 49a361a..84dcde1 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 b5c6e25..e291ddd 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 bdb1dc6..4af6089 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 4281109..0363e19 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 0984e6e..ba4488e 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2775,6 +2775,7 @@ with I<--current>.
 =item B<snapshot-list> I<domain> [{I<--parent> | I<--roots> | I<--tree>}]
 [{[I<--from>] B<snapshot> | 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.
@@ -2801,7 +2802,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
@@ -2810,6 +2811,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<snapshot-dumpxml> I<domain> I<snapshot> [I<--security-info>]

 Output the snapshot XML for the domain's snapshot named I<snapshot>.
-- 
1.7.11.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]