
On Wed, Jul 09, 2014 at 06:23:24PM +0200, Timm Bäder wrote:
... which returns a GList of GVirDomainSnapshots, i.e. without any tree structure or other relationship between the snapshots. --- libvirt-gobject/libvirt-gobject-domain.c | 21 +++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 4 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 26 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index adb5179..8f48c2e 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -1600,3 +1600,24 @@ cleanup: g_hash_table_unref (snap_table); return ret; } + +/** + * gvir_domain_get_snapshots: + * @dom: The domain + * Returns: (element-type LibvirtGObject.DomainSnapshot) (transfer full): A + * list of all the snapshots available for the given domain. The returned + * list should be freed with g_list_free(), after its elements have been + * unreffed with g_object_unref(). + */ +GList *gvir_domain_get_snapshots(GVirDomain *dom) +{ + GList *snapshots = NULL; + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL); + + if (dom->priv->snapshots != NULL) { + snapshots = g_hash_table_get_values(dom->priv->snapshots); + g_list_foreach(snapshots, (GFunc)g_object_ref, NULL); + } + + return snapshots;
You need to take the snapshot list mutex while generating the list copy, otherwise you could race with a call to gvir_domain_fetch_snapshot running in another thread and destroying the objects you are copying. Christophe