From nobody Sun Dec 22 09:01:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1733507361909700.591263312325; Fri, 6 Dec 2024 09:49:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E4E2313A9; Fri, 6 Dec 2024 12:49:20 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 46EAC1470; Fri, 6 Dec 2024 12:48:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6073BBC5; Fri, 6 Dec 2024 12:47:55 -0500 (EST) Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0FF5F9DE for ; Fri, 6 Dec 2024 12:47:54 -0500 (EST) Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-29e5aedbebdso1209814fac.0 for ; Fri, 06 Dec 2024 09:47:54 -0800 (PST) Received: from home.. ([2603:8081:c640:1::100a]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29f566ea976sm932125fac.15.2024.12.06.09.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Dec 2024 09:47:52 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733507273; x=1734112073; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s1UtpOT8Cwhv8BvqJakmv1cxaiS6BNPPLzXXuOLjPkQ=; b=IuaHeLy+BdHG0Q02usptbJRnix7lFT8aTrXBgnpoofb/E0K2OFFyFpYJqv0oZY2C76 m8nxD0h4yaYmn3S9V4AuROellfHRUPxI2ElaSVfqKlGIRTRmX226cC5VXPW7fafsoL9U hOt1fxuJgtJJfVNkhcGs92ezBHgw6cD7ZBgeByiWMUZhIJ/8dF1HlaQqpbsrUx52rwpv Yz8gfDcc2UXbCzxkZyos//xi+iqBx4V10Fq6k7KAHJ5RtStLJQum+RV6omWCkHeM0tLY VvuOkiNEOFtHmy4EKUOrVwuzHW9pWYbyuxoM+8XYY9E/w2yi8UzsaidZlabKauG4wx2w d//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733507273; x=1734112073; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s1UtpOT8Cwhv8BvqJakmv1cxaiS6BNPPLzXXuOLjPkQ=; b=DiL3uNhxqQ2LEmmKTCzfi7F0EOZRFmlzSt5H4x/WTZQeECrTFFPpPDJxATHHqgBHF5 Iw9AZFzReCLqat1O+qdw3Pp/jXRsnc0pnzK2XyZWNzMP0Ne0Ye5KCyRfMFceaEu+AsWr LiVm/VDSIWUhVJfIsZShe54Okj9dOBvaH7EIUAOJbj4Wco4FYEUZ2gAzTGoGJIYs/xv5 pJlDylTiMG4ulCIf/lQ4wkMsd+ka51UpSLX1jUA3+7iMFcCJPplDYFHHxG8d3dEsCnow dS1mL0BPL3XyrKIee1F0yi+0VQoeUaXwaODJ980GnRUQqYoKV5U9NdkPvtctzfAL5aog J37Q== X-Gm-Message-State: AOJu0YyvOXhYohhBs7/7IbgdG1CLIHJhQTy1mT3ilGpq0UyIUlEOz0TJ 7hQGahfaukJ3rlifRoJtipDHnSfJVGdQQpSbIfbTTEWAiuW1zeXQ6mdqkyr7 X-Gm-Gg: ASbGnctas+NbmArpt9iR5Y9sRpJ3t+rbQGrUjhJ6xGE9kPd34DNlpuXlzXJ64Vdgagb cwguzONdzyxUi80NnHhyDd9wPvzFmQmfJUpL91NJYU7RZDdldMah276D8Yx6kColAEgEsn17/C1 7RBQg+KMJ8btJrjPmBmRAkhLuMKoxinqYZk9MSMzCOTawU4InoemZva9WJLPPeUQFn/NVZs2Rmj zZEbOq09LE/M0KNMq/ndq/AbOFc+L4/Fg== X-Google-Smtp-Source: AGHT+IElFSEeF1bbX/IEyAV4JncNJqoPkYuauU4pJg+AtOb3U2NhWmnqMVXDorqcy2E9atI98ytogw== X-Received: by 2002:a05:6870:dc4b:b0:288:a953:a5c7 with SMTP id 586e51a60fabf-29f732d8925mr2036970fac.14.1733507273022; Fri, 06 Dec 2024 09:47:53 -0800 (PST) From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 1/8] domain: move logcontext mgmt from qemu to hypervisor Date: Fri, 6 Dec 2024 11:47:42 -0600 Message-ID: <20241206174749.33455-2-praveenkpaladugu@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241206174749.33455-1-praveenkpaladugu@gmail.com> References: <20241206174749.33455-1-praveenkpaladugu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: K3I2PKYPDPC5W2RIPBNJ2UCNGXDEGAXT X-Message-ID-Hash: K3I2PKYPDPC5W2RIPBNJ2UCNGXDEGAXT X-MailFrom: praveenkpaladugu@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: liuwe@microsoft.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1733507362655116600 Content-Type: text/plain; charset="utf-8" Move logcontext management from qemu to hypevisor to be shared across hypervisors. This commit only replaces the names. Build fixes will follow in next commit. Signed-off-by: Praveen K Paladugu --- .../domain_logcontext.c} | 60 +++++++++---------- src/hypervisor/domain_logcontext.h | 41 +++++++++++++ src/hypervisor/meson.build | 1 + src/qemu/meson.build | 1 - src/qemu/qemu_domain.c | 28 ++++----- src/qemu/qemu_domain.h | 12 ++-- src/qemu/qemu_logcontext.h | 41 ------------- src/qemu/qemu_nbdkit.c | 8 +-- src/qemu/qemu_process.c | 43 ++++++------- 9 files changed, 118 insertions(+), 117 deletions(-) rename src/{qemu/qemu_logcontext.c =3D> hypervisor/domain_logcontext.c} (8= 4%) create mode 100644 src/hypervisor/domain_logcontext.h delete mode 100644 src/qemu/qemu_logcontext.h diff --git a/src/qemu/qemu_logcontext.c b/src/hypervisor/domain_logcontext.c similarity index 84% rename from src/qemu/qemu_logcontext.c rename to src/hypervisor/domain_logcontext.c index 6e20f58bfa..3776d68ab9 100644 --- a/src/qemu/qemu_logcontext.c +++ b/src/hypervisor/domain_logcontext.c @@ -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 * modify it under the terms of the GNU Lesser General Public @@ -18,7 +18,7 @@ =20 #include =20 -#include "qemu_logcontext.h" +#include "domain_logcontext.h" #include "viralloc.h" #include "virlog.h" #include "virstring.h" @@ -26,12 +26,12 @@ =20 #include =20 -#define VIR_FROM_THIS VIR_FROM_QEMU +#define VIR_FROM_THIS VIR_FROM_DOMAIN =20 -VIR_LOG_INIT("qemu.qemu_logcontext"); +VIR_LOG_INIT("domain.domain_logcontext"); =20 =20 -struct _qemuLogContext { +struct _domainLogContext { GObject parent; =20 int writefd; @@ -42,48 +42,48 @@ struct _qemuLogContext { virLogManager *manager; }; =20 -G_DEFINE_TYPE(qemuLogContext, qemu_log_context, G_TYPE_OBJECT); +G_DEFINE_TYPE(domainLogContext, domain_log_context, G_TYPE_OBJECT); =20 static void -qemuLogContextFinalize(GObject *obj); +domainLogContextFinalize(GObject *obj); =20 =20 static void -qemu_log_context_init(qemuLogContext *logctxt G_GNUC_UNUSED) +domain_log_context_init(domainLogContext *logctxt G_GNUC_UNUSED) { } =20 =20 static void -qemu_log_context_class_init(qemuLogContextClass *klass) +domain_log_context_class_init(domainLogContextClass *klass) { GObjectClass *obj =3D G_OBJECT_CLASS(klass); =20 - obj->finalize =3D qemuLogContextFinalize; + obj->finalize =3D domainLogContextFinalize; } =20 =20 static void -qemuLogContextFinalize(GObject *object) +domainLogContextFinalize(GObject *object) { - qemuLogContext *ctxt =3D QEMU_LOG_CONTEXT(object); + domainLogContext *ctxt =3D DOMAIN_LOG_CONTEXT(object); VIR_DEBUG("ctxt=3D%p", ctxt); =20 virLogManagerFree(ctxt->manager); VIR_FREE(ctxt->path); VIR_FORCE_CLOSE(ctxt->writefd); 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); } =20 =20 -qemuLogContext * -qemuLogContextNew(virQEMUDriver *driver, - virDomainObj *vm, - const char *basename) +domainLogContext * +domainLogContextNew(virQEMUDriver *driver, + virDomainObj *vm, + const char *basename) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - qemuLogContext *ctxt =3D QEMU_LOG_CONTEXT(g_object_new(QEMU_TYPE_LOG_C= ONTEXT, NULL)); + domainLogContext *ctxt =3D DOMAIN_LOG_CONTEXT(g_object_new(DOMAIN_TYPE= _LOG_CONTEXT, NULL)); =20 VIR_DEBUG("Context new %p stdioLogD=3D%d", ctxt, cfg->stdioLogD); ctxt->writefd =3D -1; @@ -155,8 +155,8 @@ qemuLogContextNew(virQEMUDriver *driver, =20 =20 int -qemuLogContextWrite(qemuLogContext *ctxt, - const char *fmt, ...) +domainLogContextWrite(domainLogContext *ctxt, + const char *fmt, ...) { va_list argptr; g_autofree char *message =3D NULL; @@ -186,8 +186,8 @@ qemuLogContextWrite(qemuLogContext *ctxt, =20 =20 ssize_t -qemuLogContextRead(qemuLogContext *ctxt, - char **msg) +domainLogContextRead(domainLogContext *ctxt, + char **msg) { char *buf; size_t buflen; @@ -238,7 +238,7 @@ qemuLogContextRead(qemuLogContext *ctxt, =20 =20 /** - * qemuLogContextFilter: Read and filter log for relevant messages + * domainLogContextFilter: Read and filter log for relevant messages * @ctxt: the domain log context * @msg: pointer to buffer to store the read messages in * @max: maximum length of the message returned in @msg after filtering @@ -249,9 +249,9 @@ qemuLogContextRead(qemuLogContext *ctxt, * after a new line if possible. */ int -qemuLogContextReadFiltered(qemuLogContext *ctxt, - char **msg, - size_t max) +domainLogContextReadFiltered(domainLogContext *ctxt, + char **msg, + size_t max) { char *buf; char *eol; @@ -259,7 +259,7 @@ qemuLogContextReadFiltered(qemuLogContext *ctxt, size_t skip; ssize_t got; =20 - if ((got =3D qemuLogContextRead(ctxt, &buf)) < 0) + if ((got =3D domainLogContextRead(ctxt, &buf)) < 0) return -1; =20 /* Filter out debug messages from intermediate libvirt process */ @@ -302,14 +302,14 @@ qemuLogContextReadFiltered(qemuLogContext *ctxt, =20 =20 int -qemuLogContextGetWriteFD(qemuLogContext *ctxt) +domainLogContextGetWriteFD(domainLogContext *ctxt) { return ctxt->writefd; } =20 =20 void -qemuLogContextMarkPosition(qemuLogContext *ctxt) +domainLogContextMarkPosition(domainLogContext *ctxt) { if (ctxt->manager) virLogManagerDomainGetLogFilePosition(ctxt->manager, @@ -323,7 +323,7 @@ qemuLogContextMarkPosition(qemuLogContext *ctxt) =20 =20 virLogManager * -qemuLogContextGetManager(qemuLogContext *ctxt) +domainLogContextGetManager(domainLogContext *ctxt) { return ctxt->manager; } diff --git a/src/hypervisor/domain_logcontext.h b/src/hypervisor/domain_log= context.h new file mode 100644 index 0000000000..0842f994d6 --- /dev/null +++ b/src/hypervisor/domain_logcontext.h @@ -0,0 +1,41 @@ +/* + * domain_logcontext.h: Domin 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 + * . + */ + +#pragma once + +#include +#include "logging/log_manager.h" +#include "virconftypes.h" + +#define DOMAIN_TYPE_LOG_CONTEXT domain_log_context_get_type() +G_DECLARE_FINAL_TYPE(domainLogContext, domain_log_context, DOMAIN, LOG_CON= TEXT, GObject); + +domainLogContext *domainLogContextNew(virQEMUDriver *driver, + virDomainObj *vm, + 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); diff --git a/src/hypervisor/meson.build b/src/hypervisor/meson.build index 819a9a82a2..c32703af88 100644 --- a/src/hypervisor/meson.build +++ b/src/hypervisor/meson.build @@ -2,6 +2,7 @@ hypervisor_sources =3D [ 'domain_cgroup.c', 'domain_driver.c', 'domain_interface.c', + 'domain_logcontext.c', 'virclosecallbacks.c', 'virhostdev.c', ] diff --git a/src/qemu/meson.build b/src/qemu/meson.build index 2a85e2e604..43a8ad7c3b 100644 --- a/src/qemu/meson.build +++ b/src/qemu/meson.build @@ -22,7 +22,6 @@ qemu_driver_sources =3D [ 'qemu_hotplug.c', 'qemu_interface.c', 'qemu_interop_config.c', - 'qemu_logcontext.c', 'qemu_migration.c', 'qemu_migration_cookie.c', 'qemu_migration_params.c', diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1fc4e2f33f..411e80e94e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5399,7 +5399,7 @@ static void G_GNUC_PRINTF(5, 6) qemuDomainObjTaintMsg(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuLogContext *logCtxt, + domainLogContext *logCtxt, const char *fmt, ...) { virErrorPtr orig_err =3D NULL; @@ -5452,12 +5452,12 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver, goto cleanup; =20 if (logCtxt) { - rc =3D qemuLogContextWrite(logCtxt, - "%s: Domain id=3D%d is tainted: %s%s%s%s\= n", - timestamp, - obj->def->id, - virDomainTaintTypeToString(taint), - extraprefix, extramsg, extrasuffix); + rc =3D domainLogContextWrite(logCtxt, + "%s: Domain id=3D%d is tainted: %s%s%s%= s\n", + timestamp, + obj->def->id, + virDomainTaintTypeToString(taint), + extraprefix, extramsg, extrasuffix); } else { rc =3D qemuDomainLogAppendMessage(driver, obj, "%s: Domain id=3D%d is tainted: %s= %s%s%s\n", @@ -5478,7 +5478,7 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL); qemuDomainSaveStatus(obj); @@ -5487,7 +5487,7 @@ void qemuDomainObjTaint(virQEMUDriver *driver, static void qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { qemuDomainObjPrivate *priv =3D obj->privateData; virQEMUCaps *qemuCaps =3D priv->qemuCaps; @@ -5505,7 +5505,7 @@ qemuDomainObjCheckMachineTaint(virQEMUDriver *driver, static void qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuLogContext *logCtxt, + domainLogContext *logCtxt, bool incomingMigration) { qemuDomainObjPrivate *priv =3D obj->privateData; @@ -5537,7 +5537,7 @@ qemuDomainObjCheckCPUTaint(virQEMUDriver *driver, =20 void qemuDomainObjCheckTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuLogContext *logCtxt, + domainLogContext *logCtxt, bool incomingMigration) { size_t i; @@ -5593,7 +5593,7 @@ void qemuDomainObjCheckTaint(virQEMUDriver *driver, void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainDiskDef *disk, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { if (disk->rawio =3D=3D VIR_TRISTATE_BOOL_YES) qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES, @@ -5610,7 +5610,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriver *drive= r, void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainHostdevDef *hostdev, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { if (!virHostdevIsSCSIDevice(hostdev)) return; @@ -5623,7 +5623,7 @@ void qemuDomainObjCheckHostdevTaint(virQEMUDriver *dr= iver, void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainNetDef *net, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { /* script is only useful for NET_TYPE_ETHERNET (qemu) and * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index e810f79599..dba2696a27 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -26,13 +26,13 @@ #include "virperf.h" #include "domain_addr.h" #include "domain_conf.h" +#include "domain_logcontext.h" #include "qemu_monitor.h" #include "qemu_agent.h" #include "qemu_blockjob.h" #include "qemu_domainjob.h" #include "qemu_conf.h" #include "qemu_capabilities.h" -#include "qemu_logcontext.h" #include "qemu_migration_params.h" #include "qemu_nbdkit.h" #include "qemu_slirp.h" @@ -641,24 +641,24 @@ char *qemuDomainDefFormatLive(virQEMUDriver *driver, void qemuDomainObjTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainTaintFlags taint, - qemuLogContext *logCtxt); + domainLogContext *logCtxt); =20 void qemuDomainObjCheckTaint(virQEMUDriver *driver, virDomainObj *obj, - qemuLogContext *logCtxt, + domainLogContext *logCtxt, bool incomingMigration); void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainDiskDef *disk, - qemuLogContext *logCtxt); + domainLogContext *logCtxt); void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainHostdevDef *disk, - qemuLogContext *logCtxt); + domainLogContext *logCtxt); void qemuDomainObjCheckNetTaint(virQEMUDriver *driver, virDomainObj *obj, virDomainNetDef *net, - qemuLogContext *logCtxt); + domainLogContext *logCtxt); =20 int qemuDomainLogAppendMessage(virQEMUDriver *driver, virDomainObj *vm, diff --git a/src/qemu/qemu_logcontext.h b/src/qemu/qemu_logcontext.h deleted file mode 100644 index 738e908bc3..0000000000 --- a/src/qemu/qemu_logcontext.h +++ /dev/null @@ -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 - * . - */ - -#pragma once - -#include -#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); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index f099f35e1e..de7c62a037 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -1185,7 +1185,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, g_autofree char *uristring =3D NULL; g_autofree char *basename =3D g_strdup_printf("%s-nbdkit-%i", vm->def-= >name, proc->source->id); int logfd =3D -1; - g_autoptr(qemuLogContext) logContext =3D NULL; + g_autoptr(domainLogContext) logContext =3D NULL; #if WITH_NBDKIT struct nbd_handle *nbd =3D NULL; #endif @@ -1200,12 +1200,12 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, if (!(cmd =3D qemuNbdkitProcessBuildCommand(proc))) return -1; =20 - if (!(logContext =3D qemuLogContextNew(driver, vm, basename))) { + if (!(logContext =3D domainLogContextNew(driver, vm, basename))) { virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); return -1; } =20 - logfd =3D qemuLogContextGetWriteFD(logContext); + logfd =3D domainLogContextGetWriteFD(logContext); =20 VIR_DEBUG("starting nbdkit process for %s", qemuBlockStorageSourceGetS= torageNodename(proc->source)); virCommandSetErrorFD(cmd, &logfd); @@ -1283,7 +1283,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, if ((uri =3D qemuBlockStorageSourceGetURI(proc->source))) uristring =3D virURIFormat(uri); =20 - if (qemuLogContextReadFiltered(logContext, &errbuf, 1024) < 0) + if (domainLogContextReadFiltered(logContext, &errbuf, 1024) < 0) VIR_WARN("Unable to read from nbdkit log"); =20 virReportError(VIR_ERR_OPERATION_FAILED, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bee7a39e4e..d182206f20 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1840,7 +1840,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon, static void qemuProcessMonitorLogFree(void *opaque) { - qemuLogContext *logCtxt =3D opaque; + domainLogContext *logCtxt =3D opaque; g_clear_object(&logCtxt); } =20 @@ -1866,7 +1866,7 @@ static int qemuConnectMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob, - qemuLogContext *logCtxt, + domainLogContext *logCtxt, bool reconnect) { qemuDomainObjPrivate *priv =3D vm->privateData; @@ -1918,13 +1918,13 @@ qemuConnectMonitor(virQEMUDriver *driver, =20 =20 static int -qemuProcessReportLogError(qemuLogContext *logCtxt, +qemuProcessReportLogError(domainLogContext *logCtxt, const char *msgprefix) { g_autofree char *logmsg =3D NULL; =20 /* 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; =20 virResetLastError(); @@ -1943,7 +1943,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon G_G= NUC_UNUSED, const char *msg, void *opaque) { - qemuLogContext *logCtxt =3D opaque; + domainLogContext *logCtxt =3D opaque; qemuProcessReportLogError(logCtxt, msg); } =20 @@ -2244,7 +2244,7 @@ static int qemuProcessWaitForMonitor(virQEMUDriver *driver, virDomainObj *vm, int asyncJob, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { int ret =3D -1; g_autoptr(GHashTable) info =3D NULL; @@ -4740,7 +4740,7 @@ static void qemuLogOperation(virDomainObj *vm, const char *msg, virCommand *cmd, - qemuLogContext *logCtxt) + domainLogContext *logCtxt) { g_autofree char *timestamp =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; @@ -4754,20 +4754,21 @@ qemuLogOperation(virDomainObj *vm, if ((timestamp =3D virTimeStringNow()) =3D=3D NULL) return; =20 - if (qemuLogContextWrite(logCtxt, - "%s: %s %s, qemu version: %d.%d.%d%s, kernel: = %s, hostname: %s\n", - timestamp, msg, VIR_LOG_VERSION_STRING, - (qemuVersion / 1000000) % 1000, - (qemuVersion / 1000) % 1000, - qemuVersion % 1000, - NULLSTR_EMPTY(package), - uts.release, - NULLSTR_EMPTY(hostname)) < 0) + if (domainLogContextWrite(logCtxt, + "%s: %s %s, qemu version: %d.%d.%d%s, kernel= : %s, + hostname: %s\n", + timestamp, msg, VIR_LOG_VERSION_STRING, + (qemuVersion / 1000000) % 1000, + (qemuVersion / 1000) % 1000, + qemuVersion % 1000, + NULLSTR_EMPTY(package), + uts.release, + NULLSTR_EMPTY(hostname)) < 0) return; =20 if (cmd) { g_autofree char *args =3D virCommandToString(cmd, true); - qemuLogContextWrite(logCtxt, "%s\n", args); + domainLogContextWrite(logCtxt, "%s\n", args); } } =20 @@ -7765,7 +7766,7 @@ qemuProcessLaunch(virConnectPtr conn, int ret =3D -1; int rv; int logfile =3D -1; - g_autoptr(qemuLogContext) logCtxt =3D NULL; + g_autoptr(domainLogContext) logCtxt =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virCommand) cmd =3D NULL; struct qemuProcessHookData hookData; @@ -7815,11 +7816,11 @@ qemuProcessLaunch(virConnectPtr conn, hookData.cfg =3D cfg; =20 VIR_DEBUG("Creating domain log file"); - if (!(logCtxt =3D qemuLogContextNew(driver, vm, vm->def->name))) { + if (!(logCtxt =3D domainLogContextNew(driver, vm, vm->def->name))) { virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); goto cleanup; } - logfile =3D qemuLogContextGetWriteFD(logCtxt); + logfile =3D domainLogContextGetWriteFD(logCtxt); =20 if (qemuProcessGenID(vm, flags) < 0) goto cleanup; @@ -7855,7 +7856,7 @@ qemuProcessLaunch(virConnectPtr conn, =20 qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming !=3D NULL); =20 - qemuLogContextMarkPosition(logCtxt); + domainLogContextMarkPosition(logCtxt); =20 if (qemuProcessEnableDomainNamespaces(driver, vm) < 0) goto cleanup; --=20 2.47.0