Turn virDomainObjPtr into a virObjectPtr

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@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-11 14:35:46 +01:00
parent 46ec5f85c8
commit 31cb030ab6
13 changed files with 93 additions and 126 deletions

View File

@ -660,6 +660,21 @@ VIR_ENUM_IMPL(virDomainNumatuneMemPlacementMode,
#define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE #define VIR_DOMAIN_XML_WRITE_FLAGS VIR_DOMAIN_XML_SECURE
#define VIR_DOMAIN_XML_READ_FLAGS VIR_DOMAIN_XML_INACTIVE #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 void
virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights, virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
int ndevices) int ndevices)
@ -725,7 +740,7 @@ virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
{ {
virDomainObjPtr obj = payload; virDomainObjPtr obj = payload;
virDomainObjLock(obj); virDomainObjLock(obj);
if (virDomainObjUnref(obj) > 0) if (virObjectUnref(obj))
virDomainObjUnlock(obj); virDomainObjUnlock(obj);
} }
@ -1639,10 +1654,10 @@ void virDomainDefFree(virDomainDefPtr def)
} }
static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr snapshots); static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr snapshots);
static void virDomainObjFree(virDomainObjPtr dom)
static void virDomainObjDispose(void *obj)
{ {
if (!dom) virDomainObjPtr dom = obj;
return;
VIR_DEBUG("obj=%p", dom); VIR_DEBUG("obj=%p", dom);
virDomainDefFree(dom->def); virDomainDefFree(dom->def);
@ -1654,37 +1669,18 @@ static void virDomainObjFree(virDomainObjPtr dom)
virMutexDestroy(&dom->lock); virMutexDestroy(&dom->lock);
virDomainSnapshotObjListDeinit(&dom->snapshots); 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) virDomainObjPtr virDomainObjNew(virCapsPtr caps)
{
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 domain; virDomainObjPtr domain;
if (VIR_ALLOC(domain) < 0) { if (virDomainObjInitialize() < 0)
virReportOOMError(); return NULL;
if (!(domain = virObjectNew(virDomainObjClass)))
return NULL; return NULL;
}
if (caps->privateDataAllocFunc && if (caps->privateDataAllocFunc &&
!(domain->privateData = (caps->privateDataAllocFunc)())) { !(domain->privateData = (caps->privateDataAllocFunc)())) {
@ -1706,7 +1702,6 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
virDomainObjLock(domain); virDomainObjLock(domain);
virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF, virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN); VIR_DOMAIN_SHUTOFF_UNKNOWN);
domain->refs = 1;
virDomainSnapshotObjListInit(&domain->snapshots); virDomainSnapshotObjListInit(&domain->snapshots);
@ -9417,8 +9412,7 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
return obj; return obj;
error: error:
/* obj was never shared, so unref should return 0 */ virObjectUnref(obj);
ignore_value(virDomainObjUnref(obj));
VIR_FREE(nodes); VIR_FREE(nodes);
return NULL; return NULL;
} }
@ -13527,9 +13521,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
return obj; return obj;
error: error:
/* obj was never shared, so unref should return 0 */ virObjectUnref(obj);
if (obj)
ignore_value(virDomainObjUnref(obj));
VIR_FREE(statusFile); VIR_FREE(statusFile);
return NULL; return NULL;
} }

View File

