From: Steve Dickson <steved@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Subject: [PATCH 1/1] conffile: process config.d directory config files.
Date: Thu, 29 Oct 2020 17:04:01 -0400 [thread overview]
Message-ID: <20201029210401.446244-2-steved@redhat.com> (raw)
In-Reply-To: <20201029210401.446244-1-steved@redhat.com>
When a /etc/nfs.conf.d or /etc/nfsmount.conf.d directory
exists and there are config file(s) in those directory
exist, those config file(s) are used instead of the given
/etc/nfs.conf and /etc/nfsmount.conf files.
Signed-off-by: Steve Dickson <steved@redhat.com>
---
support/nfs/conffile.c | 78 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 77 insertions(+), 1 deletion(-)
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index 3d13610..c60e511 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -52,6 +52,7 @@
#include <libgen.h>
#include <sys/file.h>
#include <time.h>
+#include <dirent.h>
#include "conffile.h"
#include "xlog.h"
@@ -609,6 +610,69 @@ conf_load_file(const char *conf_file)
return 0;
}
+static int
+conf_init_dir(const char *conf_file)
+{
+ struct dirent **namelist = NULL;
+ char *dname, fname[PATH_MAX + 1];
+ int n = 0, nfiles = 0, i, fname_len, dname_len;
+
+ dname = malloc(strlen(conf_file) + 3);
+ if (dname == NULL) {
+ xlog(L_WARNING, "conf_init_dir: malloc: %s", strerror(errno));
+ return nfiles;
+ }
+ sprintf(dname, "%s.d", conf_file);
+
+ n = scandir(dname, &namelist, NULL, versionsort);
+ if (n < 0) {
+ if (errno != ENOENT) {
+ xlog(L_WARNING, "conf_init_dir: scandir %s: %s",
+ dname, strerror(errno));
+ }
+ free(dname);
+ return nfiles;
+ } else if (n == 0) {
+ free(dname);
+ return nfiles;
+ }
+
+ dname_len = strlen(dname);
+ for (i = 0; i < n; i++ ) {
+ struct dirent *d = namelist[i];
+
+ switch (d->d_type) {
+ case DT_UNKNOWN:
+ case DT_REG:
+ case DT_LNK:
+ break;
+ default:
+ continue;
+ }
+ if (*d->d_name == '.')
+ continue;
+
+ fname_len = strlen(d->d_name);
+ if (!fname_len || (fname_len + dname_len) > PATH_MAX) {
+ xlog(L_WARNING, "conf_init_dir: Too long file name: %s in %s",
+ d->d_name, dname);
+ continue;
+ }
+ sprintf(fname, "%s/%s", dname, d->d_name);
+
+ if (conf_load_file(fname))
+ continue;
+ nfiles++;
+ }
+
+ for (i = 0; i < n; i++)
+ free(namelist[i]);
+ free(namelist);
+ free(dname);
+
+ return nfiles;
+}
+
int
conf_init_file(const char *conf_file)
{
@@ -619,7 +683,19 @@ conf_init_file(const char *conf_file)
TAILQ_INIT (&conf_trans_queue);
- if (conf_file == NULL) conf_file=NFS_CONFFILE;
+ if (conf_file == NULL)
+ conf_file=NFS_CONFFILE;
+
+ /*
+ * Check to see if there is a config directory
+ * if so use those file(s) if they exist
+ */
+ if (conf_init_dir(conf_file) != 0)
+ return 0;
+
+ /*
+ * Otherwise using the giving config file
+ */
return conf_load_file(conf_file);
}
--
2.26.2
next prev parent reply other threads:[~2020-10-29 21:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 21:04 [RFC PATCH 0/1] Enable config.d directory to be processed Steve Dickson
2020-10-29 21:04 ` Steve Dickson [this message]
2020-11-02 13:03 ` Alice Mitchell
2020-11-02 13:24 ` Steve Dickson
2020-11-02 14:23 ` Steve Dickson
2020-11-02 15:05 ` Alice Mitchell
2020-11-02 15:16 ` Chuck Lever
2020-11-02 16:37 ` Steve Dickson
2020-11-02 16:42 ` Steve Dickson
2020-11-02 15:57 ` Alice Mitchell
2020-11-02 19:42 ` Steve Dickson
2020-11-02 22:01 ` McIntyre, Vincent (CASS, Marsfield)
2020-11-03 10:14 ` Alice Mitchell
2020-11-03 17:16 ` 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=20201029210401.446244-2-steved@redhat.com \
--to=steved@redhat.com \
--cc=linux-nfs@vger.kernel.org \
/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