]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
snapshot: add virDomainSnapshotRef API
authorEric Blake <eblake@redhat.com>
Fri, 8 Jun 2012 16:28:55 +0000 (10:28 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 8 Jun 2012 16:32:36 +0000 (10:32 -0600)
virDomainSnapshotPtr has a refcount member, but no one was able
to use it.  Furthermore, all of our other vir*Ptr objects have
a *Ref method to match their *Free method.  Thankfully, this is
client-side only, so we can use this new function regardless of
how old the server side is!  (I have future patches to virsh
that want to use it.)

* include/libvirt/libvirt.h.in (virDomainSnapshotRef): Declare.
* src/libvirt.c (virDomainSnapshotRef): Implement it.
* src/libvirt_public.syms (LIBVIRT_0.9.13): Export it.

include/libvirt/libvirt.h.in
src/libvirt.c
src/libvirt_public.syms

index da3ce29fd6fea55cb33356761fa3705f3ea4509e..fcb66955d4123d9a5d0a6687b0eeb744b15dfb62 100644 (file)
@@ -3424,6 +3424,7 @@ typedef enum {
 int virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
                             unsigned int flags);
 
+int virDomainSnapshotRef(virDomainSnapshotPtr snapshot);
 int virDomainSnapshotFree(virDomainSnapshotPtr snapshot);
 
 /*
index 6386ed48be7aded06e9a8101fa3de2aaa2c09e69..00358d68bbaeff457be0d335c3b1d0d77b324601 100644 (file)
@@ -17486,6 +17486,39 @@ error:
     return -1;
 }
 
+/**
+ * virDomainSnapshotRef:
+ * @snapshot: the snapshot to hold a reference on
+ *
+ * Increment the reference count on the snapshot. For each
+ * additional call to this method, there shall be a corresponding
+ * call to virDomainSnapshotFree to release the reference count, once
+ * the caller no longer needs the reference to this object.
+ *
+ * This method is typically useful for applications where multiple
+ * threads are using a connection, and it is required that the
+ * connection and domain remain open until all threads have finished
+ * using the snapshot. ie, each new thread using a snapshot would
+ * increment the reference count.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainSnapshotRef(virDomainSnapshotPtr snapshot)
+{
+    if ((!VIR_IS_DOMAIN_SNAPSHOT(snapshot))) {
+        virLibDomainSnapshotError(VIR_ERR_INVALID_DOMAIN_SNAPSHOT,
+                                  __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    virMutexLock(&snapshot->domain->conn->lock);
+    VIR_DEBUG("snapshot=%p, refs=%d", snapshot, snapshot->refs);
+    snapshot->refs++;
+    virMutexUnlock(&snapshot->domain->conn->lock);
+    return 0;
+}
+
 /**
  * virDomainSnapshotFree:
  * @snapshot: a domain snapshot object
index 46c13fbfdcd7b962785b1b5b6ba684ae374d2ebf..ba61595be758aab2cf9e0c4dfba84b814fccd864 100644 (file)
@@ -534,4 +534,9 @@ LIBVIRT_0.9.11 {
         virDomainPMWakeup;
 } LIBVIRT_0.9.10;
 
+LIBVIRT_0.9.13 {
+    global:
+        virDomainSnapshotRef;
+} LIBVIRT_0.9.11;
+
 # .... define new API here using predicted next version number ....