[PATCH 1/2] exportfs: Refactor exportfs() and unexportfs()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Separate parsing the "client:/path" argument from the actual
processing.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=817557
Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx>
---
 utils/exportfs/exportfs.c |   74 +++++++++++++++++++++++++++++++--------------
 1 file changed, 51 insertions(+), 23 deletions(-)

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index 8c86790..771d6eb 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -299,23 +299,13 @@ export_all(int verbose)
 
 
 static void
-exportfs(char *arg, char *options, int verbose)
+exportfs_parsed(char *hname, char *path, char *options, int verbose)
 {
 	struct exportent *eep;
 	nfs_export	*exp = NULL;
 	struct addrinfo	*ai = NULL;
-	char		*path;
-	char		*hname = arg;
 	int		htype;
 
-	if ((path = strchr(arg, ':')) != NULL)
-		*path++ = '\0';
-
-	if (!path || *path != '/') {
-		xlog(L_ERROR, "Invalid exporting option: %s", arg);
-		return;
-	}
-
 	if ((htype = client_gettype(hname)) == MCL_FQDN) {
 		ai = host_addrinfo(hname);
 		if (ai != NULL) {
@@ -345,24 +335,38 @@ out:
 	freeaddrinfo(ai);
 }
 
+static int exportfs_legacy(char *arg, char *options, int verbose)
+{
+	char *path;
+
+	if ((path = strchr(arg, ':')) != NULL)
+		*path++ = '\0';
+
+	if (!path || *path != '/')
+		return 1;
+
+	exportfs_parsed(arg, path, options, verbose);
+	return 0;
+}
+
 static void
-unexportfs(char *arg, int verbose)
+exportfs(char *arg, char *options, int verbose)
+{
+	int failed;
+
+	failed = exportfs_legacy(arg, options, verbose);
+	if (failed)
+		xlog(L_ERROR, "Invalid export syntax: %s", arg);
+}
+
+static void
+unexportfs_parsed(char *hname, char *path, int verbose)
 {
 	nfs_export	*exp;
 	struct addrinfo *ai = NULL;
-	char		*path;
-	char		*hname = arg;
 	int		htype;
 	int		success = 0;
 
-	if ((path = strchr(arg, ':')) != NULL)
-		*path++ = '\0';
-
-	if (!path || *path != '/') {
-		xlog(L_ERROR, "Invalid unexporting option: %s", arg);
-		return;
-	}
-
 	if ((htype = client_gettype(hname)) == MCL_FQDN) {
 		ai = host_addrinfo(hname);
 		if (ai)
@@ -403,11 +407,35 @@ unexportfs(char *arg, int verbose)
 		success = 1;
 	}
 	if (!success)
-		xlog(L_ERROR, "Could not find '%s:%s' to unexport.", arg, path);
+		xlog(L_ERROR, "Could not find '%s:%s' to unexport.", hname, path);
 
 	freeaddrinfo(ai);
 }
 
+static int unexportfs_legacy(char *arg, int verbose)
+{
+	char *path;
+
+	if ((path = strchr(arg, ':')) != NULL)
+		*path++ = '\0';
+
+	if (!path || *path != '/')
+		return 1;
+
+	unexportfs_parsed(arg, path, verbose);
+	return 0;
+}
+
+static void
+unexportfs(char *arg, int verbose)
+{
+	int failed;
+
+	failed = unexportfs_legacy(arg, verbose);
+	if (failed)
+		xlog(L_ERROR, "Invalid export syntax: %s", arg);
+}
+
 static int can_test(void)
 {
 	char buf[1024];

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux