@@ -20,6 +20,7 @@
#include "xmalloc.h"
#include "nfslib.h"
#include "exportfs.h"
+#include "nfsd_path.h"
exp_hash_table exportlist[MCL_MAXTYPES] = {{NULL, {{NULL,NULL}, }}, };
static int export_hash(char *);
@@ -30,6 +31,28 @@ static void export_add(nfs_export *exp);
static int export_check(const nfs_export *exp, const struct addrinfo *ai,
const char *path);
+/* Return a real path for the export. */
+static void
+exportent_mkrealpath(struct exportent *eep)
+{
+ char *chroot = nfsd_path_nfsd_rootdir();
+ char *ret = NULL;
+
+ if (chroot)
+ ret = nfsd_path_prepend_dir(chroot, eep->e_path);
+ if (!ret)
+ ret = xstrdup(eep->e_path);
+ eep->e_realpath = ret;
+}
+
+char *
+exportent_realpath(struct exportent *eep)
+{
+ if (!eep->e_realpath)
+ exportent_mkrealpath(eep);
+ return eep->e_realpath;
+}
+
void
exportent_release(struct exportent *eep)
{
@@ -39,6 +62,7 @@ exportent_release(struct exportent *eep)
free(eep->e_fslocdata);
free(eep->e_uuid);
xfree(eep->e_hostname);
+ xfree(eep->e_realpath);
}
static void
@@ -171,5 +171,6 @@ struct export_features {
struct export_features *get_export_features(void);
void fix_pseudoflavor_flags(struct exportent *ep);
+char *exportent_realpath(struct exportent *eep);
#endif /* EXPORTFS_H */
@@ -84,6 +84,7 @@ struct exportent {
char * e_uuid;
struct sec_entry e_secinfo[SECFLAVOR_COUNT+1];
unsigned int e_ttl;
+ char * e_realpath;
};
struct rmtabent {
@@ -77,9 +77,11 @@ nfsd_path_prepend_dir(const char *dir, const char *pathname)
dirlen--;
if (!dirlen)
return NULL;
+ while (pathname[0] == '/')
+ pathname++;
len = dirlen + strlen(pathname) + 1;
ret = xmalloc(len + 1);
- snprintf(ret, len, "%.*s/%s", (int)dirlen, dir, pathname);
+ snprintf(ret, len+1, "%.*s/%s", (int)dirlen, dir, pathname);
return ret;
}
@@ -155,6 +155,7 @@ getexportent(int fromkernel, int fromexports)
}
xfree(ee.e_hostname);
+ xfree(ee.e_realpath);
ee = def_ee;
/* Check for default client */
@@ -358,6 +359,7 @@ dupexportent(struct exportent *dst, struct exportent *src)
if (src->e_uuid)
dst->e_uuid = strdup(src->e_uuid);
dst->e_hostname = NULL;
+ dst->e_realpath = NULL;
}
struct exportent *
@@ -369,6 +371,8 @@ mkexportent(char *hname, char *path, char *options)
xfree(ee.e_hostname);
ee.e_hostname = xstrdup(hname);
+ xfree(ee.e_realpath);
+ ee.e_realpath = NULL;
if (strlen(path) >= sizeof(ee.e_path)) {
xlog(L_ERROR, "path name %s too long", path);
Add a helper that can prepend the nfsd root directory path in order to allow mountd to perform its comparisons with mtab etc. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> --- support/export/export.c | 24 ++++++++++++++++++++++++ support/include/exportfs.h | 1 + support/include/nfslib.h | 1 + support/misc/nfsd_path.c | 4 +++- support/nfs/exports.c | 4 ++++ 5 files changed, 33 insertions(+), 1 deletion(-)