From 6193c4656e67f8d5f7a7de01aff4f24b2fe7e782 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 21 Mar 2024 13:15:40 +0100 Subject: [PATCH] virsh: Fix '--name' and '--parent' used together in '(snapshot|checkpoint)-list' command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- docs/manpages/virsh.rst | 15 ++++++++++----- tools/virsh-checkpoint.c | 18 ++++++++++++------ tools/virsh-snapshot.c | 18 ++++++++++++------ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 28d430bf92..37c63f5962 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -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 diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index e425041ca7..e3fd6b2df2 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -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; diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index d64649a8da..80448ca08d 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -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;