Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp706870pxp; Fri, 11 Mar 2022 12:54:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYHhGyQkhfF89kr49pGTpwxkunvq8y9WxN34OpOWslOjVisRWUMCDRqczKW4mE8XtXsfpx X-Received: by 2002:a17:902:e889:b0:151:a56d:eb8f with SMTP id w9-20020a170902e88900b00151a56deb8fmr11925688plg.142.1647032098613; Fri, 11 Mar 2022 12:54:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647032098; cv=none; d=google.com; s=arc-20160816; b=VFFph0mash5f17MpIlfeNRuFROQDWPtqT7J9mi0P9NXRuU8kCnHKgZ18J7G4tej8SV pwnSlWOxHtZMW1H/Rsirn11BauYti8ZGfr7k7+GJFCoOcApRYn1NQGDFHVJOHuDLKziX yJQ6TO1RFRFx8tMTEUksmqR4JvH+rAt/lqwdEOjOKwWa53dV6IMcIZk7bfGfaJDnWs4m X+YAn2PHoypNkUTu3/jMH26hdZ/47UlHeWwqBJxyylyLjkAcS+yw0LQ0aWOjgg3oY03b AV4sPod0e1e4rmt4/5uoUM0RHuZEMy6Vg2Y7Y40MuzNXxV+GsXdqmaYMeMED8sbcSwW6 Kp6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PX82FmfUjpzWNaKubKpmm2Pr9P/DWkk8799evqvgPWk=; b=sZ20EvP8Snv2G2JEcjPlplD5mnXkjN2Lzc7p51+bkwI7rQK1b737VhzaMqKRehK5rB KFgiGTyvLKf4UqLeSbBEg/46JyfnLzvsAqN+2K9/Xf9gWB9c3cQKtK4DzqHonjXyONIf EiULoFW6/W1va3DVtbEZFQSCITp6J6ZyLXaoyQp+X7OBeKa5psZ18AwrUSKlP2MOI8d/ ay1YMKoh51DBxRT/3LcP5lyKnBNJB0SJvX6zDCPIQSKWD9jj84P2+wuTfKvuIju7S1zv 2HxWWrBn60etQBTtlau7IhNwuYIJZX8LyWJKtqyRVeOt96BUiisoWmIcKj0jtVgJKglB e+nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P0GqGqwa; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o16-20020a63f150000000b00372ceaad167si8476761pgk.406.2022.03.11.12.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 12:54:58 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P0GqGqwa; spf=softfail (google.com: domain of transitioning linux-nfs-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 431931F1255; Fri, 11 Mar 2022 12:46:07 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348705AbiCKTH7 (ORCPT + 99 others); Fri, 11 Mar 2022 14:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351030AbiCKTHw (ORCPT ); Fri, 11 Mar 2022 14:07:52 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F9091AE650 for ; Fri, 11 Mar 2022 11:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647025606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PX82FmfUjpzWNaKubKpmm2Pr9P/DWkk8799evqvgPWk=; b=P0GqGqwawdFUfuOnuxGV7hhBzyuYuTxF6oiBmYGwdsaFNXprhTjnq/5UZCQlT/YyD0lpxP I5Ilk0a+gBjUC9gQNfA4SwOZtCPS6XoEyZAuF52PYe8KUjvW+kMUOPJt8JlujuildtUFRj eWLgPtoGFV5FVl0C8Kxq4/YVqI16RKo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-OALZsrckPFOJNxXfwHTk3w-1; Fri, 11 Mar 2022 14:06:45 -0500 X-MC-Unique: OALZsrckPFOJNxXfwHTk3w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B07C1006AA6; Fri, 11 Mar 2022 19:06:44 +0000 (UTC) Received: from nyarly.rlyeh.local (ovpn-116-72.gru2.redhat.com [10.97.116.72]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A72260BF4; Fri, 11 Mar 2022 19:06:39 +0000 (UTC) From: Thiago Becker To: linux-nfs@vger.kernel.org Cc: steved@redhat.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com, kolga@netapp.com, Thiago Becker Subject: [RFC v2 PATCH 3/7] readahead: create logging facility Date: Fri, 11 Mar 2022 16:06:13 -0300 Message-Id: <20220311190617.3294919-4-tbecker@redhat.com> In-Reply-To: <20220311190617.3294919-1-tbecker@redhat.com> References: <20220311190617.3294919-1-tbecker@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Create logs for nfs-readahead-udev, logging to syslog. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker --- tools/nfs-readahead-udev/Makefile.am | 2 +- tools/nfs-readahead-udev/log.h | 16 ++++++++++ tools/nfs-readahead-udev/main.c | 8 +++++ tools/nfs-readahead-udev/syslog.c | 47 ++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tools/nfs-readahead-udev/log.h create mode 100644 tools/nfs-readahead-udev/syslog.c diff --git a/tools/nfs-readahead-udev/Makefile.am b/tools/nfs-readahead-udev/Makefile.am index 873cc175..5078db9a 100644 --- a/tools/nfs-readahead-udev/Makefile.am +++ b/tools/nfs-readahead-udev/Makefile.am @@ -1,5 +1,5 @@ libexec_PROGRAMS = nfs-readahead-udev -nfs_readahead_udev_SOURCES = main.c +nfs_readahead_udev_SOURCES = main.c syslog.c udev_rulesdir = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfs-readahead-udev/log.h b/tools/nfs-readahead-udev/log.h new file mode 100644 index 00000000..2a14e552 --- /dev/null +++ b/tools/nfs-readahead-udev/log.h @@ -0,0 +1,16 @@ +#ifndef __ra_log_h__ +#define __ra_log_h__ +#include + +extern void log_open(void); +extern void log_close(void); + +extern void debug(const char *, ...); +extern void info(const char *, ...); +extern void notice(const char *, ...); +extern void warn(const char *, ...); +extern void err(const char *, ...); +extern void crit(const char *, ...); +extern void alert(const char *, ...); +extern void emerg(const char *, ...); +#endif diff --git a/tools/nfs-readahead-udev/main.c b/tools/nfs-readahead-udev/main.c index e454108e..dd2c9f8c 100644 --- a/tools/nfs-readahead-udev/main.c +++ b/tools/nfs-readahead-udev/main.c @@ -1,7 +1,15 @@ #include +#include "log.h" + int main(int argc, char **argv, char **envp) { unsigned int readahead = 128; + + log_open(); + + info("Setting the readahead to 128\n"); + + log_close(); printf("%d\n", readahead); } diff --git a/tools/nfs-readahead-udev/syslog.c b/tools/nfs-readahead-udev/syslog.c new file mode 100644 index 00000000..5eeb2579 --- /dev/null +++ b/tools/nfs-readahead-udev/syslog.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include "log.h" + +#define MSG_SIZE (1024 * sizeof(char)) + +void log_open(void) +{ + openlog("nfs_readahead", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); + setlogmask(LOG_UPTO(LOG_DEBUG)); +} + +void log_close(void) +{ + closelog(); +} + +static void vlog(int level, const char *fmt, va_list *args) +{ + char *msg = malloc(MSG_SIZE); + if (!msg) + return; + + vsnprintf(msg, MSG_SIZE, fmt, *args); + syslog(level, "%s", msg); + + free(msg); +} + +#define GENERATE_LOGGER(name, level) \ + void name(const char *fmt, ...) { \ + va_list args; \ + va_start(args, fmt); \ + vlog(LOG_##level, fmt, &args); \ + va_end(args); \ +} + +GENERATE_LOGGER(debug, DEBUG); +GENERATE_LOGGER(info, INFO); +GENERATE_LOGGER(notice, NOTICE); +GENERATE_LOGGER(warn, WARNING); +GENERATE_LOGGER(err, ERR); +GENERATE_LOGGER(crit, CRIT); +GENERATE_LOGGER(alert, ALERT); +GENERATE_LOGGER(emerg, EMERG); -- 2.35.1