@ -43,6 +43,7 @@
# include "virnetdevvportprofile.h" # include "virnetdevvportprofile.h"
# include "virnetdevopenvswitch.h" # include "virnetdevopenvswitch.h"
# include "virnetdevbandwidth.h" # include "virnetdevbandwidth.h"
# include "virobject.h"
/* forward declarations of all device types, required by /* forward declarations of all device types, required by
* virDomainDeviceDef * virDomainDeviceDef
@ -1809,8 +1810,9 @@ struct _virDomainStateReason {
typedef struct _virDomainObj virDomainObj; typedef struct _virDomainObj virDomainObj;
typedef virDomainObj *virDomainObjPtr; typedef virDomainObj *virDomainObjPtr;
struct _virDomainObj { struct _virDomainObj {
virObject object;
virMutex lock; virMutex lock;
int refs;
pid_t pid; pid_t pid;
virDomainStateReason state; virDomainStateReason state;
@ -1847,6 +1849,7 @@ virDomainObjIsActive(virDomainObjPtr dom)
return dom->def->id != -1; return dom->def->id != -1;
} }
virDomainObjPtr virDomainObjNew(virCapsPtr caps);
int virDomainObjListInit(virDomainObjListPtr objs); int virDomainObjListInit(virDomainObjListPtr objs);
void virDomainObjListDeinit(virDomainObjListPtr objs); void virDomainObjListDeinit(virDomainObjListPtr objs);
@ -1909,9 +1912,6 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
void *opaque); void *opaque);
void virDomainDefFree(virDomainDefPtr vm); 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); virDomainChrDefPtr virDomainChrDefNew(void);

View File

@ -428,12 +428,11 @@ virDomainObjListGetInactiveNames;
virDomainObjListInit; virDomainObjListInit;
virDomainObjListNumOfDomains; virDomainObjListNumOfDomains;
virDomainObjLock; virDomainObjLock;
virDomainObjRef; virDomainObjNew;
virDomainObjSetDefTransient; virDomainObjSetDefTransient;
virDomainObjSetState; virDomainObjSetState;
virDomainObjTaint; virDomainObjTaint;
virDomainObjUnlock; virDomainObjUnlock;
virDomainObjUnref;
virDomainPausedReasonTypeFromString; virDomainPausedReasonTypeFromString;
virDomainPausedReasonTypeToString; virDomainPausedReasonTypeToString;
virDomainPciRombarModeTypeFromString; virDomainPciRombarModeTypeFromString;

View File

@ -134,7 +134,7 @@ libxlDomainObjUnref(void *data)
{ {
virDomainObjPtr vm = data; virDomainObjPtr vm = data;
ignore_value(virDomainObjUnref(vm)); virObjectUnref(vm);
} }
static void static void
@ -484,13 +484,13 @@ libxlCreateDomEvents(virDomainObjPtr vm)
/* Add a reference to the domain object while it is injected in /* Add a reference to the domain object while it is injected in
* the event loop. * the event loop.
*/ */
virDomainObjRef(vm); virObjectRef(vm);
if ((priv->eventHdl = virEventAddHandle( if ((priv->eventHdl = virEventAddHandle(
fd, fd,
VIR_EVENT_HANDLE_READABLE | VIR_EVENT_HANDLE_ERROR, VIR_EVENT_HANDLE_READABLE | VIR_EVENT_HANDLE_ERROR,
libxlEventHandler, libxlEventHandler,
vm, libxlDomainObjUnref)) < 0) { vm, libxlDomainObjUnref)) < 0) {
ignore_value(virDomainObjUnref(vm)); virObjectUnref(vm);
goto error; goto error;
} }

View File

