From nobody Wed May 15 01:53:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1675090928; cv=none; d=zohomail.com; s=zohoarc; b=RnJyhQ3YbZs1goife4UK3ksZpeg6UFm7jbFvnONo+16jcKAzRShod2JC9LrFpCMDI+1PrJAYtS1l5Ta9Cj7cDFo0OX8zD47P4DhQ0ezEbes8RRad6yywYIFT27kCIvvB7k6EY6iUHSM5g2+bWCmF7VM9Uy1Y75fPfzAHRGYiGis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675090928; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=06HtmV5hruxtT7pjZlOeB7IUL3byx5NRNKP4z3pXce4=; b=nXTH9AgKEme/IRQnXQw+Q/HzGvkmIkTUAshvAF9eksSbzRolF4kQXiNORVRHRRR3Z0W2KvustdxS803+4qjB/lxppI6wzeVcGhAWNZL6MPn2ge6uLIUED81ggUmAfKoRkFV0wscGAmXoBtIT4q4/SJ4Ka6Wret3hik/bHrXEohc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1675090928212868.4029705462024; Mon, 30 Jan 2023 07:02:08 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-JjTgl7lXO3Cg7e6Lh2W0vw-1; Mon, 30 Jan 2023 10:01:03 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4CB63C0F668; Mon, 30 Jan 2023 15:00:36 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9800F1121314; Mon, 30 Jan 2023 15:00:34 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 447D41946589; Mon, 30 Jan 2023 15:00:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5B10F1946587 for ; Mon, 30 Jan 2023 15:00:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3EB4C140EBF6; Mon, 30 Jan 2023 15:00:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 371DB140EBF5 for ; Mon, 30 Jan 2023 15:00:28 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0891185CBE3 for ; Mon, 30 Jan 2023 15:00:28 +0000 (UTC) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-205-pFfIdx73Pb2kcB7oAz-39A-1; Mon, 30 Jan 2023 10:00:24 -0500 Received: from [192.168.16.74] (helo=dv.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1pMVdp-00AYfM-RS; Mon, 30 Jan 2023 16:00:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675090871; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=06HtmV5hruxtT7pjZlOeB7IUL3byx5NRNKP4z3pXce4=; b=F9IVzqhWRs0jRRtEQHnC2Qscp+JsbccPi/ySS7EsTDdFj9FS1znDsKM7cOw08uP0li64wR sQ9HfACO6RMMbkPw1zjApcyQbGuHIXf2UW8Rh4bswv0bQWhwjsXqQ/mFxHSSorSUCdC53y eH5V/XzVMXjeFgr5oDV7kT/c8tVgPWo= X-MC-Unique: JjTgl7lXO3Cg7e6Lh2W0vw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: pFfIdx73Pb2kcB7oAz-39A-1 From: Oleg Vasilev To: libvir-list@redhat.com Subject: [PATCH v3 1/5] logging: refactor to store config inside log handler Date: Mon, 30 Jan 2023 20:59:58 +0600 Message-Id: <20230130150002.322315-2-oleg.vasilev@virtuozzo.com> In-Reply-To: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> References: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kletzander , Den Lunev , Oleg Vasilev Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675090941832100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Oleg Vasilev Reviewed-by: Martin Kletzander --- src/logging/log_daemon.c | 6 ++---- src/logging/log_handler.c | 29 ++++++++++++----------------- src/logging/log_handler.h | 17 ++++++++--------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 9b70ffad2f..8025245350 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -145,8 +145,7 @@ virLogDaemonNew(virLogDaemonConfig *config, bool privil= eged) g_clear_pointer(&srv, virObjectUnref); =20 if (!(logd->handler =3D virLogHandlerNew(privileged, - config->max_size, - config->max_backups, + config, virLogDaemonInhibitor, logd))) goto error; @@ -231,8 +230,7 @@ virLogDaemonNewPostExecRestart(virJSONValue *object, bo= ol privileged, =20 if (!(logd->handler =3D virLogHandlerNewPostExecRestart(child, privileged, - config->max_size, - config->max_back= ups, + config, virLogDaemonInhi= bitor, logd))) goto error; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index bf1e3f35c5..7342404b00 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -58,8 +58,7 @@ struct _virLogHandler { virObjectLockable parent; =20 bool privileged; - size_t max_size; - size_t max_backups; + virLogDaemonConfig *config; =20 virLogHandlerLogFile **files; size_t nfiles; @@ -185,8 +184,7 @@ virLogHandlerDomainLogFileEvent(int watch, =20 virLogHandler * virLogHandlerNew(bool privileged, - size_t max_size, - size_t max_backups, + virLogDaemonConfig *config, virLogHandlerShutdownInhibitor inhibitor, void *opaque) { @@ -199,8 +197,7 @@ virLogHandlerNew(bool privileged, return NULL; =20 handler->privileged =3D privileged; - handler->max_size =3D max_size; - handler->max_backups =3D max_backups; + handler->config =3D config; handler->inhibitor =3D inhibitor; handler->opaque =3D opaque; =20 @@ -253,8 +250,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandler *hand= ler, } =20 if ((file->file =3D virRotatingFileWriterNew(path, - handler->max_size, - handler->max_backups, + handler->config->max_size, + handler->config->max_backup= s, false, DEFAULT_MODE)) =3D=3D NULL) goto error; @@ -282,8 +279,7 @@ virLogHandlerLogFilePostExecRestart(virLogHandler *hand= ler, virLogHandler * virLogHandlerNewPostExecRestart(virJSONValue *object, bool privileged, - size_t max_size, - size_t max_backups, + virLogDaemonConfig *config, virLogHandlerShutdownInhibitor inhibitor, void *opaque) { @@ -292,8 +288,7 @@ virLogHandlerNewPostExecRestart(virJSONValue *object, size_t i; =20 if (!(handler =3D virLogHandlerNew(privileged, - max_size, - max_backups, + config, inhibitor, opaque))) return NULL; @@ -393,8 +388,8 @@ virLogHandlerDomainOpenLogFile(virLogHandler *handler, file->domname =3D g_strdup(domname); =20 if ((file->file =3D virRotatingFileWriterNew(path, - handler->max_size, - handler->max_backups, + handler->config->max_size, + handler->config->max_backup= s, trunc, DEFAULT_MODE)) =3D=3D NULL) goto error; @@ -525,7 +520,7 @@ virLogHandlerDomainReadLogFile(virLogHandler *handler, =20 virObjectLock(handler); =20 - if (!(file =3D virRotatingFileReaderNew(path, handler->max_backups))) + if (!(file =3D virRotatingFileReaderNew(path, handler->config->max_bac= kups))) goto error; =20 if (virRotatingFileReaderSeek(file, inode, offset) < 0) @@ -579,8 +574,8 @@ virLogHandlerDomainAppendLogFile(virLogHandler *handler, =20 if (!writer) { if (!(newwriter =3D virRotatingFileWriterNew(path, - handler->max_size, - handler->max_backups, + handler->config->max_si= ze, + handler->config->max_ba= ckups, false, DEFAULT_MODE))) goto cleanup; diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h index 099378b361..c9af033cd3 100644 --- a/src/logging/log_handler.h +++ b/src/logging/log_handler.h @@ -22,6 +22,7 @@ =20 #include "internal.h" #include "virjson.h" +#include "log_daemon_config.h" =20 typedef struct _virLogHandler virLogHandler; =20 @@ -30,16 +31,14 @@ typedef void (*virLogHandlerShutdownInhibitor)(bool inh= ibit, void *opaque); =20 virLogHandler *virLogHandlerNew(bool privileged, - size_t max_size, - size_t max_backups, - virLogHandlerShutdownInhibitor inhibitor, - void *opaque); + virLogDaemonConfig *config, + virLogHandlerShutdownInhibitor inhibitor, + void *opaque); virLogHandler *virLogHandlerNewPostExecRestart(virJSONValue *child, - bool privileged, - size_t max_size, - size_t max_backups, - virLogHandlerShutdownInhi= bitor inhibitor, - void *opaque); + bool privileged, + virLogDaemonConfig *config, + virLogHandlerShutdownInhibi= tor inhibitor, + void *opaque); =20 void virLogHandlerFree(virLogHandler *handler); =20 --=20 2.39.1 From nobody Wed May 15 01:53:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1675090863; cv=none; d=zohomail.com; s=zohoarc; b=TAZBrcM4QV9/1/a2yL+7jklGiutTM6zJNV13YONNwUcEFxnJpxjh6ny4zhnE0Aq3hpsqe3UUT94/9l8tTKA/XZPZTGrP16S5h16mTka8P7ztLdHc2+Eq0g4ByYnV4T0rSS4BDdZQ6PwtiC5/4856FWoB0RNjxGowIlwPwUo78vk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675090863; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vaOpaA/w6OLJSRZX9Ahu+0hUc3YcxqoxjV8YqT4/ka4=; b=SZhnl0getHM49ck1BvypCiOi1OmCN98/7CIcKAE7uyxu7mxRcmrosB74xrWW93R+rQ8lNbfjGp3PbuwLO8ZORY+H8P8i/stEaaPe7w2ftBP06H/S25beMsel0BKqtjAdnte+5VIYKUjejYjQJ9bAJmNRaN4+veNRZv2oOJ8Qukk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675090863494717.0066619503461; Mon, 30 Jan 2023 07:01:03 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-103-sybXfM7lNP2EnV-sjOn_Mw-1; Mon, 30 Jan 2023 10:01:00 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24C852801E65; Mon, 30 Jan 2023 15:00:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10A24492B05; Mon, 30 Jan 2023 15:00:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7C21119465B8; Mon, 30 Jan 2023 15:00:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A11271946587 for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 922D4140EBF6; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A897140EBF5 for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E05638288A1 for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622-IcHCKDgbPsqeKPhZx8XtWA-1; Mon, 30 Jan 2023 10:00:27 -0500 Received: from [192.168.16.74] (helo=dv.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1pMVdq-00AYfM-S5; Mon, 30 Jan 2023 16:00:19 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675090862; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vaOpaA/w6OLJSRZX9Ahu+0hUc3YcxqoxjV8YqT4/ka4=; b=K0EZCRuzfxQ20B9/MCZF2jXfjFAPAt/yyXi+GDkJG9FbdoBpFAsTlBlfNPKwWKm7Zfh2OH LiErN3Vq9YAqkHQCGMPI4yDKbqRFgn5TAXo7PcDWFre3rJ7eyyMjbzEe32cKB20QuC5ai3 1pi5k1R99wuDfS9SHlpthZ7i4pimNVA= X-MC-Unique: sybXfM7lNP2EnV-sjOn_Mw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: IcHCKDgbPsqeKPhZx8XtWA-1 From: Oleg Vasilev To: libvir-list@redhat.com Subject: [PATCH v3 2/5] logging: move virLogHandler to header Date: Mon, 30 Jan 2023 20:59:59 +0600 Message-Id: <20230130150002.322315-3-oleg.vasilev@virtuozzo.com> In-Reply-To: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> References: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kletzander , Den Lunev , Oleg Vasilev Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675090870318100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Oleg Vasilev Reviewed-by: Martin Kletzander --- src/logging/log_handler.c | 26 -------------------------- src/logging/log_handler.h | 31 ++++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 7342404b00..8fc7e9b2a8 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -22,11 +22,9 @@ =20 #include "log_handler.h" #include "virerror.h" -#include "virobject.h" #include "virfile.h" #include "viralloc.h" #include "virlog.h" -#include "virrotatingfile.h" #include "viruuid.h" #include "virutil.h" =20 @@ -42,30 +40,6 @@ VIR_LOG_INIT("logging.log_handler"); =20 #define DEFAULT_MODE 0600 =20 -typedef struct _virLogHandlerLogFile virLogHandlerLogFile; -struct _virLogHandlerLogFile { - virRotatingFileWriter *file; - int watch; - int pipefd; /* Read from QEMU via this */ - bool drained; - - char *driver; - unsigned char domuuid[VIR_UUID_BUFLEN]; - char *domname; -}; - -struct _virLogHandler { - virObjectLockable parent; - - bool privileged; - virLogDaemonConfig *config; - - virLogHandlerLogFile **files; - size_t nfiles; - - virLogHandlerShutdownInhibitor inhibitor; - void *opaque; -}; =20 static virClass *virLogHandlerClass; static void virLogHandlerDispose(void *obj); diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h index c9af033cd3..d473a19fc6 100644 --- a/src/logging/log_handler.h +++ b/src/logging/log_handler.h @@ -23,13 +23,38 @@ #include "internal.h" #include "virjson.h" #include "log_daemon_config.h" - -typedef struct _virLogHandler virLogHandler; - +#include "virobject.h" +#include "virrotatingfile.h" =20 typedef void (*virLogHandlerShutdownInhibitor)(bool inhibit, void *opaque); =20 +typedef struct _virLogHandlerLogFile virLogHandlerLogFile; +struct _virLogHandlerLogFile { + virRotatingFileWriter *file; + int watch; + int pipefd; /* Read from QEMU via this */ + bool drained; + + char *driver; + unsigned char domuuid[VIR_UUID_BUFLEN]; + char *domname; +}; + +typedef struct _virLogHandler virLogHandler; +struct _virLogHandler { + virObjectLockable parent; + + bool privileged; + virLogDaemonConfig *config; + + virLogHandlerLogFile **files; + size_t nfiles; + + virLogHandlerShutdownInhibitor inhibitor; + void *opaque; +}; + virLogHandler *virLogHandlerNew(bool privileged, virLogDaemonConfig *config, virLogHandlerShutdownInhibitor inhibitor, --=20 2.39.1 From nobody Wed May 15 01:53:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1675090904; cv=none; d=zohomail.com; s=zohoarc; b=AVG/BUnzsdcLswvDRgBJW+bEzh/Wa8XF3pM6EzK8CksCNM20hj8C026HI3Wv8xEdph1edcDf58QbnksIhp6Dq13Aj0giuk6HyhpBK61yZvYhsK2NKBt+WpC7FFyJR5VoPiBPLkcUG1Xx9JLHTOP6Qku4TwjL1qSeaEn5qYgvY1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675090904; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O87h54K/5VMU8bfCqEjj6aBCEdAsre1omfuPiyL91z4=; b=lRmvC4eeUuZot0Fig/QNKHIxRvGoRzG8IHOov/L+BDXQvF0iHZmqSy/mw/ndGeaAJY+SaQ7HSsirQns9tL2NlJIc3SsmP97eGGx/kp5xe5P67wLFoylkpv9JmlyDHiHehNC5l3DqOkP6Q6zl2IkTQfn/jZjhl6UpbJeVCco57ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675090904381744.3865691411368; Mon, 30 Jan 2023 07:01:44 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-0xzjd0U2OAinAaGKE0mUCw-1; Mon, 30 Jan 2023 10:01:39 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F04129A9D4C; Mon, 30 Jan 2023 15:00:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBF7F1121314; Mon, 30 Jan 2023 15:00:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BAD21194658F; Mon, 30 Jan 2023 15:00:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EB4DF1946587 for ; Mon, 30 Jan 2023 15:00:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DF21D492B01; Mon, 30 Jan 2023 15:00:33 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast07.extmail.prod.ext.rdu2.redhat.com [10.11.55.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7646492B00 for ; Mon, 30 Jan 2023 15:00:33 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB9523C0F696 for ; Mon, 30 Jan 2023 15:00:33 +0000 (UTC) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-148-gckIwK1QMAiGGxQ1b9mGGQ-1; Mon, 30 Jan 2023 10:00:28 -0500 Received: from [192.168.16.74] (helo=dv.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1pMVdr-00AYfM-SV; Mon, 30 Jan 2023 16:00:20 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675090903; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=O87h54K/5VMU8bfCqEjj6aBCEdAsre1omfuPiyL91z4=; b=VFPE20hE38IMZqExu3lOLvBUZDEqSDqeEljhn7Qa66EmYBYd+jVaImE6iK0vqmJnFh9YZZ NUC1ned1TV79Gu8xSm13g79RYjeT47QufWzP+DoS21tBX2KsFfnOMm4P3sob1iXZtivYqp rDFnSLHBkor2NXL6TVl0vmIKu2fpBtA= X-MC-Unique: 0xzjd0U2OAinAaGKE0mUCw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: gckIwK1QMAiGGxQ1b9mGGQ-1 From: Oleg Vasilev To: libvir-list@redhat.com Subject: [PATCH v3 3/5] logging: add configuration for future log cleaner Date: Mon, 30 Jan 2023 21:00:00 +0600 Message-Id: <20230130150002.322315-4-oleg.vasilev@virtuozzo.com> In-Reply-To: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> References: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kletzander , Den Lunev , Oleg Vasilev Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675090910619100001 Content-Type: text/plain; charset="utf-8"; x-default="true" We want to specify the folder to clean and how much time can a log chain live. Signed-off-by: Oleg Vasilev Reviewed-by: Martin Kletzander --- src/logging/log_daemon_config.c | 9 +++++++++ src/logging/log_daemon_config.h | 3 +++ src/logging/test_virtlogd.aug.in | 2 ++ src/logging/virtlogd.aug | 2 ++ src/logging/virtlogd.conf | 14 ++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_confi= g.c index 4436745488..248bd927d3 100644 --- a/src/logging/log_daemon_config.c +++ b/src/logging/log_daemon_config.c @@ -28,6 +28,7 @@ #include "virutil.h" =20 #define VIR_FROM_THIS VIR_FROM_CONF +#define DEFAULT_LOG_ROOT LOCALSTATEDIR "/log/libvirt/" =20 VIR_LOG_INIT("logging.log_daemon_config"); =20 @@ -60,6 +61,7 @@ virLogDaemonConfigNew(bool privileged G_GNUC_UNUSED) data->admin_max_clients =3D 5000; data->max_size =3D 1024 * 1024 * 2; data->max_backups =3D 3; + data->max_age_days =3D 0; =20 return data; } @@ -72,6 +74,7 @@ virLogDaemonConfigFree(virLogDaemonConfig *data) =20 g_free(data->log_filters); g_free(data->log_outputs); + g_free(data->log_root); =20 g_free(data); } @@ -94,6 +97,12 @@ virLogDaemonConfigLoadOptions(virLogDaemonConfig *data, return -1; if (virConfGetValueSizeT(conf, "max_backups", &data->max_backups) < 0) return -1; + if (virConfGetValueSizeT(conf, "max_age_days", &data->max_age_days) < = 0) + return -1; + if (virConfGetValueString(conf, "log_root", &data->log_root) < 0) + return -1; + if (!data->log_root) + data->log_root =3D g_strdup(DEFAULT_LOG_ROOT); =20 return 0; } diff --git a/src/logging/log_daemon_config.h b/src/logging/log_daemon_confi= g.h index 2ab0f67c96..43922feedf 100644 --- a/src/logging/log_daemon_config.h +++ b/src/logging/log_daemon_config.h @@ -33,6 +33,9 @@ struct _virLogDaemonConfig { =20 size_t max_backups; size_t max_size; + + char *log_root; + size_t max_age_days; }; =20 =20 diff --git a/src/logging/test_virtlogd.aug.in b/src/logging/test_virtlogd.a= ug.in index cd5b0d91f8..8dfad39506 100644 --- a/src/logging/test_virtlogd.aug.in +++ b/src/logging/test_virtlogd.aug.in @@ -9,3 +9,5 @@ module Test_virtlogd =3D { "admin_max_clients" =3D "5" } { "max_size" =3D "2097152" } { "max_backups" =3D "3" } + { "max_age_days" =3D "0" } + { "log_root" =3D "/var/log/libvirt" } diff --git a/src/logging/virtlogd.aug b/src/logging/virtlogd.aug index 0f1b290c72..bdf61dea6e 100644 --- a/src/logging/virtlogd.aug +++ b/src/logging/virtlogd.aug @@ -31,6 +31,8 @@ module Virtlogd =3D | int_entry "admin_max_clients" | int_entry "max_size" | int_entry "max_backups" + | int_entry "max_age_days" + | str_entry "log_root" =20 (* Each entry in the config is one of the following three ... *) let entry =3D logging_entry diff --git a/src/logging/virtlogd.conf b/src/logging/virtlogd.conf index c53a1112bd..5214e96121 100644 --- a/src/logging/virtlogd.conf +++ b/src/logging/virtlogd.conf @@ -101,3 +101,17 @@ # Maximum number of backup files to keep. Defaults to 3, # not including the primary active file #max_backups =3D 3 + +# Maximum age for log files to live after the last modification. +# Defaults to 0, which means "forever". +# +# WARNING: since virtlogd has no way to differentiate which files it used = to +# manage, the garbage collection mechanism will collect ALL files, once it= s age +# reach max_age_days. Use only if you know what you mean. +#max_age_days =3D 0 + +# Root of all logs managed by virtlogd. Used to GC logs from obsolete mach= ines. +# +# WARNING: all files under this location potentially can be GC-ed. See the +# warning for max_age_days. +#log_root =3D "/var/log/libvirt" --=20 2.39.1 From nobody Wed May 15 01:53:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1675090905; cv=none; d=zohomail.com; s=zohoarc; b=VEOSir3VwnGZlDoog0u1zRRNVT0QwqUQYOCNlH0VbXkiwTDsBmyzSKc5zkPe56nkeS3LIxl+flgNhSDc6t/Tc0N1/78fB7XwA+CeD9c/bzuzmU21MqpXpkpf5hw6Wp6xS9ETVLIxoEnUWHOLVLYPfFsupoqXNRdmD8HyFaJWbDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675090905; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q1VA87LyqoPGhR7VpTMW8JuKpQ93IkTNWY4HiuwRcNI=; b=OdA5ms+yTjIv/4BxsC5r81xv59GKYgnsva+ZQ0trt8KZ0x4NcOf8i6bN/nBY2GiQx6Ek8mCqXKZOgSC0iNCtykRykFO3RWsJyejGFalxVYo+ulk3g2ImjyRj8gODXYZmWyB+C5087/ARqlsQxOkxwZHSlKwUt9TXS3xdyF8nWho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675090905433420.0219756754541; Mon, 30 Jan 2023 07:01:45 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-u_Z91cb7M7KpS2VwMZzsuA-1; Mon, 30 Jan 2023 10:01:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12DE51C0896F; Mon, 30 Jan 2023 15:00:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F068040444C0; Mon, 30 Jan 2023 15:00:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1C46A19465BD; Mon, 30 Jan 2023 15:00:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9208E194658F for ; Mon, 30 Jan 2023 15:00:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 695E6492B06; Mon, 30 Jan 2023 15:00:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61D31492B05 for ; Mon, 30 Jan 2023 15:00:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41AA885CBF5 for ; Mon, 30 Jan 2023 15:00:35 +0000 (UTC) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622-4TVZ7FpgMImN3gdpSnRdzw-1; Mon, 30 Jan 2023 10:00:30 -0500 Received: from [192.168.16.74] (helo=dv.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1pMVds-00AYfM-T0; Mon, 30 Jan 2023 16:00:21 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675090904; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Q1VA87LyqoPGhR7VpTMW8JuKpQ93IkTNWY4HiuwRcNI=; b=A//tFjxbGIxXg7VT/Tp+mLwtnqOyXHA7H7oBS+eW0tpvY6ZKz0SFGWf1jJ4oi4+BBzU5Rd P2Sqs2/xnJ9L4YcIi3eVze9MrGDBxRJdxrSVJV0+YHoelZe3VlydAxczlaz/ZY+FCxotge +V3NqUlS4fcDlBzd64vzGBQ9YlpV7w0= X-MC-Unique: u_Z91cb7M7KpS2VwMZzsuA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 4TVZ7FpgMImN3gdpSnRdzw-1 From: Oleg Vasilev To: libvir-list@redhat.com Subject: [PATCH v3 4/5] logging: add log cleanup for obsolete domains Date: Mon, 30 Jan 2023 21:00:01 +0600 Message-Id: <20230130150002.322315-5-oleg.vasilev@virtuozzo.com> In-Reply-To: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> References: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kletzander , Den Lunev , Oleg Vasilev Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675090916334100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Before, logs from deleted machines have been piling up, since there were no garbage collection mechanism. Now, virtlogd can be configured to periodically scan the log folder for orphan logs with no recent modificatio= ns and delete it. A single chain of recent and rotated logs is deleted in a single transactio= n. Signed-off-by: Oleg Vasilev Reviewed-by: Martin Kletzander --- po/POTFILES | 1 + src/logging/log_cleaner.c | 268 ++++++++++++++++++++++++++++++++++++++ src/logging/log_cleaner.h | 29 +++++ src/logging/log_handler.h | 2 + src/logging/meson.build | 1 + 5 files changed, 301 insertions(+) create mode 100644 src/logging/log_cleaner.c create mode 100644 src/logging/log_cleaner.h diff --git a/po/POTFILES b/po/POTFILES index 169e2a41dc..2fb6d18e27 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -123,6 +123,7 @@ src/locking/lock_driver_lockd.c src/locking/lock_driver_sanlock.c src/locking/lock_manager.c src/locking/sanlock_helper.c +src/logging/log_cleaner.c src/logging/log_daemon.c src/logging/log_daemon_dispatch.c src/logging/log_handler.c diff --git a/src/logging/log_cleaner.c b/src/logging/log_cleaner.c new file mode 100644 index 0000000000..3de54d0795 --- /dev/null +++ b/src/logging/log_cleaner.c @@ -0,0 +1,268 @@ +/* + * log_cleaner.c: cleans obsolete log files + * + * Copyright (C) 2022 Virtuozzo International GmbH + * + * 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 "log_cleaner.h" +#include "log_handler.h" + +#include "virerror.h" +#include "virobject.h" +#include "virfile.h" +#include "viralloc.h" +#include "virlog.h" +#include "virrotatingfile.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_LOGGING + +VIR_LOG_INIT("logging.log_cleaner"); + +/* Cleanup log root (/var/log/libvirt) and all subfolders (e.g. /var/log/l= ibvirt/qemu) */ +#define CLEANER_LOG_DEPTH 1 +#define CLEANER_LOG_TIMEOUT_MS (24 * 3600 * 1000) /* One day */ +#define MAX_TIME ((time_t) G_MAXINT64) + +static GRegex *log_regex; + +typedef struct _virLogCleanerChain virLogCleanerChain; +struct _virLogCleanerChain { + int rotated_max_index; + time_t last_modified; +}; + +typedef struct _virLogCleanerData virLogCleanerData; +struct _virLogCleanerData { + virLogHandler *handler; + time_t oldest_to_keep; + GHashTable *chains; +}; + +static const char* +virLogCleanerParseFilename(const char *path, + int *rotated_index) +{ + g_autoptr(GMatchInfo) matchInfo =3D NULL; + g_autofree const char *rotated_index_str =3D NULL; + g_autofree const char *clear_path =3D NULL; + const char *chain_prefix =3D NULL; + + clear_path =3D realpath(path, NULL); + if (!clear_path) { + VIR_WARN("Failed to resolve path %s: %s", path, g_strerror(errno)); + return NULL; + } + + if (!g_regex_match(log_regex, path, 0, &matchInfo)) + return NULL; + + chain_prefix =3D g_match_info_fetch(matchInfo, 1); + if (!rotated_index) + return chain_prefix; + + *rotated_index =3D 0; + rotated_index_str =3D g_match_info_fetch(matchInfo, 3); + + if (!rotated_index_str) + return chain_prefix; + + if (virStrToLong_i(rotated_index_str, NULL, 10, rotated_index) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse rotated index from '%s'"), + rotated_index_str); + return NULL; + } + return chain_prefix; +} + +static void +virLogCleanerProcessFile(virLogCleanerData *data, + const char *path, + struct stat *sb) +{ + int rotated_index =3D 0; + g_autofree const char *chain_prefix =3D NULL; + virLogCleanerChain *chain; + + if (!S_ISREG(sb->st_mode)) + return; + + chain_prefix =3D virLogCleanerParseFilename(path, &rotated_index); + + if (!chain_prefix) + return; + + if (rotated_index > data->handler->config->max_backups) { + if (unlink(path) < 0) { + VIR_WARN("Unable to delete %s: %s", path, g_strerror(errno)); + } + return; + } + + chain =3D g_hash_table_lookup(data->chains, chain_prefix); + + if (!chain) { + chain =3D g_new0(virLogCleanerChain, 1); + g_hash_table_insert(data->chains, g_steal_pointer((gpointer*) &cha= in_prefix), chain); + } + + chain->last_modified =3D MAX(chain->last_modified, sb->st_mtime); + chain->rotated_max_index =3D MAX(chain->rotated_max_index, + rotated_index); +} + +static GHashTable* +virLogCleanerCreateTable(virLogHandler *handler) +{ + /* HashTable: (const char*) chain_prefix -> (virLogCleanerChain*) chai= n */ + GHashTable *chains =3D g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); + size_t i; + virLogHandlerLogFile *file; + const char *chain_prefix; + virLogCleanerChain *chain; + VIR_LOCK_GUARD lock =3D virObjectLockGuard(handler); + + for (i =3D 0; i < handler->nfiles; i++) { + file =3D handler->files[i]; + chain_prefix =3D virLogCleanerParseFilename(virRotatingFileWriterG= etPath(file->file), + NULL); + if (!chain_prefix) + continue; + + chain =3D g_new0(virLogCleanerChain, 1); + chain->last_modified =3D MAX_TIME; /* Here we set MAX_TIME to the = currently + * opened files to prevent its de= letion. */ + g_hash_table_insert(chains, (void *) chain_prefix, chain); + } + + return chains; +} + +static void +virLogCleanerProcessFolder(virLogCleanerData *data, + const char *path, + int depth_left) +{ + DIR *dir; + struct dirent *entry; + struct stat sb; + + if (virDirOpenIfExists(&dir, path) < 0) + return; + + while (virDirRead(dir, &entry, path) > 0) { + g_autofree char *newpath =3D NULL; + + newpath =3D g_strdup_printf("%s/%s", path, entry->d_name); + + if (stat(newpath, &sb) < 0) { + VIR_WARN("Unable to stat %s: %s", newpath, g_strerror(errno)); + continue; + } + + if (S_ISDIR(sb.st_mode)) { + if (depth_left > 0) + virLogCleanerProcessFolder(data, newpath, depth_left - 1); + continue; + } + + virLogCleanerProcessFile(data, newpath, &sb); + } + + virDirClose(dir); +} + +static void +virLogCleanerDeleteFile(char *path) +{ + int rc; + if ((rc =3D unlink(path)) < 0 && errno !=3D ENOENT) + VIR_WARN("Unable to delete %s: %s", path, g_strerror(errno)); + VIR_FREE(path); +} + +static void +virLogCleanerChainCB(gpointer key, + gpointer value, + gpointer user_data) +{ + const char* chain_prefix =3D key; + virLogCleanerChain* chain =3D value; + virLogCleanerData* data =3D user_data; + size_t i; + + if (chain->last_modified > data->oldest_to_keep) + return; + + virLogCleanerDeleteFile(g_strdup_printf("%s.log", chain_prefix)); + + for (i =3D 0; i <=3D chain->rotated_max_index; i++) + virLogCleanerDeleteFile(g_strdup_printf("%s.log.%ld", chain_prefix= , i)); +} + +static void +virLogCleanerTimer(int timer G_GNUC_UNUSED, void *opaque) +{ + virLogHandler *handler =3D opaque; + virLogCleanerData data =3D { + .handler =3D handler, + .oldest_to_keep =3D time(NULL) - 3600 * 24 * handler->config->max_= age_days, + .chains =3D virLogCleanerCreateTable(handler), + }; + + /* First prepare the hashmap of chains to delete */ + virLogCleanerProcessFolder(&data, + handler->config->log_root, + CLEANER_LOG_DEPTH); + g_hash_table_foreach(data.chains, virLogCleanerChainCB, &data); + g_hash_table_destroy(data.chains); +} + +int +virLogCleanerInit(virLogHandler *handler) +{ + if (handler->config->max_age_days <=3D 0) + return 0; + + log_regex =3D g_regex_new("^(.*)\\.log(\\.(\\d+))?$", 0, 0, NULL); + if (!log_regex) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to compile regex")); + return -1; + } + + handler->cleanup_log_timer =3D virEventAddTimeout(CLEANER_LOG_TIMEOUT_= MS, + virLogCleanerTimer, + handler, NULL); + return handler->cleanup_log_timer; +} + +void +virLogCleanerShutdown(virLogHandler *handler) +{ + if (handler->cleanup_log_timer !=3D -1) { + virEventRemoveTimeout(handler->cleanup_log_timer); + handler->cleanup_log_timer =3D -1; + } + + g_regex_unref(log_regex); + log_regex =3D NULL; +} diff --git a/src/logging/log_cleaner.h b/src/logging/log_cleaner.h new file mode 100644 index 0000000000..1a9a94b68d --- /dev/null +++ b/src/logging/log_cleaner.h @@ -0,0 +1,29 @@ +/* + * log_cleaner.h: cleans obsolete log files + * + * Copyright (C) 2022 Virtuozzo International GmbH + * + * 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 "log_handler.h" + +int +virLogCleanerInit(virLogHandler *handler); + +void +virLogCleanerShutdown(virLogHandler *handler); diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h index d473a19fc6..97dad27eda 100644 --- a/src/logging/log_handler.h +++ b/src/logging/log_handler.h @@ -48,6 +48,8 @@ struct _virLogHandler { bool privileged; virLogDaemonConfig *config; =20 + int cleanup_log_timer; + virLogHandlerLogFile **files; size_t nfiles; =20 diff --git a/src/logging/meson.build b/src/logging/meson.build index 7066f16fad..fa6af50fa6 100644 --- a/src/logging/meson.build +++ b/src/logging/meson.build @@ -30,6 +30,7 @@ log_daemon_sources =3D files( 'log_daemon_config.c', 'log_daemon_dispatch.c', 'log_handler.c', + 'log_cleaner.c', ) =20 if conf.has('WITH_REMOTE') --=20 2.39.1 From nobody Wed May 15 01:53:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1675091030; cv=none; d=zohomail.com; s=zohoarc; b=Ul3pSdwb17K0ml28WU2x2UW4llPh+mny/41LeYBNMDJ9daLUH0cP9Qo9opE2TmV+fjJLI1rW907UDWCAMEXWvop/rxG7yNIXEL8akYGR7Y+v6ok8z4f/Si5s6uQI4GajuYeJiMRvigrlMDZpV5o0F6axsGzwAisNHZ7RZ6bKwW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675091030; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hlh4gjfTQHZHX+KbCIGg2bzFKIP+nKUUb+iIj/veDC0=; b=RUMRNAPhIQxTuSv9nB2r2fyVEumg8hdnCrmI1dV1P00LKQ1MzSp9rla6Bn368zOcQDu/iIbSzndQ5jVDGt8s6E514TXoRkOhtNjOrYIz0SOGmPi8Uiw3tAo0HxjQAtXlAS71DD8h73DOITcv2SvnsbeEkpNOQyHpCuT2JHPDqgE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675091030399514.947077087862; Mon, 30 Jan 2023 07:03:50 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-uwtFfLLGObeoVg2jqWawPA-1; Mon, 30 Jan 2023 10:01:01 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 552272801E5F; Mon, 30 Jan 2023 15:00:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DB9440C2064; Mon, 30 Jan 2023 15:00:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B41101946A46; Mon, 30 Jan 2023 15:00:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F39701946587 for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D70342166B29; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFCD12166B26 for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B518F85CBEA for ; Mon, 30 Jan 2023 15:00:30 +0000 (UTC) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-622-vNLZobwZNsKyhSXTpTxwNA-1; Mon, 30 Jan 2023 10:00:27 -0500 Received: from [192.168.16.74] (helo=dv.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1pMVdt-00AYfM-Tt; Mon, 30 Jan 2023 16:00:22 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675090869; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hlh4gjfTQHZHX+KbCIGg2bzFKIP+nKUUb+iIj/veDC0=; b=I0Ny5nL23vtSw9YPi8e9TLhbFRCi4a70igYCCv9YCp9OLcAqo+uaYA7sus+mMUgVv7NtVr tXIHANnla2fFnfmpZILz+jJ3CBarE5hoIHsH5VA6BgWes6NVIky14HhXdl76xzdDbWhLT8 Tpa5Z2P6idr2Tl2pSurBWw1N7JlydGQ= X-MC-Unique: uwtFfLLGObeoVg2jqWawPA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: vNLZobwZNsKyhSXTpTxwNA-1 From: Oleg Vasilev To: libvir-list@redhat.com Subject: [PATCH v3 5/5] logging: use the log cleaner Date: Mon, 30 Jan 2023 21:00:02 +0600 Message-Id: <20230130150002.322315-6-oleg.vasilev@virtuozzo.com> In-Reply-To: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> References: <20230130150002.322315-1-oleg.vasilev@virtuozzo.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Kletzander , Den Lunev , Oleg Vasilev Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675091031706100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Actually use the log cleaner introduced by previous commit. Signed-off-by: Oleg Vasilev Reviewed-by: Martin Kletzander --- src/logging/log_handler.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 8fc7e9b2a8..a739211c7c 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -21,6 +21,7 @@ #include =20 #include "log_handler.h" +#include "log_cleaner.h" #include "virerror.h" #include "virfile.h" #include "viralloc.h" @@ -175,7 +176,15 @@ virLogHandlerNew(bool privileged, handler->inhibitor =3D inhibitor; handler->opaque =3D opaque; =20 + if (virLogCleanerInit(handler) < 0) { + goto error; + } + return handler; + + error: + virObjectUnref(handler); + return NULL; } =20 =20 @@ -313,6 +322,8 @@ virLogHandlerDispose(void *obj) virLogHandler *handler =3D obj; size_t i; =20 + virLogCleanerShutdown(handler); + for (i =3D 0; i < handler->nfiles; i++) { handler->inhibitor(false, handler->opaque); virLogHandlerLogFileFree(handler->files[i]); --=20 2.39.1