Even though I recently added 'virsh snapshot-parent', doing it one
snapshot at a time is painful, so make it possible to expand the
snapshot-list table at once.
* tools/virsh.c (cmdSnapshotList): Add --parent.
* tools/virsh.pod (snapshot-list): Document it.
---
For debugging purposes, I split patch 26/43 into two pieces, then
floated this piece earlier in the series.
tools/virsh.c | 39 +++++++++++++++++++++++++++++++++------
tools/virsh.pod | 5 ++++-
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 15b9bdd..c114cfc 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12069,6 +12069,7 @@ static const vshCmdInfo info_snapshot_list[] = {
static const vshCmdOptDef opts_snapshot_list[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"parent", VSH_OT_BOOL, 0, N_("add a column showing parent
snapshot")},
{NULL, 0, 0, NULL}
};
@@ -12077,6 +12078,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
bool ret = false;
+ int flags = 0;
+ int parent_filter = 0; /* 0 for no parent information needed,
+ 1 for parent column */
int numsnaps;
char **names = NULL;
int actual = 0;
@@ -12086,11 +12090,16 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
char *doc = NULL;
virDomainSnapshotPtr snapshot = NULL;
char *state = NULL;
+ char *parent = NULL;
long long creation_longlong;
time_t creation_time_t;
char timestr[100];
struct tm time_info;
+ if (vshCommandOptBool(cmd, "parent")) {
+ parent_filter = 1;
+ }
+
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
@@ -12098,19 +12107,25 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL)
goto cleanup;
- numsnaps = virDomainSnapshotNum(dom, 0);
+ numsnaps = virDomainSnapshotNum(dom, flags);
if (numsnaps < 0)
goto cleanup;
- vshPrintExtra(ctl, " %-20s %-25s %s\n", _("Name"),
_("Creation Time"), _("State"));
- vshPrintExtra(ctl,
"---------------------------------------------------\n");
+ if (parent_filter > 0)
+ vshPrintExtra(ctl, " %-20s %-25s %-15s %s",
+ _("Name"), _("Creation Time"),
_("State"), _("Parent"));
+ else
+ vshPrintExtra(ctl, " %-20s %-25s %s",
+ _("Name"), _("Creation Time"),
_("State"));
+ vshPrintExtra(ctl, "\n\
+------------------------------------------------------------\n");
if (numsnaps) {
if (VIR_ALLOC_N(names, numsnaps) < 0)
goto cleanup;
- actual = virDomainSnapshotListNames(dom, names, numsnaps, 0);
+ actual = virDomainSnapshotListNames(dom, names, numsnaps, flags);
if (actual < 0)
goto cleanup;
@@ -12118,6 +12133,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < actual; i++) {
/* free up memory from previous iterations of the loop */
+ VIR_FREE(parent);
VIR_FREE(state);
if (snapshot)
virDomainSnapshotFree(snapshot);
@@ -12137,6 +12153,11 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (!xml)
continue;
+ if (parent_filter) {
+ parent = virXPathString("string(/domainsnapshot/parent/name)",
+ ctxt);
+ }
+
state = virXPathString("string(/domainsnapshot/state)", ctxt);
if (state == NULL)
continue;
@@ -12149,9 +12170,14 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
continue;
}
localtime_r(&creation_time_t, &time_info);
- strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z",
&time_info);
+ strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z",
+ &time_info);
- vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state);
+ if (parent)
+ vshPrint(ctl, " %-20s %-25s %-15s %s\n",
+ names[i], timestr, state, parent);
+ else
+ vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state);
}
}
@@ -12159,6 +12185,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
cleanup:
/* this frees up memory from the last iteration of the loop */
+ VIR_FREE(parent);
VIR_FREE(state);
if (snapshot)
virDomainSnapshotFree(snapshot);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e17f309..ce7ad02 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1585,10 +1585,13 @@ Output the snapshot XML for the domain's current snapshot (if
any).
If I<--name> is specified, just list the snapshot name instead of the
full xml.
-=item B<snapshot-list> I<domain>
+=item B<snapshot-list> I<domain> [I<--parent>]
List all of the available snapshots for the given domain.
+If I<--parent> is specified, add a column to the output table giving
+the name of the parent of each snapshot.
+
=item B<snapshot-dumpxml> I<domain> I<snapshot>
Output the snapshot XML for the domain's snapshot named I<snapshot>.
--
1.7.4.4