@ -565,7 +565,7 @@ static void virLXCProcessMonitorDestroy(virLXCMonitorPtr mon,
priv = vm->privateData; priv = vm->privateData;
if (priv->monitor == mon) if (priv->monitor == mon)
priv->monitor = NULL; priv->monitor = NULL;
if (virDomainObjUnref(vm) > 0) if (virObjectUnref(vm))
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
} }
@ -666,12 +666,12 @@ static virLXCMonitorPtr virLXCProcessConnectMonitor(virLXCDriverPtr driver,
/* Hold an extra reference because we can't allow 'vm' to be /* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active */ * deleted while the monitor is active */
virDomainObjRef(vm); virObjectRef(vm);
monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks); monitor = virLXCMonitorNew(vm, driver->stateDir, &monitorCallbacks);
if (monitor == NULL) if (monitor == NULL)
ignore_value(virDomainObjUnref(vm)); virObjectUnref(vm);
if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) { if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 0) {
if (monitor) { if (monitor) {

View File

@ -598,17 +598,8 @@ int openvzLoadDomains(struct openvz_driver *driver) {
} }
*line++ = '\0'; *line++ = '\0';
if (VIR_ALLOC(dom) < 0) if (!(dom = virDomainObjNew(driver->caps)))
goto no_memory; goto cleanup;
if (virMutexInit(&dom->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
VIR_FREE(dom);
goto cleanup;
}
virDomainObjLock(dom);
if (VIR_ALLOC(dom->def) < 0) if (VIR_ALLOC(dom->def) < 0)
goto no_memory; goto no_memory;
@ -623,7 +614,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
VIR_DOMAIN_RUNNING_UNKNOWN); VIR_DOMAIN_RUNNING_UNKNOWN);
} }
dom->refs = 1;
dom->pid = veid; dom->pid = veid;
if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_SHUTOFF) if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_SHUTOFF)
dom->def->id = -1; dom->def->id = -1;
@ -683,7 +673,6 @@ int openvzLoadDomains(struct openvz_driver *driver) {
goto cleanup; goto cleanup;
} }
virDomainObjUnlock(dom);
dom = NULL; dom = NULL;
} }
@ -700,9 +689,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
virCommandFree(cmd); virCommandFree(cmd);
VIR_FREE(temp); VIR_FREE(temp);
VIR_FREE(outbuf); VIR_FREE(outbuf);
/* dom hasn't been shared yet, so unref should return 0 */ virObjectUnref(dom);
if (dom)
ignore_value(virDomainObjUnref(dom));
return -1; return -1;
} }

View File

@ -774,7 +774,7 @@ qemuDomainObjBeginJobInternal(struct qemud_driver *driver,
return -1; return -1;
then = now + QEMU_JOB_WAIT_TIME; then = now + QEMU_JOB_WAIT_TIME;
virDomainObjRef(obj); virObjectRef(obj);
if (driver_locked) if (driver_locked)
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
@ -854,8 +854,7 @@ error:
qemuDriverLock(driver); qemuDriverLock(driver);
virDomainObjLock(obj); virDomainObjLock(obj);
} }
/* Safe to ignore value since ref count was incremented above */ virObjectUnref(obj);
ignore_value(virDomainObjUnref(obj));
return -1; return -1;
} }
@ -922,10 +921,10 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
* To be called after completing the work associated with the * To be called after completing the work associated with the
* earlier qemuDomainBeginJob() call * earlier qemuDomainBeginJob() call
* *
* Returns remaining refcount on 'obj', maybe 0 to indicated it * Returns true if @obj was still referenced, false if it was
* was deleted * disposed of.
*/ */
int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj) bool qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
{ {
qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainObjPrivatePtr priv = obj->privateData;
enum qemuDomainJob job = priv->job.active; enum qemuDomainJob job = priv->job.active;
@ -941,10 +940,10 @@ int qemuDomainObjEndJob(struct qemud_driver *driver, virDomainObjPtr obj)
qemuDomainObjSaveJob(driver, obj); qemuDomainObjSaveJob(driver, obj);
virCondSignal(&priv->job.cond); virCondSignal(&priv->job.cond);
return virDomainObjUnref(obj); return virObjectUnref(obj);
} }
int bool
qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj) qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
{ {
qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainObjPrivatePtr priv = obj->privateData;
@ -958,7 +957,7 @@ qemuDomainObjEndAsyncJob(struct qemud_driver *driver, virDomainObjPtr obj)
qemuDomainObjSaveJob(driver, obj); qemuDomainObjSaveJob(driver, obj);
virCondBroadcast(&priv->job.asyncCond); virCondBroadcast(&priv->job.asyncCond);
return virDomainObjUnref(obj); return virObjectUnref(obj);
} }
static int static int
@ -1031,9 +1030,7 @@ qemuDomainObjExitMonitorInternal(struct qemud_driver *driver,
qemuDomainObjSaveJob(driver, obj); qemuDomainObjSaveJob(driver, obj);
virCondSignal(&priv->job.cond); virCondSignal(&priv->job.cond);
/* safe to ignore since the surrounding async job increased virObjectUnref(obj);
* the reference counter as well */
ignore_value(virDomainObjUnref(obj));
} }
} }
@ -1207,7 +1204,7 @@ void qemuDomainObjExitAgentWithDriver(struct qemud_driver *driver,
void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver, void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
virDomainObjPtr obj) virDomainObjPtr obj)
{ {
virDomainObjRef(obj); virObjectRef(obj);
virDomainObjUnlock(obj); virDomainObjUnlock(obj);
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
} }
@ -1217,9 +1214,7 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
{ {
qemuDriverLock(driver); qemuDriverLock(driver);
virDomainObjLock(obj); virDomainObjLock(obj);
/* Safe to ignore value, since we incremented ref in virObjectUnref(obj);
* qemuDomainObjEnterRemoteWithDriver */
ignore_value(virDomainObjUnref(obj));
} }

