Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1946283 Signed-off-by: Thiago Becker <tbecker@xxxxxxxxxx> --- tools/nfsrahead/Makefile.am | 1 + tools/nfsrahead/main.c | 40 +++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/tools/nfsrahead/Makefile.am b/tools/nfsrahead/Makefile.am index afccc520..d0b5d170 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 = /etc/udev/rules.d udev_rules_DATA = 99-nfs_bdi.rules diff --git a/tools/nfsrahead/main.c b/tools/nfsrahead/main.c index 2cf77424..86c71a67 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,26 +113,49 @@ 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, char **envp) { 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; } - info("Setting %s readahead to 128\n", device.mountpoint); + xlog(L_WARNING, "setting %s readahead to %d\n", device.mountpoint, readahead); printf("%d\n", readahead); -- 2.35.1