From: Thiago Rafael Becker <trbecker@gmail.com>
To: linux-nfs@vger.kernel.org
Cc: tbecker@redhat.com, steved@redhat.com, chuck.lever@oracle.com,
Thiago Rafael Becker <trbecker@gmail.com>
Subject: [RFC PATCH 3/7] readahead: create logging facility
Date: Wed, 9 Mar 2022 15:26:49 -0300 [thread overview]
Message-ID: <20220309182653.1885252-4-trbecker@gmail.com> (raw)
In-Reply-To: <20220309182653.1885252-1-trbecker@gmail.com>
Create logs for nfs-readahead-udev, logging to syslog.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283
Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
---
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 <stdarg.h>
+
+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 <stdio.h>
+#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 <syslog.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#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
next prev parent reply other threads:[~2022-03-09 18:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-09 18:26 [RFC PATCH 0/7] Introduce nfs-readahead-udev Thiago Rafael Becker
2022-03-09 18:26 ` [RFC PATCH 1/7] Create nfs-readahead-udev Thiago Rafael Becker
2022-03-09 18:26 ` [RFC PATCH 2/7] readahead: configure udev Thiago Rafael Becker
2022-03-09 18:26 ` Thiago Rafael Becker [this message]
2022-03-09 18:26 ` [RFC PATCH 4/7] readahead: only set readahead for nfs devices Thiago Rafael Becker
2022-03-09 18:26 ` [RFC PATCH 5/7] readahead: create the configuration file Thiago Rafael Becker
2022-03-09 18:26 ` [RFC PATCH 6/7] readahead: add mountpoint and fstype options Thiago Rafael Becker
2022-03-09 18:26 ` [RFC PATCH 7/7] readahead: documentation Thiago Rafael Becker
2022-03-09 19:33 ` [RFC PATCH 0/7] Introduce nfs-readahead-udev Chuck Lever III
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220309182653.1885252-4-trbecker@gmail.com \
--to=trbecker@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
--cc=tbecker@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox