[libvirt] [PATCH 06/13] Turn virDomainObjPtr into a virObjectPtr

Daniel P. Berrange berrange at redhat.com
Tue Jul 31 16:58:26 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

Switch virDomainObjPtr to use the virObject APIs for reference
counting. The main change is that virObjectUnref does not return
the reference count, merely a bool indicating whether the object
still has any refs left. Checking the return value is also not
mandatory.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 src/conf/domain_conf.c    |   59 ++++++++++++++++++++-------------------------
 src/conf/domain_conf.h    |    8 +++---
 src/libvirt_private.syms  |    3 +--
 src/libxl/libxl_driver.c  |    6 ++---
 src/lxc/lxc_process.c     |    6 ++---
 src/openvz/openvz_conf.c  |   19 +++------------
 src/qemu/qemu_domain.c    |   27 +++++++++------------
 src/qemu/qemu_domain.h    |    8 +++---
 src/qemu/qemu_driver.c    |    2 +-
 src/qemu/qemu_migration.c |   22 ++++++++---------
 src/qemu/qemu_migration.h |    4 +--
 src/qemu/qemu_process.c   |   50 ++++++++++++++++++--------------------
 src/vmware/vmware_conf.c  |    4 +--
 13 files changed, 93 insertions(+), 125 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 143d92e..72d41f5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -658,6 +658,21 @@ VIR_ENUM_IMPL(virDomainNumatuneMemPlacementMode,
 #define VIR_DOMAIN_XML_WRITE_FLAGS  VIR_DOMAIN_XML_SECURE
 #define VIR_DOMAIN_XML_READ_FLAGS   VIR_DOMAIN_XML_INACTIVE
 
+static virClassPtr virDomainObjClass;
+static void virDomainObjDispose(void *obj);
+
+static int virDomainObjOnceInit(void)
+{
+    if (!(virDomainObjClass = virClassNew("virDomainObj",
+                                          sizeof(virDomainObj),
+                                          virDomainObjDispose)))
+        return -1;
+
+    return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virDomainObj)
+
 void
 virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
                                int ndevices)
@@ -723,7 +738,7 @@ virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
 {
     virDomainObjPtr obj = payload;
     virDomainObjLock(obj);
-    if (virDomainObjUnref(obj) > 0)
+    if (!virObjectUnref(obj))
         virDomainObjUnlock(obj);
 }
 
@@ -1637,10 +1652,10 @@ void virDomainDefFree(virDomainDefPtr def)
 }
 
 static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr snapshots);
-static void virDomainObjFree(virDomainObjPtr dom)
+
+static void virDomainObjDispose(void *obj)
 {
-    if (!dom)
-        return;
+    virDomainObjPtr dom = obj;
 
     VIR_DEBUG("obj=%p", dom);
     virDomainDefFree(dom->def);
@@ -1652,37 +1667,18 @@ static void virDomainObjFree(virDomainObjPtr dom)
     virMutexDestroy(&dom->lock);
 
     virDomainSnapshotObjListDeinit(&dom->snapshots);
-
-    VIR_FREE(dom);
-}
-
-void virDomainObjRef(virDomainObjPtr dom)
-{
-    dom->refs++;
-    VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
 }
 
 
-int virDomainObjUnref(virDomainObjPtr dom)
-{
-    dom->refs--;
-    VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
-    if (dom->refs == 0) {
-        virDomainObjUnlock(dom);
-        virDomainObjFree(dom);
-        return 0;
-    }
-    return dom->refs;
-}
-
-static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
+virDomainObjPtr virDomainObjNew(virCapsPtr caps)
 {
     virDomainObjPtr domain;
 
-    if (VIR_ALLOC(domain) < 0) {
-        virReportOOMError();
+    if (virDomainObjInitialize() < 0)
+        return NULL;
+
+    if (!(domain = virObjectNew(virDomainObjClass)))
         return NULL;
-    }
 
     if (caps->privateDataAllocFunc &&
         !(domain->privateData = (caps->privateDataAllocFunc)())) {
@@ -1704,7 +1700,6 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
     virDomainObjLock(domain);
     virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF,
                                  VIR_DOMAIN_SHUTOFF_UNKNOWN);
-    domain->refs = 1;
 
     virDomainSnapshotObjListInit(&domain->snapshots);
 
@@ -9326,8 +9321,7 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
     return obj;
 
 error:
-    /* obj was never shared, so unref should return 0 */
-    ignore_value(virDomainObjUnref(obj));
+    virObjectUnref(obj);
     VIR_FREE(nodes);
     return NULL;
 }
