mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
snapshot: add virDomainSnapshotRef API
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.
This commit is contained in:
parent
d581313acf
commit
9d08debe88
@ -3424,6 +3424,7 @@ typedef enum {
|
||||
int virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
||||
unsigned int flags);
|
||||
|
||||
int virDomainSnapshotRef(virDomainSnapshotPtr snapshot);
|
||||
int virDomainSnapshotFree(virDomainSnapshotPtr snapshot);
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
@ -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 ....
|
||||
|
Loading…
Reference in New Issue
Block a user