From 7c570f06bdaf52b0088d6bd971abcb064c3e062f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 18 Jun 2019 12:44:39 +0100 Subject: [PATCH] network: add virNetworkPortRef API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normal practice is to provide a Ref API for all objects, but this was forgotten for the virNetworkPortPtr object. Reviewed-by: Ján Tomko Signed-off-by: Daniel P. Berrangé --- include/libvirt/libvirt-network.h | 3 +++ src/libvirt-network.c | 32 +++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 3 files changed, 36 insertions(+) diff --git a/include/libvirt/libvirt-network.h b/include/libvirt/libvirt-network.h index 97eceef754..c9ff0a49ed 100644 --- a/include/libvirt/libvirt-network.h +++ b/include/libvirt/libvirt-network.h @@ -455,4 +455,7 @@ virNetworkListAllPorts(virNetworkPtr network, int virNetworkPortFree(virNetworkPortPtr port); +int +virNetworkPortRef(virNetworkPortPtr port); + #endif /* LIBVIRT_NETWORK_H */ diff --git a/src/libvirt-network.c b/src/libvirt-network.c index 6ed32c8ba2..c182064c0f 100644 --- a/src/libvirt-network.c +++ b/src/libvirt-network.c @@ -1690,3 +1690,35 @@ virNetworkPortFree(virNetworkPortPtr port) virObjectUnref(port); return 0; } + + +/** + * virNetworkPortRef: + * @port: a network port object + * + * Increment the reference count on the network port. For each + * additional call to this method, there shall be a corresponding + * call to virNetworkPortFree 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 network port, and it is required that the + * port remain resident until all threads have finished using + * it. ie, each new thread using a network port would increment + * the reference count. + * + * Returns 0 in case of success, -1 in case of failure. + */ +int +virNetworkPortRef(virNetworkPortPtr port) +{ + VIR_DEBUG("port=%p refs=%d", port, + port ? port->parent.u.s.refs : 0); + + virResetLastError(); + + virCheckNetworkPortReturn(port, -1); + + virObjectRef(port); + return 0; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 46c32a081b..75f7fdfb0c 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -831,6 +831,7 @@ LIBVIRT_5.5.0 { virNetworkPortGetUUIDString; virNetworkPortDelete; virNetworkPortFree; + virNetworkPortRef; virNetworkPortSetParameters; } LIBVIRT_5.2.0;