@@ -13384,9 +13378,8 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
     return obj;
 
 error:
-    /* obj was never shared, so unref should return 0 */
     if (obj)
-        ignore_value(virDomainObjUnref(obj));
+        virObjectUnref(obj);
     VIR_FREE(statusFile);
     return NULL;
 }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index bc02caf..1d831b5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -43,6 +43,7 @@
 # include "virnetdevvportprofile.h"
 # include "virnetdevopenvswitch.h"
 # include "virnetdevbandwidth.h"
+# include "virobject.h"
 
 /* forward declarations of all device types, required by
  * virDomainDeviceDef
@@ -1807,8 +1808,9 @@ struct _virDomainStateReason {
 typedef struct _virDomainObj virDomainObj;
 typedef virDomainObj *virDomainObjPtr;
 struct _virDomainObj {
+    virObject object;
+
     virMutex lock;
-    int refs;
 
     pid_t pid;
     virDomainStateReason state;
@@ -1845,6 +1847,7 @@ virDomainObjIsActive(virDomainObjPtr dom)
     return dom->def->id != -1;
 }
 
+virDomainObjPtr virDomainObjNew(virCapsPtr caps);
 
 int virDomainObjListInit(virDomainObjListPtr objs);
 void virDomainObjListDeinit(virDomainObjListPtr objs);
@@ -1907,9 +1910,6 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
                                void *opaque);
 
 void virDomainDefFree(virDomainDefPtr vm);
-void virDomainObjRef(virDomainObjPtr vm);
-/* Returns 1 if the object was freed, 0 if more refs exist */
-int virDomainObjUnref(virDomainObjPtr vm) ATTRIBUTE_RETURN_CHECK;
 
 virDomainChrDefPtr virDomainChrDefNew(void);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2031701..d1a4c65 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -425,12 +425,11 @@ virDomainObjListGetInactiveNames;
 virDomainObjListInit;
 virDomainObjListNumOfDomains;
 virDomainObjLock;
-virDomainObjRef;
+virDomainObjNew;
 virDomainObjSetDefTransient;
 virDomainObjSetState;
 virDomainObjTaint;
 virDomainObjUnlock;
-virDomainObjUnref;
 virDomainPausedReasonTypeFromString;
 virDomainPausedReasonTypeToString;
 virDomainPciRombarModeTypeFromString;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 873f973..150900f 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -134,7 +134,7 @@ libxlDomainObjUnref(void *data)
 {
     virDomainObjPtr vm = data;
 
-    ignore_value(virDomainObjUnref(vm));
+    virObjectUnref(vm);
 }
 
 static void
@@ -484,13 +484,13 @@ libxlCreateDomEvents(virDomainObjPtr vm)
     /* Add a reference to the domain object while it is injected in
      * the event loop.
      */
-    virDomainObjRef(vm);
+    virObjectRef(vm);
     if ((priv->eventHdl = virEventAddHandle(
              fd,
              VIR_EVENT_HANDLE_READABLE | VIR_EVENT_HANDLE_ERROR,
              libxlEventHandler,
              vm, libxlDomainObjUnref)) < 0) {
-        ignore_value(virDomainObjUnref(vm));
+        virObjectUnref(vm);
         goto error;
     }
 
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 65b463f..046ed86 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -565,7 +565,7 @@ static void virLXCProcessMonitorDestroy(virLXCMonitorPtr mon,
     priv = vm->privateData;
     if (priv->monitor == mon)
         priv->monitor = NULL;
-    if (virDomainObjUnref(vm) > 0)
+    if (virObjectUnref(vm))
         virDomainObjUnlock(vm);
 }
 
@@ -666,12 +666,12 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
 
     /* Hold an extra reference because we can't allow 'vm' to be
      * deleted while the monitor is active */
-    virDomainObjRef(vm);
+    virObjectRef(vm);
 
     monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks);
 
     if (monitor == NULL)
