diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2014-03-17 10:35:19 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2014-03-17 10:37:30 -0400 |
commit | ebd488515f534ba8eaf2d91d0451d329e78023f0 (patch) | |
tree | 6e281b53dcb10f2f743c226db5f6e958e0ae1a2c /utils/exportfs/exportfs.c | |
parent | 6a28ddbfd09f5b766346f268efaf1a0670a5e21e (diff) | |
download | nfs-utils-ebd488515f534ba8eaf2d91d0451d329e78023f0.tar.gz nfs-utils-ebd488515f534ba8eaf2d91d0451d329e78023f0.tar.xz nfs-utils-ebd488515f534ba8eaf2d91d0451d329e78023f0.zip |
exportfs: Refactor exportfs() and unexportfs()
Separate parsing the "client:/path" argument from the actual
processing.
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=817557
Tested-by: Steve Dickson <steved@redaht.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/exportfs/exportfs.c')
-rw-r--r-- | utils/exportfs/exportfs.c | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index 8c86790..cb81611 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_generic(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_generic(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_generic(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_generic(arg, verbose); + if (failed) + xlog(L_ERROR, "Invalid export syntax: %s", arg); +} + static int can_test(void) { char buf[1024]; |