]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Fix '--name' and '--parent' used together in '(snapshot|checkpoint)-list'...
authorPeter Krempa <pkrempa@redhat.com>
Thu, 21 Mar 2024 12:15:40 +0000 (13:15 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Apr 2024 12:24:30 +0000 (14:24 +0200)
Until now when '--name' was used the parent was not printed and the
option was ignored. One option would be to declare the options mutually
exclusive, but for testing it may come handy to print both the snapshot
name and parent. Adjust the code to print them tab-separated and adjust
the docs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/manpages/virsh.rst
tools/virsh-checkpoint.c
tools/virsh-snapshot.c

index 28d430bf92f67e1f21b565605381092aae220b8f..37c63f59621ab5bbc950cc3024363160981588d6 100644 (file)
@@ -7673,9 +7673,11 @@ If *--parent* is specified, add a column to the output table giving
 the name of the parent of each snapshot.  If *--roots* is specified,
 the list will be filtered to just snapshots that have no parents.
 If *--tree* is specified, the output will be in a tree format, listing
-just snapshot names.  These three options are mutually exclusive. If
-*--name* is specified only the snapshot name is printed. This option is
-mutually exclusive with *--tree*.
+just snapshot names.  These three options are mutually exclusive.
+
+If *--name* is specified only the snapshot name is printed optionally
+followed by a tab-separated name of the parent snapshot if *--parent* is used
+as well. This option is mutually exclusive with *--tree*.
 
 If *--from* is provided, filter the list to snapshots which are
 children of the given ``snapshot``; or if *--current* is provided,
@@ -7989,8 +7991,11 @@ the name of the parent of each checkpoint.  If *--roots* is
 specified, the list will be filtered to just checkpoints that have no
 parents.  If *--tree* is specified, the output will be in a tree
 format, listing just checkpoint names.  These three options are
-mutually exclusive. If *--name* is specified only the checkpoint name
-is printed. This option is mutually exclusive with *--tree*.
+mutually exclusive.
+
+If *--name* is specified only the checkpoint name is printed optionally
+followed by a tab-separated name of the parent checkpoint if *--parent* is used
+as well. This option is mutually exclusive with *--tree*.
 
 If *--from* is provided, filter the list to checkpoints which are
 children of the given ``checkpoint``.  When used in isolation or with
index e425041ca7a520dd864ee4c2753a809977502141..e3fd6b2df25df48ab02394e2255d1a209870fdba 100644 (file)
@@ -754,12 +754,6 @@ cmdCheckpointList(vshControl *ctl,
         chk_name = virDomainCheckpointGetName(checkpoint);
         assert(chk_name);
 
-        if (name) {
-            /* just print the checkpoint name */
-            vshPrint(ctl, "%s\n", chk_name);
-            continue;
-        }
-
         if (!(doc = virDomainCheckpointGetXMLDesc(checkpoint, 0)))
             continue;
 
@@ -770,6 +764,18 @@ cmdCheckpointList(vshControl *ctl,
             parent_chk = virXPathString("string(/domaincheckpoint/parent/name)",
                                         ctxt);
 
+        if (name) {
+            vshPrint(ctl, "%s", chk_name);
+
+            if (parent_chk)
+                vshPrint(ctl, "\t%s", parent_chk);
+
+            vshPrint(ctl, "\n");
+
+            /* just print the checkpoint name */
+            continue;
+        }
+
         if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctxt,
                              &creation_longlong) < 0)
             continue;
index d64649a8da2e5361b84345795ff67dd74b9ac4db..80448ca08de332da512615bdee2e03819fad73b1 100644 (file)
@@ -1516,12 +1516,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
         snap_name = virDomainSnapshotGetName(snapshot);
         assert(snap_name);
 
-        if (name) {
-            /* just print the snapshot name */
-            vshPrint(ctl, "%s\n", snap_name);
-            continue;
-        }
-
         if (!(doc = virDomainSnapshotGetXMLDesc(snapshot, 0)))
             continue;
 
@@ -1532,6 +1526,18 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
             parent_snap = virXPathString("string(/domainsnapshot/parent/name)",
                                          ctxt);
 
+        if (name) {
+            vshPrint(ctl, "%s", snap_name);
+
+            if (parent_snap)
+                vshPrint(ctl, "\t%s", parent_snap);
+
+            vshPrint(ctl, "\n");
+
+            /* just print the snapshot name */
+            continue;
+        }
+
         if (!(state = virXPathString("string(/domainsnapshot/state)", ctxt)))
             continue;