-        ignore_value(virDomainObjUnref(vm));
+        virObjectUnref(vm);
 
     if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
         if (monitor) {
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 5dc071c..e62bf8c 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -598,17 +598,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
         }
         *line++ = '\0';
 
-        if (VIR_ALLOC(dom) < 0)
-            goto no_memory;
-
-        if (virMutexInit(&dom->lock) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("cannot initialize mutex"));
-            VIR_FREE(dom);
-            goto cleanup;
-        }
-
-        virDomainObjLock(dom);
+        if (!(dom = virDomainObjNew(driver->caps)))
+             goto cleanup;
 
         if (VIR_ALLOC(dom->def) < 0)
             goto no_memory;
@@ -623,7 +614,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
                                  VIR_DOMAIN_RUNNING_UNKNOWN);
         }
 
-        dom->refs = 1;
         dom->pid = veid;
         if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_SHUTOFF)
             dom->def->id = -1;
@@ -683,7 +673,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
             goto cleanup;
         }
 
-        virDomainObjUnlock(dom);
         dom = NULL;
     }
 
@@ -700,9 +689,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
     virCommandFree(cmd);
     VIR_FREE(temp);
     VIR_FREE(outbuf);
-    /* dom hasn't been shared yet, so unref should return 0 */
-    if (dom)
-        ignore_value(virDomainObjUnref(dom));
+    virObjectUnref(dom);
     return -1;
 }
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 86f0265..4acbb20 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -774,7 +774,7 @@ qemuDomainObjBeginJobInternal(struct qemud_driver *driver,
         return -1;
     then = now + QEMU_JOB_WAIT_TIME;
 
-    virDomainObjRef(obj);
+    virObjectRef(obj);
     if (driver_locked)
         qemuDriverUnlock(driver);
 
@@ -854,8 +854,7 @@ error:
         qemuDriverLock(driver);
         virDomainObjLock(obj);
     }
-    /* Safe to ignore value since ref count was incremented above */
-    ignore_value(virDomainObjUnref(obj));
+    virObjectUnref(obj);
     return -1;
 }
 
@@ -922,10 +921,10 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
  * To be called after completing the work associated with the
  * earlier qemuDomainBeginJob() call
  *
- * Returns remaining refcount on 'obj', maybe 0 to indicated it
- * was deleted
+ * Returns true if @obj was still referenced, false if it was
+ * disposed of.
  */
-int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
+bool qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
 {
     qemuDomainObjPrivatePtr priv = obj->privateData;
     enum qemuDomainJob job = priv->job.active;
@@ -941,10 +940,10 @@ int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
         qemuDomainObjSaveJob(driver, obj);
     virCondSignal(&priv->job.cond);
 
-    return virDomainObjUnref(obj);
+    return virObjectUnref(obj);
 }
 
-int
+bool
 qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
 {
     qemuDomainObjPrivatePtr priv = obj->privateData;
@@ -958,7 +957,7 @@ qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
     qemuDomainObjSaveJob(driver, obj);
     virCondBroadcast(&priv->job.asyncCond);
 
-    return virDomainObjUnref(obj);
+    return virObjectUnref(obj);
 }
 
 static int
@@ -1031,9 +1030,7 @@ qemuDomainObjExitMonitorInternal(struct qemud_driver *driver,
         qemuDomainObjSaveJob(driver, obj);
         virCondSignal(&priv->job.cond);
 
-        /* safe to ignore since the surrounding async job increased
-         * the reference counter as well */
-        ignore_value(virDomainObjUnref(obj));
+        virObjectUnref(obj);
     }
 }
 
@@ -1207,7 +1204,7 @@ void qemuDomainObjExitAgentWithDriver(struct qemud_driver *driver,
 void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
                                         virDomainObjPtr obj)
 {
-    virDomainObjRef(obj);
+    virObjectRef(obj);
     virDomainObjUnlock(obj);
     qemuDriverUnlock(driver);
 }
@@ -1217,9 +1214,7 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
 {
     qemuDriverLock(driver);
     virDomainObjLock(obj);
-    /* Safe to ignore value, since we incremented ref in
-     * qemuDomainObjEnterRemoteWithDriver */
-    ignore_value(virDomainObjUnref(obj));
+    virObjectUnref(obj);
 }
 
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 9f9467d..d5ea33d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -193,11 +193,11 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
                                          enum qemuDomainAsyncJob asyncJob)
     ATTRIBUTE_RETURN_CHECK;
 
