summaryrefslogtreecommitdiffstats
path: root/support
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 /support
parent1789737ec6dd43c9d1436aeb6c07fab52206f412 (diff)
downloadnfs-utils-a15bd948606bf4816bf819c0b0c75761f3eb6359.tar.gz
nfs-utils-a15bd948606bf4816bf819c0b0c75761f3eb6359.tar.xz
nfs-utils-a15bd948606bf4816bf819c0b0c75761f3eb6359.zip
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 'support')
-rw-r--r--support/export/xtab.c83
-rw-r--r--support/include/nfslib.h35
-rw-r--r--support/nfs/cacheio.c6
-rw-r--r--support/nfs/rmtab.c4
4 files changed, 105 insertions, 23 deletions
diff --git a/support/export/xtab.c b/support/export/xtab.c
index 22cf539..d42eeef 100644
--- a/support/export/xtab.c
+++ b/support/export/xtab.c
@@ -14,12 +14,20 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <libgen.h>
#include "nfslib.h"
#include "exportfs.h"
#include "xio.h"
#include "xlog.h"
#include "v4root.h"
+#include "misc.h"
+
+static char state_base_dirname[PATH_MAX] = NFS_STATEDIR;
+extern struct state_paths etab;
int v4root_needed;
static void cond_rename(char *newfile, char *oldfile);
@@ -65,7 +73,7 @@ xtab_read(char *xtab, char *lockfn, int is_export)
int
xtab_export_read(void)
{
- return xtab_read(_PATH_ETAB, _PATH_ETABLCK, 1);
+ return xtab_read(etab.statefn, etab.lockfn, 1);
}
/*
@@ -112,7 +120,7 @@ xtab_write(char *xtab, char *xtabtmp, char *lockfn, int is_export)
int
xtab_export_write()
{
- return xtab_write(_PATH_ETAB, _PATH_ETABTMP, _PATH_ETABLCK, 1);
+ return xtab_write(etab.statefn, etab.tmpfn, etab.lockfn, 1);
}
/*
@@ -158,3 +166,74 @@ static void cond_rename(char *newfile, char *oldfile)
rename(newfile, oldfile);
return;
}
+
+/*
+ * Returns a dynamically allocated, '\0'-terminated buffer
+ * containing an appropriate pathname, or NULL if an error
+ * occurs. Caller must free the returned result with free(3).
+ */
+static char *
+state_make_pathname(const char *tabname)
+{
+ return generic_make_pathname(state_base_dirname, tabname);
+}
+
+/**
+ * state_setup_basedir - set up basedir
+ * @progname: C string containing name of program, for error messages
+ * @parentdir: C string containing pathname to on-disk state, or NULL
+ *
+ * This runs before logging is set up, so error messages are directed
+ * to stderr.
+ *
+ * Returns true and sets up our basedir, if @parentdir was valid
+ * and usable; otherwise false is returned.
+ */
+_Bool
+state_setup_basedir(const char *progname, const char *parentdir)
+{
+ return generic_setup_basedir(progname, parentdir, state_base_dirname,
+ PATH_MAX);
+}
+
+int
+setup_state_path_names(const char *progname, const char *statefn,
+ const char *tmpfn, const char *lockfn,
+ struct state_paths *paths)
+{
+ paths->statefn = state_make_pathname(statefn);
+ if (!paths->statefn) {
+ fprintf(stderr, "%s: state_make_pathname(%s) failed\n",
+ progname, statefn);
+ goto out_err;
+ }
+ paths->tmpfn = state_make_pathname(tmpfn);
+ if (!paths->tmpfn) {
+ fprintf(stderr, "%s: state_make_pathname(%s) failed\n",
+ progname, tmpfn);
+ goto out_free_statefn;
+ }
+ paths->lockfn = state_make_pathname(lockfn);
+ if (!paths->lockfn) {
+ fprintf(stderr, "%s: state_make_pathname(%s) failed\n",
+ progname, lockfn);
+ goto out_free_tmpfn;
+ }
+ return 1;
+
+out_free_tmpfn:
+ free(paths->tmpfn);
+out_free_statefn:
+ free(paths->statefn);
+out_err:
+ return 0;
+
+}
+
+void
+free_state_path_names(struct state_paths *paths)
+{
+ free(paths->statefn);
+ free(paths->tmpfn);
+ free(paths->lockfn);
+}
diff --git a/support/include/nfslib.h b/support/include/nfslib.h
index 1498977..ab8b2bf 100644
--- a/support/include/nfslib.h
+++ b/support/include/nfslib.h
@@ -35,29 +35,24 @@
#ifndef _PATH_IDMAPDCONF
#define _PATH_IDMAPDCONF "/etc/idmapd.conf"
#endif
-#ifndef _PATH_ETAB
-#define _PATH_ETAB NFS_STATEDIR "/etab"
-#endif
-#ifndef _PATH_ETABTMP
-#define _PATH_ETABTMP NFS_STATEDIR "/etab.tmp"
-#endif
-#ifndef _PATH_ETABLCK
-#define _PATH_ETABLCK NFS_STATEDIR "/.etab.lock"
-#endif
-#ifndef _PATH_RMTAB
-#define _PATH_RMTAB NFS_STATEDIR "/rmtab"
-#endif
-#ifndef _PATH_RMTABTMP
-#define _PATH_RMTABTMP _PATH_RMTAB ".tmp"
-#endif
-#ifndef _PATH_RMTABLCK
-#define _PATH_RMTABLCK NFS_STATEDIR "/.rmtab.lock"
-#endif
#ifndef _PATH_PROC_EXPORTS
#define _PATH_PROC_EXPORTS "/proc/fs/nfs/exports"
#define _PATH_PROC_EXPORTS_ALT "/proc/fs/nfsd/exports"
#endif
+#define ETAB "etab"
+#define ETABTMP "etab.tmp"
+#define ETABLCK ".etab.lock"
+#define RMTAB "rmtab"
+#define RMTABTMP "rmtab.tmp"
+#define RMTABLCK ".rmtab.lock"
+
+struct state_paths {
+ char *statefn;
+ char *tmpfn;
+ char *lockfn;
+};
+
/* Maximum number of security flavors on an export: */
#define SECFLAVOR_COUNT 8
@@ -120,6 +115,10 @@ void fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
void fendrmtabent(FILE *fp);
void frewindrmtabent(FILE *fp);
+_Bool state_setup_basedir(const char *, const char *);
+int setup_state_path_names(const char *, const char *, const char *, const char *, struct state_paths *);
+void free_state_path_names(struct state_paths *);
+
/* mydaemon */
void daemon_init(bool fg);
void daemon_ready(void);
diff --git a/support/nfs/cacheio.c b/support/nfs/cacheio.c
index e5e2579..9912afa 100644
--- a/support/nfs/cacheio.c
+++ b/support/nfs/cacheio.c
@@ -27,6 +27,8 @@
#include <time.h>
#include <errno.h>
+extern struct state_paths etab;
+
void qword_add(char **bpp, int *lp, char *str)
{
char *bp = *bpp;
@@ -199,7 +201,7 @@ int qword_get_uint(char **bpp, unsigned int *anint)
}
/* flush the kNFSd caches.
- * Set the flush time to the mtime of _PATH_ETAB or
+ * Set the flush time to the mtime of the etab state file or
* if force, to now.
* the caches to flush are:
* auth.unix.ip nfsd.export nfsd.fh
@@ -228,7 +230,7 @@ cache_flush(int force)
};
now = time(0);
if (force ||
- stat(_PATH_ETAB, &stb) != 0 ||
+ stat(etab.statefn, &stb) != 0 ||
stb.st_mtime > now)
stb.st_mtime = time(0);
diff --git a/support/nfs/rmtab.c b/support/nfs/rmtab.c
index 59dfbdf..2ecb2cc 100644
--- a/support/nfs/rmtab.c
+++ b/support/nfs/rmtab.c
@@ -33,12 +33,14 @@
static FILE *rmfp = NULL;
+extern struct state_paths rmtab;
+
int
setrmtabent(char *type)
{
if (rmfp)
fclose(rmfp);
- rmfp = fsetrmtabent(_PATH_RMTAB, type);
+ rmfp = fsetrmtabent(rmtab.statefn, type);
return (rmfp != NULL);
}