diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2009-04-23 19:31:40 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@citi.umich.edu> | 2009-04-28 13:54:26 -0400 |
commit | 4eb68c266cb1754ffa0040e882882680ece8cf34 (patch) | |
tree | 2c4f5b51ca01170616a57b41db7392fce512d4a9 | |
parent | 4cd5dc751a5889b5b37aa88752e33a58d8f6b624 (diff) |
NFSD: Refactor transport addition out of __write_ports()
Clean up: Refactor transport addition out of __write_ports() to make
it easier to understand and maintain.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
-rw-r--r-- | fs/nfsd/nfsctl.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 2c1dce8e9a06..748532b93fd9 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c | |||
@@ -911,6 +911,36 @@ static ssize_t write_versions(struct file *file, char *buf, size_t size) | |||
911 | } | 911 | } |
912 | 912 | ||
913 | /* | 913 | /* |
914 | * A transport listener is added by writing it's transport name and | ||
915 | * a port number. | ||
916 | */ | ||
917 | static ssize_t __write_ports_addxprt(char *buf) | ||
918 | { | ||
919 | char transport[16]; | ||
920 | int port, err; | ||
921 | |||
922 | if (sscanf(buf, "%15s %4u", transport, &port) != 2) | ||
923 | return -EINVAL; | ||
924 | |||
925 | if (port < 1 || port > USHORT_MAX) | ||
926 | return -EINVAL; | ||
927 | |||
928 | err = nfsd_create_serv(); | ||
929 | if (err != 0) | ||
930 | return err; | ||
931 | |||
932 | err = svc_create_xprt(nfsd_serv, transport, | ||
933 | PF_INET, port, SVC_SOCK_ANONYMOUS); | ||
934 | if (err < 0) { | ||
935 | /* Give a reasonable perror msg for bad transport string */ | ||
936 | if (err == -ENOENT) | ||
937 | err = -EPROTONOSUPPORT; | ||
938 | return err; | ||
939 | } | ||
940 | return 0; | ||
941 | } | ||
942 | |||
943 | /* | ||
914 | * A transport listener is removed by writing a "-", it's transport | 944 | * A transport listener is removed by writing a "-", it's transport |
915 | * name, and it's port number. | 945 | * name, and it's port number. |
916 | */ | 946 | */ |
@@ -986,29 +1016,9 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size) | |||
986 | kfree(toclose); | 1016 | kfree(toclose); |
987 | return len; | 1017 | return len; |
988 | } | 1018 | } |
989 | /* | 1019 | |
990 | * Add a transport listener by writing it's transport name | 1020 | if (isalpha(buf[0])) |
991 | */ | 1021 | return __write_ports_addxprt(buf); |
992 | if (isalpha(buf[0])) { | ||
993 | int err; | ||
994 | char transport[16]; | ||
995 | int port; | ||
996 | if (sscanf(buf, "%15s %4d", transport, &port) == 2) { | ||
997 | if (port < 1 || port > 65535) | ||
998 | return -EINVAL; | ||
999 | err = nfsd_create_serv(); | ||
1000 | if (!err) { | ||
1001 | err = svc_create_xprt(nfsd_serv, | ||
1002 | transport, PF_INET, port, | ||
1003 | SVC_SOCK_ANONYMOUS); | ||
1004 | if (err == -ENOENT) | ||
1005 | /* Give a reasonable perror msg for | ||
1006 | * bad transport string */ | ||
1007 | err = -EPROTONOSUPPORT; | ||
1008 | } | ||
1009 | return err < 0 ? err : 0; | ||
1010 | } | ||
1011 | } | ||
1012 | 1022 | ||
1013 | if (buf[0] == '-' && isalpha(buf[1])) | 1023 | if (buf[0] == '-' && isalpha(buf[1])) |
1014 | return __write_ports_delxprt(buf); | 1024 | return __write_ports_delxprt(buf); |