-int qemuDomainObjEndJob(struct qemud_driver *driver,
-                        virDomainObjPtr obj)
+bool qemuDomainObjEndJob(struct qemud_driver *driver,
+                         virDomainObjPtr obj)
     ATTRIBUTE_RETURN_CHECK;
-int qemuDomainObjEndAsyncJob(struct qemud_driver *driver,
-                             virDomainObjPtr obj)
+bool qemuDomainObjEndAsyncJob(struct qemud_driver *driver,
+                              virDomainObjPtr obj)
     ATTRIBUTE_RETURN_CHECK;
 void qemuDomainObjSetJobPhase(struct qemud_driver *driver,
                               virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0da5c5a..0ef74e0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3402,7 +3402,7 @@ endjob:
     ignore_value(qemuDomainObjEndAsyncJob(driver, wdEvent->vm));
 
 unlock:
-    if (virDomainObjUnref(wdEvent->vm) > 0)
+    if (virObjectUnref(wdEvent->vm))
         virDomainObjUnlock(wdEvent->vm);
     qemuDriverUnlock(driver);
     VIR_FREE(wdEvent);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 362ef9b..b7a417f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1369,7 +1369,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
      * This prevents any other APIs being invoked while incoming
      * migration is taking place.
      */
-    if (qemuMigrationJobContinue(vm) == 0) {
+    if (!qemuMigrationJobContinue(vm)) {
         vm = NULL;
         virReportError(VIR_ERR_OPERATION_FAILED,
                        "%s", _("domain disappeared"));
@@ -1396,7 +1396,7 @@ cleanup:
     return ret;
 
 endjob:
-    if (qemuMigrationJobFinish(driver, vm) == 0) {
+    if (!qemuMigrationJobFinish(driver, vm)) {
         vm = NULL;
     }
     goto cleanup;
@@ -2682,7 +2682,7 @@ endjob:
                                          VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
     }
 
-    if (qemuMigrationJobFinish(driver, vm) == 0) {
+    if (!qemuMigrationJobFinish(driver, vm)) {
         vm = NULL;
     } else if (!virDomainObjIsActive(vm) &&
                (!vm->persistent ||
@@ -2724,7 +2724,7 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
     virDomainEventPtr event = NULL;
     int ret = -1;
     bool resume;
-    int refs;
+    bool hasrefs;
 
     /* If we didn't start the job in the begin phase, start it now. */
     if (!(flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
@@ -2772,10 +2772,10 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
 
 endjob:
     if (ret < 0)
-        refs = qemuMigrationJobFinish(driver, vm);
+        hasrefs = qemuMigrationJobFinish(driver, vm);
     else
-        refs = qemuMigrationJobContinue(vm);
-    if (refs == 0) {
+        hasrefs = qemuMigrationJobContinue(vm);
+    if (!hasrefs) {
         vm = NULL;
     } else if (!virDomainObjIsActive(vm) && !vm->persistent) {
         qemuDomainRemoveInactive(driver, vm);
@@ -3376,15 +3376,15 @@ qemuMigrationJobStartPhase(struct qemud_driver *driver,
                            virDomainObjPtr vm,
                            enum qemuMigrationJobPhase phase)
 {
-    virDomainObjRef(vm);
+    virObjectRef(vm);
     qemuMigrationJobSetPhase(driver, vm, phase);
 }
 
-int
+bool
 qemuMigrationJobContinue(virDomainObjPtr vm)
 {
     qemuDomainObjReleaseAsyncJob(vm);
-    return virDomainObjUnref(vm);
+    return virObjectUnref(vm);
 }
 
 bool
@@ -3407,7 +3407,7 @@ qemuMigrationJobIsActive(virDomainObjPtr vm,
     return true;
 }
 
-int
+bool
 qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr vm)
 {
     return qemuDomainObjEndAsyncJob(driver, vm);
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index e6ca215..1740204 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -66,12 +66,12 @@ void qemuMigrationJobStartPhase(struct qemud_driver *driver,
                                 virDomainObjPtr vm,
                                 enum qemuMigrationJobPhase phase)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-int qemuMigrationJobContinue(virDomainObjPtr obj)
+bool qemuMigrationJobContinue(virDomainObjPtr obj)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 bool qemuMigrationJobIsActive(virDomainObjPtr vm,
                               enum qemuDomainAsyncJob job)
     ATTRIBUTE_NONNULL(1);
-int qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr obj)
+bool qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr obj)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
 int qemuMigrationSetOffline(struct qemud_driver *driver,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0d4f5ae..3a08c5b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -173,7 +173,7 @@ static void qemuProcessHandleAgentDestroy(qemuAgentPtr agent,
     priv = vm->privateData;
     if (priv->agent == agent)
         priv->agent = NULL;
-    if (virDomainObjUnref(vm) > 0)
+    if (virObjectUnref(vm))
         virDomainObjUnlock(vm);
 }
 
@@ -225,7 +225,7 @@ qemuConnectAgent(struct qemud_driver *driver, virDomainObjPtr vm)
 
     /* Hold an extra reference because we can't allow 'vm' to be
      * deleted while the agent is active */
-    virDomainObjRef(vm);
+    virObjectRef(vm);
 
     ignore_value(virTimeMillisNow(&priv->agentStart));
     virDomainObjUnlock(vm);
@@ -246,9 +246,8 @@ qemuConnectAgent(struct qemud_driver *driver, virDomainObjPtr vm)
         goto cleanup;
     }
 
-    /* Safe to ignore value since ref count was incremented above */
     if (agent == NULL)
-        ignore_value(virDomainObjUnref(vm));
+        virObjectUnref(vm);
 
     if (!virDomainObjIsActive(vm)) {
         qemuAgentClose(agent);
@@ -584,7 +583,7 @@ qemuProcessFakeReboot(void *opaque)
     ret = 0;
 
 endjob:
-    if (qemuDomainObjEndJob(driver, vm) == 0)
+    if (!qemuDomainObjEndJob(driver, vm))
         vm = NULL;
 
 cleanup:
@@ -593,7 +592,7 @@ cleanup:
             ignore_value(qemuProcessKill(driver, vm,
                                          VIR_QEMU_PROCESS_KILL_FORCE));
         }
-        if (virDomainObjUnref(vm) > 0)
+        if (virObjectUnref(vm))
             virDomainObjUnlock(vm);
     }
     if (event)
@@ -610,7 +609,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
 
     if (priv->fakeReboot) {
         qemuDomainSetFakeReboot(driver, vm, false);
-        virDomainObjRef(vm);
+        virObjectRef(vm);
         virThread th;
         if (virThreadCreate(&th,
                             false,
@@ -619,8 +618,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
             VIR_ERROR(_("Failed to create reboot thread, killing domain"));
             ignore_value(qemuProcessKill(driver, vm,
                                          VIR_QEMU_PROCESS_KILL_NOWAIT));
-            /* Safe to ignore value since ref count was incremented above */
-            ignore_value(virDomainObjUnref(vm));
+            virObjectUnref(vm);
         }
     } else {
         ignore_value(qemuProcessKill(driver, vm, VIR_QEMU_PROCESS_KILL_NOWAIT));
@@ -801,9 +799,9 @@ qemuProcessHandleWatchdog(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
             /* Hold an extra reference because we can't allow 'vm' to be
              * deleted before handling watchdog event is finished.
              */
-            virDomainObjRef(vm);
+            virObjectRef(vm);
             if (virThreadPoolSendJob(driver->workerPool, 0, wdEvent) < 0) {
-                if (virDomainObjUnref(vm) == 0)
+                if (!virObjectUnref(vm))
                     vm = NULL;
                 VIR_FREE(wdEvent);
             }
@@ -1022,7 +1020,7 @@ static void qemuProcessHandleMonitorDestroy(qemuMonitorPtr mon,
     priv = vm->privateData;
     if (priv->mon == mon)
         priv->mon = NULL;
-    if (virDomainObjUnref(vm) > 0)
+    if (virObjectUnref(vm))
         virDomainObjUnlock(vm);
 }
 
@@ -1213,7 +1211,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
 
     /* Hold an extra reference because we can't allow 'vm' to be
      * deleted while the monitor is active */
-    virDomainObjRef(vm);
+    virObjectRef(vm);
 
     ignore_value(virTimeMillisNow(&priv->monStart));
     virDomainObjUnlock(vm);
@@ -1228,9 +1226,8 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
     virDomainObjLock(vm);
     priv->monStart = 0;
 
-    /* Safe to ignore value since ref count was incremented above */
     if (mon == NULL)
-        ignore_value(virDomainObjUnref(vm));
+        virObjectUnref(vm);
 
     if (!virDomainObjIsActive(vm)) {
         qemuMonitorClose(mon);
@@ -3068,7 +3065,7 @@ qemuProcessReconnect(void *opaque)
 
     /* Hold an extra reference because we can't allow 'vm' to be
      * deleted if qemuConnectMonitor() failed */
-    virDomainObjRef(obj);
+    virObjectRef(obj);
 
     /* XXX check PID liveliness & EXE path */
     if (qemuConnectMonitor(driver, obj) < 0)
@@ -3165,10 +3162,10 @@ qemuProcessReconnect(void *opaque)
         driver->nextvmid = obj->def->id + 1;
 
 endjob:
-    if (qemuDomainObjEndJob(driver, obj) == 0)
+    if (!qemuDomainObjEndJob(driver, obj))
         obj = NULL;
 
-    if (obj && virDomainObjUnref(obj) > 0)
+    if (obj && virObjectUnref(obj))
         virDomainObjUnlock(obj);
 
     qemuDriverUnlock(driver);
@@ -3178,18 +3175,18 @@ endjob:
     return;
 
 error:
-    if (qemuDomainObjEndJob(driver, obj) == 0)
+    if (!qemuDomainObjEndJob(driver, obj))
         obj = NULL;
 
     if (obj) {
         if (!virDomainObjIsActive(obj)) {
-            if (virDomainObjUnref(obj) > 0)
+            if (virObjectUnref(obj))
                 virDomainObjUnlock(obj);
             qemuDriverUnlock(driver);
             return;
         }
 
-        if (virDomainObjUnref(obj) > 0) {
+        if (virObjectUnref(obj)) {
             /* We can't get the monitor back, so must kill the VM
              * to remove danger of it ending up running twice if
              * user tries to start it again later
@@ -3277,9 +3274,9 @@ qemuProcessReconnectHelper(void *payload,
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Could not create thread. QEMU initialization "
                          "might be incomplete"));
-        if (qemuDomainObjEndJob(src->driver, obj) == 0) {
+        if (!qemuDomainObjEndJob(src->driver, obj)) {
             obj = NULL;
-        } else if (virDomainObjUnref(obj) > 0) {
+        } else if (virObjectUnref(obj)) {
            /* We can't spawn a thread and thus connect to monitor.
             * Kill qemu */
             qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, 0);
@@ -3950,12 +3947,11 @@ cleanup:
          * a case, but there are too many to maintain certainty, so we
          * will do this as a precaution).
          */
-        virDomainObjRef(vm);
+        virObjectRef(vm);
         virDomainObjUnlock(vm);
         qemuDriverLock(driver);
         virDomainObjLock(vm);
-        /* Safe to ignore value since ref count was incremented above */
-        ignore_value(virDomainObjUnref(vm));
+        virObjectUnref(vm);
     }
     return ret;
 }
@@ -4407,7 +4403,7 @@ qemuProcessAutoDestroy(struct qemud_driver *driver,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
 
-    if (qemuDomainObjEndJob(driver, dom) == 0)
+    if (!qemuDomainObjEndJob(driver, dom))
         dom = NULL;
     if (dom && !dom->persistent)
         qemuDomainRemoveInactive(driver, dom);
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 9fb95c4..b52c002 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -213,9 +213,7 @@ cleanup:
     VIR_FREE(directoryName);
     VIR_FREE(fileName);
     VIR_FREE(vmx);
-    /* any non-NULL vm here has not been shared, so unref will return 0 */
-    if (vm)
-        ignore_value(virDomainObjUnref(vm));
+    virObjectUnref(vm);
     return ret;
 }
 
-- 
1.7.10.4




More information about the libvir-list mailing list