diff --git a/support/export/auth.c b/support/export/auth.c
index 2d7960f1..3d9e07b5 100644
--- a/support/export/auth.c
+++ b/support/export/auth.c
@@ -175,7 +175,7 @@ auth_authenticate_newcache(const struct sockaddr *caller,
const char *path, struct addrinfo *ai,
enum auth_error *error)
{
- nfs_export *exp;
+ nfs_export *exp, *found;
int i;
free(my_client.m_hostname);
@@ -189,6 +189,7 @@ auth_authenticate_newcache(const struct sockaddr *caller,
my_exp.m_client = &my_client;
exp = NULL;
+ found = NULL;
for (i = 0; !exp && i < MCL_MAXTYPES; i++)
for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
if (strcmp(path, exp->m_export.e_path))
@@ -198,8 +199,11 @@ auth_authenticate_newcache(const struct sockaddr *caller,
if (exp->m_export.e_flags & NFSEXP_V4ROOT)
/* not acceptable for v[23] export */
continue;
- break;
+ /* we have a match - see if it is a higher priority */
+ if (!found || exp->m_export.e_priority >
found->m_export.e_priority)
+ found = exp;
}
+ exp = found;
*error = not_exported;
if (!exp)
return NULL;
diff --git a/support/export/cache.c b/support/export/cache.c
index 6c0a44a3..dfb0051b 100644
--- a/support/export/cache.c
+++ b/support/export/cache.c
@@ -877,6 +877,14 @@ static int nfsd_handle_fh(int f, char *bp, int blen)
xlog(L_WARNING, "%s and %s have same
filehandle for %s, using first",
found_path, path, dom);
} else {
+ /* same path, see if this one has a
higher export priority */
+ if (exp->m_export.e_priority >
found->e_priority) {
+ found = &exp->m_export;
+ free(found_path);
+ found_path = strdup(path);
+ if (found_path == NULL)
+ goto out;
+ }
/* same path, if one is V4ROOT, choose
the other */
if (found->e_flags & NFSEXP_V4ROOT) {
found = &exp->m_export;
@@ -1178,6 +1186,12 @@ lookup_export(char *dom, char *path, struct addrinfo *ai)
found_type = i;
continue;
}
+ /* see if this one has a higher export priority */
+ if (exp->m_export.e_priority >
found->m_export.e_priority) {
+ found = exp;
+ found_type = i;
+ continue;
+ }
/* Always prefer non-V4ROOT exports */
if (exp->m_export.e_flags & NFSEXP_V4ROOT)
continue;
diff --git a/support/include/nfslib.h b/support/include/nfslib.h
index eff2a486..ab22ecaf 100644
--- a/support/include/nfslib.h
+++ b/support/include/nfslib.h
@@ -99,6 +99,7 @@ struct exportent {
unsigned int e_ttl;
char * e_realpath;
int e_reexport;
+ int e_priority;
};
struct rmtabent {
diff --git a/support/nfs/exports.c b/support/nfs/exports.c
index a6816e60..afc139db 100644
--- a/support/nfs/exports.c
+++ b/support/nfs/exports.c
@@ -106,6 +106,7 @@ static void init_exportent (struct exportent *ee,
int fromkernel)
ee->e_uuid = NULL;
ee->e_ttl = default_ttl;
ee->e_reexport = REEXP_NONE;
+ ee->e_priority = 0;
}
struct exportent *
@@ -374,6 +375,9 @@ putexportent(struct exportent *ep)
fprintf(fp, "%d,", id[i]);
}
fprintf(fp, "anonuid=%d,anongid=%d", ep->e_anonuid, ep->e_anongid);
+ if (ep->e_priority) {
+ fprintf(fp, ",priority=%d", ep->e_priority);
+ }
secinfo_show(fp, ep);
xprtsecinfo_show(fp, ep);
fprintf(fp, ")\n");
@@ -834,6 +838,14 @@ bad_option:
setflags(NFSEXP_FSID, active, ep);
saw_reexport = 1;
+ } else if (strncmp(opt, "priority=", 9) == 0) {
+ char *oe;
+ ep->e_priority = strtol(opt+9, &oe, 10);
+ if (opt[9]=='\0' || *oe != '\0') {
+ xlog(L_ERROR, "%s: %d: bad priority \"%s\"\n",
+ flname, flline, opt);
+ goto bad_option;
+ }
} else {
xlog(L_ERROR, "%s:%d: unknown keyword \"%s\"\n",
flname, flline, opt);
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index b03a047b..5e6a64b6 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -753,6 +753,8 @@ dump(int verbose, int export_format)
break;
#endif
}
+ if (ep->e_priority)
+ c = dumpopt(c, "priority=%d", ep->e_priority);
secinfo_show(stdout, ep);
xprtsecinfo_show(stdout, ep);
printf("%c\n", (c != '(')? ')' : ' ');