[PATCH 3/5] Introduce virDomainObjEndAPI

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

 



This is basically turning qemuDomObjEndAPI into a more general
function. Other drivers which gets a reference to domain objects may
benefit from this function too.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 22 ++++++++++++++++++++++
 src/conf/domain_conf.h   |  2 ++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_domain.c   |  7 +------
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index aad4ec0..686c614 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2460,6 +2460,28 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
 }
 
 
+/**
+ * virDomainObjEndAPI:
+ * @vm: domain object
+ *
+ * Finish working with a domain object in an API.  This function
+ * clears whatever was left of a domain that was gathered using
+ * virDomainObjListFindByUUIDRef(). Currently that means only unlocking and
+ * decrementing the reference counter of that domain.  And in order to
+ * make sure the caller does not access the domain, the pointer is
+ * cleared.
+ */
+void
+virDomainObjEndAPI(virDomainObjPtr *vm)
+{
+    if (!*vm)
+        return;
+
+    virObjectUnlock(*vm);
+    virObjectUnref(*vm);
+    *vm = NULL;
+}
+
 
 /*
  *
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 25d3ee6..9955052 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2397,6 +2397,8 @@ virDomainObjPtr virDomainObjListFindByUUIDRef(virDomainObjListPtr doms,
 virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
                                            const char *name);
 
+void virDomainObjEndAPI(virDomainObjPtr *vm);
+
 bool virDomainObjTaint(virDomainObjPtr obj,
                        virDomainTaintFlags taint);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8c50ea2..e6555f1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -374,6 +374,7 @@ virDomainNostateReasonTypeFromString;
 virDomainNostateReasonTypeToString;
 virDomainObjAssignDef;
 virDomainObjCopyPersistentDef;
+virDomainObjEndAPI;
 virDomainObjFormat;
 virDomainObjGetMetadata;
 virDomainObjGetPersistentDef;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 1368386..b588c11 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2988,12 +2988,7 @@ qemuDomainAgentAvailable(virDomainObjPtr vm,
 void
 qemuDomObjEndAPI(virDomainObjPtr *vm)
 {
-    if (!*vm)
-        return;
-
-    virObjectUnlock(*vm);
-    virObjectUnref(*vm);
-    *vm = NULL;
+    virDomainObjEndAPI(vm);
 }
 
 
-- 
2.0.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]