mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 06:35:24 +00:00
list: new helper function to collect snapshots
Wraps the conversion from 'char *name' to virDomainSnapshotPtr in a reusable manner. * src/conf/virdomainlist.h (virDomainListSnapshots): New declaration. * src/conf/virdomainlist.c (virDomainListSnapshots): Implement it. * src/libvirt_private.syms (virdomainlist.h): Export it.
This commit is contained in:
parent
dbb564f862
commit
8548a9c501
@ -180,3 +180,47 @@ cleanup:
|
||||
VIR_FREE(data.domains);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
virDomainPtr dom,
|
||||
virDomainSnapshotPtr **snaps,
|
||||
unsigned int flags)
|
||||
{
|
||||
int count = virDomainSnapshotObjListNum(snapshots, from, flags);
|
||||
virDomainSnapshotPtr *list;
|
||||
char **names;
|
||||
int ret = -1;
|
||||
int i;
|
||||
|
||||
if (!snaps)
|
||||
return count;
|
||||
if (VIR_ALLOC_N(names, count) < 0 ||
|
||||
VIR_ALLOC_N(list, count + 1) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainSnapshotObjListGetNames(snapshots, from, names, count,
|
||||
flags) < 0)
|
||||
goto cleanup;
|
||||
for (i = 0; i < count; i++)
|
||||
if ((list[i] = virGetDomainSnapshot(dom, names[i])) == NULL)
|
||||
goto cleanup;
|
||||
|
||||
ret = count;
|
||||
*snaps = list;
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < count; i++)
|
||||
VIR_FREE(names[i]);
|
||||
VIR_FREE(names);
|
||||
if (ret < 0 && list) {
|
||||
for (i = 0; i < count; i++)
|
||||
if (list[i])
|
||||
virDomainSnapshotFree(list[i]);
|
||||
VIR_FREE(list);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -75,4 +75,10 @@
|
||||
int virDomainList(virConnectPtr conn, virHashTablePtr domobjs,
|
||||
virDomainPtr **domains, unsigned int flags);
|
||||
|
||||
int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
virDomainPtr dom,
|
||||
virDomainSnapshotPtr **snaps,
|
||||
unsigned int flags);
|
||||
|
||||
#endif /* __VIR_DOMAIN_LIST_H__ */
|
||||
|
@ -1239,6 +1239,7 @@ virDBusGetSystemBus;
|
||||
|
||||
# virdomainlist.h
|
||||
virDomainList;
|
||||
virDomainListSnapshots;
|
||||
|
||||
|
||||
# virfile.h
|
||||
|
Loading…
Reference in New Issue
Block a user