From nobody Sun Dec 22 07:56: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 1734619801176666.8313542970283; Thu, 19 Dec 2024 06:50:01 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0F13C16C1; Thu, 19 Dec 2024 09:49:59 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EAF5415EB; Thu, 19 Dec 2024 09:46:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BD8441537; Thu, 19 Dec 2024 09:46:12 -0500 (EST) Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 8C77914E2 for ; Thu, 19 Dec 2024 09:46:11 -0500 (EST) Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-71e163493efso496893a34.3 for ; Thu, 19 Dec 2024 06:46:11 -0800 (PST) Received: from home.. ([2603:8081:c640:1::1009]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-71fc97a40afsm272978a34.25.2024.12.19.06.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 06:46:09 -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.5 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_H3,RCVD_IN_MSPIKE_WL,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=1734619570; x=1735224370; 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=YsTjRFLYYKLK6zPxLwt+uvXBBaibofbEWDTaNrlIgHw=; b=UEQWGoPL//IfIHoP553PLvvIK2gxi+JkHGeYCbfCH/6HmAR10hJ5xthtVZj1lI4bzi VOjzOMiTW4Bfeoznc/1OUog2k0Eanmqk/fDc6hev21oNSpdLNsOEqFqGspS9bIMcS0/d HqnTW0mRPjGSR0u4gmQBO/RjKdtju5Mj1hHf+VpMwxu2eZpJ+IyOc2KnwytiANr94jUa DRl9t0NB/LTZzRaQKkbaROzV9/7uy8JuKXdjalsakmxWBlWuubdjkib0187EhF0fc5sQ Q/Z11zhmWby0aIXKTxxpUvQftqPYPOgQkU+C89G+u7WxxiqfxPdGwoRE9JUPYc+jajis fCQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734619570; x=1735224370; 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=YsTjRFLYYKLK6zPxLwt+uvXBBaibofbEWDTaNrlIgHw=; b=TdNc4N7LvQ57XGMKbpw9isBJELk99xCbD9RBgD8XQ42WsQM8inaJ0huBM9X68OvWiN xsHhp3t3LgGSrQ5BtgPcmFOXFF4C9vpOAW/dJObtVcLEkL1ltGAwRgsXgU48O9f5hbWG Q+YCbjJGjyzyhQGFqesQQpX8kEjANilu9k8qY+saSEeceZoW7ISUz+ci4YuExQaj8Lvt 24mHEqQjhZaeidC5VdFAE/F4Q65EkqWofilTAIhF2yluThttyqa7Zn8+FTpqRiihsphf NvYGmN+Tcx+M1wCMdCkuPeVFjt0Uq+nQ6r49KlzKeO8Cby6Sfb15ThqWdxT4BTpi17F4 zgMA== X-Gm-Message-State: AOJu0Yz+Y5D53Jciqz5mLOYIv3zx1fYhP9wRsopCECVBvo0SLLIcwie1 8rfrPfkbdZ16i7akAO87zK791OXSHkmeU3bfL2WPCxvh7CaixJdFB2Pdx3BX X-Gm-Gg: ASbGncuSZ0UgyJmq/8xXx04z798BcbXfOrvwQDGwCu+2qcq/+XM0Zi7CXdU7dpTt8K4 FaEMkvt+2pqCYrlRmof34WCXxvlaUPIPyZwxjXiaZQpDtwRFspRA4R5aJH97026CbfjiTSbLKjc 1sP5VDRj0jWECOL8HmCn+OYEhCrN9DttAVlD4EH35zlZK+NHgxwuKgfsQ3CrpodCqp0CbQueK9b lrrcN04k27rGhN8n66/jKrCZgZpK3Z2Z1mUPli2 X-Google-Smtp-Source: AGHT+IEe7mEXbn+p9VGUmp9DVlW2LiwrSDEH8dxjGYmSIRHeXl0A1CCbkeDYcxd6EPpvWBKPuuDNUw== X-Received: by 2002:a05:6830:6dce:b0:71d:f239:c091 with SMTP id 46e09a7af769-71fb75642a9mr4198715a34.6.1734619570330; Thu, 19 Dec 2024 06:46:10 -0800 (PST) From: Praveen K Paladugu To: devel@lists.libvirt.org Subject: [PATCH 07/10] qemu: delete qemu_logcontext files Date: Thu, 19 Dec 2024 08:45:58 -0600 Message-ID: <20241219144601.16394-8-praveenkpaladugu@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241219144601.16394-1-praveenkpaladugu@gmail.com> References: <20241219144601.16394-1-praveenkpaladugu@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: VNV442QXJJOZT4ORYLLXND6YOIFBB35B X-Message-ID-Hash: VNV442QXJJOZT4ORYLLXND6YOIFBB35B 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: 1734619802570116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Praveen K Paladugu --- po/POTFILES | 1 - src/qemu/meson.build | 1 - src/qemu/qemu_logcontext.c | 329 ------------------------------------- src/qemu/qemu_logcontext.h | 41 ----- 4 files changed, 372 deletions(-) delete mode 100644 src/qemu/qemu_logcontext.c delete mode 100644 src/qemu/qemu_logcontext.h diff --git a/po/POTFILES b/po/POTFILES index 1d3c3c0a81..43b4d005e3 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -181,7 +181,6 @@ src/qemu/qemu_hostdev.c src/qemu/qemu_hotplug.c src/qemu/qemu_interface.c src/qemu/qemu_interop_config.c -src/qemu/qemu_logcontext.c src/qemu/qemu_migration.c src/qemu/qemu_migration_cookie.c src/qemu/qemu_migration_params.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_logcontext.c b/src/qemu/qemu_logcontext.c deleted file mode 100644 index 6e20f58bfa..0000000000 --- a/src/qemu/qemu_logcontext.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * qemu_logcontext.c: 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 - * . - */ - -#include - -#include "qemu_logcontext.h" -#include "viralloc.h" -#include "virlog.h" -#include "virstring.h" -#include "virutil.h" - -#include - -#define VIR_FROM_THIS VIR_FROM_QEMU - -VIR_LOG_INIT("qemu.qemu_logcontext"); - - -struct _qemuLogContext { - GObject parent; - - int writefd; - int readfd; /* Only used if manager =3D=3D NULL */ - off_t pos; - ino_t inode; /* Only used if manager !=3D NULL */ - char *path; - virLogManager *manager; -}; - -G_DEFINE_TYPE(qemuLogContext, qemu_log_context, G_TYPE_OBJECT); - -static void -qemuLogContextFinalize(GObject *obj); - - -static void -qemu_log_context_init(qemuLogContext *logctxt G_GNUC_UNUSED) -{ -} - - -static void -qemu_log_context_class_init(qemuLogContextClass *klass) -{ - GObjectClass *obj =3D G_OBJECT_CLASS(klass); - - obj->finalize =3D qemuLogContextFinalize; -} - - -static void -qemuLogContextFinalize(GObject *object) -{ - qemuLogContext *ctxt =3D QEMU_LOG_CONTEXT(object); - VIR_DEBUG("ctxt=3D%p", ctxt); - - 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); -} - - -qemuLogContext * -qemuLogContextNew(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)); - - VIR_DEBUG("Context new %p stdioLogD=3D%d", ctxt, cfg->stdioLogD); - ctxt->writefd =3D -1; - ctxt->readfd =3D -1; - - ctxt->path =3D g_strdup_printf("%s/%s.log", cfg->logDir, basename); - - if (cfg->stdioLogD) { - ctxt->manager =3D virLogManagerNew(driver->privileged); - if (!ctxt->manager) - goto error; - - ctxt->writefd =3D virLogManagerDomainOpenLogFile(ctxt->manager, - "qemu", - vm->def->uuid, - vm->def->name, - ctxt->path, - 0, - &ctxt->inode, - &ctxt->pos); - if (ctxt->writefd < 0) - goto error; - } else { - if ((ctxt->writefd =3D open(ctxt->path, O_WRONLY | O_CREAT | O_APP= END, S_IRUSR | S_IWUSR)) < 0) { - virReportSystemError(errno, _("failed to create logfile %1$s"), - ctxt->path); - goto error; - } - if (virSetCloseExec(ctxt->writefd) < 0) { - virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), - ctxt->path); - goto error; - } - - /* For unprivileged startup we must truncate the file since - * we can't rely on logrotate. We don't use O_TRUNC since - * it is better for SELinux policy if we truncate afterwards */ - if (!driver->privileged && - ftruncate(ctxt->writefd, 0) < 0) { - virReportSystemError(errno, _("failed to truncate %1$s"), - ctxt->path); - goto error; - } - - if ((ctxt->readfd =3D open(ctxt->path, O_RDONLY)) < 0) { - virReportSystemError(errno, _("failed to open logfile %1$s"), - ctxt->path); - goto error; - } - if (virSetCloseExec(ctxt->readfd) < 0) { - virReportSystemError(errno, _("failed to set close-on-exec fla= g on %1$s"), - ctxt->path); - goto error; - } - - if ((ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END)) < 0) { - virReportSystemError(errno, _("failed to seek in log file %1$s= "), - ctxt->path); - goto error; - } - } - - return ctxt; - - error: - g_clear_object(&ctxt); - return NULL; -} - - -int -qemuLogContextWrite(qemuLogContext *ctxt, - const char *fmt, ...) -{ - va_list argptr; - g_autofree char *message =3D NULL; - int ret =3D -1; - - va_start(argptr, fmt); - - message =3D g_strdup_vprintf(fmt, argptr); - if (!ctxt->manager && - lseek(ctxt->writefd, 0, SEEK_END) < 0) { - virReportSystemError(errno, "%s", - _("Unable to seek to end of domain logfile")); - goto cleanup; - } - if (safewrite(ctxt->writefd, message, strlen(message)) < 0) { - virReportSystemError(errno, "%s", - _("Unable to write to domain logfile")); - goto cleanup; - } - - ret =3D 0; - - cleanup: - va_end(argptr); - return ret; -} - - -ssize_t -qemuLogContextRead(qemuLogContext *ctxt, - char **msg) -{ - char *buf; - size_t buflen; - - VIR_DEBUG("Context read %p manager=3D%p inode=3D%llu pos=3D%llu", - ctxt, ctxt->manager, - (unsigned long long)ctxt->inode, - (unsigned long long)ctxt->pos); - - if (ctxt->manager) { - buf =3D virLogManagerDomainReadLogFile(ctxt->manager, - ctxt->path, - ctxt->inode, - ctxt->pos, - 1024 * 128, - 0); - if (!buf) - return -1; - buflen =3D strlen(buf); - } else { - ssize_t got; - - buflen =3D 1024 * 128; - - /* Best effort jump to start of messages */ - ignore_value(lseek(ctxt->readfd, ctxt->pos, SEEK_SET)); - - buf =3D g_new0(char, buflen); - - got =3D saferead(ctxt->readfd, buf, buflen - 1); - if (got < 0) { - VIR_FREE(buf); - virReportSystemError(errno, "%s", - _("Unable to read from log file")); - return -1; - } - - buf[got] =3D '\0'; - - buf =3D g_renew(char, buf, got + 1); - buflen =3D got; - } - - *msg =3D buf; - - return buflen; -} - - -/** - * qemuLogContextFilter: 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 - * - * Reads log output from @ctxt and filters it. Skips messages not produced= by - * the target executable or irrelevant messages. If @max is not zero, @buf= will - * contain at most @max characters from the end of the log and @buf will s= tart - * after a new line if possible. - */ -int -qemuLogContextReadFiltered(qemuLogContext *ctxt, - char **msg, - size_t max) -{ - char *buf; - char *eol; - char *filter_next; - size_t skip; - ssize_t got; - - if ((got =3D qemuLogContextRead(ctxt, &buf)) < 0) - return -1; - - /* Filter out debug messages from intermediate libvirt process */ - filter_next =3D buf; - while ((eol =3D strchr(filter_next, '\n'))) { - *eol =3D '\0'; - if (virLogProbablyLogMessage(filter_next) || - strstr(filter_next, "char device redirected to")) { - skip =3D (eol + 1) - filter_next; - memmove(filter_next, eol + 1, buf + got - eol); - got -=3D skip; - } else { - filter_next =3D eol + 1; - *eol =3D '\n'; - } - } - - if (got > 0 && - buf[got - 1] =3D=3D '\n') { - buf[got - 1] =3D '\0'; - got--; - } - - if (max > 0 && got > max) { - skip =3D got - max; - - if (buf[skip - 1] !=3D '\n' && - (eol =3D strchr(buf + skip, '\n')) && - !virStringIsEmpty(eol + 1)) - skip =3D eol + 1 - buf; - - memmove(buf, buf + skip, got - skip + 1); - got -=3D skip; - } - - buf =3D g_renew(char, buf, got + 1); - *msg =3D buf; - return 0; -} - - -int -qemuLogContextGetWriteFD(qemuLogContext *ctxt) -{ - return ctxt->writefd; -} - - -void -qemuLogContextMarkPosition(qemuLogContext *ctxt) -{ - if (ctxt->manager) - virLogManagerDomainGetLogFilePosition(ctxt->manager, - ctxt->path, - 0, - &ctxt->inode, - &ctxt->pos); - else - ctxt->pos =3D lseek(ctxt->writefd, 0, SEEK_END); -} - - -virLogManager * -qemuLogContextGetManager(qemuLogContext *ctxt) -{ - return ctxt->manager; -} 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); --=20 2.47.0