From nobody Mon Feb 9 20:10:53 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=oracle.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1709192901511272.5398029491291; Wed, 28 Feb 2024 23:48:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 700A21B6D; Thu, 29 Feb 2024 02:48:20 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1C39B1A45; Thu, 29 Feb 2024 02:46:19 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7A5E41A40; Thu, 29 Feb 2024 02:46:15 -0500 (EST) Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 9BA131A22 for ; Thu, 29 Feb 2024 02:46:14 -0500 (EST) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41T1x9te016399 for ; Thu, 29 Feb 2024 06:47:09 GMT Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3wf7ccmj1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 29 Feb 2024 06:47:08 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 41T6cXbP019283 for ; Thu, 29 Feb 2024 06:47:07 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3wgbdnvwqv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 29 Feb 2024 06:47:07 +0000 Received: from SJ0PR10MB5768.namprd10.prod.outlook.com (2603:10b6:a03:421::12) by CH2PR10MB4150.namprd10.prod.outlook.com (2603:10b6:610:ac::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Thu, 29 Feb 2024 06:47:06 +0000 Received: from SJ0PR10MB5768.namprd10.prod.outlook.com ([fe80::64bd:3256:48da:16cc]) by SJ0PR10MB5768.namprd10.prod.outlook.com ([fe80::64bd:3256:48da:16cc%7]) with mapi id 15.20.7316.039; Thu, 29 Feb 2024 06:47:05 +0000 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=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y42D9QE6Kj8xf5PdXwdNEQlGHMnGM4+d8/X2B9Pw7BZwxu0Wz1Jz4+So5jZ3I0uKBEaFHzFdmbuiNClRGQgLTExW5TUSdp9dkYC1q6e95YmwSDi6qiRi2pWvlhy64pSx5hp99LBW0gVnnfUIfCDOG2bemmevOQBYc/ggC+Zw9y66eq1ZoUiV36gdt2Zp98KIOQJ9/sTzIiRXQd9U/XKyQHx/buZ45brXDsBZ7YfjWKoDzh6xW/4/Jyey9QmsRNQ/8TWgdosoyCiO3n7xRGGn950RjRKCUJ9NlNDUUhuOahVTMeVcQSaQOcHxz1OtmiWOz4ozNA+bzfWUlzOiMwJBVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3i0/9EuLFPMAsAv/p2bxLAoUfLD3afoiMGqbA9tNNJI=; b=Zro7tm9RlA9TYlgIsJvCI/HhuLrs0qOV4tIxKnOOhGsyvezltIxs85VNI/1uNykxkvzdlnpA+Fg+ILXVIHLQmQcMPBbRzvZSvvKh7hSVlmjTZ5DsKW0AZ0Xl94/mce23kDoafqWOdqSe5hYccsA30L4gCiR/BmUJGsKt4x4FaSB8WFnkfQrLG80C/94lhteR6PuTAdAqZa+2WB+42vLcyzLz8yks33A0TQLU/FNRomPN/yjezRo/gzWgsmmAhIQ+USwCefHCy3oBnxJmT4F5+Ura35gGsHvJ77neNcTJjYA+Bz3JdR16l6NHNwaypJbmGLJDbGh3pZaP3yRYLSQxlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none From: Shaleen Bathla To: devel@lists.libvirt.org Subject: [libvirt] [PATCH 3/4] util: virrotatingfile: virtlogd timestamp appending logic Date: Thu, 29 Feb 2024 12:16:38 +0530 Message-Id: <20240229064639.1731653-4-shaleen.bathla@oracle.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240229064639.1731653-1-shaleen.bathla@oracle.com> References: <20240229064639.1731653-1-shaleen.bathla@oracle.com> X-ClientProxiedBy: SJ0PR03CA0331.namprd03.prod.outlook.com (2603:10b6:a03:39c::6) To SJ0PR10MB5768.namprd10.prod.outlook.com (2603:10b6:a03:421::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5768:EE_|CH2PR10MB4150:EE_ X-MS-Office365-Filtering-Correlation-Id: fa6763f9-4cae-4c94-249f-08dc38f23e45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t3b2A1gLcHla71M+8QtRe+vSY3K4PvqcyglJoifiRO9ZNoktk9v9iU+78wPcuaIXOUBQC8fCYRHIDmHxKzdGnHfp2mUGXXaHBQK5NQsnlbAv7Gj2WRKEUwKXJfwoK8bpQcqUHRS5g1e99bQMmJkQ0t354mP7kM85p37ediboLq5MDdoUanqEzetiGU9UdbcYpWdzbhZNNzWylgLp3mxZvvbHiqy7LqAQ+6u3WWtSEimSUZ+PevRTMLpdVj8e8RbUiOfaN/FPH1XJZtnMx48ofLhOsRXxxy69Z8XxfxApmRv6yB0lkC+h3U6XQiiCjAamz5lP/kM+4MDTGg1tImrir7aKFOT7u7SO0o6cQwvt0MxBS1BWb+c8EPJkC2F5jwB8c34sNW8OX3Lg0ZNKb3LzUK5/DOCvmTOnQuSj1zNyUalsTV7Qb5eUMWbAPUEMsA82TDME7h/XU1e2xSFokuQgl5OndRLFHJEKTlm0ybvFV4wf6T4fckTBfk++khqBNkzGtn/5MjZtF8rgfXPkYDoEh76xxjtAmXa8RXlAKezOIhNRE5Hhh9KJGY6VWZ8Jv9D081okW0TeT1EUVqoeYUjw4duUrNAabzdH+sHY/iyQualh+r45Ait+TZdS+gjucJaWwgYLAGrWEaYmvWncCIZLrA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5768.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?G/28ZiIyjeZOoG6LOO5o2LpvAeI6fx4H4aHRJxo7Z+7VmcW+vBOgFMuJRJHm?= =?us-ascii?Q?n/oLrf6G1C1HTiwMxv8ffXrntV+8HRuhXg17is7m93knoAM9DiTNrG+03XAf?= =?us-ascii?Q?Br28BuAW9EbVgD8JYCszQjsjZH9MoGGsr9GD0FLVTNa5XPJnnp1Wd30SboBN?= =?us-ascii?Q?7LsaoD1/xMUYJ6M5cMul3TyCGiGaKFyYEiOmI7ClwuTfqSUoH3HubZcrbODz?= =?us-ascii?Q?WhFq80+dQBcLyAj94ik2Sl/gcQxbS0j5fja9Zs3Q7V1CbJHES0P8gEr+0Zsl?= =?us-ascii?Q?em7COgihb4YCTiK5BsO6cQmlK4Zl9GyUTaU2np9IsMmjo9BcV5euJeNeV+K8?= =?us-ascii?Q?tnSTp3/FxRZWDBtvE+Z2hM269z3b+ngrrQbsZftBsvJzDDN8Q6LdcphVFw6i?= =?us-ascii?Q?9JWtATR7q90fzIUDU/eBGQsgytcQpDEsPsaJEyqLdfcKWs+WLHVlamHOvtZr?= =?us-ascii?Q?Zi68QQoIyLtyblme18OBJY1t2WIa3W/aniz9CktuFA3LQ29UQpLk7I2R80hO?= =?us-ascii?Q?wCvfap9EWAlRTzGMZeKl701vkpfvBFKRdJMqRZh6T0uITC4Irn/ep9Ydu02J?= =?us-ascii?Q?mhZBk+Tgfngl6gAnBp/oqddam0WlHZ8lJ7e3DS6qPyH++zuwmEF9asnJnoV3?= =?us-ascii?Q?jVUa27iIZO4LU0hKXzS2k4x7DcG98YGsFTcPOr8Bj5+IiLOJ8gxg6rBcGs7O?= =?us-ascii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3yCDCyeoQb1D3pAKE9dLlGmTIAtEdfDi+ivFsp?= =?us-ascii?Q?1g=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Pc86j5r7ykv6RB6KC4Pyd+1+jt6iNEBzLGD+K5Bxm67i3Y3Dc7WUF/tZlEsLXqQwxLXwnlPbu9un7STxa2RIdamSYhYQR3+9Kx5cg0FBukD8wrLU0viwWTH32I7WUlqvQqcxGDas+cy1MMnqNqHYXQAKU29PuEvr8NiZF0FUFrqvD0EVQ9x5OWXNmfPnQzSNYXNNXsCeG8OkTVfH2iDwhi+S3OyfCILjxROd0zn7tElkKWDWNVjGtXtrMPiJzhDPMTNPOtWN4PecBx26Nyn1HgEpbOr25TH1EqZfTQUvaDyCvYwrO/Erb6RgsWSj9YI2KwBP2MV2XuXlLMmuHdLvvq5Kp71G37brmXrLT9+XNknZA9adQIrWj1WXQfjKk57iUsIcVD8RD73G1EoWHEWsnpipsiNqHVaJHHCAPKiiYGZMSjM8wFNZxBCWwUIV+iTXKBSUqXM8otu/sIwZSXeBvzZBH2l1sFks3t646F6jV0/XYetZW/3uX4KVyCOE2BHP5JcOXl6pH2Q6nMJwWkmG4V3lCWVqyBuLbHgWe5aaLhfJGvuMt4kKq878Uca7u4KTeJs6MreA67xdCj5nH86uZUcs1zZYT4HR2erFWcU5bt4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa6763f9-4cae-4c94-249f-08dc38f23e45 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5768.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 06:47:05.8651 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1cJjLPFEKi0pQ5Jx0tO+yZzRGkr3EysqD6iCmVGNxptg+UwkxRZkWaaTU1aiwVwxKS/0ukr1nuNexRgrA7UD9txLjia2w3062H0EsyLxAqs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4150 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-28_08,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 mlxscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402290051 X-Proofpoint-ORIG-GUID: -pladK4Hpg2hfv-o7o70Jrnp90iCsfwh X-Proofpoint-GUID: -pladK4Hpg2hfv-o7o70Jrnp90iCsfwh Message-ID-Hash: EAHE4SUWCKBV7UHHJFRAESQCIM7CID7X X-Message-ID-Hash: EAHE4SUWCKBV7UHHJFRAESQCIM7CID7X X-MailFrom: shaleen.bathla@oracle.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 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: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1709192903582100001 Make use of timestamp option in virtlogd config and append timestamp to domain event logs after every '\n' character. Signed-off-by: Shaleen Bathla --- src/logging/log_handler.c | 10 +++++++--- src/util/virrotatingfile.c | 36 ++++++++++++++++++++++++++++++++++-- src/util/virrotatingfile.h | 3 ++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 71517bbbe5ff..9be338d92ca1 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -116,6 +116,7 @@ virLogHandlerDomainLogFileEvent(int watch, virLogHandlerLogFile *logfile; char buf[1024]; ssize_t len; + bool timestamp =3D false; =20 virObjectLock(handler); logfile =3D virLogHandlerGetLogFileFromWatch(handler, watch); @@ -130,6 +131,9 @@ virLogHandlerDomainLogFileEvent(int watch, goto cleanup; } =20 + if (handler->config && handler->config->timestamp) + timestamp =3D true; + reread: len =3D read(fd, buf, sizeof(buf)); if (len < 0) { @@ -143,7 +147,7 @@ virLogHandlerDomainLogFileEvent(int watch, goto error; } =20 - if (virRotatingFileWriterAppend(logfile->file, buf, len) !=3D len) + if (virRotatingFileWriterAppend(logfile->file, buf, len, timestamp) != =3D len) goto error; =20 cleanup: @@ -440,7 +444,7 @@ virLogHandlerDomainLogFileDrain(virLogHandlerLogFile *f= ile) return; } =20 - if (virRotatingFileWriterAppend(file->file, buf, len) !=3D len) + if (virRotatingFileWriterAppend(file->file, buf, len, 0) !=3D len) return; } } @@ -568,7 +572,7 @@ virLogHandlerDomainAppendLogFile(virLogHandler *handler, writer =3D newwriter; } =20 - if (virRotatingFileWriterAppend(writer, message, strlen(message)) < 0) + if (virRotatingFileWriterAppend(writer, message, strlen(message), 0) <= 0) goto cleanup; =20 ret =3D 0; diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c index 2a44c9bf93e3..5443e850721b 100644 --- a/src/util/virrotatingfile.c +++ b/src/util/virrotatingfile.c @@ -431,7 +431,7 @@ virRotatingFileWriterAppendTimestamp(virRotatingFileWri= ter* file) timestamp[len-1] =3D ' '; timestamp[len] =3D '\0'; =20 - if (virRotatingFileWriterAppend(file, timestamp, len) !=3D len) { + if (virRotatingFileWriterAppend(file, timestamp, len, 0) !=3D len) { g_free(timestamp); return -1; } @@ -446,6 +446,7 @@ virRotatingFileWriterAppendTimestamp(virRotatingFileWri= ter* file) * @file: the file context * @buf: the data buffer * @len: the number of bytes in @buf + * @timestamp: append timestamp config option * * Append the data in @buf to the file, performing rollover * of the files if their size would exceed the limit @@ -455,10 +456,12 @@ virRotatingFileWriterAppendTimestamp(virRotatingFileW= riter* file) ssize_t virRotatingFileWriterAppend(virRotatingFileWriter *file, const char *buf, - size_t len) + size_t len, + bool timestamp) { ssize_t ret =3D 0; size_t i; + while (len) { size_t towrite =3D len; bool forceRollover =3D false; @@ -488,6 +491,35 @@ virRotatingFileWriterAppend(virRotatingFileWriter *fil= e, } } =20 + if (timestamp && towrite) { + int last_nl =3D -1; + for (i =3D 0; i < towrite; i++) { + if (buf[i] =3D=3D '\n') { + if (safewrite(file->entry->fd, buf+last_nl+1, i-last_n= l) !=3D i-last_nl) { + virReportSystemError(errno, + _("Unable to write to fil= e %1$s"), + file->basepath); + return -1; + } + if (virRotatingFileWriterAppendTimestamp(file) !=3D 0)= { + virReportSystemError(errno, + _("Unable to write to fil= e %1$s"), + file->basepath); + return -1; + } + last_nl =3D i; + } + } + + last_nl++; + buf +=3D last_nl; + len -=3D last_nl; + ret +=3D last_nl; + file->entry->pos +=3D last_nl; + file->entry->len +=3D last_nl; + towrite -=3D last_nl; + } + if (towrite) { if (safewrite(file->entry->fd, buf, towrite) !=3D towrite) { virReportSystemError(errno, diff --git a/src/util/virrotatingfile.h b/src/util/virrotatingfile.h index 1ed8838e7df2..388774bc3913 100644 --- a/src/util/virrotatingfile.h +++ b/src/util/virrotatingfile.h @@ -43,7 +43,8 @@ off_t virRotatingFileWriterGetOffset(virRotatingFileWrite= r *file); =20 ssize_t virRotatingFileWriterAppend(virRotatingFileWriter *file, const char *buf, - size_t len); + size_t len, + bool timestamp); =20 int virRotatingFileReaderSeek(virRotatingFileReader *file, ino_t inode, --=20 2.39.3 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org