mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
list: use the new snapshot API in virsh when possible
Using the new API is so much shorter than the rest of the remainder of the function. * tools/virsh.c (vshSnapshotList): Use the new API.
This commit is contained in:
parent
37bb0447bb
commit
a7f7bf02fd
@ -16786,13 +16786,42 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
int count = -1;
|
int count = -1;
|
||||||
bool descendants = false;
|
bool descendants = false;
|
||||||
bool roots = false;
|
bool roots = false;
|
||||||
|
virDomainSnapshotPtr *snaps;
|
||||||
vshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
|
vshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
|
||||||
vshSnapshotListPtr ret = NULL;
|
vshSnapshotListPtr ret = NULL;
|
||||||
const char *fromname = NULL;
|
const char *fromname = NULL;
|
||||||
int start_index = -1;
|
int start_index = -1;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
|
|
||||||
/* 0.9.13 will be adding a new listing API. */
|
/* Try the interface available in 0.9.13 and newer. */
|
||||||
|
if (!ctl->useSnapshotOld) {
|
||||||
|
if (from)
|
||||||
|
count = virDomainSnapshotListAllChildren(from, &snaps, flags);
|
||||||
|
else
|
||||||
|
count = virDomainListAllSnapshots(dom, &snaps, flags);
|
||||||
|
}
|
||||||
|
if (count >= 0) {
|
||||||
|
/* When mixing --from and --tree, we also want a copy of from
|
||||||
|
* in the list, but with no parent for that one entry. */
|
||||||
|
snaplist->snaps = vshCalloc(ctl, sizeof(*snaplist->snaps),
|
||||||
|
count + (tree && from));
|
||||||
|
snaplist->nsnaps = count;
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
snaplist->snaps[i].snap = snaps[i];
|
||||||
|
VIR_FREE(snaps);
|
||||||
|
if (tree) {
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
|
||||||
|
&snaplist->snaps[i].parent) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (from) {
|
||||||
|
snaps[snaplist->nsnaps++] = from;
|
||||||
|
virDomainSnapshotRef(from);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goto success;
|
||||||
|
}
|
||||||
|
|
||||||
/* Assume that if we got this far, then the --no-leaves and
|
/* Assume that if we got this far, then the --no-leaves and
|
||||||
* --no-metadata flags were not supported. Disable groups that
|
* --no-metadata flags were not supported. Disable groups that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user