[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 9/8] 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.
---

Assume's Peter's patch has already been applied:
https://www.redhat.com/archives/libvir-list/2012-June/msg00543.html

 src/conf/virdomainlist.c |   41 +++++++++++++++++++++++++++++++++++++++++
 src/conf/virdomainlist.h |    6 ++++++
 src/libvirt_private.syms |    1 +
 3 files changed, 48 insertions(+)

diff --git a/src/conf/virdomainlist.c b/src/conf/virdomainlist.c
index 246b838..a6aaec7 100644
--- a/src/conf/virdomainlist.c
+++ b/src/conf/virdomainlist.c
@@ -180,3 +180,44 @@ 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;
+    }
+
+    virDomainSnapshotObjListGetNames(snapshots, from, names, count, flags);
+    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) {
+        if (list[i])
+            virDomainSnapshotFree(list[i]);
+        VIR_FREE(list);
+    }
+    return ret;
+}
diff --git a/src/conf/virdomainlist.h b/src/conf/virdomainlist.h
index caee592..138d622 100644
--- a/src/conf/virdomainlist.h
+++ b/src/conf/virdomainlist.h
@@ -63,4 +63,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__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b37fe68..2fe5068 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1239,6 +1239,7 @@ virDBusGetSystemBus;

 # virdomainlist.h
 virDomainList;
+virDomainListSnapshots;


 # virfile.h
-- 
1.7.10.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]