First we need to specify flag to wait while qemu finishes
its logging. Second virtlogd will not receive EOF as both
qemu and libvirtd keep logging pipe fd. Thus let's close
it after qemu process startup is finished as it will not be used
anymore. All following logging on behalf of qemu by libvirt
is done either thru daemon API or by receiving new writing descriptor.
Beware, qemuDomainLogContextFree is unref actually.
---
src/qemu/qemu_domain.c | 7 ++++++-
src/qemu/qemu_domain.h | 1 +
src/qemu/qemu_process.c | 2 ++
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fd79390..6662907 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3841,12 +3841,13 @@ ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt,
char *buf;
size_t buflen;
if (ctxt->manager) {
+ int flags = VIR_LOG_MANAGER_PROTOCOL_DOMAIN_READ_LOG_FILE_WAIT;
buf = virLogManagerDomainReadLogFile(ctxt->manager,
ctxt->path,
ctxt->inode,
ctxt->pos,
1024 * 128,
- 0);
+ flags);
if (!buf)
return -1;
buflen = strlen(buf);
@@ -3974,6 +3975,10 @@ virLogManagerPtr
qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt)
return ctxt->manager;
}
+void qemuDomainLogContextHalfClose(qemuDomainLogContextPtr ctxt)
+{
+ VIR_FORCE_CLOSE(ctxt->writefd);
+}
void qemuDomainLogContextFree(qemuDomainLogContextPtr ctxt)
{
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 13c0372..71fe6ad 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -499,6 +499,7 @@ ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt,
int qemuDomainLogContextGetWriteFD(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextMarkPosition(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextRef(qemuDomainLogContextPtr ctxt);
+void qemuDomainLogContextHalfClose(qemuDomainLogContextPtr ctxt);
void qemuDomainLogContextFree(qemuDomainLogContextPtr ctxt);
virLogManagerPtr qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7596579..737b2e0 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5493,6 +5493,8 @@ qemuProcessLaunch(virConnectPtr conn,
cleanup:
qemuDomainSecretDestroy(vm);
virCommandFree(cmd);
+ if (logCtxt)
+ qemuDomainLogContextHalfClose(logCtxt);
qemuDomainLogContextFree(logCtxt);
virObjectUnref(cfg);
virObjectUnref(caps);
--
1.8.3.1