summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorScott Mayhew <smayhew@redhat.com>2017-02-15 10:21:40 -0500
committerSteve Dickson <steved@redhat.com>2017-02-15 10:41:59 -0500
commita15bd948606bf4816bf819c0b0c75761f3eb6359 (patch)
treeb0d721f8b474f26ebe7415ecb3dae7e4a7cace15 /utils
parent1789737ec6dd43c9d1436aeb6c07fab52206f412 (diff)
downloadnfs-utils-a15bd948606bf4816bf819c0b0c75761f3eb6359.tar.gz
mountd/exportfs: implement the -s/--state-directory-path option
Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Scott Mayhew <smayhew@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/exportfs/exportfs.c13
-rw-r--r--utils/exportfs/exportfs.man23
-rw-r--r--utils/mountd/auth.c8
-rw-r--r--utils/mountd/mountd.c31
-rw-r--r--utils/mountd/mountd.man2
-rw-r--r--utils/mountd/rmtab.c26
6 files changed, 76 insertions, 27 deletions
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 61dddfb..02d5b6d 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -52,6 +52,8 @@ static const char *lockfile = EXP_LOCKFILE;
static int _lockfd = -1;
char *conf_path = NFS_CONFFILE;
+struct state_paths etab;
+
/*
* If we aren't careful, changes made by exportfs can be lost
* when multiple exports process run at once:
@@ -95,6 +97,7 @@ main(int argc, char **argv)
int f_ignore = 0;
int i, c;
int force_flush = 0;
+ char *s;
if ((progname = strrchr(argv[0], '/')) != NULL)
progname++;
@@ -108,6 +111,11 @@ main(int argc, char **argv)
conf_init();
xlog_from_conffile("exportfs");
+ /* NOTE: following uses "mountd" section of nfs.conf !!!! */
+ s = conf_get_str("mountd", "state-directory-path");
+ if (s && !state_setup_basedir(argv[0], s))
+ exit(1);
+
while ((c = getopt(argc, argv, "ad:fhio:ruvs")) != EOF) {
switch(c) {
case 'a':
@@ -159,13 +167,17 @@ main(int argc, char **argv)
xlog(L_ERROR, "-r and -u are incompatible");
return 1;
}
+ if (!setup_state_path_names(progname, ETAB, ETABTMP, ETABLCK, &etab))
+ return 1;
if (optind == argc && ! f_all) {
if (force_flush) {
cache_flush(1);
+ free_state_path_names(&etab);
return 0;
} else {
xtab_export_read();
dump(f_verbose, f_export_format);
+ free_state_path_names(&etab);
return 0;
}
}
@@ -206,6 +218,7 @@ main(int argc, char **argv)
}
xtab_export_write();
cache_flush(force_flush);
+ free_state_path_names(&etab);
return export_errno;
}
diff --git a/utils/exportfs/exportfs.man b/utils/exportfs/exportfs.man
index 45b6d83..91d3589 100644
--- a/utils/exportfs/exportfs.man
+++ b/utils/exportfs/exportfs.man
@@ -148,6 +148,29 @@ options.
.TP
.B -s
Display the current export list suitable for /etc/exports.
+
+.SH CONFIGURATION FILE
+The
+.B [exportfs]
+section of the
+.I /etc/nfs.conf
+configuration file can contain a
+.B debug
+value, which can be one or more from the list
+.BR general ,
+.BR call ,
+.BR auth ,
+.BR parse ,
+.BR all .
+When a list is given, the members should be comma-separated.
+
+.B exportfs
+will also recognize the
+.B state-directory-path
+value from the
+.B [mountd]
+section.
+
.SH DISCUSSION
.SS Exporting Directories
The first synopsis shows how to invoke
diff --git a/utils/mountd/auth.c b/utils/mountd/auth.c
index d065830..8299256 100644
--- a/utils/mountd/auth.c
+++ b/utils/mountd/auth.c
@@ -41,6 +41,8 @@ static nfs_client my_client;
extern int use_ipaddr;
+extern struct state_paths etab;
+
void
auth_init(void)
{
@@ -84,10 +86,10 @@ auth_reload()
static unsigned int counter;
int fd;
- if ((fd = open(_PATH_ETAB, O_RDONLY)) < 0) {
- xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
+ if ((fd = open(etab.statefn, O_RDONLY)) < 0) {
+ xlog(L_FATAL, "couldn't open %s", etab.statefn);
} else if (fstat(fd, &stb) < 0) {
- xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
+ xlog(L_FATAL, "couldn't stat %s", etab.statefn);
close(fd);
} else if (last_fd != -1 && stb.st_ino == last_inode) {
/* We opened the etab file before, and its inode
diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c
index 61699e6..bbadfaf 100644
--- a/utils/mountd/mountd.c
+++ b/utils/mountd/mountd.c
@@ -29,6 +29,7 @@
#include "mountd.h"
#include "rpcmisc.h"
#include "pseudoflavors.h"
+#include "nfslib.h"
extern void my_svc_run(void);
@@ -40,6 +41,9 @@ int reverse_resolve = 0;
int manage_gids;
int use_ipaddr = -1;
+struct state_paths etab;
+struct state_paths rmtab;
+
char *conf_path = NFS_CONFFILE;
/* PRC: a high-availability callout program can be specified with -H
@@ -110,8 +114,8 @@ unregister_services (void)
static void
cleanup_lockfiles (void)
{
- unlink(_PATH_ETABLCK);
- unlink(_PATH_RMTABLCK);
+ unlink(etab.lockfn);
+ unlink(rmtab.lockfn);
}
/* Wait for all worker child processes to exit and reap them */
@@ -181,6 +185,8 @@ fork_workers(void)
wait_for_workers();
unregister_services();
cleanup_lockfiles();
+ free_state_path_names(&etab);
+ free_state_path_names(&rmtab);
xlog(L_NOTICE, "mountd: no more workers, exiting\n");
exit(0);
}
@@ -198,6 +204,8 @@ killer (int sig)
wait_for_workers();
}
cleanup_lockfiles();
+ free_state_path_names(&etab);
+ free_state_path_names(&rmtab);
xlog (L_NOTICE, "Caught signal %d, un-registering and exiting.", sig);
exit(0);
}
@@ -656,7 +664,6 @@ get_exportlist(void)
int
main(int argc, char **argv)
{
- char *state_dir = NFS_STATEDIR;
char *progname;
char *s;
unsigned int listeners = 0;
@@ -684,8 +691,8 @@ main(int argc, char **argv)
ha_callout_prog = conf_get_str("mountd", "ha-callout");
s = conf_get_str("mountd", "state-directory-path");
- if (s)
- state_dir = s;
+ if (s && !state_setup_basedir(argv[0], s))
+ exit(1);
/* NOTE: following uses "nfsd" section of nfs.conf !!!! */
if (conf_get_bool("nfsd", "udp", NFSCTL_UDPISSET(_rpcprotobits)))
@@ -758,7 +765,8 @@ main(int argc, char **argv)
reverse_resolve = 1;
break;
case 's':
- state_dir = xstrdup(optarg);
+ if (!state_setup_basedir(argv[0], optarg))
+ exit(1);
break;
case 't':
num_threads = atoi (optarg);
@@ -790,11 +798,10 @@ main(int argc, char **argv)
fprintf(stderr, "%s: No protocol versions specified!\n", progname);
usage(progname, 1);
}
- if (chdir(state_dir)) {
- fprintf(stderr, "%s: chdir(%s) failed: %s\n",
- progname, state_dir, strerror(errno));
- exit(1);
- }
+ if (!setup_state_path_names(progname, ETAB, ETABTMP, ETABLCK, &etab))
+ return 1;
+ if (!setup_state_path_names(progname, RMTAB, RMTABTMP, RMTABLCK, &rmtab))
+ return 1;
if (getrlimit (RLIMIT_NOFILE, &rlim) != 0)
fprintf(stderr, "%s: getrlimit (RLIMIT_NOFILE) failed: %s\n",
@@ -888,6 +895,8 @@ main(int argc, char **argv)
xlog(L_ERROR, "RPC service loop terminated unexpectedly. Exiting...\n");
unregister_services();
+ free_state_path_names(&etab);
+ free_state_path_names(&rmtab);
exit(1);
}
diff --git a/utils/mountd/mountd.man b/utils/mountd/mountd.man
index 9f0a51f..9978afc 100644
--- a/utils/mountd/mountd.man
+++ b/utils/mountd/mountd.man
@@ -144,7 +144,7 @@ Instead, mount the nfsd filesystem on
.IR /proc/fs/nfsd .
.TP
.BI "\-s," "" " \-\-state\-directory\-path " directory
-Specify a directory in which to place statd state information.
+Specify a directory in which to place state information (etab and rmtab).
If this option is not specified the default of
.I /var/lib/nfs
is used.
diff --git a/utils/mountd/rmtab.c b/utils/mountd/rmtab.c
index 527377f..3ae0dbb 100644
--- a/utils/mountd/rmtab.c
+++ b/utils/mountd/rmtab.c
@@ -28,6 +28,8 @@
extern int reverse_resolve;
+extern struct state_paths rmtab;
+
/* If new path is a link do not destroy it but place the
* file where the link points.
*/
@@ -59,7 +61,7 @@ mountlist_add(char *host, const char *path)
int lockid;
long pos;
- if ((lockid = xflock(_PATH_RMTABLCK, "a")) < 0)
+ if ((lockid = xflock(rmtab.lockfn, "a")) < 0)
return;
setrmtabent("r+");
while ((rep = getrmtabent(1, &pos)) != NULL) {
@@ -99,13 +101,13 @@ mountlist_del(char *hname, const char *path)
int lockid;
int match;
- if ((lockid = xflock(_PATH_RMTABLCK, "w")) < 0)
+ if ((lockid = xflock(rmtab.lockfn, "w")) < 0)
return;
if (!setrmtabent("r")) {
xfunlock(lockid);
return;
}
- if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
+ if (!(fp = fsetrmtabent(rmtab.tmpfn, "w"))) {
endrmtabent();
xfunlock(lockid);
return;
@@ -121,9 +123,9 @@ mountlist_del(char *hname, const char *path)
if (!match || rep->r_count)
fputrmtabent(fp, rep, NULL);
}
- if (slink_safe_rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
+ if (slink_safe_rename(rmtab.tmpfn, rmtab.statefn) < 0) {
xlog(L_ERROR, "couldn't rename %s to %s",
- _PATH_RMTABTMP, _PATH_RMTAB);
+ rmtab.tmpfn, rmtab.statefn);
}
endrmtabent(); /* close & unlink */
fendrmtabent(fp);
@@ -138,7 +140,7 @@ mountlist_del_all(const struct sockaddr *sap)
FILE *fp;
int lockid;
- if ((lockid = xflock(_PATH_RMTABLCK, "w")) < 0)
+ if ((lockid = xflock(rmtab.lockfn, "w")) < 0)
return;
hostname = host_canonname(sap);
if (hostname == NULL) {
@@ -151,7 +153,7 @@ mountlist_del_all(const struct sockaddr *sap)
if (!setrmtabent("r"))
goto out_free;
- if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w")))
+ if (!(fp = fsetrmtabent(rmtab.tmpfn, "w")))
goto out_close;
while ((rep = getrmtabent(1, NULL)) != NULL) {
@@ -160,9 +162,9 @@ mountlist_del_all(const struct sockaddr *sap)
continue;
fputrmtabent(fp, rep, NULL);
}
- if (slink_safe_rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
+ if (slink_safe_rename(rmtab.tmpfn, rmtab.statefn) < 0) {
xlog(L_ERROR, "couldn't rename %s to %s",
- _PATH_RMTABTMP, _PATH_RMTAB);
+ rmtab.tmpfn, rmtab.statefn);
}
fendrmtabent(fp);
out_close:
@@ -195,11 +197,11 @@ mountlist_list(void)
struct stat stb;
int lockid;
- if ((lockid = xflock(_PATH_RMTABLCK, "r")) < 0)
+ if ((lockid = xflock(rmtab.lockfn, "r")) < 0)
return NULL;
- if (stat(_PATH_RMTAB, &stb) < 0) {
+ if (stat(rmtab.statefn, &stb) < 0) {
xlog(L_ERROR, "can't stat %s: %s",
- _PATH_RMTAB, strerror(errno));
+ rmtab.statefn, strerror(errno));
xfunlock(lockid);
return NULL;
}