View File

@ -193,11 +193,11 @@ int qemuDomainObjBeginAsyncJobWithDriver(struct qemud_driver *driver,
enum qemuDomainAsyncJob asyncJob) enum qemuDomainAsyncJob asyncJob)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjEndJob(struct qemud_driver *driver, bool qemuDomainObjEndJob(struct qemud_driver *driver,
virDomainObjPtr obj) virDomainObjPtr obj)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjEndAsyncJob(struct qemud_driver *driver, bool qemuDomainObjEndAsyncJob(struct qemud_driver *driver,
virDomainObjPtr obj) virDomainObjPtr obj)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
void qemuDomainObjSetJobPhase(struct qemud_driver *driver, void qemuDomainObjSetJobPhase(struct qemud_driver *driver,
virDomainObjPtr obj, virDomainObjPtr obj,

View File

@ -3402,7 +3402,7 @@ endjob:
ignore_value(qemuDomainObjEndAsyncJob(driver, wdEvent->vm)); ignore_value(qemuDomainObjEndAsyncJob(driver, wdEvent->vm));
unlock: unlock:
if (virDomainObjUnref(wdEvent->vm) > 0) if (virObjectUnref(wdEvent->vm))
virDomainObjUnlock(wdEvent->vm); virDomainObjUnlock(wdEvent->vm);
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
VIR_FREE(wdEvent); VIR_FREE(wdEvent);

View File

@ -1369,7 +1369,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
* This prevents any other APIs being invoked while incoming * This prevents any other APIs being invoked while incoming
* migration is taking place. * migration is taking place.
*/ */
if (qemuMigrationJobContinue(vm) == 0) { if (!qemuMigrationJobContinue(vm)) {
vm = NULL; vm = NULL;
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("domain disappeared")); "%s", _("domain disappeared"));
@ -1396,7 +1396,7 @@ cleanup:
return ret; return ret;
endjob: endjob:
if (qemuMigrationJobFinish(driver, vm) == 0) { if (!qemuMigrationJobFinish(driver, vm)) {
vm = NULL; vm = NULL;
} }
goto cleanup; goto cleanup;
@ -2680,7 +2680,7 @@ endjob:
VIR_DOMAIN_EVENT_RESUMED_MIGRATED); VIR_DOMAIN_EVENT_RESUMED_MIGRATED);
} }
if (qemuMigrationJobFinish(driver, vm) == 0) { if (!qemuMigrationJobFinish(driver, vm)) {
vm = NULL; vm = NULL;
} else if (!virDomainObjIsActive(vm) && } else if (!virDomainObjIsActive(vm) &&
(!vm->persistent || (!vm->persistent ||
@ -2722,7 +2722,7 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
virDomainEventPtr event = NULL; virDomainEventPtr event = NULL;
int ret = -1; int ret = -1;
bool resume; bool resume;
int refs; bool hasrefs;
/* If we didn't start the job in the begin phase, start it now. */ /* If we didn't start the job in the begin phase, start it now. */
if (!(flags & VIR_MIGRATE_CHANGE_PROTECTION)) { if (!(flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
@ -2770,10 +2770,10 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
endjob: endjob:
if (ret < 0) if (ret < 0)
refs = qemuMigrationJobFinish(driver, vm); hasrefs = qemuMigrationJobFinish(driver, vm);
else else
refs = qemuMigrationJobContinue(vm); hasrefs = qemuMigrationJobContinue(vm);
if (refs == 0) { if (!hasrefs) {
vm = NULL; vm = NULL;
} else if (!virDomainObjIsActive(vm) && !vm->persistent) { } else if (!virDomainObjIsActive(vm) && !vm->persistent) {
qemuDomainRemoveInactive(driver, vm); qemuDomainRemoveInactive(driver, vm);
@ -3374,15 +3374,15 @@ qemuMigrationJobStartPhase(struct qemud_driver *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
enum qemuMigrationJobPhase phase) enum qemuMigrationJobPhase phase)
{ {
virDomainObjRef(vm); virObjectRef(vm);
qemuMigrationJobSetPhase(driver, vm, phase); qemuMigrationJobSetPhase(driver, vm, phase);
} }
int bool
qemuMigrationJobContinue(virDomainObjPtr vm) qemuMigrationJobContinue(virDomainObjPtr vm)
{ {
qemuDomainObjReleaseAsyncJob(vm); qemuDomainObjReleaseAsyncJob(vm);
return virDomainObjUnref(vm); return virObjectUnref(vm);
} }
bool bool
@ -3405,7 +3405,7 @@ qemuMigrationJobIsActive(virDomainObjPtr vm,
return true; return true;
} }
int bool
qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr vm) qemuMigrationJobFinish(struct qemud_driver *driver, virDomainObjPtr vm)
{ {
return qemuDomainObjEndAsyncJob(driver, vm); return qemuDomainObjEndAsyncJob(driver, vm);

View File

@ -66,12 +66,12 @@ void qemuMigrationJobStartPhase(struct qemud_driver *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
enum qemuMigrationJobPhase phase) enum qemuMigrationJobPhase phase)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuMigrationJobContinue(virDomainObjPtr obj) bool qemuMigrationJobContinue(virDomainObjPtr obj)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
bool qemuMigrationJobIsActive(virDomainObjPtr vm, bool qemuMigrationJobIsActive(virDomainObjPtr vm,
enum qemuDomainAsyncJob job) enum qemuDomainAsyncJob job)
ATTRIBUTE_NONNULL(1); 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; ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int qemuMigrationSetOffline(struct qemud_driver *driver, int qemuMigrationSetOffline(struct qemud_driver *driver,

View File

@ -173,7 +173,7 @@ static void qemuProcessHandleAgentDestroy(qemuAgentPtr agent,
priv = vm->privateData; priv = vm->privateData;
if (priv->agent == agent) if (priv->agent == agent)
priv->agent = NULL; priv->agent = NULL;
if (virDomainObjUnref(vm) > 0) if (virObjectUnref(vm))
virDomainObjUnlock(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 /* Hold an extra reference because we can't allow 'vm' to be
* deleted while the agent is active */ * deleted while the agent is active */
virDomainObjRef(vm); virObjectRef(vm);
ignore_value(virTimeMillisNow(&priv->agentStart)); ignore_value(virTimeMillisNow(&priv->agentStart));
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
@ -246,9 +246,8 @@ qemuConnectAgent(struct qemud_driver *driver, virDomainObjPtr vm)
goto cleanup; goto cleanup;
} }
/* Safe to ignore value since ref count was incremented above */
if (agent == NULL) if (agent == NULL)
ignore_value(virDomainObjUnref(vm)); virObjectUnref(vm);
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
qemuAgentClose(agent); qemuAgentClose(agent);
@ -584,7 +583,7 @@ qemuProcessFakeReboot(void *opaque)
ret = 0; ret = 0;
endjob: endjob:
if (qemuDomainObjEndJob(driver, vm) == 0) if (!qemuDomainObjEndJob(driver, vm))
vm = NULL; vm = NULL;
cleanup: cleanup:
@ -593,7 +592,7 @@ cleanup:
ignore_value(qemuProcessKill(driver, vm, ignore_value(qemuProcessKill(driver, vm,
VIR_QEMU_PROCESS_KILL_FORCE)); VIR_QEMU_PROCESS_KILL_FORCE));
} }
if (virDomainObjUnref(vm) > 0) if (virObjectUnref(vm))
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
} }
if (event) if (event)
@ -610,7 +609,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
if (priv->fakeReboot) { if (priv->fakeReboot) {
qemuDomainSetFakeReboot(driver, vm, false); qemuDomainSetFakeReboot(driver, vm, false);
virDomainObjRef(vm); virObjectRef(vm);
virThread th; virThread th;
if (virThreadCreate(&th, if (virThreadCreate(&th,
false, false,
@ -619,8 +618,7 @@ qemuProcessShutdownOrReboot(struct qemud_driver *driver,
VIR_ERROR(_("Failed to create reboot thread, killing domain")); VIR_ERROR(_("Failed to create reboot thread, killing domain"));
ignore_value(qemuProcessKill(driver, vm, ignore_value(qemuProcessKill(driver, vm,
VIR_QEMU_PROCESS_KILL_NOWAIT)); VIR_QEMU_PROCESS_KILL_NOWAIT));
/* Safe to ignore value since ref count was incremented above */ virObjectUnref(vm);
ignore_value(virDomainObjUnref(vm));
} }
} else { } else {
ignore_value(qemuProcessKill(driver, vm, VIR_QEMU_PROCESS_KILL_NOWAIT)); 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 /* Hold an extra reference because we can't allow 'vm' to be
* deleted before handling watchdog event is finished. * deleted before handling watchdog event is finished.
*/ */
virDomainObjRef(vm); virObjectRef(vm);
if (virThreadPoolSendJob(driver->workerPool, 0, wdEvent) < 0) { if (virThreadPoolSendJob(driver->workerPool, 0, wdEvent) < 0) {
if (virDomainObjUnref(vm) == 0) if (!virObjectUnref(vm))
vm = NULL; vm = NULL;
VIR_FREE(wdEvent); VIR_FREE(wdEvent);
} }
@ -1022,7 +1020,7 @@ static void qemuProcessHandleMonitorDestroy(qemuMonitorPtr mon,
priv = vm->privateData; priv = vm->privateData;
if (priv->mon == mon) if (priv->mon == mon)
priv->mon = NULL; priv->mon = NULL;
if (virDomainObjUnref(vm) > 0) if (virObjectUnref(vm))
virDomainObjUnlock(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 /* Hold an extra reference because we can't allow 'vm' to be
* deleted while the monitor is active */ * deleted while the monitor is active */
virDomainObjRef(vm); virObjectRef(vm);
ignore_value(virTimeMillisNow(&priv->monStart)); ignore_value(virTimeMillisNow(&priv->monStart));
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
@ -1228,9 +1226,8 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
virDomainObjLock(vm); virDomainObjLock(vm);
priv->monStart = 0; priv->monStart = 0;
/* Safe to ignore value since ref count was incremented above */
if (mon == NULL) if (mon == NULL)
ignore_value(virDomainObjUnref(vm)); virObjectUnref(vm);
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
qemuMonitorClose(mon); qemuMonitorClose(mon);
@ -3068,7 +3065,7 @@ qemuProcessReconnect(void *opaque)
/* Hold an extra reference because we can't allow 'vm' to be /* Hold an extra reference because we can't allow 'vm' to be
* deleted if qemuConnectMonitor() failed */ * deleted if qemuConnectMonitor() failed */
virDomainObjRef(obj); virObjectRef(obj);
/* XXX check PID liveliness & EXE path */ /* XXX check PID liveliness & EXE path */
if (qemuConnectMonitor(driver, obj) < 0) if (qemuConnectMonitor(driver, obj) < 0)
@ -3165,10 +3162,10 @@ qemuProcessReconnect(void *opaque)
driver->nextvmid = obj->def->id + 1; driver->nextvmid = obj->def->id + 1;
endjob: endjob:
if (qemuDomainObjEndJob(driver, obj) == 0) if (!qemuDomainObjEndJob(driver, obj))
obj = NULL; obj = NULL;
if (obj && virDomainObjUnref(obj) > 0) if (obj && virObjectUnref(obj))
virDomainObjUnlock(obj); virDomainObjUnlock(obj);
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
@ -3178,18 +3175,18 @@ endjob:
return; return;
error: error:
if (qemuDomainObjEndJob(driver, obj) == 0) if (!qemuDomainObjEndJob(driver, obj))
obj = NULL; obj = NULL;
if (obj) { if (obj) {
if (!virDomainObjIsActive(obj)) { if (!virDomainObjIsActive(obj)) {
if (virDomainObjUnref(obj) > 0) if (virObjectUnref(obj))
virDomainObjUnlock(obj); virDomainObjUnlock(obj);
qemuDriverUnlock(driver); qemuDriverUnlock(driver);
return; return;
} }
if (virDomainObjUnref(obj) > 0) { if (virObjectUnref(obj)) {
/* We can't get the monitor back, so must kill the VM /* We can't get the monitor back, so must kill the VM
* to remove danger of it ending up running twice if * to remove danger of it ending up running twice if
* user tries to start it again later * user tries to start it again later
@ -3277,9 +3274,9 @@ qemuProcessReconnectHelper(void *payload,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not create thread. QEMU initialization " _("Could not create thread. QEMU initialization "
"might be incomplete")); "might be incomplete"));
if (qemuDomainObjEndJob(src->driver, obj) == 0) { if (!qemuDomainObjEndJob(src->driver, obj)) {
obj = NULL; obj = NULL;
} else if (virDomainObjUnref(obj) > 0) { } else if (virObjectUnref(obj)) {
/* We can't spawn a thread and thus connect to monitor. /* We can't spawn a thread and thus connect to monitor.
* Kill qemu */ * Kill qemu */
qemuProcessStop(src->driver, obj, VIR_DOMAIN_SHUTOFF_FAILED, 0); 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 * a case, but there are too many to maintain certainty, so we
* will do this as a precaution). * will do this as a precaution).
*/ */
virDomainObjRef(vm); virObjectRef(vm);
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
qemuDriverLock(driver); qemuDriverLock(driver);
virDomainObjLock(vm); virDomainObjLock(vm);
/* Safe to ignore value since ref count was incremented above */ virObjectUnref(vm);
ignore_value(virDomainObjUnref(vm));
} }
return ret; return ret;
} }
@ -4407,7 +4403,7 @@ qemuProcessAutoDestroy(struct qemud_driver *driver,
VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED); VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
if (qemuDomainObjEndJob(driver, dom) == 0) if (!qemuDomainObjEndJob(driver, dom))
dom = NULL; dom = NULL;
if (dom && !dom->persistent) if (dom && !dom->persistent)
qemuDomainRemoveInactive(driver, dom); qemuDomainRemoveInactive(driver, dom);

View File

@ -213,9 +213,7 @@ cleanup:
VIR_FREE(directoryName); VIR_FREE(directoryName);
VIR_FREE(fileName); VIR_FREE(fileName);
VIR_FREE(vmx); VIR_FREE(vmx);
/* any non-NULL vm here has not been shared, so unref will return 0 */ virObjectUnref(vm);
if (vm)
ignore_value(virDomainObjUnref(vm));
return ret; return ret;
} }