hypervisor: Move QEMU log context to hypervisor

While doing so, also drop QEMU specific arguments from
domainLogContextNew() and replace them with hypervisor agnostic
ones.

Signed-off-by: Praveen K Paladugu <praveenkpaladugu@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Praveen K Paladugu 2024-12-19 08:45:52 -06:00 committed by Michal Privoznik
parent 94b393dd6e
commit 334d2f604c
11 changed files with 146 additions and 125 deletions

View File

@ -94,6 +94,7 @@ src/hyperv/hyperv_util.c
src/hyperv/hyperv_wmi.c src/hyperv/hyperv_wmi.c
src/hypervisor/domain_cgroup.c src/hypervisor/domain_cgroup.c
src/hypervisor/domain_driver.c src/hypervisor/domain_driver.c
src/hypervisor/domain_logcontext.c
src/hypervisor/domain_interface.c src/hypervisor/domain_interface.c
src/hypervisor/virhostdev.c src/hypervisor/virhostdev.c
src/interface/interface_backend_netcf.c src/interface/interface_backend_netcf.c
@ -180,7 +181,6 @@ src/qemu/qemu_hostdev.c
src/qemu/qemu_hotplug.c src/qemu/qemu_hotplug.c
src/qemu/qemu_interface.c src/qemu/qemu_interface.c
src/qemu/qemu_interop_config.c src/qemu/qemu_interop_config.c
src/qemu/qemu_logcontext.c
src/qemu/qemu_migration.c src/qemu/qemu_migration.c
src/qemu/qemu_migration_cookie.c src/qemu/qemu_migration_cookie.c
src/qemu/qemu_migration_params.c src/qemu/qemu_migration_params.c

View File

