[libvirt] [PATCHv2 07/13] snapshot: expose new flags in virsh

Eric Blake eblake at redhat.com
Fri Jun 15 04:18:32 UTC 2012


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.
---

v2: fix typo in flag name

 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 4f841fd..3e1018e 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -17010,6 +17010,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
@@ -17244,8 +17268,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,
@@ -17274,6 +17302,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;
@@ -17323,10 +17352,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 6408881..7cb4adc 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2552,7 +2552,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<--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.
@@ -2572,13 +2572,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<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>]

-- 
1.7.10.2




More information about the libvir-list mailing list