diff options
author | Bryan Schumaker <bjschuma@netapp.com> | 2012-05-10 15:07:40 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-05-14 20:30:30 -0400 |
commit | b72e4f42a33137acc037546277a08f407d3c1016 (patch) | |
tree | 7223923f675b73bd1e670927376347084a7bf5b8 /fs/nfs/super.c | |
parent | 486aa699ffb6ec28adbc147326d62ac9294de8dc (diff) |
NFS: Create a single function for text mount data
The v2/3 and v4 cases were very similar, with just a few parameters
changed. This makes it easy to share code.
Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/super.c')
-rw-r--r-- | fs/nfs/super.c | 151 |
1 files changed, 70 insertions, 81 deletions
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index c69c8064011c..db636d709f28 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -66,6 +66,7 @@ | |||
66 | #include "pnfs.h" | 66 | #include "pnfs.h" |
67 | 67 | ||
68 | #define NFSDBG_FACILITY NFSDBG_VFS | 68 | #define NFSDBG_FACILITY NFSDBG_VFS |
69 | #define NFS_TEXT_DATA 1 | ||
69 | 70 | ||
70 | #ifdef CONFIG_NFS_V3 | 71 | #ifdef CONFIG_NFS_V3 |
71 | #define NFS_DEFAULT_VERSION 3 | 72 | #define NFS_DEFAULT_VERSION 3 |
@@ -333,8 +334,7 @@ static const struct super_operations nfs_sops = { | |||
333 | }; | 334 | }; |
334 | 335 | ||
335 | #ifdef CONFIG_NFS_V4 | 336 | #ifdef CONFIG_NFS_V4 |
336 | static int nfs4_validate_text_mount_data(void *options, | 337 | static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *); |
337 | struct nfs_parsed_mount_data *args, const char *dev_name); | ||
338 | static struct dentry *nfs4_try_mount(int flags, const char *dev_name, | 338 | static struct dentry *nfs4_try_mount(int flags, const char *dev_name, |
339 | struct nfs_parsed_mount_data *data); | 339 | struct nfs_parsed_mount_data *data); |
340 | static struct dentry *nfs4_mount(struct file_system_type *fs_type, | 340 | static struct dentry *nfs4_mount(struct file_system_type *fs_type, |
@@ -964,6 +964,7 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void) | |||
964 | data->auth_flavors[0] = RPC_AUTH_UNIX; | 964 | data->auth_flavors[0] = RPC_AUTH_UNIX; |
965 | data->auth_flavor_len = 1; | 965 | data->auth_flavor_len = 1; |
966 | data->minorversion = 0; | 966 | data->minorversion = 0; |
967 | data->need_mount = true; | ||
967 | data->net = current->nsproxy->net_ns; | 968 | data->net = current->nsproxy->net_ns; |
968 | security_init_mnt_opts(&data->lsm_opts); | 969 | security_init_mnt_opts(&data->lsm_opts); |
969 | } | 970 | } |
@@ -1754,9 +1755,11 @@ static struct dentry *nfs_try_mount(int flags, const char *dev_name, | |||
1754 | int status; | 1755 | int status; |
1755 | struct nfs_server *server; | 1756 | struct nfs_server *server; |
1756 | 1757 | ||
1757 | status = nfs_request_mount(mount_info->parsed, mntfh); | 1758 | if (mount_info->parsed->need_mount) { |
1758 | if (status) | 1759 | status = nfs_request_mount(mount_info->parsed, mntfh); |
1759 | return ERR_PTR(status); | 1760 | if (status) |
1761 | return ERR_PTR(status); | ||
1762 | } | ||
1760 | 1763 | ||
1761 | /* Get a volume representation */ | 1764 | /* Get a volume representation */ |
1762 | server = nfs_create_server(mount_info->parsed, mntfh); | 1765 | server = nfs_create_server(mount_info->parsed, mntfh); |
@@ -1911,6 +1914,7 @@ static int nfs_validate_mount_data(void *options, | |||
1911 | args->acregmax = data->acregmax; | 1914 | args->acregmax = data->acregmax; |
1912 | args->acdirmin = data->acdirmin; | 1915 | args->acdirmin = data->acdirmin; |
1913 | args->acdirmax = data->acdirmax; | 1916 | args->acdirmax = data->acdirmax; |
1917 | args->need_mount = false; | ||
1914 | 1918 | ||
1915 | memcpy(sap, &data->addr, sizeof(data->addr)); | 1919 | memcpy(sap, &data->addr, sizeof(data->addr)); |
1916 | args->nfs_server.addrlen = sizeof(data->addr); | 1920 | args->nfs_server.addrlen = sizeof(data->addr); |
@@ -1962,38 +1966,8 @@ static int nfs_validate_mount_data(void *options, | |||
1962 | } | 1966 | } |
1963 | 1967 | ||
1964 | break; | 1968 | break; |
1965 | default: { | 1969 | default: |
1966 | int status; | 1970 | return NFS_TEXT_DATA; |
1967 | |||
1968 | if (nfs_parse_mount_options((char *)options, args) == 0) | ||
1969 | return -EINVAL; | ||
1970 | |||
1971 | if (!nfs_verify_server_address(sap)) | ||
1972 | goto out_no_address; | ||
1973 | |||
1974 | if (args->version == 4) | ||
1975 | #ifdef CONFIG_NFS_V4 | ||
1976 | return nfs4_validate_text_mount_data(options, | ||
1977 | args, dev_name); | ||
1978 | #else | ||
1979 | goto out_v4_not_compiled; | ||
1980 | #endif | ||
1981 | |||
1982 | nfs_set_port(sap, &args->nfs_server.port, 0); | ||
1983 | |||
1984 | nfs_set_mount_transport_protocol(args); | ||
1985 | |||
1986 | status = nfs_parse_devname(dev_name, | ||
1987 | &args->nfs_server.hostname, | ||
1988 | PAGE_SIZE, | ||
1989 | &args->nfs_server.export_path, | ||
1990 | NFS_MAXPATHLEN); | ||
1991 | |||
1992 | if (status) | ||
1993 | return status; | ||
1994 | |||
1995 | break; | ||
1996 | } | ||
1997 | } | 1971 | } |
1998 | 1972 | ||
1999 | #ifndef CONFIG_NFS_V3 | 1973 | #ifndef CONFIG_NFS_V3 |
@@ -2022,12 +1996,6 @@ out_v3_not_compiled: | |||
2022 | return -EPROTONOSUPPORT; | 1996 | return -EPROTONOSUPPORT; |
2023 | #endif /* !CONFIG_NFS_V3 */ | 1997 | #endif /* !CONFIG_NFS_V3 */ |
2024 | 1998 | ||
2025 | #ifndef CONFIG_NFS_V4 | ||
2026 | out_v4_not_compiled: | ||
2027 | dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n"); | ||
2028 | return -EPROTONOSUPPORT; | ||
2029 | #endif /* !CONFIG_NFS_V4 */ | ||
2030 | |||
2031 | out_nomem: | 1999 | out_nomem: |
2032 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); | 2000 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); |
2033 | return -ENOMEM; | 2001 | return -ENOMEM; |
@@ -2041,6 +2009,60 @@ out_invalid_fh: | |||
2041 | return -EINVAL; | 2009 | return -EINVAL; |
2042 | } | 2010 | } |
2043 | 2011 | ||
2012 | static int nfs_validate_text_mount_data(void *options, | ||
2013 | struct nfs_parsed_mount_data *args, | ||
2014 | const char *dev_name) | ||
2015 | { | ||
2016 | int port = 0; | ||
2017 | int max_namelen = PAGE_SIZE; | ||
2018 | int max_pathlen = NFS_MAXPATHLEN; | ||
2019 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; | ||
2020 | |||
2021 | if (nfs_parse_mount_options((char *)options, args) == 0) | ||
2022 | return -EINVAL; | ||
2023 | |||
2024 | if (!nfs_verify_server_address(sap)) | ||
2025 | goto out_no_address; | ||
2026 | |||
2027 | if (args->version == 4) { | ||
2028 | #ifdef CONFIG_NFS_V4 | ||
2029 | port = NFS_PORT; | ||
2030 | max_namelen = NFS4_MAXNAMLEN; | ||
2031 | max_pathlen = NFS4_MAXPATHLEN; | ||
2032 | nfs_validate_transport_protocol(args); | ||
2033 | nfs4_validate_mount_flags(args); | ||
2034 | #else | ||
2035 | goto out_v4_not_compiled; | ||
2036 | #endif /* CONFIG_NFS_V4 */ | ||
2037 | } else | ||
2038 | nfs_set_mount_transport_protocol(args); | ||
2039 | |||
2040 | nfs_set_port(sap, &args->nfs_server.port, port); | ||
2041 | |||
2042 | if (args->auth_flavor_len > 1) | ||
2043 | goto out_bad_auth; | ||
2044 | |||
2045 | return nfs_parse_devname(dev_name, | ||
2046 | &args->nfs_server.hostname, | ||
2047 | max_namelen, | ||
2048 | &args->nfs_server.export_path, | ||
2049 | max_pathlen); | ||
2050 | |||
2051 | #ifndef CONFIG_NFS_V4 | ||
2052 | out_v4_not_compiled: | ||
2053 | dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n"); | ||
2054 | return -EPROTONOSUPPORT; | ||
2055 | #endif /* !CONFIG_NFS_V4 */ | ||
2056 | |||
2057 | out_no_address: | ||
2058 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); | ||
2059 | return -EINVAL; | ||
2060 | |||
2061 | out_bad_auth: | ||
2062 | dfprintk(MOUNT, "NFS: Too many RPC auth flavours specified\n"); | ||
2063 | return -EINVAL; | ||
2064 | } | ||
2065 | |||
2044 | static int | 2066 | static int |
2045 | nfs_compare_remount_data(struct nfs_server *nfss, | 2067 | nfs_compare_remount_data(struct nfs_server *nfss, |
2046 | struct nfs_parsed_mount_data *data) | 2068 | struct nfs_parsed_mount_data *data) |
@@ -2438,6 +2460,8 @@ static struct dentry *nfs_fs_mount(struct file_system_type *fs_type, | |||
2438 | 2460 | ||
2439 | /* Validate the mount data */ | 2461 | /* Validate the mount data */ |
2440 | error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name); | 2462 | error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name); |
2463 | if (error == NFS_TEXT_DATA) | ||
2464 | error = nfs_validate_text_mount_data(raw_data, data, dev_name); | ||
2441 | if (error < 0) { | 2465 | if (error < 0) { |
2442 | mntroot = ERR_PTR(error); | 2466 | mntroot = ERR_PTR(error); |
2443 | goto out; | 2467 | goto out; |
@@ -2572,37 +2596,6 @@ static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args) | |||
2572 | NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); | 2596 | NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); |
2573 | } | 2597 | } |
2574 | 2598 | ||
2575 | static int nfs4_validate_text_mount_data(void *options, | ||
2576 | struct nfs_parsed_mount_data *args, | ||
2577 | const char *dev_name) | ||
2578 | { | ||
2579 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; | ||
2580 | |||
2581 | nfs_set_port(sap, &args->nfs_server.port, NFS_PORT); | ||
2582 | |||
2583 | nfs_validate_transport_protocol(args); | ||
2584 | |||
2585 | nfs4_validate_mount_flags(args); | ||
2586 | |||
2587 | if (args->version != 4) { | ||
2588 | dfprintk(MOUNT, | ||
2589 | "NFS4: Illegal mount version\n"); | ||
2590 | return -EINVAL; | ||
2591 | } | ||
2592 | |||
2593 | if (args->auth_flavor_len > 1) { | ||
2594 | dfprintk(MOUNT, | ||
2595 | "NFS4: Too many RPC auth flavours specified\n"); | ||
2596 | return -EINVAL; | ||
2597 | } | ||
2598 | |||
2599 | return nfs_parse_devname(dev_name, | ||
2600 | &args->nfs_server.hostname, | ||
2601 | NFS4_MAXNAMLEN, | ||
2602 | &args->nfs_server.export_path, | ||
2603 | NFS4_MAXPATHLEN); | ||
2604 | } | ||
2605 | |||
2606 | /* | 2599 | /* |
2607 | * Validate NFSv4 mount options | 2600 | * Validate NFSv4 mount options |
2608 | */ | 2601 | */ |
@@ -2673,13 +2666,7 @@ static int nfs4_validate_mount_data(void *options, | |||
2673 | 2666 | ||
2674 | break; | 2667 | break; |
2675 | default: | 2668 | default: |
2676 | if (nfs_parse_mount_options((char *)options, args) == 0) | 2669 | return NFS_TEXT_DATA; |
2677 | return -EINVAL; | ||
2678 | |||
2679 | if (!nfs_verify_server_address(sap)) | ||
2680 | return -EINVAL; | ||
2681 | |||
2682 | return nfs4_validate_text_mount_data(options, args, dev_name); | ||
2683 | } | 2670 | } |
2684 | 2671 | ||
2685 | return 0; | 2672 | return 0; |
@@ -2880,6 +2867,8 @@ static struct dentry *nfs4_mount(struct file_system_type *fs_type, | |||
2880 | 2867 | ||
2881 | /* Validate the mount data */ | 2868 | /* Validate the mount data */ |
2882 | error = nfs4_validate_mount_data(raw_data, data, dev_name); | 2869 | error = nfs4_validate_mount_data(raw_data, data, dev_name); |
2870 | if (error == NFS_TEXT_DATA) | ||
2871 | error = nfs_validate_text_mount_data(raw_data, data, dev_name); | ||
2883 | if (error < 0) { | 2872 | if (error < 0) { |
2884 | res = ERR_PTR(error); | 2873 | res = ERR_PTR(error); |
2885 | goto out; | 2874 | goto out; |