Linux NFS development
 help / color / mirror / Atom feed
From: Thiago Becker <tbecker@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: steved@redhat.com, trond.myklebust@hammerspace.com,
	anna.schumaker@netapp.com, kolga@netapp.com,
	Thiago Becker <tbecker@redhat.com>
Subject: [PATCH v4 4/7] nfsrahead: add logging
Date: Fri,  1 Apr 2022 12:32:05 -0300	[thread overview]
Message-ID: <20220401153208.3120851-5-tbecker@redhat.com> (raw)
In-Reply-To: <20220401153208.3120851-1-tbecker@redhat.com>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283
Signed-off-by: Thiago Becker <tbecker@redhat.com>
---
 tools/nfsrahead/Makefile.am |  1 +
 tools/nfsrahead/main.c      | 40 ++++++++++++++++++++++++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am
index 0daddc4b..60a1102a 100644
--- a/tools/nfsrahead/Makefile.am
+++ b/tools/nfsrahead/Makefile.am
@@ -1,6 +1,7 @@
 libexec_PROGRAMS = nfsrahead
 nfsrahead_SOURCES = main.c
 nfsrahead_LDFLAGS= -lmount
+nfsrahead_LDADD = ../../support/nfs/libnfsconf.la
 
 udev_rulesdir = /usr/lib/udev/rules.d/
 udev_rules_DATA = 99-nfs.rules
diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c
index 8fe6d648..b630b92f 100644
--- a/tools/nfsrahead/main.c
+++ b/tools/nfsrahead/main.c
@@ -2,14 +2,19 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <libmount/libmount.h>
 #include <sys/sysmacros.h>
 
+#include "xlog.h"
+
 #ifndef MOUNTINFO_PATH
 #define MOUNTINFO_PATH "/proc/self/mountinfo"
 #endif
 
+#define CONF_NAME "nfsrahead"
+
 /* Device information from the system */
 struct device_info {
 	char *device_number;
@@ -108,25 +113,50 @@ static int get_device_info(const char *device_number, struct device_info *device
 	return ret;
 }
 
+#define L_DEFAULT (L_WARNING | L_ERROR | L_FATAL)
+
 int main(int argc, char **argv)
 {
 	int ret = 0;
 	struct device_info device;
-	unsigned int readahead = 128;
-
-	if (argc != 2) {
-		return -EINVAL;
+	unsigned int readahead = 128, verbose = 0, log_stderr = 0;
+	char opt;
+
+	while((opt = getopt(argc, argv, "dF")) != -1) {
+		switch (opt) {
+		case 'd':
+			verbose = 1;
+			break;
+		case 'F':
+			log_stderr = 1;
+			break;
+		}
 	}
 
-	if ((ret = get_device_info(argv[1], &device)) != 0) {
+	xlog_stderr(log_stderr);
+	xlog_syslog(~log_stderr);
+	xlog_config(L_DEFAULT | (L_NOTICE & verbose), 1);
+	xlog_open(CONF_NAME);
+
+	// xlog_err causes the system to exit
+	if ((argc - optind) != 1)
+		xlog_err("expected the device number of a BDI; is udev ok?");
+
+	if ((ret = get_device_info(argv[optind], &device)) != 0) {
+		xlog(L_ERROR, "unable to find device %s\n", argv[optind]);
 		goto out;
 	}
 
 	if (strncmp("nfs", device.fstype, 3) != 0) {
+		xlog(L_NOTICE,
+			"not setting readahead for non supported fstype %s on device %s\n",
+			device.fstype, argv[optind]);
 		ret = -EINVAL;
 		goto out;
 	}
 
+	xlog(L_WARNING, "setting %s readahead to %d\n", device.mountpoint, readahead);
+
 	printf("%d\n", readahead);
 
 out:
-- 
2.35.1


  parent reply	other threads:[~2022-04-01 16:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-01 15:32 [PATCH v4 0/7] Intruduce nfsrahead Thiago Becker
2022-04-01 15:32 ` [PATCH v4 1/7] Create nfsrahead Thiago Becker
2022-04-01 15:32 ` [PATCH v4 2/7] nfsrahead: configure udev Thiago Becker
2022-04-01 15:32 ` [PATCH v4 3/7] nfsrahead: only set readahead for nfs devices Thiago Becker
2022-04-01 15:32 ` Thiago Becker [this message]
2022-04-01 15:32 ` [PATCH v4 5/7] nfsrahead: get the information from the config file Thiago Becker
2022-04-01 15:32 ` [PATCH v4 6/7] nfsrahead: User documentation Thiago Becker
2022-04-04 12:13 ` [PATCH v4 7/7] nfsrahead: retry getting the device if it fails Thiago Becker
2022-04-19 19:57 ` [PATCH v4 0/7] Intruduce nfsrahead Steve Dickson

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=20220401153208.3120851-5-tbecker@redhat.com \
    --to=tbecker@redhat.com \
    --cc=anna.schumaker@netapp.com \
    --cc=kolga@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    --cc=trond.myklebust@hammerspace.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