* [PATCH] exportfs: Completely unexport directory by path alone
@ 2014-09-26 14:44 Andreas Reis
0 siblings, 0 replies; only message in thread
From: Andreas Reis @ 2014-09-26 14:44 UTC (permalink / raw)
To: linux-nfs
Patch to allow complete unexport of a directory without having to state each of its clients.
Ie, "exportfs -u /foo/bar" unexports all entries matching that path.
Useful when one doesn't want to / can't do the bookkeeping required otherwise.
Signed-off-by: Andreas Reis <andreas.reis@gmail.com>
---
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index bdea12b..ae90808 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -393,65 +393,90 @@ unexportfs_parsed(char *hname, char *path, int verbose)
{
nfs_export *exp;
struct addrinfo *ai = NULL;
- int htype;
- int success = 0;
-
- if ((htype = client_gettype(hname)) == MCL_FQDN) {
- ai = host_addrinfo(hname);
- if (ai)
- hname = ai->ai_canonname;
+ int htype = 0;
+ bool success = false;
+
+ if(hname) {
+ if ((htype = client_gettype(hname)) == MCL_FQDN) {
+ ai = host_addrinfo(hname);
+ if (ai)
+ hname = ai->ai_canonname;
+ }
}
- for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
- if (path && strcmp(path, exp->m_export.e_path))
- continue;
- if (htype != exp->m_client->m_type)
- continue;
- if (htype == MCL_FQDN
- && !matchhostname(exp->m_export.e_hostname,
- hname))
- continue;
- if (htype != MCL_FQDN
- && strcasecmp(exp->m_export.e_hostname, hname))
- continue;
- if (verbose) {
-#if 0
- if (exp->m_exported) {
- printf("unexporting %s:%s from kernel\n",
- exp->m_client->m_hostname,
- exp->m_export.e_path);
+ do {
+
+ for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
+ if (path && strcmp(path, exp->m_export.e_path))
+ continue;
+ if (htype != exp->m_client->m_type)
+ continue;
+ if (hname) {
+ if (htype == MCL_FQDN
+ && !matchhostname(exp->m_export.e_hostname,
+ hname))
+ continue;
+ if (htype != MCL_FQDN
+ && strcasecmp(exp->m_export.e_hostname, hname))
+ continue;
}
- else
+ if (verbose) {
+#if 0
+ if (exp->m_exported) {
+ printf("unexporting %s:%s from kernel\n",
+ exp->m_client->m_hostname,
+ exp->m_export.e_path);
+ }
+ else
#endif
- printf("unexporting %s:%s\n",
- exp->m_client->m_hostname,
- exp->m_export.e_path);
- }
+ printf("unexporting %s:%s\n",
+ exp->m_client->m_hostname,
+ exp->m_export.e_path);
+ }
#if 0
- if (exp->m_exported && !export_unexport(exp))
- error(exp, errno);
+ if (exp->m_exported && !export_unexport(exp))
+ error(exp, errno);
#endif
- exp->m_xtabent = 0;
- exp->m_mayexport = 0;
- success = 1;
+ exp->m_xtabent = 0;
+ exp->m_mayexport = 0;
+ success = true;
+ }
+
+ if(hname)
+ break;
+ else
+ ++htype;
+
+ } while(htype < MCL_MAXTYPES);
+
+ if (!success) {
+ if(hname)
+ xlog(L_ERROR, "Could not find '%s:%s' to unexport.", hname, path);
+ else
+ xlog(L_ERROR, "No clients of '%s' found to unexport.", path);
}
- if (!success)
- xlog(L_ERROR, "Could not find '%s:%s' to unexport.", hname, path);
- freeaddrinfo(ai);
+ if(hname)
+ freeaddrinfo(ai);
}
static int unexportfs_generic(char *arg, int verbose)
{
- char *path;
+ char *path = strchr(arg, ':');
- if ((path = strchr(arg, ':')) != NULL)
+ if (path) {
*path++ = '\0';
+ if (*path != '/')
+ return 1;
+ unexportfs_parsed(arg, path, verbose);
+ } else {
+ // unqualified unexport
+ if (*arg != '/')
+ return 1;
+ // NULL as signal
+ unexportfs_parsed(NULL, arg, verbose);
+ }
- if (!path || *path != '/')
- return 1;
-
- unexportfs_parsed(arg, path, verbose);
return 0;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2014-09-26 14:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-26 14:44 [PATCH] exportfs: Completely unexport directory by path alone Andreas Reis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.