提交 b8cc5098 编写于 作者: M Marc Hartmayer 提交者: Michal Privoznik

qemu: Turn qemuDomainLogContext into virObject

This way qemuDomainLogContextRef() and qemuDomainLogContextFree() is
no longer needed. The naming qemuDomainLogContextFree() was also
somewhat misleading. Additionally, it's easier to turn
qemuDomainLogContext in a self-locking object.
Signed-off-by: NMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: NBjoern Walk <bwalk@linux.vnet.ibm.com>
上级 20e95cb7
......@@ -111,7 +111,8 @@ VIR_ENUM_IMPL(qemuDomainNamespace, QEMU_DOMAIN_NS_LAST,
struct _qemuDomainLogContext {
int refs;
virObject parent;
int writefd;
int readfd; /* Only used if manager == NULL */
off_t pos;
......@@ -120,6 +121,36 @@ struct _qemuDomainLogContext {
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)
......@@ -4195,7 +4226,7 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
cleanup:
VIR_FREE(timestamp);
if (closeLog)
qemuDomainLogContextFree(logCtxt);
virObjectUnref(logCtxt);
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
......@@ -4307,13 +4338,15 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(virQEMUDriverPtr driver,
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;
......@@ -4381,7 +4414,7 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(virQEMUDriverPtr driver,
return ctxt;
error:
qemuDomainLogContextFree(ctxt);
virObjectUnref(ctxt);
ctxt = NULL;
goto cleanup;
}
......@@ -4550,39 +4583,12 @@ void qemuDomainLogContextMarkPosition(qemuDomainLogContextPtr ctxt)
}
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)
......
......@@ -540,8 +540,6 @@ ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt,
char **msg);
int qemuDomainLogContextGetWriteFD(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextMarkPosition(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextRef(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextFree(qemuDomainLogContextPtr ctxt);
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);
......
......@@ -1692,7 +1692,7 @@ static void
qemuProcessMonitorLogFree(void *opaque)
{
qemuDomainLogContextPtr logCtxt = opaque;
qemuDomainLogContextFree(logCtxt);
virObjectUnref(logCtxt);
}
static int
......@@ -1731,7 +1731,7 @@ qemuConnectMonitor(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob,
driver);
if (mon && logCtxt) {
qemuDomainLogContextRef(logCtxt);
virObjectRef(logCtxt);
qemuMonitorSetDomainLog(mon,
qemuProcessMonitorReportLogError,
logCtxt,
......@@ -5875,7 +5875,7 @@ qemuProcessLaunch(virConnectPtr conn,
cleanup:
qemuDomainSecretDestroy(vm);
virCommandFree(cmd);
qemuDomainLogContextFree(logCtxt);
virObjectUnref(logCtxt);
virObjectUnref(cfg);
virObjectUnref(caps);
VIR_FREE(nicindexes);
......@@ -6671,7 +6671,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
goto error;
}
qemuDomainLogContextFree(logCtxt);
virObjectUnref(logCtxt);
VIR_FREE(seclabel);
VIR_FREE(sec_managers);
virObjectUnref(cfg);
......@@ -6691,7 +6691,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
qemuMonitorClose(priv->mon);
priv->mon = NULL;
qemuDomainLogContextFree(logCtxt);
virObjectUnref(logCtxt);
VIR_FREE(seclabel);
VIR_FREE(sec_managers);
if (seclabelgen)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册