@ -1,5 +1,5 @@
/* /*
* qemu_logcontext.c: QEMU log context * domain_logcontext.c: Domain log context
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,20 +18,22 @@
#include <config.h> #include <config.h>
#include "qemu_logcontext.h" #include "domain_logcontext.h"
#include "viralloc.h" #include "viralloc.h"
#include "virlog.h" #include "virlog.h"
#include "virstring.h" #include "virstring.h"
#include "virutil.h" #include "virutil.h"
#include "virfile.h"
#include "virerror.h"
#include <fcntl.h> #include <fcntl.h>
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_DOMAIN
VIR_LOG_INIT("qemu.qemu_logcontext"); VIR_LOG_INIT("domain.domain_logcontext");
struct _qemuLogContext { struct _domainLogContext {
GObject parent; GObject parent;
int writefd; int writefd;
@ -42,62 +44,64 @@ struct _qemuLogContext {
virLogManager *manager; virLogManager *manager;
}; };
G_DEFINE_TYPE(qemuLogContext, qemu_log_context, G_TYPE_OBJECT); G_DEFINE_TYPE(domainLogContext, domain_log_context, G_TYPE_OBJECT);
static void static void
qemuLogContextFinalize(GObject *obj); domainLogContextFinalize(GObject *obj);
static void static void
qemu_log_context_init(qemuLogContext *logctxt G_GNUC_UNUSED) domain_log_context_init(domainLogContext *logctxt G_GNUC_UNUSED)
{ {
} }
static void static void
qemu_log_context_class_init(qemuLogContextClass *klass) domain_log_context_class_init(domainLogContextClass *klass)
{ {
GObjectClass *obj = G_OBJECT_CLASS(klass); GObjectClass *obj = G_OBJECT_CLASS(klass);
obj->finalize = qemuLogContextFinalize; obj->finalize = domainLogContextFinalize;
} }
static void static void
qemuLogContextFinalize(GObject *object) domainLogContextFinalize(GObject *object)
{ {
qemuLogContext *ctxt = QEMU_LOG_CONTEXT(object); domainLogContext *ctxt = DOMAIN_LOG_CONTEXT(object);
VIR_DEBUG("ctxt=%p", ctxt); VIR_DEBUG("ctxt=%p", ctxt);
virLogManagerFree(ctxt->manager); virLogManagerFree(ctxt->manager);
VIR_FREE(ctxt->path); VIR_FREE(ctxt->path);
VIR_FORCE_CLOSE(ctxt->writefd); VIR_FORCE_CLOSE(ctxt->writefd);
VIR_FORCE_CLOSE(ctxt->readfd); VIR_FORCE_CLOSE(ctxt->readfd);
G_OBJECT_CLASS(qemu_log_context_parent_class)->finalize(object); G_OBJECT_CLASS(domain_log_context_parent_class)->finalize(object);
} }
qemuLogContext * domainLogContext *
qemuLogContextNew(virQEMUDriver *driver, domainLogContextNew(bool stdioLogD,
virDomainObj *vm, char *logDir,
const char *basename) const char *driver_name,
virDomainObj *vm,
bool privileged,
const char *basename)
{ {
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); domainLogContext *ctxt = DOMAIN_LOG_CONTEXT(g_object_new(DOMAIN_TYPE_LOG_CONTEXT, NULL));
qemuLogContext *ctxt = QEMU_LOG_CONTEXT(g_object_new(QEMU_TYPE_LOG_CONTEXT, NULL));
VIR_DEBUG("Context new %p stdioLogD=%d", ctxt, cfg->stdioLogD); VIR_DEBUG("Context new %p stdioLogD=%d", ctxt, stdioLogD);
ctxt->writefd = -1; ctxt->writefd = -1;
ctxt->readfd = -1; ctxt->readfd = -1;
ctxt->path = g_strdup_printf("%s/%s.log", cfg->logDir, basename); ctxt->path = g_strdup_printf("%s/%s.log", logDir, basename);
if (cfg->stdioLogD) { if (stdioLogD) {
ctxt->manager = virLogManagerNew(driver->privileged); ctxt->manager = virLogManagerNew(privileged);
if (!ctxt->manager) if (!ctxt->manager)
goto error; goto error;
ctxt->writefd = virLogManagerDomainOpenLogFile(ctxt->manager, ctxt->writefd = virLogManagerDomainOpenLogFile(ctxt->manager,
"qemu", driver_name,
vm->def->uuid, vm->def->uuid,
vm->def->name, vm->def->name,
ctxt->path, ctxt->path,
@ -121,7 +125,7 @@ qemuLogContextNew(virQEMUDriver *driver,
/* For unprivileged startup we must truncate the file since /* For unprivileged startup we must truncate the file since
* we can't rely on logrotate. We don't use O_TRUNC since * we can't rely on logrotate. We don't use O_TRUNC since
* it is better for SELinux policy if we truncate afterwards */ * it is better for SELinux policy if we truncate afterwards */
if (!driver->privileged && if (!privileged &&
ftruncate(ctxt->writefd, 0) < 0) { ftruncate(ctxt->writefd, 0) < 0) {
virReportSystemError(errno, _("failed to truncate %1$s"), virReportSystemError(errno, _("failed to truncate %1$s"),
ctxt->path); ctxt->path);
@ -155,8 +159,8 @@ qemuLogContextNew(virQEMUDriver *driver,
int int
qemuLogContextWrite(qemuLogContext *ctxt, domainLogContextWrite(domainLogContext *ctxt,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list argptr; va_list argptr;
g_autofree char *message = NULL; g_autofree char *message = NULL;
@ -186,8 +190,8 @@ qemuLogContextWrite(qemuLogContext *ctxt,
ssize_t ssize_t
qemuLogContextRead(qemuLogContext *ctxt, domainLogContextRead(domainLogContext *ctxt,
char **msg) char **msg)
{ {
char *buf; char *buf;
size_t buflen; size_t buflen;
@ -238,7 +242,7 @@ qemuLogContextRead(qemuLogContext *ctxt,
/** /**
* qemuLogContextFilter: Read and filter log for relevant messages * domainLogContextFilter: Read and filter log for relevant messages
* @ctxt: the domain log context * @ctxt: the domain log context
* @msg: pointer to buffer to store the read messages in * @msg: pointer to buffer to store the read messages in
* @max: maximum length of the message returned in @msg after filtering * @max: maximum length of the message returned in @msg after filtering
@ -249,9 +253,9 @@ qemuLogContextRead(qemuLogContext *ctxt,
* after a new line if possible. * after a new line if possible.
*/ */
int int
qemuLogContextReadFiltered(qemuLogContext *ctxt, domainLogContextReadFiltered(domainLogContext *ctxt,
char **msg, char **msg,
size_t max) size_t max)
{ {
char *buf; char *buf;
char *eol; char *eol;
@ -259,7 +263,7 @@ qemuLogContextReadFiltered(qemuLogContext *ctxt,
size_t skip; size_t skip;
ssize_t got; ssize_t got;
if ((got = qemuLogContextRead(ctxt, &buf)) < 0) if ((got = domainLogContextRead(ctxt, &buf)) < 0)
return -1; return -1;
/* Filter out debug messages from intermediate libvirt process */ /* Filter out debug messages from intermediate libvirt process */
@ -302,14 +306,14 @@ qemuLogContextReadFiltered(qemuLogContext *ctxt,
int int
qemuLogContextGetWriteFD(qemuLogContext *ctxt) domainLogContextGetWriteFD(domainLogContext *ctxt)
{ {
return ctxt->writefd; return ctxt->writefd;
} }
void void
qemuLogContextMarkPosition(qemuLogContext *ctxt) domainLogContextMarkPosition(domainLogContext *ctxt)
{ {
if (ctxt->manager) if (ctxt->manager)
virLogManagerDomainGetLogFilePosition(ctxt->manager, virLogManagerDomainGetLogFilePosition(ctxt->manager,
@ -323,7 +327,7 @@ qemuLogContextMarkPosition(qemuLogContext *ctxt)
virLogManager * virLogManager *
qemuLogContextGetManager(qemuLogContext *ctxt) domainLogContextGetManager(domainLogContext *ctxt)
{ {
return ctxt->manager; return ctxt->manager;
} }

View File

@ -0,0 +1,45 @@
/*
* domain_logcontext.h: Domain log context
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib-object.h>
#include "logging/log_manager.h"
#include "virconftypes.h"
#include "domain_conf.h"
#define DOMAIN_TYPE_LOG_CONTEXT domain_log_context_get_type()
G_DECLARE_FINAL_TYPE(domainLogContext, domain_log_context, DOMAIN, LOG_CONTEXT, GObject);
domainLogContext *domainLogContextNew(bool stdioLogD,
char *logDir,
const char *driver_name,
virDomainObj *vm,
bool privileged,
const char *basename);
int domainLogContextWrite(domainLogContext *ctxt,
const char *fmt, ...) G_GNUC_PRINTF(2, 3);
ssize_t domainLogContextRead(domainLogContext *ctxt,
char **msg);
int domainLogContextReadFiltered(domainLogContext *ctxt,
char **msg,
size_t max);
int domainLogContextGetWriteFD(domainLogContext *ctxt);
void domainLogContextMarkPosition(domainLogContext *ctxt);
virLogManager *domainLogContextGetManager(domainLogContext *ctxt);

View File

@ -2,6 +2,7 @@ hypervisor_sources = [
'domain_cgroup.c', 'domain_cgroup.c',
'domain_driver.c', 'domain_driver.c',
'domain_interface.c', 'domain_interface.c',
'domain_logcontext.c',
'virclosecallbacks.c', 'virclosecallbacks.c',
'virhostdev.c', 'virhostdev.c',
] ]

View File

@ -1665,6 +1665,12 @@ virDomainInterfaceStopDevice;
virDomainInterfaceStopDevices; virDomainInterfaceStopDevices;
virDomainInterfaceVportRemove; virDomainInterfaceVportRemove;
# hypervisor/domain_logcontext.h
domainLogContextGetWriteFD;
domainLogContextMarkPosition;
domainLogContextNew;
domainLogContextReadFiltered;
domainLogContextWrite;
# hypervisor/virclosecallbacks.h # hypervisor/virclosecallbacks.h
virCloseCallbacksDomainAdd; virCloseCallbacksDomainAdd;

View File

@ -22,7 +22,6 @@ qemu_driver_sources = [
'qemu_hotplug.c', 'qemu_hotplug.c',
'qemu_interface.c', 'qemu_interface.c',
'qemu_interop_config.c', 'qemu_interop_config.c',
'qemu_logcontext.c',
'qemu_migration.c', 'qemu_migration.c',
'qemu_migration_cookie.c', 'qemu_migration_cookie.c',
'qemu_migration_params.c', 'qemu_migration_params.c',

View File

@ -5399,7 +5399,7 @@ static void G_GNUC_PRINTF(5, 6)
qemuDomainObjTaintMsg(virQEMUDriver *driver, qemuDomainObjTaintMsg(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainTaintFlags taint, virDomainTaintFlags taint,
qemuLogContext *logCtxt, domainLogContext *logCtxt,
const char *fmt, ...) const char *fmt, ...)
{ {
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
@ -5452,12 +5452,12 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver,
goto cleanup; goto cleanup;
if (logCtxt) { if (logCtxt) {
rc = qemuLogContextWrite(logCtxt, rc = domainLogContextWrite(logCtxt,
"%s: Domain id=%d is tainted: %s%s%s%s\n", "%s: Domain id=%d is tainted: %s%s%s%s\n",
timestamp, timestamp,
obj->def->id, obj->def->id,
virDomainTaintTypeToString(taint), virDomainTaintTypeToString(taint),
extraprefix, extramsg, extrasuffix); extraprefix, extramsg, extrasuffix);
} else { } else {
rc = qemuDomainLogAppendMessage(driver, obj, rc = qemuDomainLogAppendMessage(driver, obj,
"%s: Domain id=%d is tainted: %s%s%s%s\n", "%s: Domain id=%d is tainted: %s%s%s%s\n",
@ -5478,7 +5478,7 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver,
void qemuDomainObjTaint(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainTaintFlags taint, virDomainTaintFlags taint,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL); qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL);
qemuDomainSaveStatus(obj); qemuDomainSaveStatus(obj);
@ -5487,7 +5487,7 @@ void qemuDomainObjTaint(virQEMUDriver *driver,
static void static void
qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, qemuDomainObjCheckMachineTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
qemuDomainObjPrivate *priv = obj->privateData; qemuDomainObjPrivate *priv = obj->privateData;
virQEMUCaps *qemuCaps = priv->qemuCaps; virQEMUCaps *qemuCaps = priv->qemuCaps;
@ -5505,7 +5505,7 @@ qemuDomainObjCheckMachineTaint(virQEMUDriver *driver,
static void static void
qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, qemuDomainObjCheckCPUTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
qemuLogContext *logCtxt, domainLogContext *logCtxt,
bool incomingMigration) bool incomingMigration)
{ {
qemuDomainObjPrivate *priv = obj->privateData; qemuDomainObjPrivate *priv = obj->privateData;
@ -5537,7 +5537,7 @@ qemuDomainObjCheckCPUTaint(virQEMUDriver *driver,
void qemuDomainObjCheckTaint(virQEMUDriver *driver, void qemuDomainObjCheckTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
qemuLogContext *logCtxt, domainLogContext *logCtxt,
bool incomingMigration) bool incomingMigration)
{ {
size_t i; size_t i;
@ -5593,7 +5593,7 @@ void qemuDomainObjCheckTaint(virQEMUDriver *driver,
void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainDiskDef *disk, virDomainDiskDef *disk,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
if (disk->rawio == VIR_TRISTATE_BOOL_YES) if (disk->rawio == VIR_TRISTATE_BOOL_YES)
qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES,
@ -5610,7 +5610,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainHostdevDef *hostdev, virDomainHostdevDef *hostdev,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
if (!virHostdevIsSCSIDevice(hostdev)) if (!virHostdevIsSCSIDevice(hostdev))
return; return;
@ -5623,7 +5623,7 @@ void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainNetDef *net, virDomainNetDef *net,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
/* script is only useful for NET_TYPE_ETHERNET (qemu) and /* script is only useful for NET_TYPE_ETHERNET (qemu) and
* NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for

View File

@ -26,13 +26,13 @@
#include "virperf.h" #include "virperf.h"
#include "domain_addr.h" #include "domain_addr.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "domain_logcontext.h"
#include "qemu_monitor.h" #include "qemu_monitor.h"
#include "qemu_agent.h" #include "qemu_agent.h"
#include "qemu_blockjob.h" #include "qemu_blockjob.h"
#include "qemu_domainjob.h" #include "qemu_domainjob.h"
#include "qemu_conf.h" #include "qemu_conf.h"
#include "qemu_capabilities.h" #include "qemu_capabilities.h"
#include "qemu_logcontext.h"
#include "qemu_migration_params.h" #include "qemu_migration_params.h"
#include "qemu_nbdkit.h" #include "qemu_nbdkit.h"
#include "qemu_slirp.h" #include "qemu_slirp.h"
@ -641,24 +641,24 @@ char *qemuDomainDefFormatLive(virQEMUDriver *driver,
void qemuDomainObjTaint(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainTaintFlags taint, virDomainTaintFlags taint,
qemuLogContext *logCtxt); domainLogContext *logCtxt);
void qemuDomainObjCheckTaint(virQEMUDriver *driver, void qemuDomainObjCheckTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
qemuLogContext *logCtxt, domainLogContext *logCtxt,
bool incomingMigration); bool incomingMigration);
void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainDiskDef *disk, virDomainDiskDef *disk,
qemuLogContext *logCtxt); domainLogContext *logCtxt);
void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainHostdevDef *disk, virDomainHostdevDef *disk,
qemuLogContext *logCtxt); domainLogContext *logCtxt);
void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
virDomainObj *obj, virDomainObj *obj,
virDomainNetDef *net, virDomainNetDef *net,
qemuLogContext *logCtxt); domainLogContext *logCtxt);
int qemuDomainLogAppendMessage(virQEMUDriver *driver, int qemuDomainLogAppendMessage(virQEMUDriver *driver,
virDomainObj *vm, virDomainObj *vm,

View File

@ -1,41 +0,0 @@
/*
* qemu_logcontext.h: QEMU log context
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib-object.h>
#include "qemu_conf.h"
#include "logging/log_manager.h"
#define QEMU_TYPE_LOG_CONTEXT qemu_log_context_get_type()
G_DECLARE_FINAL_TYPE(qemuLogContext, qemu_log_context, QEMU, LOG_CONTEXT, GObject);
qemuLogContext *qemuLogContextNew(virQEMUDriver *driver,
virDomainObj *vm,
const char *basename);
int qemuLogContextWrite(qemuLogContext *ctxt,
const char *fmt, ...) G_GNUC_PRINTF(2, 3);
ssize_t qemuLogContextRead(qemuLogContext *ctxt,
char **msg);
int qemuLogContextReadFiltered(qemuLogContext *ctxt,
char **msg,
size_t max);
int qemuLogContextGetWriteFD(qemuLogContext *ctxt);
void qemuLogContextMarkPosition(qemuLogContext *ctxt);
virLogManager *qemuLogContextGetManager(qemuLogContext *ctxt);

View File

@ -1177,6 +1177,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
virQEMUDriver *driver) virQEMUDriver *driver)
{ {
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
int rc; int rc;
int exitstatus = 0; int exitstatus = 0;
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
@ -1185,7 +1186,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
g_autofree char *uristring = NULL; g_autofree char *uristring = NULL;
g_autofree char *basename = g_strdup_printf("%s-nbdkit-%i", vm->def->name, proc->source->id); g_autofree char *basename = g_strdup_printf("%s-nbdkit-%i", vm->def->name, proc->source->id);
int logfd = -1; int logfd = -1;
g_autoptr(qemuLogContext) logContext = NULL; g_autoptr(domainLogContext) logContext = NULL;
#if WITH_NBDKIT #if WITH_NBDKIT
struct nbd_handle *nbd = NULL; struct nbd_handle *nbd = NULL;
#endif #endif
@ -1200,12 +1201,15 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
if (!(cmd = qemuNbdkitProcessBuildCommand(proc))) if (!(cmd = qemuNbdkitProcessBuildCommand(proc)))
return -1; return -1;
if (!(logContext = qemuLogContextNew(driver, vm, basename))) { if (!(logContext = domainLogContextNew(cfg->stdioLogD, cfg->logDir,
QEMU_DRIVER_NAME,
vm, driver->privileged,
basename))) {
virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
return -1; return -1;
} }
logfd = qemuLogContextGetWriteFD(logContext); logfd = domainLogContextGetWriteFD(logContext);
VIR_DEBUG("starting nbdkit process for %s", qemuBlockStorageSourceGetStorageNodename(proc->source)); VIR_DEBUG("starting nbdkit process for %s", qemuBlockStorageSourceGetStorageNodename(proc->source));
virCommandSetErrorFD(cmd, &logfd); virCommandSetErrorFD(cmd, &logfd);
@ -1283,7 +1287,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
if ((uri = qemuBlockStorageSourceGetURI(proc->source))) if ((uri = qemuBlockStorageSourceGetURI(proc->source)))
uristring = virURIFormat(uri); uristring = virURIFormat(uri);
if (qemuLogContextReadFiltered(logContext, &errbuf, 1024) < 0) if (domainLogContextReadFiltered(logContext, &errbuf, 1024) < 0)
VIR_WARN("Unable to read from nbdkit log"); VIR_WARN("Unable to read from nbdkit log");
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,

View File

@ -1840,7 +1840,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon,
static void static void
qemuProcessMonitorLogFree(void *opaque) qemuProcessMonitorLogFree(void *opaque)
{ {
qemuLogContext *logCtxt = opaque; domainLogContext *logCtxt = opaque;
g_clear_object(&logCtxt); g_clear_object(&logCtxt);
} }
@ -1866,7 +1866,7 @@ static int
qemuConnectMonitor(virQEMUDriver *driver, qemuConnectMonitor(virQEMUDriver *driver,
virDomainObj *vm, virDomainObj *vm,
int asyncJob, int asyncJob,
qemuLogContext *logCtxt, domainLogContext *logCtxt,
bool reconnect) bool reconnect)
{ {
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
@ -1918,13 +1918,13 @@ qemuConnectMonitor(virQEMUDriver *driver,
static int static int
qemuProcessReportLogError(qemuLogContext *logCtxt, qemuProcessReportLogError(domainLogContext *logCtxt,
const char *msgprefix) const char *msgprefix)
{ {
g_autofree char *logmsg = NULL; g_autofree char *logmsg = NULL;
/* assume that 1024 chars of qemu log is the right balance */ /* assume that 1024 chars of qemu log is the right balance */
if (qemuLogContextReadFiltered(logCtxt, &logmsg, 1024) < 0) if (domainLogContextReadFiltered(logCtxt, &logmsg, 1024) < 0)
return -1; return -1;
virResetLastError(); virResetLastError();
@ -1943,7 +1943,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon G_GNUC_UNUSED,
const char *msg, const char *msg,
void *opaque) void *opaque)
{ {
qemuLogContext *logCtxt = opaque; domainLogContext *logCtxt = opaque;
qemuProcessReportLogError(logCtxt, msg); qemuProcessReportLogError(logCtxt, msg);
} }
@ -2244,7 +2244,7 @@ static int
qemuProcessWaitForMonitor(virQEMUDriver *driver, qemuProcessWaitForMonitor(virQEMUDriver *driver,
virDomainObj *vm, virDomainObj *vm,
int asyncJob, int asyncJob,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
int ret = -1; int ret = -1;
g_autoptr(GHashTable) info = NULL; g_autoptr(GHashTable) info = NULL;
@ -4740,7 +4740,7 @@ static void
qemuLogOperation(virDomainObj *vm, qemuLogOperation(virDomainObj *vm,
const char *msg, const char *msg,
virCommand *cmd, virCommand *cmd,
qemuLogContext *logCtxt) domainLogContext *logCtxt)
{ {
g_autofree char *timestamp = NULL; g_autofree char *timestamp = NULL;
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
@ -4754,20 +4754,20 @@ qemuLogOperation(virDomainObj *vm,
if ((timestamp = virTimeStringNow()) == NULL) if ((timestamp = virTimeStringNow()) == NULL)
return; return;
if (qemuLogContextWrite(logCtxt, if (domainLogContextWrite(logCtxt,
"%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n", "%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n",
timestamp, msg, VIR_LOG_VERSION_STRING, timestamp, msg, VIR_LOG_VERSION_STRING,
(qemuVersion / 1000000) % 1000, (qemuVersion / 1000000) % 1000,
(qemuVersion / 1000) % 1000, (qemuVersion / 1000) % 1000,
qemuVersion % 1000, qemuVersion % 1000,
NULLSTR_EMPTY(package), NULLSTR_EMPTY(package),
uts.release, uts.release,
NULLSTR_EMPTY(hostname)) < 0) NULLSTR_EMPTY(hostname)) < 0)
return; return;
if (cmd) { if (cmd) {
g_autofree char *args = virCommandToString(cmd, true); g_autofree char *args = virCommandToString(cmd, true);
qemuLogContextWrite(logCtxt, "%s\n", args); domainLogContextWrite(logCtxt, "%s\n", args);
} }
} }
@ -7775,7 +7775,7 @@ qemuProcessLaunch(virConnectPtr conn,
int ret = -1; int ret = -1;
int rv; int rv;
int logfile = -1; int logfile = -1;
g_autoptr(qemuLogContext) logCtxt = NULL; g_autoptr(domainLogContext) logCtxt = NULL;
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
struct qemuProcessHookData hookData; struct qemuProcessHookData hookData;
@ -7825,11 +7825,14 @@ qemuProcessLaunch(virConnectPtr conn,
hookData.cfg = cfg; hookData.cfg = cfg;
VIR_DEBUG("Creating domain log file"); VIR_DEBUG("Creating domain log file");
if (!(logCtxt = qemuLogContextNew(driver, vm, vm->def->name))) { if (!(logCtxt = domainLogContextNew(cfg->stdioLogD, cfg->logDir,
QEMU_DRIVER_NAME,
vm, driver->privileged,
vm->def->name))) {
virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
goto cleanup; goto cleanup;
} }
logfile = qemuLogContextGetWriteFD(logCtxt); logfile = domainLogContextGetWriteFD(logCtxt);
if (qemuProcessGenID(vm, flags) < 0) if (qemuProcessGenID(vm, flags) < 0)
goto cleanup; goto cleanup;
@ -7865,7 +7868,7 @@ qemuProcessLaunch(virConnectPtr conn,
qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming != NULL); qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming != NULL);
qemuLogContextMarkPosition(logCtxt); domainLogContextMarkPosition(logCtxt);
if (qemuProcessEnableDomainNamespaces(driver, vm) < 0) if (qemuProcessEnableDomainNamespaces(driver, vm) < 0)
goto cleanup; goto cleanup;