struct _qemuDomainLogContext {
- int refs;
+ virObject parent;
+
int writefd;
int readfd; /* Only used if manager == NULL */
off_t pos;
virLogManagerPtr manager;
};
+static virClassPtr qemuDomainLogContextClass;
+
+static void qemuDomainLogContextDispose(void *obj);
+
+static int
+qemuDomainLogContextOnceInit(void)
+{
+ if (!(qemuDomainLogContextClass = virClassNew(virClassForObject(),
+ "qemuDomainLogContext",
+ sizeof(qemuDomainLogContext),
+ qemuDomainLogContextDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(qemuDomainLogContext)
+
+static void
+qemuDomainLogContextDispose(void *obj)
+{
+ qemuDomainLogContextPtr ctxt = obj;
+ VIR_DEBUG("ctxt=%p", ctxt);
+
+ virLogManagerFree(ctxt->manager);
+ VIR_FREE(ctxt->path);
+ VIR_FORCE_CLOSE(ctxt->writefd);
+ VIR_FORCE_CLOSE(ctxt->readfd);
+}
+
const char *
qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
int phase ATTRIBUTE_UNUSED)
cleanup:
VIR_FREE(timestamp);
if (closeLog)
- qemuDomainLogContextFree(logCtxt);
+ virObjectUnref(logCtxt);
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
qemuDomainLogContextPtr ctxt = NULL;
- if (VIR_ALLOC(ctxt) < 0)
- goto error;
+ if (qemuDomainLogContextInitialize() < 0)
+ goto cleanup;
+
+ if (!(ctxt = virObjectNew(qemuDomainLogContextClass)))
+ goto cleanup;
VIR_DEBUG("Context new %p stdioLogD=%d", ctxt, cfg->stdioLogD);
ctxt->writefd = -1;
ctxt->readfd = -1;
- virAtomicIntSet(&ctxt->refs, 1);
if (virAsprintf(&ctxt->path, "%s/%s.log", cfg->logDir, vm->def->name) < 0)
goto error;
return ctxt;
error:
- qemuDomainLogContextFree(ctxt);
+ virObjectUnref(ctxt);
ctxt = NULL;
goto cleanup;
}
}
-void qemuDomainLogContextRef(qemuDomainLogContextPtr ctxt)
-{
- VIR_DEBUG("Context ref %p", ctxt);
- virAtomicIntInc(&ctxt->refs);
-}
-
-
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt)
{
return ctxt->manager;
}
-void qemuDomainLogContextFree(qemuDomainLogContextPtr ctxt)
-{
- bool lastRef;
-
- if (!ctxt)
- return;
-
- lastRef = virAtomicIntDecAndTest(&ctxt->refs);
- VIR_DEBUG("Context free %p lastref=%d", ctxt, lastRef);
- if (!lastRef)
- return;
-
- virLogManagerFree(ctxt->manager);
- VIR_FREE(ctxt->path);
- VIR_FORCE_CLOSE(ctxt->writefd);
- VIR_FORCE_CLOSE(ctxt->readfd);
- VIR_FREE(ctxt);
-}
-
-
/* Locate an appropriate 'qemu-img' binary. */
const char *
qemuFindQemuImgBinary(virQEMUDriverPtr driver)
qemuProcessMonitorLogFree(void *opaque)
{
qemuDomainLogContextPtr logCtxt = opaque;
- qemuDomainLogContextFree(logCtxt);
+ virObjectUnref(logCtxt);
}
static int
driver);
if (mon && logCtxt) {
- qemuDomainLogContextRef(logCtxt);
+ virObjectRef(logCtxt);
qemuMonitorSetDomainLog(mon,
qemuProcessMonitorReportLogError,
logCtxt,
cleanup:
qemuDomainSecretDestroy(vm);
virCommandFree(cmd);
- qemuDomainLogContextFree(logCtxt);
+ virObjectUnref(logCtxt);
virObjectUnref(cfg);
virObjectUnref(caps);
VIR_FREE(nicindexes);
goto error;
}
- qemuDomainLogContextFree(logCtxt);
+ virObjectUnref(logCtxt);
VIR_FREE(seclabel);
VIR_FREE(sec_managers);
virObjectUnref(cfg);
qemuMonitorClose(priv->mon);
priv->mon = NULL;
- qemuDomainLogContextFree(logCtxt);
+ virObjectUnref(logCtxt);
VIR_FREE(seclabel);
VIR_FREE(sec_managers);
if (seclabelgen)