nfs: Mount API conversion
Subsystems (3)
v3 cover nfs: Mount API conversion
Hi Anna,
Here's a set of patches that converts NFS to use the mount API. Note that there are a lot of preliminary patches, some from David and some from Al. The final patch (the one that does the actual conversion) from the David's initial posting has been split into 4 separate patches, and the entire set has been rebased on top of v5.3-rc6.
Changes since v2:
- fixed the conversion of the nconnect= option
- added '#if IS_ENABLED(CONFIG_NFS_V4)' around nfs4_parse_monolithic() to avoid unused-function warning when compiling with v4 disabled
-Scott
Al Viro (15):
saner calling conventions for nfs_fs_mount_common()
nfs: stash server into struct nfs_mount_info
nfs: lift setting mount_info from nfs4_remote{,_referral}_mount
nfs: fold nfs4_remote_fs_type and nfs4_remote_referral_fs_type
nfs: don't bother setting/restoring export_path around
do_nfs_root_mount()
nfs4: fold nfs_do_root_mount/nfs_follow_remote_path
nfs: lift setting mount_info from nfs_xdev_mount()
nfs: stash nfs_subversion reference into nfs_mount_info
nfs: don't bother passing nfs_subversion to ->try_mount() and
nfs_fs_mount_common()
nfs: merge xdev and remote file_system_type
nfs: unexport nfs_fs_mount_common()
nfs: don't pass nfs_subversion to ->create_server()
nfs: get rid of mount_info ->fill_super() nfs_clone_sb_security(): simplify the check for server bogosity
nfs: get rid of ->set_security()
David Howells (8):
NFS: Move mount parameterisation bits into their own file
NFS: Constify mount argument match tables
NFS: Rename struct nfs_parsed_mount_data to struct nfs_fs_context
NFS: Split nfs_parse_mount_options()
NFS: Deindent nfs_fs_context_parse_option()
NFS: Add a small buffer in nfs_fs_context to avoid string dup
NFS: Do some tidying of the parsing code
NFS: Add fs_context support.
Scott Mayhew (3):
NFS: rename nfs_fs_context pointer arg in a few functions
NFS: Convert mount option parsing to use functionality from
fs_parser.h
NFS: Attach supplementary error information to fs_context.
fs/nfs/Makefile | 2 +- fs/nfs/client.c | 80 +- fs/nfs/fs_context.c | 1425 ++++++++++++++++++++++++++++ fs/nfs/fscache.c | 2 +- fs/nfs/getroot.c | 73 +- fs/nfs/internal.h | 132 +-- fs/nfs/namespace.c | 144 +-- fs/nfs/nfs3_fs.h | 2 +- fs/nfs/nfs3client.c | 6 +- fs/nfs/nfs3proc.c | 2 +- fs/nfs/nfs4_fs.h | 9 +- fs/nfs/nfs4client.c | 99 +- fs/nfs/nfs4namespace.c | 285 +++--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4super.c | 257 ++--- fs/nfs/proc.c | 2 +- fs/nfs/super.c | 1962 ++++----------------------------------- include/linux/nfs_xdr.h | 9 +- 18 files changed, 2156 insertions(+), 2337 deletions(-) create mode 100644 fs/nfs/fs_context.c
Signature · 1 line
2.17.2
PATCH v3 1/26 saner calling conventions for nfs_fs_mount_common()
From: Al Viro <[email protected]>
Allow it to take ERR_PTR() for server and return ERR_CAST() of it in such case. All callers used to open-code that...
--- fs/nfs/nfs4super.c | 16 +--------------- fs/nfs/super.c | 11 ++++------- 2 files changed, 5 insertions(+), 22 deletions(-)
fs/nfs/nfs4super.c +1 -15
@@ -110,21 +110,12 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags, {struct nfs_mount_info *mount_info = info;struct nfs_server *server; -struct dentry *mntroot =ERR_PTR (-ENOMEM ); mount_info->set_security = nfs_set_sb_security;/* Get a volume representation */ server =nfs4_create_server (mount_info, &nfs_v4); -if (IS_ERR (server)) { - mntroot =ERR_CAST (server); - goto out; - } - - mntroot =nfs_fs_mount_common (server, flags, dev_name, mount_info, &nfs_v4); - -out: -return mntroot; +return nfs_fs_mount_common (server, flags, dev_name, mount_info, &nfs_v4); } static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
@@ -280,11 +271,6 @@ nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,/* create a new volume representation */ server =nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh); -if (IS_ERR (server)) { - mntroot =ERR_CAST (server); - goto out; - } - mntroot =nfs_fs_mount_common (server, flags, dev_name, &mount_info, &nfs_v4); out:nfs_free_fhandle (mount_info.mntfh);
fs/nfs/super.c +4 -7
@@ -1903,9 +1903,6 @@ struct dentry *nfs_try_mount(int flags, const char *dev_name,else server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); -if (IS_ERR (server)) -return ERR_CAST (server); -return nfs_fs_mount_common (server, flags, dev_name, mount_info, nfs_mod); }EXPORT_SYMBOL_GPL (nfs_try_mount);
@@ -2641,6 +2638,9 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server, };int error; +if (IS_ERR (server)) +return ERR_CAST (server); +if (server->flags &NFS_MOUNT_UNSHARED ) compare_super =NULL ;
@@ -2789,10 +2789,7 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags,/* create a new volume representation */ server = nfs_mod->rpc_ops->clone_server (NFS_SB (data->sb), data->fh, data->fattr, data->authflavor); -if (IS_ERR (server)) - mntroot =ERR_CAST (server); -else - mntroot =nfs_fs_mount_common (server, flags, + mntroot =nfs_fs_mount_common (server, flags, dev_name, &mount_info, nfs_mod); dprintk("<-- nfs_xdev_mount() = %ld\n",
Signature · 1 line
2.17.2
PATCH v3 2/26 nfs: stash server into struct nfs_mount_info
In reply to Scott MayhewFrom: Al Viro <[email protected]>
--- fs/nfs/internal.h | 3 ++- fs/nfs/nfs4super.c | 10 ++++------ fs/nfs/super.c | 19 ++++++++----------- 3 files changed, 14 insertions(+), 18 deletions(-)
fs/nfs/internal.h +2 -1
@@ -150,6 +150,7 @@ struct nfs_mount_info {int (*set_security)(struct super_block *,struct dentry *,struct nfs_mount_info *);struct nfs_parsed_mount_data *parsed;struct nfs_clone_mount *cloned; +struct nfs_server *server;struct nfs_fh *mntfh; };
@@ -405,7 +406,7 @@ struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *, struct nfs_subversion *);int nfs_set_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *); -struct dentry *nfs_fs_mount_common (struct nfs_server *,int ,const char *, +struct dentry *nfs_fs_mount_common (int ,const char *,struct nfs_mount_info *,struct nfs_subversion *);struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *); struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
fs/nfs/nfs4super.c +4 -6
@@ -109,13 +109,12 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *info) { struct nfs_mount_info *mount_info = info; -struct nfs_server *server; mount_info->set_security = nfs_set_sb_security;/* Get a volume representation */ - server =nfs4_create_server (mount_info, &nfs_v4); -return nfs_fs_mount_common (server, flags, dev_name, mount_info, &nfs_v4); + mount_info->server =nfs4_create_server (mount_info, &nfs_v4); +return nfs_fs_mount_common (flags, dev_name, mount_info, &nfs_v4); } static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
@@ -260,7 +259,6 @@ nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags, .set_security = nfs_clone_sb_security, .cloned = raw_data, }; -struct nfs_server *server;struct dentry *mntroot =ERR_PTR (-ENOMEM );dprintk ("--> nfs4_referral_get_sb()\n" );
@@ -270,8 +268,8 @@ nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags, goto out;/* create a new volume representation */ - server =nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh); - mntroot =nfs_fs_mount_common (server, flags, dev_name, &mount_info, &nfs_v4); + mount_info.server =nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh); + mntroot =nfs_fs_mount_common (flags, dev_name, &mount_info, &nfs_v4); out:nfs_free_fhandle (mount_info.mntfh);return mntroot;
fs/nfs/super.c +8 -11
@@ -1896,14 +1896,12 @@ struct dentry *nfs_try_mount(int flags, const char *dev_name, struct nfs_mount_info *mount_info, struct nfs_subversion *nfs_mod) { - struct nfs_server *server; -if (mount_info->parsed->need_mount) - server =nfs_try_mount_request (mount_info, nfs_mod); + mount_info->server =nfs_try_mount_request (mount_info, nfs_mod);else - server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); + mount_info->server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); -return nfs_fs_mount_common (server, flags, dev_name, mount_info, nfs_mod); +return nfs_fs_mount_common (flags, dev_name, mount_info, nfs_mod); }EXPORT_SYMBOL_GPL (nfs_try_mount);
@@ -2624,20 +2622,21 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot, }EXPORT_SYMBOL_GPL (nfs_clone_sb_security); -struct dentry *nfs_fs_mount_common (struct nfs_server *server, -int flags,const char *dev_name, +struct dentry *nfs_fs_mount_common (int flags,const char *dev_name,struct nfs_mount_info *mount_info,struct nfs_subversion *nfs_mod) {struct super_block *s;struct dentry *mntroot =ERR_PTR (-ENOMEM );int (*compare_super)(struct super_block *,void *) = nfs_compare_super; +struct nfs_server *server = mount_info->server;struct nfs_sb_mountdata sb_mntdata = { .mntflags = flags, .server = server, };int error; + mount_info->server =NULL ;if (IS_ERR (server))return ERR_CAST (server);
@@ -2778,7 +2777,6 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags, .set_security = nfs_clone_sb_security, .cloned = data, }; -struct nfs_server *server;struct dentry *mntroot =ERR_PTR (-ENOMEM );struct nfs_subversion *nfs_mod =NFS_SB (data->sb)->nfs_client->cl_nfs_mod;
@@ -2787,10 +2785,9 @@ nfs_xdev_mount(struct file_system_type *fs_type, int flags, mount_info.mntfh = mount_info.cloned->fh;/* create a new volume representation */ - server = nfs_mod->rpc_ops->clone_server (NFS_SB (data->sb), data->fh, data->fattr, data->authflavor); + mount_info.server = nfs_mod->rpc_ops->clone_server (NFS_SB (data->sb), data->fh, data->fattr, data->authflavor); - mntroot =nfs_fs_mount_common (server, flags, - dev_name, &mount_info, nfs_mod); + mntroot =nfs_fs_mount_common (flags, dev_name, &mount_info, nfs_mod);dprintk ("<-- nfs_xdev_mount() = %ld\n" ,IS_ERR (mntroot) ?PTR_ERR (mntroot) :0L );
Signature · 1 line
2.17.2
PATCH v3 3/26 nfs: lift setting mount_info from nfs4_remote{,_referral}_mount
In reply to Scott MayhewFrom: Al Viro <[email protected]>
Do that (fhandle allocation, setting struct server up) in nfs4_referral_mount() and nfs4_try_mount() resp. and pass the server and pointer to mount_info into nfs_do_root_mount() so that nfs4_remote_referral_mount()/nfs_remote_mount() could be merged.
Since we are moving stuff from ->mount() instances to the points prior to vfs_kern_mount() that would trigger those, we need to make sure that do_nfs_root_mount() will do the corresponding cleanup itself if it doesn't trigger those ->mount() instances.
--- fs/nfs/nfs4super.c | 67 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 32 deletions(-)
fs/nfs/nfs4super.c +35 -32
@@ -108,32 +108,37 @@ static struct dentry * nfs4_remote_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *info) { - struct nfs_mount_info *mount_info = info; - - mount_info->set_security = nfs_set_sb_security; - -/* Get a volume representation */ - mount_info->server =nfs4_create_server (mount_info, &nfs_v4); -return nfs_fs_mount_common (flags, dev_name, mount_info, &nfs_v4); + return nfs_fs_mount_common(flags, dev_name, info, &nfs_v4); }static struct vfsmount *nfs_do_root_mount (struct file_system_type *fs_type, -int flags,void *data,const char *hostname) +struct nfs_server *server,int flags, +struct nfs_mount_info *info, +const char *hostname) {struct vfsmount *root_mnt;char *root_devname;size_t len; +if (IS_ERR (server)) +return ERR_CAST (server); + len =strlen (hostname) +5 ; root_devname =kmalloc (len,GFP_KERNEL ); -if (root_devname ==NULL ) +if (root_devname ==NULL ) { +nfs_free_server (server);return ERR_PTR (-ENOMEM ); + }/* Does hostname needs to be enclosed in brackets? */ if (strchr (hostname,':' ))snprintf (root_devname, len,"[%s]:/" , hostname);else snprintf (root_devname, len,"%s:/" , hostname); - root_mnt =vfs_kern_mount (fs_type, flags, root_devname, data); + info->server = server; + root_mnt =vfs_kern_mount (fs_type, flags, root_devname, info); +if (info->server) +nfs_free_server (info->server); + info->server =NULL ;kfree (root_devname);return root_mnt; }
@@ -234,11 +239,15 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,struct dentry *res;struct nfs_parsed_mount_data *data = mount_info->parsed; + mount_info->set_security = nfs_set_sb_security; +dfprintk (MOUNT ,"--> nfs4_try_mount()\n" ); export_path = data->nfs_server.export_path; data->nfs_server.export_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_fs_type, flags, mount_info, + root_mnt =nfs_do_root_mount (&nfs4_remote_fs_type, +nfs4_create_server (mount_info, &nfs_v4), + flags, mount_info, data->nfs_server.hostname); data->nfs_server.export_path = export_path;
@@ -254,25 +263,7 @@ static struct dentry * nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *raw_data) { - struct nfs_mount_info mount_info = { - .fill_super = nfs_fill_super, - .set_security = nfs_clone_sb_security, - .cloned = raw_data, - }; -struct dentry *mntroot =ERR_PTR (-ENOMEM ); - -dprintk ("--> nfs4_referral_get_sb()\n" ); - - mount_info.mntfh =nfs_alloc_fhandle (); -if (mount_info.cloned ==NULL || mount_info.mntfh ==NULL ) - goto out; - -/* create a new volume representation */ - mount_info.server =nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh); - mntroot =nfs_fs_mount_common (flags, dev_name, &mount_info, &nfs_v4); -out: -nfs_free_fhandle (mount_info.mntfh); -return mntroot; + return nfs_fs_mount_common(flags, dev_name, raw_data, &nfs_v4); }/*
@@ -282,23 +273,35 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *raw_data) { struct nfs_clone_mount *data = raw_data; +struct nfs_mount_info mount_info = { + .fill_super = nfs_fill_super, + .set_security = nfs_clone_sb_security, + .cloned = data, + };char *export_path;struct vfsmount *root_mnt;struct dentry *res;dprintk ("--> nfs4_referral_mount()\n" ); + mount_info.mntfh =nfs_alloc_fhandle (); +if (!mount_info.mntfh) +return ERR_PTR (-ENOMEM ); + export_path = data->mnt_path; data->mnt_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_referral_fs_type, - flags, data, data->hostname); +nfs4_create_referral_server (mount_info.cloned, + mount_info.mntfh), + flags, &mount_info, data->hostname); data->mnt_path = export_path; res =nfs_follow_remote_path (root_mnt, export_path);dprintk ("<-- nfs4_referral_mount() = %d%s\n" ,PTR_ERR_OR_ZERO (res),IS_ERR (res) ?" [error]" :"" ); + +nfs_free_fhandle (mount_info.mntfh);return res; }
Signature · 1 line
2.17.2
PATCH v3 4/26 nfs: fold nfs4_remote_fs_type and nfs4_remote_referral_fs_type
In reply to Scott MayhewFrom: Al Viro <[email protected]>
They are identical now.
--- fs/nfs/nfs4super.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
fs/nfs/nfs4super.c +4 -22
@@ -22,8 +22,6 @@ static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *raw_data);static struct dentry *nfs4_referral_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *raw_data); -static struct dentry *nfs4_remote_referral_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data);static struct file_system_type nfs4_remote_fs_type = { .owner =THIS_MODULE ,
@@ -33,14 +31,6 @@ static struct file_system_type nfs4_remote_fs_type = { .fs_flags = FS_RENAME_DOES_D_MOVE|FS_BINARY_MOUNTDATA, }; -static struct file_system_type nfs4_remote_referral_fs_type = { - .owner =THIS_MODULE , - .name ="nfs4" , - .mount = nfs4_remote_referral_mount, - .kill_sb = nfs_kill_super, - .fs_flags =FS_RENAME_DOES_D_MOVE |FS_BINARY_MOUNTDATA , -}; -struct file_system_type nfs4_referral_fs_type = { .owner =THIS_MODULE , .name ="nfs4" ,
@@ -111,8 +101,7 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,return nfs_fs_mount_common (flags, dev_name, info, &nfs_v4); } -static struct vfsmount *nfs_do_root_mount (struct file_system_type *fs_type, -struct nfs_server *server,int flags, +static struct vfsmount *nfs_do_root_mount (struct nfs_server *server,int flags,struct nfs_mount_info *info,const char *hostname) {
@@ -135,7 +124,7 @@ static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,else snprintf (root_devname, len,"%s:/" , hostname); info->server = server; - root_mnt =vfs_kern_mount (fs_type, flags, root_devname, info); + root_mnt =vfs_kern_mount (&nfs4_remote_fs_type, flags, root_devname, info);if (info->server)nfs_free_server (info->server); info->server =NULL ;
@@ -245,7 +234,7 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name, export_path = data->nfs_server.export_path; data->nfs_server.export_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_fs_type, + root_mnt =nfs_do_root_mount (nfs4_create_server (mount_info, &nfs_v4), flags, mount_info, data->nfs_server.hostname);
@@ -259,13 +248,6 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,return res; } -static struct dentry * -nfs4_remote_referral_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) -{ -return nfs_fs_mount_common (flags, dev_name, raw_data, &nfs_v4); -} -/* * Create an NFS4 server record on referral traversal */
@@ -290,7 +272,7 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, export_path = data->mnt_path; data->mnt_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_referral_fs_type, + root_mnt =nfs_do_root_mount (nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh), flags, &mount_info, data->hostname);
Signature · 1 line
2.17.2
PATCH v3 5/26 nfs: don't bother setting/restoring export_path around do_nfs_root_mount()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
nothing in it will be looking at that thing anyway
--- fs/nfs/nfs4super.c | 4 ---- 1 file changed, 4 deletions(-)
fs/nfs/nfs4super.c +0 -4
@@ -233,12 +233,10 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,dfprintk (MOUNT ,"--> nfs4_try_mount()\n" ); export_path = data->nfs_server.export_path; - data->nfs_server.export_path ="/" ; root_mnt =nfs_do_root_mount (nfs4_create_server (mount_info, &nfs_v4), flags, mount_info, data->nfs_server.hostname); - data->nfs_server.export_path = export_path; res =nfs_follow_remote_path (root_mnt, export_path);
@@ -271,12 +269,10 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,return ERR_PTR (-ENOMEM ); export_path = data->mnt_path; - data->mnt_path ="/" ; root_mnt =nfs_do_root_mount (nfs4_create_referral_server (mount_info.cloned, mount_info.mntfh), flags, &mount_info, data->hostname); - data->mnt_path = export_path; res =nfs_follow_remote_path (root_mnt, export_path); dprintk("<-- nfs4_referral_mount() = %d%s\n",
Signature · 1 line
2.17.2
PATCH v3 6/26 nfs4: fold nfs_do_root_mount/nfs_follow_remote_path
In reply to Scott MayhewFrom: Al Viro <[email protected]>
--- fs/nfs/nfs4super.c | 88 +++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 51 deletions(-)
fs/nfs/nfs4super.c +37 -51
@@ -101,37 +101,6 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,return nfs_fs_mount_common (flags, dev_name, info, &nfs_v4); } -static struct vfsmount *nfs_do_root_mount (struct nfs_server *server,int flags, -struct nfs_mount_info *info, -const char *hostname) -{ -struct vfsmount *root_mnt; -char *root_devname; -size_t len; - -if (IS_ERR (server)) -return ERR_CAST (server); - - len =strlen (hostname) +5 ; - root_devname =kmalloc (len,GFP_KERNEL ); -if (root_devname ==NULL ) { -nfs_free_server (server); -return ERR_PTR (-ENOMEM ); - } -/* Does hostname needs to be enclosed in brackets? */ -if (strchr (hostname,':' )) -snprintf (root_devname, len,"[%s]:/" , hostname); -else -snprintf (root_devname, len,"%s:/" , hostname); - info->server = server; - root_mnt =vfs_kern_mount (&nfs4_remote_fs_type, flags, root_devname, info); -if (info->server) -nfs_free_server (info->server); - info->server =NULL ; -kfree (root_devname); -return root_mnt; -} -struct nfs_referral_count {struct list_head list;const struct task_struct *task;
@@ -198,11 +167,38 @@ static void nfs_referral_loop_unprotect(void)kfree (p); } -static struct dentry *nfs_follow_remote_path (struct vfsmount *root_mnt, -const char *export_path) +static struct dentry *do_nfs4_mount (struct nfs_server *server,int flags, +struct nfs_mount_info *info, +const char *hostname, +const char *export_path) { +struct vfsmount *root_mnt;struct dentry *dentry; +char *root_devname;int err; +size_t len; + +if (IS_ERR (server)) +return ERR_CAST (server); + + len =strlen (hostname) +5 ; + root_devname =kmalloc (len,GFP_KERNEL ); +if (root_devname ==NULL ) { +nfs_free_server (server); +return ERR_PTR (-ENOMEM ); + } + +/* Does hostname needs to be enclosed in brackets? */ +if (strchr (hostname,':' )) +snprintf (root_devname, len,"[%s]:/" , hostname); +else +snprintf (root_devname, len,"%s:/" , hostname); + info->server = server; + root_mnt =vfs_kern_mount (&nfs4_remote_fs_type, flags, root_devname, info); +if (info->server) +nfs_free_server (info->server); + info->server =NULL ; +kfree (root_devname);if (IS_ERR (root_mnt))return ERR_CAST (root_mnt);
@@ -223,22 +219,17 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,struct nfs_mount_info *mount_info, struct nfs_subversion *nfs_mod) { - char *export_path; -struct vfsmount *root_mnt; -struct dentry *res; struct nfs_parsed_mount_data *data = mount_info->parsed; +struct dentry *res; mount_info->set_security = nfs_set_sb_security;dfprintk (MOUNT ,"--> nfs4_try_mount()\n" ); - export_path = data->nfs_server.export_path; - root_mnt =nfs_do_root_mount ( -nfs4_create_server (mount_info, &nfs_v4), - flags, mount_info, - data->nfs_server.hostname); - - res =nfs_follow_remote_path (root_mnt, export_path); + res =do_nfs4_mount (nfs4_create_server (mount_info, &nfs_v4), + flags, mount_info, + data->nfs_server.hostname, + data->nfs_server.export_path); dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", PTR_ERR_OR_ZERO(res),
@@ -258,8 +249,6 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, .set_security = nfs_clone_sb_security, .cloned = data, }; -char *export_path; -struct vfsmount *root_mnt;struct dentry *res;dprintk ("--> nfs4_referral_mount()\n" );
@@ -268,13 +257,10 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type,if (!mount_info.mntfh)return ERR_PTR (-ENOMEM ); - export_path = data->mnt_path; - root_mnt =nfs_do_root_mount ( -nfs4_create_referral_server (mount_info.cloned, - mount_info.mntfh), - flags, &mount_info, data->hostname); + res =do_nfs4_mount (nfs4_create_referral_server (mount_info.cloned, + mount_info.mntfh), + flags, &mount_info, data->hostname, data->mnt_path); - res =nfs_follow_remote_path (root_mnt, export_path);dprintk ("<-- nfs4_referral_mount() = %d%s\n" ,PTR_ERR_OR_ZERO (res),IS_ERR (res) ?" [error]" :"" );
Signature · 1 line
2.17.2
PATCH v3 7/26 nfs: lift setting mount_info from nfs_xdev_mount()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
Do it in nfs_do_submount() instead. As a side benefit, nfs_clone_data doesn't need ->fh and ->fattr anymore.
--- fs/nfs/internal.h | 3 +-- fs/nfs/namespace.c | 35 +++++++++++++++++++++-------------- fs/nfs/super.c | 25 ++++--------------------- 3 files changed, 26 insertions(+), 37 deletions(-)
fs/nfs/internal.h +1 -2
@@ -42,8 +42,6 @@ static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)struct nfs_clone_mount {const struct super_block *sb;const struct dentry *dentry; -struct nfs_fh *fh; -struct nfs_fattr *fattr;char *hostname;char *mnt_path;struct sockaddr *addr;
@@ -413,6 +411,7 @@ struct dentry * nfs_xdev_mount_common(struct file_system_type *, int, const char *, struct nfs_mount_info *);void nfs_kill_super (struct super_block *);void nfs_fill_super (struct super_block *,struct nfs_mount_info *); +void nfs_clone_super (struct super_block *,struct nfs_mount_info *);extern struct rpc_stat nfs_rpcstat;
fs/nfs/namespace.c +21 -14
@@ -19,6 +19,7 @@#include <linux/vfs.h> #include <linux/sunrpc/gss_api.h> #include "internal.h" +#include "nfs.h" #define NFSDBG_FACILITY NFSDBG_VFS
@@ -210,16 +211,6 @@ void nfs_release_automount_timer(void)cancel_delayed_work (&nfs_automount_task); } -/* -* Clone a mountpoint of the appropriate type -*/ -static struct vfsmount *nfs_do_clone_mount (struct nfs_server *server, -const char *devname, -struct nfs_clone_mount *mountdata) -{ -return vfs_submount (mountdata->dentry, &nfs_xdev_fs_type, devname, mountdata); -} -/** * nfs_do_submount - set up mountpoint when crossing a filesystem boundary * @dentry: parent directory
@@ -231,13 +222,20 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server,struct vfsmount *nfs_do_submount (struct dentry *dentry,struct nfs_fh *fh,struct nfs_fattr *fattr,rpc_authflavor_t authflavor) { +struct super_block *sb = dentry->d_sb;struct nfs_clone_mount mountdata = { - .sb = dentry->d_sb, + .sb = sb, .dentry = dentry, - .fh = fh, - .fattr = fattr, .authflavor = authflavor, }; +struct nfs_mount_info mount_info = { + .fill_super = nfs_clone_super, + .set_security = nfs_clone_sb_security, + .cloned = &mountdata, + .mntfh = fh, + }; +struct nfs_subversion *nfs_mod =NFS_SB (sb)->nfs_client->cl_nfs_mod; +struct nfs_server *server;struct vfsmount *mnt;char *page = (char *)__get_free_page (GFP_USER );char *devname;
@@ -245,12 +243,21 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh,if (page ==NULL )return ERR_PTR (-ENOMEM ); + server = nfs_mod->rpc_ops->clone_server (NFS_SB (sb), fh, + fattr, authflavor); +if (IS_ERR (server)) +return ERR_CAST (server); + + mount_info.server = server; + devname =nfs_devname (dentry, page,PAGE_SIZE );if (IS_ERR (devname)) mnt =ERR_CAST (devname);else - mnt =nfs_do_clone_mount (NFS_SB (dentry->d_sb), devname, &mountdata); + mnt =vfs_submount (dentry, &nfs_xdev_fs_type, devname, &mount_info); +if (mount_info.server) +nfs_free_server (mount_info.server);free_page ((unsigned long )page);return mnt; }
fs/nfs/super.c +4 -21
@@ -2386,7 +2386,7 @@ EXPORT_SYMBOL_GPL(nfs_fill_super);/* * Finish setting up a cloned NFS2/3/4 superblock */ -static void nfs_clone_super (struct super_block *sb, +void nfs_clone_super (struct super_block *sb,struct nfs_mount_info *mount_info) {const struct super_block *old_sb = mount_info->cloned->sb;
@@ -2771,27 +2771,10 @@ static struct dentry * nfs_xdev_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *raw_data) { - struct nfs_clone_mount *data = raw_data; -struct nfs_mount_info mount_info = { - .fill_super = nfs_clone_super, - .set_security = nfs_clone_sb_security, - .cloned = data, - }; -struct dentry *mntroot =ERR_PTR (-ENOMEM ); -struct nfs_subversion *nfs_mod =NFS_SB (data->sb)->nfs_client->cl_nfs_mod; - -dprintk ("--> nfs_xdev_mount()\n" ); + struct nfs_mount_info *info = raw_data; +struct nfs_subversion *nfs_mod =NFS_SB (info->cloned->sb)->nfs_client->cl_nfs_mod; - mount_info.mntfh = mount_info.cloned->fh; - -/* create a new volume representation */ - mount_info.server = nfs_mod->rpc_ops->clone_server (NFS_SB (data->sb), data->fh, data->fattr, data->authflavor); - - mntroot =nfs_fs_mount_common (flags, dev_name, &mount_info, nfs_mod); - -dprintk ("<-- nfs_xdev_mount() = %ld\n" , -IS_ERR (mntroot) ?PTR_ERR (mntroot) :0L ); -return mntroot; +return nfs_fs_mount_common (flags, dev_name, info, nfs_mod); }#if IS_ENABLED (CONFIG_NFS_V4 )
Signature · 1 line
2.17.2
PATCH v3 8/26 nfs: stash nfs_subversion reference into nfs_mount_info
In reply to Scott MayhewFrom: Al Viro <[email protected]>
That will allow to get rid of passing those references around in quite a few places. Moreover, that will allow to merge xdev and remote file_system_type.
--- fs/nfs/internal.h | 1 + fs/nfs/namespace.c | 6 +++--- fs/nfs/nfs4super.c | 1 + fs/nfs/super.c | 1 + 4 files changed, 6 insertions(+), 3 deletions(-)
fs/nfs/internal.h +1 -0
@@ -150,6 +150,7 @@ struct nfs_mount_info {struct nfs_clone_mount *cloned;struct nfs_server *server;struct nfs_fh *mntfh; +struct nfs_subversion *nfs_mod; };extern int nfs_mount (struct nfs_mount_request *info);
fs/nfs/namespace.c +3 -3
@@ -233,8 +233,8 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, .set_security = nfs_clone_sb_security, .cloned = &mountdata, .mntfh = fh, + .nfs_mod = NFS_SB(sb)->nfs_client->cl_nfs_mod, }; -struct nfs_subversion *nfs_mod =NFS_SB (sb)->nfs_client->cl_nfs_mod;struct nfs_server *server;struct vfsmount *mnt;char *page = (char *)__get_free_page (GFP_USER );
@@ -243,8 +243,8 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh,if (page ==NULL )return ERR_PTR (-ENOMEM ); - server = nfs_mod->rpc_ops->clone_server (NFS_SB (sb), fh, - fattr, authflavor); + server = mount_info.nfs_mod->rpc_ops->clone_server (NFS_SB (sb), fh, + fattr, authflavor);if (IS_ERR (server))return ERR_CAST (server);
fs/nfs/nfs4super.c +1 -0
@@ -248,6 +248,7 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, .fill_super = nfs_fill_super, .set_security = nfs_clone_sb_security, .cloned = data, + .nfs_mod = &nfs_v4, };struct dentry *res;
fs/nfs/super.c +1 -0
@@ -2736,6 +2736,7 @@ struct dentry *nfs_fs_mount(struct file_system_type *fs_type, mntroot =ERR_CAST (nfs_mod); goto out; } + mount_info.nfs_mod = nfs_mod; mntroot = nfs_mod->rpc_ops->try_mount (flags, dev_name, &mount_info, nfs_mod);
Signature · 1 line
2.17.2
PATCH v3 9/26 nfs: don't bother passing nfs_subversion to ->try_mount() and nfs_fs_mount_common()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
--- fs/nfs/internal.h | 6 ++---- fs/nfs/nfs4_fs.h | 2 +- fs/nfs/nfs4super.c | 5 ++--- fs/nfs/super.c | 19 ++++++++----------- include/linux/nfs_xdr.h | 3 +-- 5 files changed, 14 insertions(+), 21 deletions(-)
fs/nfs/internal.h +2 -4
@@ -401,12 +401,10 @@ extern struct file_system_type nfs_xdev_fs_type;extern struct file_system_type nfs4_referral_fs_type;#endif bool nfs_auth_info_match (const struct nfs_auth_info *,rpc_authflavor_t ); -struct dentry *nfs_try_mount (int ,const char *,struct nfs_mount_info *, -struct nfs_subversion *); +struct dentry *nfs_try_mount (int ,const char *,struct nfs_mount_info *);int nfs_set_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *); -struct dentry *nfs_fs_mount_common (int ,const char *, -struct nfs_mount_info *,struct nfs_subversion *); +struct dentry *nfs_fs_mount_common (int ,const char *,struct nfs_mount_info *);struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *);struct dentry *nfs_xdev_mount_common (struct file_system_type *,int ,const char *,struct nfs_mount_info *);
fs/nfs/nfs4_fs.h +1 -1
@@ -517,7 +517,7 @@ extern const nfs4_stateid invalid_stateid;/* nfs4super.c */ struct nfs_mount_info ;extern struct nfs_subversion nfs_v4; -struct dentry *nfs4_try_mount (int ,const char *,struct nfs_mount_info *,struct nfs_subversion *); +struct dentry *nfs4_try_mount (int ,const char *,struct nfs_mount_info *);extern bool nfs4_disable_idmapping;extern unsigned short max_session_slots;extern unsigned short max_session_cb_slots;
fs/nfs/nfs4super.c +2 -3
@@ -98,7 +98,7 @@ static struct dentry * nfs4_remote_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *info) { - return nfs_fs_mount_common(flags, dev_name, info, &nfs_v4); + return nfs_fs_mount_common(flags, dev_name, info); } struct nfs_referral_count {
@@ -216,8 +216,7 @@ static struct dentry *do_nfs4_mount(struct nfs_server *server, int flags, }struct dentry *nfs4_try_mount (int flags,const char *dev_name, -struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_mount_info *mount_info) {struct nfs_parsed_mount_data *data = mount_info->parsed;struct dentry *res;
fs/nfs/super.c +8 -11
@@ -1893,15 +1893,15 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_inf }struct dentry *nfs_try_mount (int flags,const char *dev_name, -struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_mount_info *mount_info) { +struct nfs_subversion *nfs_mod = mount_info->nfs_mod;if (mount_info->parsed->need_mount) mount_info->server =nfs_try_mount_request (mount_info, nfs_mod);else mount_info->server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); -return nfs_fs_mount_common (flags, dev_name, mount_info, nfs_mod); +return nfs_fs_mount_common (flags, dev_name, mount_info); }EXPORT_SYMBOL_GPL (nfs_try_mount);
@@ -2623,8 +2623,7 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,EXPORT_SYMBOL_GPL (nfs_clone_sb_security);struct dentry *nfs_fs_mount_common (int flags,const char *dev_name, -struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_mount_info *mount_info) {struct super_block *s;struct dentry *mntroot =ERR_PTR (-ENOMEM );
@@ -2652,7 +2651,8 @@ struct dentry *nfs_fs_mount_common(int flags, const char *dev_name, sb_mntdata.mntflags |=SB_SYNCHRONOUS ;/* Get a superblock - note that we may end up sharing one that already exists */ - s =sget (nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata); + s =sget (mount_info->nfs_mod->nfs_fs, compare_super, nfs_set_super, + flags, &sb_mntdata);if (IS_ERR (s)) { mntroot =ERR_CAST (s); goto out_err_nosb;
@@ -2738,7 +2738,7 @@ struct dentry *nfs_fs_mount(struct file_system_type *fs_type, } mount_info.nfs_mod = nfs_mod; - mntroot = nfs_mod->rpc_ops->try_mount (flags, dev_name, &mount_info, nfs_mod); + mntroot = nfs_mod->rpc_ops->try_mount (flags, dev_name, &mount_info);put_nfs_version (nfs_mod); out:
@@ -2772,10 +2772,7 @@ static struct dentry * nfs_xdev_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *raw_data) { - struct nfs_mount_info *info = raw_data; -struct nfs_subversion *nfs_mod =NFS_SB (info->cloned->sb)->nfs_client->cl_nfs_mod; - -return nfs_fs_mount_common (flags, dev_name, info, nfs_mod); + return nfs_fs_mount_common(flags, dev_name, raw_data); }#if IS_ENABLED (CONFIG_NFS_V4 )
include/linux/nfs_xdr.h +1 -2
@@ -1638,8 +1638,7 @@ struct nfs_rpc_ops { struct nfs_fsinfo *);struct vfsmount *(*submount) (struct nfs_server *,struct dentry *,struct nfs_fh *,struct nfs_fattr *); -struct dentry *(*try_mount) (int ,const char *,struct nfs_mount_info *, -struct nfs_subversion *); +struct dentry *(*try_mount) (int ,const char *,struct nfs_mount_info *);int (*getattr) (struct nfs_server *,struct nfs_fh *,struct nfs_fattr *,struct nfs4_label *,struct inode *);
Signature · 1 line
2.17.2
PATCH v3 10/26 nfs: merge xdev and remote file_system_type
In reply to Scott MayhewFrom: Al Viro <[email protected]>
they are identical now...
--- fs/nfs/internal.h | 2 +- fs/nfs/namespace.c | 2 +- fs/nfs/nfs4super.c | 22 +--------------------- fs/nfs/super.c | 14 ++++++++------ 4 files changed, 11 insertions(+), 29 deletions(-)
fs/nfs/internal.h +1 -1
@@ -396,7 +396,7 @@ extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);/* super.c */ extern const struct super_operations nfs_sops;extern struct file_system_type nfs_fs_type; -extern struct file_system_type nfs_xdev_fs_type; +extern struct file_system_type nfs_prepared_fs_type;#if IS_ENABLED (CONFIG_NFS_V4 )extern struct file_system_type nfs4_referral_fs_type;#endif
fs/nfs/namespace.c +1 -1
@@ -254,7 +254,7 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh,if (IS_ERR (devname)) mnt =ERR_CAST (devname);else - mnt =vfs_submount (dentry, &nfs_xdev_fs_type, devname, &mount_info); + mnt =vfs_submount (dentry, &nfs_prepared_fs_type, devname, &mount_info);if (mount_info.server)nfs_free_server (mount_info.server);
fs/nfs/nfs4super.c +1 -21
@@ -18,19 +18,9 @@static int nfs4_write_inode (struct inode *inode,struct writeback_control *wbc);static void nfs4_evict_inode (struct inode *inode); -static struct dentry *nfs4_remote_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data);static struct dentry *nfs4_referral_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *raw_data); -static struct file_system_type nfs4_remote_fs_type = { - .owner =THIS_MODULE , - .name ="nfs4" , - .mount = nfs4_remote_mount, - .kill_sb = nfs_kill_super, - .fs_flags =FS_RENAME_DOES_D_MOVE |FS_BINARY_MOUNTDATA , -}; -struct file_system_type nfs4_referral_fs_type = { .owner =THIS_MODULE , .name ="nfs4" ,
@@ -91,16 +81,6 @@ static void nfs4_evict_inode(struct inode *inode)nfs_clear_inode (inode); } -/* -* Get the superblock for the NFS4 root partition -*/ -static struct dentry * -nfs4_remote_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *info) -{ -return nfs_fs_mount_common (flags, dev_name, info); -} -struct nfs_referral_count {struct list_head list;const struct task_struct *task;
@@ -194,7 +174,7 @@ static struct dentry *do_nfs4_mount(struct nfs_server *server, int flags,else snprintf (root_devname, len,"%s:/" , hostname); info->server = server; - root_mnt =vfs_kern_mount (&nfs4_remote_fs_type, flags, root_devname, info); + root_mnt =vfs_kern_mount (&nfs_prepared_fs_type, flags, root_devname, info);if (info->server)nfs_free_server (info->server); info->server =NULL ;
fs/nfs/super.c +8 -6
@@ -293,7 +293,7 @@ static match_table_t nfs_vers_tokens = { { Opt_vers_err, NULL } }; -static struct dentry *nfs_xdev_mount (struct file_system_type *fs_type, +static struct dentry *nfs_prepared_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *raw_data);struct file_system_type nfs_fs_type = {
@@ -306,13 +306,14 @@ struct file_system_type nfs_fs_type = {MODULE_ALIAS_FS ("nfs" );EXPORT_SYMBOL_GPL (nfs_fs_type); -struct file_system_type nfs_xdev_fs_type = { +struct file_system_type nfs_prepared_fs_type = { .owner =THIS_MODULE , .name ="nfs" , - .mount = nfs_xdev_mount, + .mount = nfs_prepared_mount, .kill_sb = nfs_kill_super, .fs_flags =FS_RENAME_DOES_D_MOVE |FS_BINARY_MOUNTDATA , }; +EXPORT_SYMBOL_GPL (nfs_prepared_fs_type);const struct super_operations nfs_sops = { .alloc_inode = nfs_alloc_inode,
@@ -2766,11 +2767,12 @@ void nfs_kill_super(struct super_block *s)EXPORT_SYMBOL_GPL (nfs_kill_super);/* -* Clone an NFS2/3/4 server record on xdev traversal (FSID-change) +* Internal use only: mount_info is already set up by caller. +* Used for mountpoint crossings and for nfs4 root. */ static struct dentry * -nfs_xdev_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) +nfs_prepared_mount (struct file_system_type *fs_type,int flags, +const char *dev_name,void *raw_data) {return nfs_fs_mount_common (flags, dev_name, raw_data); }
Signature · 1 line
2.17.2
PATCH v3 11/26 nfs: unexport nfs_fs_mount_common()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
Make it static, even. And remove a stale extern of (long-gone) nfs_xdev_mount_common() from internal.h, while we are at it.
--- fs/nfs/internal.h | 3 --- fs/nfs/super.c | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-)
fs/nfs/internal.h +0 -3
@@ -404,10 +404,7 @@ bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);struct dentry *nfs_try_mount (int ,const char *,struct nfs_mount_info *);int nfs_set_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *); -struct dentry *nfs_fs_mount_common (int ,const char *,struct nfs_mount_info *);struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *); -struct dentry *nfs_xdev_mount_common (struct file_system_type *,int , -const char *,struct nfs_mount_info *);void nfs_kill_super (struct super_block *);void nfs_fill_super (struct super_block *,struct nfs_mount_info *);void nfs_clone_super (struct super_block *,struct nfs_mount_info *);
fs/nfs/super.c +3 -2
@@ -1893,6 +1893,8 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_infreturn nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); } +static struct dentry *nfs_fs_mount_common (int ,const char *,struct nfs_mount_info *); +struct dentry *nfs_try_mount (int flags,const char *dev_name,struct nfs_mount_info *mount_info) {
@@ -2623,7 +2625,7 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot, }EXPORT_SYMBOL_GPL (nfs_clone_sb_security); -struct dentry *nfs_fs_mount_common (int flags,const char *dev_name, +static struct dentry *nfs_fs_mount_common (int flags,const char *dev_name,struct nfs_mount_info *mount_info) {struct super_block *s;
@@ -2705,7 +2707,6 @@ struct dentry *nfs_fs_mount_common(int flags, const char *dev_name,deactivate_locked_super (s); goto out; } -EXPORT_SYMBOL_GPL (nfs_fs_mount_common);struct dentry *nfs_fs_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *raw_data)
Signature · 1 line
2.17.2
PATCH v3 12/26 nfs: don't pass nfs_subversion to ->create_server()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
pick it from mount_info
--- fs/nfs/client.c | 4 ++-- fs/nfs/internal.h | 7 ++----- fs/nfs/nfs3_fs.h | 2 +- fs/nfs/nfs3client.c | 5 ++--- fs/nfs/nfs4client.c | 3 +-- fs/nfs/nfs4super.c | 2 +- fs/nfs/super.c | 14 +++++++------- include/linux/nfs_xdr.h | 2 +- 8 files changed, 17 insertions(+), 22 deletions(-)
fs/nfs/client.c +2 -2
@@ -940,10 +940,10 @@ EXPORT_SYMBOL_GPL(nfs_free_server);* Create a version 2 or 3 volume record * - keyed on server and FSID */ -struct nfs_server *nfs_create_server (struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_server *nfs_create_server (struct nfs_mount_info *mount_info) {struct nfs_server *server; +struct nfs_subversion *nfs_mod = mount_info->nfs_mod;struct nfs_fattr *fattr;int error;
fs/nfs/internal.h +2 -5
@@ -178,11 +178,8 @@ extern struct nfs_client *nfs4_find_client_ident(struct net *, int);extern struct nfs_client *nfs4_find_client_sessionid (struct net *,const struct sockaddr *,struct nfs4_sessionid *,u32 ); -extern struct nfs_server *nfs_create_server (struct nfs_mount_info *, -struct nfs_subversion *); -extern struct nfs_server *nfs4_create_server ( -struct nfs_mount_info *, -struct nfs_subversion *); +extern struct nfs_server *nfs_create_server (struct nfs_mount_info *); +extern struct nfs_server *nfs4_create_server (struct nfs_mount_info *);extern struct nfs_server *nfs4_create_referral_server (struct nfs_clone_mount *,struct nfs_fh *); extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
fs/nfs/nfs3_fs.h +1 -1
@@ -27,7 +27,7 @@ static inline int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,#endif /* CONFIG_NFS_V3_ACL */ /* nfs3client.c */ -struct nfs_server *nfs3_create_server (struct nfs_mount_info *,struct nfs_subversion *); +struct nfs_server *nfs3_create_server (struct nfs_mount_info *);struct nfs_server *nfs3_clone_server (struct nfs_server *,struct nfs_fh *,struct nfs_fattr *,rpc_authflavor_t );
fs/nfs/nfs3client.c +2 -3
@@ -46,10 +46,9 @@ static inline void nfs_init_server_aclclient(struct nfs_server *server) }#endif -struct nfs_server *nfs3_create_server (struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_server *nfs3_create_server (struct nfs_mount_info *mount_info) { -struct nfs_server *server =nfs_create_server (mount_info, nfs_mod); +struct nfs_server *server =nfs_create_server (mount_info);/* Create a client RPC handle for the NFS v3 ACL management interface */ if (!IS_ERR (server))nfs_init_server_aclclient (server);
fs/nfs/nfs4client.c +1 -2
@@ -1109,8 +1109,7 @@ static int nfs4_init_server(struct nfs_server *server,*/ /*struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, struct nfs_fh *mntfh)*/ -struct nfs_server *nfs4_create_server (struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +struct nfs_server *nfs4_create_server (struct nfs_mount_info *mount_info) {struct nfs_server *server;bool auth_probe;
fs/nfs/nfs4super.c +1 -1
@@ -205,7 +205,7 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,dfprintk (MOUNT ,"--> nfs4_try_mount()\n" ); - res =do_nfs4_mount (nfs4_create_server (mount_info, &nfs_v4), + res =do_nfs4_mount (nfs4_create_server (mount_info), flags, mount_info, data->nfs_server.hostname, data->nfs_server.export_path);
fs/nfs/super.c +7 -7
@@ -1820,8 +1820,7 @@ static int nfs_request_mount(struct nfs_parsed_mount_data *args,return 0 ; } -static struct nfs_server *nfs_try_mount_request (struct nfs_mount_info *mount_info, -struct nfs_subversion *nfs_mod) +static struct nfs_server *nfs_try_mount_request (struct nfs_mount_info *mount_info) {int status;unsigned int i;
@@ -1831,6 +1830,7 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_infstruct nfs_parsed_mount_data *args = mount_info->parsed;rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS ];unsigned int authlist_len =ARRAY_SIZE (authlist); +struct nfs_subversion *nfs_mod = mount_info->nfs_mod; status =nfs_request_mount (args, mount_info->mntfh, authlist, &authlist_len);
@@ -1847,7 +1847,7 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_inf args->selected_flavor);if (status)return ERR_PTR (status); -return nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); +return nfs_mod->rpc_ops->create_server (mount_info); }/*
@@ -1874,7 +1874,7 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_inf }dfprintk (MOUNT ,"NFS: attempting to use auth flavor %u\n" , flavor); args->selected_flavor = flavor; - server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); + server = nfs_mod->rpc_ops->create_server (mount_info);if (!IS_ERR (server))return server; }
@@ -1890,7 +1890,7 @@ static struct nfs_server *nfs_try_mount_request(struct nfs_mount_info *mount_inf/* Last chance! Try AUTH_UNIX */ dfprintk (MOUNT ,"NFS: attempting to use auth flavor %u\n" ,RPC_AUTH_UNIX ); args->selected_flavor =RPC_AUTH_UNIX ; -return nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); +return nfs_mod->rpc_ops->create_server (mount_info); }static struct dentry *nfs_fs_mount_common (int ,const char *,struct nfs_mount_info *);
@@ -1900,9 +1900,9 @@ struct dentry *nfs_try_mount(int flags, const char *dev_name, {struct nfs_subversion *nfs_mod = mount_info->nfs_mod;if (mount_info->parsed->need_mount) - mount_info->server =nfs_try_mount_request (mount_info, nfs_mod); + mount_info->server =nfs_try_mount_request (mount_info);else - mount_info->server = nfs_mod->rpc_ops->create_server (mount_info, nfs_mod); + mount_info->server = nfs_mod->rpc_ops->create_server (mount_info);return nfs_fs_mount_common (flags, dev_name, mount_info); }
include/linux/nfs_xdr.h +1 -1
@@ -1705,7 +1705,7 @@ struct nfs_rpc_ops {struct nfs_client *(*init_client) (struct nfs_client *,const struct nfs_client_initdata *);void (*free_client) (struct nfs_client *); -struct nfs_server *(*create_server)(struct nfs_mount_info *,struct nfs_subversion *); +struct nfs_server *(*create_server)(struct nfs_mount_info *);struct nfs_server *(*clone_server)(struct nfs_server *,struct nfs_fh *,struct nfs_fattr *,rpc_authflavor_t ); };
Signature · 1 line
2.17.2
PATCH v3 13/26 nfs: get rid of mount_info ->fill_super()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
The only possible values are nfs_fill_super and nfs_clone_super. The latter is used only when crossing into a submount and it is almost identical to the former; the only differences are
* ->s_time_gran unconditionally set to 1 (even for v2 mounts).
Regression dating back to 2012, actually.
* ->s_blocksize/->s_blocksize_bits set to that of parent.
Rather than messing with the method, stash ->s_blocksize_bits in mount_info in submount case and after the (now unconditional) call of nfs_fill_super() override ->s_blocksize/->s_blocksize_bits if that has been set.
--- fs/nfs/internal.h | 4 +-- fs/nfs/namespace.c | 2 +- fs/nfs/nfs4super.c | 1 - fs/nfs/super.c | 66 +++++++++++----------------------------------- 4 files changed, 18 insertions(+), 55 deletions(-)
fs/nfs/internal.h +1 -3
@@ -144,7 +144,7 @@ struct nfs_mount_request { };struct nfs_mount_info { -void (*fill_super)(struct super_block *,struct nfs_mount_info *); +unsigned int inherited_bsize;int (*set_security)(struct super_block *,struct dentry *,struct nfs_mount_info *);struct nfs_parsed_mount_data *parsed;struct nfs_clone_mount *cloned;
@@ -403,8 +403,6 @@ int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *);void nfs_kill_super (struct super_block *); -void nfs_fill_super (struct super_block *,struct nfs_mount_info *); -void nfs_clone_super (struct super_block *,struct nfs_mount_info *);extern struct rpc_stat nfs_rpcstat;
fs/nfs/namespace.c +1 -1
@@ -229,7 +229,7 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, .authflavor = authflavor, };struct nfs_mount_info mount_info = { - .fill_super = nfs_clone_super, + .inherited_bsize = sb->s_blocksize_bits, .set_security = nfs_clone_sb_security, .cloned = &mountdata, .mntfh = fh,
fs/nfs/nfs4super.c +0 -1
@@ -224,7 +224,6 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, {struct nfs_clone_mount *data = raw_data;struct nfs_mount_info mount_info = { - .fill_super = nfs_fill_super, .set_security = nfs_clone_sb_security, .cloned = data, .nfs_mod = &nfs_v4,
fs/nfs/super.c +16 -50
95 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v3 14/26 nfs_clone_sb_security(): simplify the check for server bogosity
In reply to Scott MayhewFrom: Al Viro <[email protected]>
We used to check ->i_op for being nfs_dir_inode_operations. With separate inode_operations for v3 and v4 that became bogus, but rather than going for protocol-dependent comparison we could've just checked ->i_fop instead; _that_ is the same for all protocol versions.
--- fs/nfs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
@@ -2569,7 +2569,7 @@ int nfs_clone_sb_security(struct super_block *s, struct dentry *mntroot,unsigned long kflags =0 , kflags_out =0 ;/* clone any lsm security options from the parent to the new sb */ -if (d_inode (mntroot)->i_op !=NFS_SB (s)->nfs_client->rpc_ops->dir_inode_ops) +if (d_inode (mntroot)->i_fop != &nfs_dir_operations)return -ESTALE ;if (NFS_SB (s)->caps &NFS_CAP_SECURITY_LABEL )
Signature · 1 line
2.17.2
PATCH v3 15/26 nfs: get rid of ->set_security()
In reply to Scott MayhewFrom: Al Viro <[email protected]>
it's always either nfs_set_sb_security() or nfs_clone_sb_security(), the choice being controlled by mount_info->cloned != NULL. No need to add methods, especially when both instances live right next to the caller and are never accessed anywhere else.
--- fs/nfs/internal.h | 3 -- fs/nfs/namespace.c | 1 - fs/nfs/nfs4super.c | 3 -- fs/nfs/super.c | 69 ++++++++++++++-------------------------------- 4 files changed, 21 insertions(+), 55 deletions(-)
fs/nfs/internal.h +0 -3
@@ -145,7 +145,6 @@ struct nfs_mount_request {struct nfs_mount_info {unsigned int inherited_bsize; -int (*set_security)(struct super_block *,struct dentry *,struct nfs_mount_info *);struct nfs_parsed_mount_data *parsed;struct nfs_clone_mount *cloned;struct nfs_server *server;
@@ -399,8 +398,6 @@ extern struct file_system_type nfs4_referral_fs_type;#endif bool nfs_auth_info_match (const struct nfs_auth_info *,rpc_authflavor_t );struct dentry *nfs_try_mount (int ,const char *,struct nfs_mount_info *); -int nfs_set_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *); -int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *);void nfs_kill_super (struct super_block *);
fs/nfs/namespace.c +0 -1
@@ -230,7 +230,6 @@ struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh, };struct nfs_mount_info mount_info = { .inherited_bsize = sb->s_blocksize_bits, - .set_security = nfs_clone_sb_security, .cloned = &mountdata, .mntfh = fh, .nfs_mod =NFS_SB (sb)->nfs_client->cl_nfs_mod,
fs/nfs/nfs4super.c +0 -3
@@ -201,8 +201,6 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,struct nfs_parsed_mount_data *data = mount_info->parsed;struct dentry *res; - mount_info->set_security = nfs_set_sb_security; -dfprintk (MOUNT ,"--> nfs4_try_mount()\n" ); res = do_nfs4_mount(nfs4_create_server(mount_info),
@@ -224,7 +222,6 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, {struct nfs_clone_mount *data = raw_data;struct nfs_mount_info mount_info = { - .set_security = nfs_clone_sb_security, .cloned = data, .nfs_mod = &nfs_v4, };
fs/nfs/super.c +21 -48
93 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v3 16/26 NFS: Move mount parameterisation bits into their own file
In reply to Scott MayhewFrom: David Howells <[email protected]>
Split various bits relating to mount parameterisation out from fs/nfs/super.c into their own file to form the basis of filesystem context handling for NFS.
No other changes are made to the code beyond removing 'static' qualifiers.
--- fs/nfs/Makefile | 2 +- fs/nfs/fs_context.c | 1418 +++++++++++++++++++++++++++++++++++++++++++ fs/nfs/internal.h | 29 + fs/nfs/super.c | 1411 ------------------------------------------ 4 files changed, 1448 insertions(+), 1412 deletions(-) create mode 100644 fs/nfs/fs_context.c
fs/nfs/Makefile +1 -1
@@ -9,7 +9,7 @@ CFLAGS_nfstrace.o += -I$(src) nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ io.o direct.o pagelist.o read.o symlink.o unlink.o \ write.o namespace.o mount_clnt.o nfstrace.o \ - export.o sysfs.o + export.o sysfs.o fs_context.o nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
fs/nfs/fs_context.c new file +1418 -0
1,418 lines not on this page · raw message
fs/nfs/internal.h +29 -0
@@ -7,6 +7,7 @@#include <linux/mount.h> #include <linux/security.h> #include <linux/crc32.h> +#include <linux/sunrpc/addr.h> #include <linux/nfs_page.h> #include <linux/wait_bit.h>
@@ -232,6 +233,22 @@ extern const struct svc_version nfs4_callback_version1;extern const struct svc_version nfs4_callback_version4;struct nfs_pageio_descriptor ; + +/* mount.c */ +#define NFS_TEXT_DATA 1 + +extern struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ); +extern void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data); +extern int nfs_parse_mount_options (char *raw,struct nfs_parsed_mount_data *mnt); +extern int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name); +extern int nfs_validate_text_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name); +/* pagelist.c */ extern int __init nfs_init_nfspagecache (void );extern void nfs_destroy_nfspagecache (void );
@@ -763,3 +780,15 @@ static inline bool nfs_error_is_fatal(int err) } } +/* +* Select between a default port value and a user-specified port value. +* If a zero value is set, then autobind will be used. +*/ +static inline void nfs_set_port (struct sockaddr *sap,int *port, +const unsigned short default_port) +{ +if (*port ==NFS_UNSPEC_PORT ) + *port = default_port; + +rpc_set_port (sap, *port); +}
fs/nfs/super.c +0 -1411
1,447 lines not on this page · raw message
Signature · 1 line
2.17.2
Re: [PATCH v3 16/26] NFS: Move mount parameterisation bits into their own file
Quoted 45 lines · Scott Mayhew
From: David Howells <[email protected]>
Split various bits relating to mount parameterisation out from
fs/nfs/super.cinto their own file to form the basis of filesystem context handling for NFS.No other changes are made to the code beyond removing 'static' qualifiers.
Signed-off-by David Howells <[email protected]>Signed-off-by Al Viro <[email protected]>---
fs/nfs/Makefile | 2 +- fs/nfs/fs_context.c | 1418 +++++++++++++++++++++++++++++++++++++++++++ fs/nfs/internal.h | 29 + fs/nfs/super.c | 1411 ------------------------------------------ 4 files changed, 1448 insertions(+), 1412 deletions(-)create mode 100644
fs/nfs/fs_context.cfs/nfs/Makefile +1
-1@@ -9,7 +9,7 @@ CFLAGS_nfstrace.o += -I$(src) nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ io.o direct.o pagelist.o read.o symlink.o unlink.o \ write.o namespace.o mount_clnt.o nfstrace.o \ - export.o sysfs.o + export.o sysfs.o fs_context.onfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.ofs/nfs/fs_context.c new file +4
-0@@ -0,0 +1,1418 @@ +/* NFS mount handling. +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected])
fs/nfs/fs_context.c line 14
Quoted 10 lines
fs/nfs/fs_context.c new file +10
-0+* +* Split from fs/nfs/super.c: +* +* Copyright (C) 1992 Rick Sladkey +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/
New source files should have an SPDX tag instead of boilerplate. I suggest:
// SPDX-License-Identifier: GPL-2.0-only
Quoted 2,915 lines
fs/nfs/fs_context.c new file +1404
-0+ +#include <linux/module.h> +#include <linux/fs.h> +#include <linux/parser.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> +#include "nfs.h" +#include "internal.h" + +#define NFSDBG_FACILITY NFSDBG_MOUNT + +#if IS_ENABLED (CONFIG_NFS_V3 ) +#define NFS_DEFAULT_VERSION 3 +#else +#define NFS_DEFAULT_VERSION 2 +#endif + +#define NFS_MAX_CONNECTIONS 16 + +enum { +/* Mount options that take no arguments */ + Opt_soft, Opt_softerr, Opt_hard, + Opt_posix, Opt_noposix, + Opt_cto, Opt_nocto, + Opt_ac, Opt_noac, + Opt_lock, Opt_nolock, + Opt_udp, Opt_tcp, Opt_rdma, + Opt_acl, Opt_noacl, + Opt_rdirplus, Opt_nordirplus, + Opt_sharecache, Opt_nosharecache, + Opt_resvport, Opt_noresvport, + Opt_fscache, Opt_nofscache, + Opt_migration, Opt_nomigration, + +/* Mount options that take integer arguments */ + Opt_port, + Opt_rsize, Opt_wsize, Opt_bsize, + Opt_timeo, Opt_retrans, + Opt_acregmin, Opt_acregmax, + Opt_acdirmin, Opt_acdirmax, + Opt_actimeo, + Opt_namelen, + Opt_mountport, + Opt_mountvers, + Opt_minorversion, + +/* Mount options that take string arguments */ + Opt_nfsvers, + Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, + Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_nconnect, + Opt_lookupcache, + Opt_fscache_uniq, + Opt_local_lock, + +/* Special mount options */ + Opt_userspace, Opt_deprecated, Opt_sloppy, + + Opt_err +}; + +static const match_table_t nfs_mount_option_tokens = { + { Opt_userspace,"bg" }, + { Opt_userspace,"fg" }, + { Opt_userspace,"retry=%s" }, + + { Opt_sloppy,"sloppy" }, + + { Opt_soft,"soft" }, + { Opt_softerr,"softerr" }, + { Opt_hard,"hard" }, + { Opt_deprecated,"intr" }, + { Opt_deprecated,"nointr" }, + { Opt_posix,"posix" }, + { Opt_noposix,"noposix" }, + { Opt_cto,"cto" }, + { Opt_nocto,"nocto" }, + { Opt_ac,"ac" }, + { Opt_noac,"noac" }, + { Opt_lock,"lock" }, + { Opt_nolock,"nolock" }, + { Opt_udp,"udp" }, + { Opt_tcp,"tcp" }, + { Opt_rdma,"rdma" }, + { Opt_acl,"acl" }, + { Opt_noacl,"noacl" }, + { Opt_rdirplus,"rdirplus" }, + { Opt_nordirplus,"nordirplus" }, + { Opt_sharecache,"sharecache" }, + { Opt_nosharecache,"nosharecache" }, + { Opt_resvport,"resvport" }, + { Opt_noresvport,"noresvport" }, + { Opt_fscache,"fsc" }, + { Opt_nofscache,"nofsc" }, + { Opt_migration,"migration" }, + { Opt_nomigration,"nomigration" }, + + { Opt_port,"port=%s" }, + { Opt_rsize,"rsize=%s" }, + { Opt_wsize,"wsize=%s" }, + { Opt_bsize,"bsize=%s" }, + { Opt_timeo,"timeo=%s" }, + { Opt_retrans,"retrans=%s" }, + { Opt_acregmin,"acregmin=%s" }, + { Opt_acregmax,"acregmax=%s" }, + { Opt_acdirmin,"acdirmin=%s" }, + { Opt_acdirmax,"acdirmax=%s" }, + { Opt_actimeo,"actimeo=%s" }, + { Opt_namelen,"namlen=%s" }, + { Opt_mountport,"mountport=%s" }, + { Opt_mountvers,"mountvers=%s" }, + { Opt_minorversion,"minorversion=%s" }, + + { Opt_nfsvers,"nfsvers=%s" }, + { Opt_nfsvers,"vers=%s" }, + + { Opt_sec,"sec=%s" }, + { Opt_proto,"proto=%s" }, + { Opt_mountproto,"mountproto=%s" }, + { Opt_addr,"addr=%s" }, + { Opt_clientaddr,"clientaddr=%s" }, + { Opt_mounthost,"mounthost=%s" }, + { Opt_mountaddr,"mountaddr=%s" }, + + { Opt_nconnect,"nconnect=%s" }, + + { Opt_lookupcache,"lookupcache=%s" }, + { Opt_fscache_uniq,"fsc=%s" }, + { Opt_local_lock,"local_lock=%s" }, + +/* The following needs to be listed after all other options */ + { Opt_nfsvers,"v%s" }, + + { Opt_err,NULL } +}; + +enum { + Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma, + Opt_xprt_rdma6, + + Opt_xprt_err +}; + +static const match_table_t nfs_xprt_protocol_tokens = { + { Opt_xprt_udp,"udp" }, + { Opt_xprt_udp6,"udp6" }, + { Opt_xprt_tcp,"tcp" }, + { Opt_xprt_tcp6,"tcp6" }, + { Opt_xprt_rdma,"rdma" }, + { Opt_xprt_rdma6,"rdma6" }, + + { Opt_xprt_err,NULL } +}; + +enum { + Opt_sec_none, Opt_sec_sys, + Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, + Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, + Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, + + Opt_sec_err +}; + +static const match_table_t nfs_secflavor_tokens = { + { Opt_sec_none,"none" }, + { Opt_sec_none,"null" }, + { Opt_sec_sys,"sys" }, + + { Opt_sec_krb5,"krb5" }, + { Opt_sec_krb5i,"krb5i" }, + { Opt_sec_krb5p,"krb5p" }, + + { Opt_sec_lkey,"lkey" }, + { Opt_sec_lkeyi,"lkeyi" }, + { Opt_sec_lkeyp,"lkeyp" }, + + { Opt_sec_spkm,"spkm3" }, + { Opt_sec_spkmi,"spkm3i" }, + { Opt_sec_spkmp,"spkm3p" }, + + { Opt_sec_err,NULL } +}; + +enum { + Opt_lookupcache_all, Opt_lookupcache_positive, + Opt_lookupcache_none, + + Opt_lookupcache_err +}; + +static match_table_t nfs_lookupcache_tokens = { + { Opt_lookupcache_all,"all" }, + { Opt_lookupcache_positive,"pos" }, + { Opt_lookupcache_positive,"positive" }, + { Opt_lookupcache_none,"none" }, + + { Opt_lookupcache_err,NULL } +}; + +enum { + Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, + Opt_local_lock_none, + + Opt_local_lock_err +}; + +static match_table_t nfs_local_lock_tokens = { + { Opt_local_lock_all,"all" }, + { Opt_local_lock_flock,"flock" }, + { Opt_local_lock_posix,"posix" }, + { Opt_local_lock_none,"none" }, + + { Opt_local_lock_err,NULL } +}; + +enum { + Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, + Opt_vers_4_1, Opt_vers_4_2, + + Opt_vers_err +}; + +static match_table_t nfs_vers_tokens = { + { Opt_vers_2,"2" }, + { Opt_vers_3,"3" }, + { Opt_vers_4,"4" }, + { Opt_vers_4_0,"4.0" }, + { Opt_vers_4_1,"4.1" }, + { Opt_vers_4_2,"4.2" }, + + { Opt_vers_err,NULL } +}; + +struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ) +{ +struct nfs_parsed_mount_data *data; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (data) { + data->timeo =NFS_UNSPEC_TIMEO ; + data->retrans =NFS_UNSPEC_RETRANS ; + data->acregmin =NFS_DEF_ACREGMIN ; + data->acregmax =NFS_DEF_ACREGMAX ; + data->acdirmin =NFS_DEF_ACDIRMIN ; + data->acdirmax =NFS_DEF_ACDIRMAX ; + data->mount_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + data->selected_flavor =RPC_AUTH_MAXFLAVOR ; + data->minorversion =0 ; + data->need_mount = true; + data->net = current->nsproxy->net_ns; + data->lsm_opts =NULL ; + } +return data; +} + +void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data) +{ +if (data) { +kfree (data->client_address); +kfree (data->mount_server.hostname); +kfree (data->nfs_server.export_path); +kfree (data->nfs_server.hostname); +kfree (data->fscache_uniq); +security_free_mnt_opts (&data->lsm_opts); +kfree (data); + } +} + +/* +* Sanity-check a server address provided by the mount command. +* +* Address family must be initialized, and address must not be +* the ANY address for that family. +*/ +static int nfs_verify_server_address (struct sockaddr *addr) +{ +switch (addr->sa_family) { +case AF_INET : { +struct sockaddr_in *sa = (struct sockaddr_in *)addr; +return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); + } +case AF_INET6 : { +struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; +return !ipv6_addr_any (sa); + } + } + +dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); +return 0 ; +} + +/* +* Sanity check the NFS transport protocol. +* +*/ +static void nfs_validate_transport_protocol (struct nfs_parsed_mount_data *mnt) +{ +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : +break ; +default : + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* For text based NFSv2/v3 mounts, the mount protocol transport default +* settings should depend upon the specified NFS transport. +*/ +static void nfs_set_mount_transport_protocol (struct nfs_parsed_mount_data *mnt) +{ +nfs_validate_transport_protocol (mnt); + +if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || + mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) +return ; +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : + mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : + mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* Add 'flavor' to 'auth_info' if not already present. +* Returns true if 'flavor' ends up in the list, false otherwise +*/ +static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, +rpc_authflavor_t flavor) +{ +unsigned int i; +unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); + +/* make sure this flavor isn't already in the list */ +for (i =0 ; i < auth_info->flavor_len; i++) { +if (flavor == auth_info->flavors[i]) +return true; + } + +if (auth_info->flavor_len +1 >= max_flavor_len) { +dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); +return false; + } + + auth_info->flavors[auth_info->flavor_len++] = flavor; +return true; +} + +/* +* Parse the value of the 'sec=' option. +*/ +static int nfs_parse_security_flavors (char *value, +struct nfs_parsed_mount_data *mnt) +{ +substring_t args[MAX_OPT_ARGS ]; +rpc_authflavor_t pseudoflavor; +char *p; + +dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); + +while ((p =strsep (&value,":" )) !=NULL ) { +switch (match_token (p, nfs_secflavor_tokens, args)) { +case Opt_sec_none: + pseudoflavor =RPC_AUTH_NULL ; +break ; +case Opt_sec_sys: + pseudoflavor =RPC_AUTH_UNIX ; +break ; +case Opt_sec_krb5: + pseudoflavor =RPC_AUTH_GSS_KRB5 ; +break ; +case Opt_sec_krb5i: + pseudoflavor =RPC_AUTH_GSS_KRB5I ; +break ; +case Opt_sec_krb5p: + pseudoflavor =RPC_AUTH_GSS_KRB5P ; +break ; +case Opt_sec_lkey: + pseudoflavor =RPC_AUTH_GSS_LKEY ; +break ; +case Opt_sec_lkeyi: + pseudoflavor =RPC_AUTH_GSS_LKEYI ; +break ; +case Opt_sec_lkeyp: + pseudoflavor =RPC_AUTH_GSS_LKEYP ; +break ; +case Opt_sec_spkm: + pseudoflavor =RPC_AUTH_GSS_SPKM ; +break ; +case Opt_sec_spkmi: + pseudoflavor =RPC_AUTH_GSS_SPKMI ; +break ; +case Opt_sec_spkmp: + pseudoflavor =RPC_AUTH_GSS_SPKMP ; +break ; +default : +dfprintk (MOUNT , +"NFS: sec= option '%s' not recognized\n" , p); +return 0 ; + } + +if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) +return 0 ; + } + +return 1 ; +} + +static int nfs_parse_version_string (char *string, +struct nfs_parsed_mount_data *mnt, +substring_t *args) +{ + mnt->flags &= ~NFS_MOUNT_VER3 ; +switch (match_token (string, nfs_vers_tokens, args)) { +case Opt_vers_2: + mnt->version =2 ; +break ; +case Opt_vers_3: + mnt->flags |=NFS_MOUNT_VER3 ; + mnt->version =3 ; +break ; +case Opt_vers_4: +/* Backward compatibility option. In future, +* the mount program should always supply +* a NFSv4 minor version number. +*/ + mnt->version =4 ; +break ; +case Opt_vers_4_0: + mnt->version =4 ; + mnt->minorversion =0 ; +break ; +case Opt_vers_4_1: + mnt->version =4 ; + mnt->minorversion =1 ; +break ; +case Opt_vers_4_2: + mnt->version =4 ; + mnt->minorversion =2 ; +break ; +default : +return 0 ; + } +return 1 ; +} + +static int nfs_get_option_str (substring_t args[],char **option) +{ +kfree (*option); + *option =match_strdup (args); +return !*option; +} + +static int nfs_get_option_ul (substring_t args[],unsigned long *option) +{ +int rc; +char *string; + + string =match_strdup (args); +if (string ==NULL ) +return -ENOMEM ; + rc =kstrtoul (string,10 , option); +kfree (string); + +return rc; +} + +static int nfs_get_option_ul_bound (substring_t args[],unsigned long *option, +unsigned long l_bound,unsigned long u_bound) +{ +int ret; + + ret =nfs_get_option_ul (args, option); +if (ret !=0 ) +return ret; +if (*option < l_bound || *option > u_bound) +return -ERANGE ; +return 0 ; +} + +/* +* Error-check and convert a string of mount options from user space into +* a data structure. The whole mount string is processed; bad options are +* skipped as they are encountered. If there were no errors, return 1; +* otherwise return 0 (zero). +*/ +int nfs_parse_mount_options (char *raw,struct nfs_parsed_mount_data *mnt) +{ +char *p, *string; +int rc, sloppy =0 , invalid_option =0 ; +unsigned short protofamily =AF_UNSPEC ; +unsigned short mountfamily =AF_UNSPEC ; + +if (!raw) { +dfprintk (MOUNT ,"NFS: mount options string was NULL.\n" ); +return 1 ; + } +dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); + + rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); +if (rc) + goto out_security_failure; + +while ((p =strsep (&raw,"," )) !=NULL ) { +substring_t args[MAX_OPT_ARGS ]; +unsigned long option; +int token; + +if (!*p) +continue ; + +dfprintk (MOUNT ,"NFS: parsing nfs mount option '%s'\n" , p); + + token =match_token (p, nfs_mount_option_tokens, args); +switch (token) { + +/* +* boolean options: foo/nofoo +*/ +case Opt_soft: + mnt->flags |=NFS_MOUNT_SOFT ; + mnt->flags &= ~NFS_MOUNT_SOFTERR ; +break ; +case Opt_softerr: + mnt->flags |=NFS_MOUNT_SOFTERR ; + mnt->flags &= ~NFS_MOUNT_SOFT ; +break ; +case Opt_hard: + mnt->flags &= ~(NFS_MOUNT_SOFT |NFS_MOUNT_SOFTERR ); +break ; +case Opt_posix: + mnt->flags |=NFS_MOUNT_POSIX ; +break ; +case Opt_noposix: + mnt->flags &= ~NFS_MOUNT_POSIX ; +break ; +case Opt_cto: + mnt->flags &= ~NFS_MOUNT_NOCTO ; +break ; +case Opt_nocto: + mnt->flags |=NFS_MOUNT_NOCTO ; +break ; +case Opt_ac: + mnt->flags &= ~NFS_MOUNT_NOAC ; +break ; +case Opt_noac: + mnt->flags |=NFS_MOUNT_NOAC ; +break ; +case Opt_lock: + mnt->flags &= ~NFS_MOUNT_NONLM ; + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_nolock: + mnt->flags |=NFS_MOUNT_NONLM ; + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case Opt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; +break ; +case Opt_rdma: + mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */ + mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; +xprt_load_transport (p); +break ; +case Opt_acl: + mnt->flags &= ~NFS_MOUNT_NOACL ; +break ; +case Opt_noacl: + mnt->flags |=NFS_MOUNT_NOACL ; +break ; +case Opt_rdirplus: + mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_nordirplus: + mnt->flags |=NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_sharecache: + mnt->flags &= ~NFS_MOUNT_UNSHARED ; +break ; +case Opt_nosharecache: + mnt->flags |=NFS_MOUNT_UNSHARED ; +break ; +case Opt_resvport: + mnt->flags &= ~NFS_MOUNT_NORESVPORT ; +break ; +case Opt_noresvport: + mnt->flags |=NFS_MOUNT_NORESVPORT ; +break ; +case Opt_fscache: + mnt->options |=NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_migration: + mnt->options |=NFS_OPTION_MIGRATION ; +break ; +case Opt_nomigration: + mnt->options &= ~NFS_OPTION_MIGRATION ; +break ; + +/* +* options that take numeric values +*/ +case Opt_port: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->nfs_server.port = option; +break ; +case Opt_rsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->rsize = option; +break ; +case Opt_wsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->wsize = option; +break ; +case Opt_bsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->bsize = option; +break ; +case Opt_timeo: +if (nfs_get_option_ul_bound (args, &option,1 ,INT_MAX )) + goto out_invalid_value; + mnt->timeo = option; +break ; +case Opt_retrans: +if (nfs_get_option_ul_bound (args, &option,0 ,INT_MAX )) + goto out_invalid_value; + mnt->retrans = option; +break ; +case Opt_acregmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = option; +break ; +case Opt_acregmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmax = option; +break ; +case Opt_acdirmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmin = option; +break ; +case Opt_acdirmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmax = option; +break ; +case Opt_actimeo: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = mnt->acregmax = + mnt->acdirmin = mnt->acdirmax = option; +break ; +case Opt_namelen: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->namlen = option; +break ; +case Opt_mountport: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->mount_server.port = option; +break ; +case Opt_mountvers: +if (nfs_get_option_ul (args, &option) || + option <NFS_MNT_VERSION || + option >NFS_MNT3_VERSION ) + goto out_invalid_value; + mnt->mount_server.version = option; +break ; +case Opt_minorversion: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; +if (option >NFS4_MAX_MINOR_VERSION ) + goto out_invalid_value; + mnt->minorversion = option; +break ; + +/* +* options that take text values +*/ +case Opt_nfsvers: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc =nfs_parse_version_string (string, mnt, args); +kfree (string); +if (!rc) + goto out_invalid_value; +break ; +case Opt_sec: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc =nfs_parse_security_flavors (string, mnt); +kfree (string); +if (!rc) { +dfprintk (MOUNT ,"NFS: unrecognized " +"security flavor\n" ); +return 0 ; + } +break ; +case Opt_proto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_xprt_protocol_tokens, args); + + protofamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case Opt_xprt_tcp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; +break ; +case Opt_xprt_rdma6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_rdma: +/* vector side protocols to TCP */ + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; +xprt_load_transport (string); +break ; +default : +dfprintk (MOUNT ,"NFS: unrecognized " +"transport protocol\n" ); +kfree (string); +return 0 ; + } +kfree (string); +break ; +case Opt_mountproto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_xprt_protocol_tokens, args); +kfree (string); + + mountfamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case Opt_xprt_tcp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; +break ; +case Opt_xprt_rdma:/* not used for side protocols */ +default : +dfprintk (MOUNT ,"NFS: unrecognized " +"transport protocol\n" ); +return 0 ; + } +break ; +case Opt_addr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->nfs_server.addrlen = +rpc_pton (mnt->net, string,strlen (string), + (struct sockaddr *) + &mnt->nfs_server.address, +sizeof (mnt->nfs_server.address)); +kfree (string); +if (mnt->nfs_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_clientaddr: +if (nfs_get_option_str (args, &mnt->client_address)) + goto out_nomem; +break ; +case Opt_mounthost: +if (nfs_get_option_str (args, + &mnt->mount_server.hostname)) + goto out_nomem; +break ; +case Opt_mountaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->mount_server.addrlen = +rpc_pton (mnt->net, string,strlen (string), + (struct sockaddr *) + &mnt->mount_server.address, +sizeof (mnt->mount_server.address)); +kfree (string); +if (mnt->mount_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_nconnect: +if (nfs_get_option_ul_bound (args, &option,1 ,NFS_MAX_CONNECTIONS )) + goto out_invalid_value; + mnt->nfs_server.nconnect = option; +break ; +case Opt_lookupcache: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_lookupcache_tokens, args); +kfree (string); +switch (token) { +case Opt_lookupcache_all: + mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG |NFS_MOUNT_LOOKUP_CACHE_NONE ); +break ; +case Opt_lookupcache_positive: + mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE ; + mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG ; +break ; +case Opt_lookupcache_none: + mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG |NFS_MOUNT_LOOKUP_CACHE_NONE ; +break ; +default : +dfprintk (MOUNT ,"NFS: invalid " +"lookupcache argument\n" ); +return 0 ; + }; +break ; +case Opt_fscache_uniq: +if (nfs_get_option_str (args, &mnt->fscache_uniq)) + goto out_nomem; + mnt->options |=NFS_OPTION_FSCACHE ; +break ; +case Opt_local_lock: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, nfs_local_lock_tokens, + args); +kfree (string); +switch (token) { +case Opt_local_lock_all: + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_local_lock_flock: + mnt->flags |=NFS_MOUNT_LOCAL_FLOCK ; +break ; +case Opt_local_lock_posix: + mnt->flags |=NFS_MOUNT_LOCAL_FCNTL ; +break ; +case Opt_local_lock_none: + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +default : +dfprintk (MOUNT ,"NFS: invalid " +"local_lock argument\n" ); +return 0 ; + }; +break ; + +/* +* Special options +*/ +case Opt_sloppy: + sloppy =1 ; +dfprintk (MOUNT ,"NFS: relaxing parsing rules\n" ); +break ; +case Opt_userspace: +case Opt_deprecated: +dfprintk (MOUNT ,"NFS: ignoring mount option " +"'%s'\n" , p); +break ; + +default : + invalid_option =1 ; +dfprintk (MOUNT ,"NFS: unrecognized mount option " +"'%s'\n" , p); + } + } + +if (!sloppy && invalid_option) +return 0 ; + +if (mnt->minorversion && mnt->version !=4 ) + goto out_minorversion_mismatch; + +if (mnt->options &NFS_OPTION_MIGRATION && + (mnt->version !=4 || mnt->minorversion !=0 )) + goto out_migration_misuse; + +/* +* verify that any proto=/mountproto= options match the address +* families in the addr=/mountaddr= options. +*/ +if (protofamily !=AF_UNSPEC && + protofamily != mnt->nfs_server.address.ss_family) + goto out_proto_mismatch; + +if (mountfamily !=AF_UNSPEC ) { +if (mnt->mount_server.addrlen) { +if (mountfamily != mnt->mount_server.address.ss_family) + goto out_mountproto_mismatch; + }else { +if (mountfamily != mnt->nfs_server.address.ss_family) + goto out_mountproto_mismatch; + } + } + +return 1 ; + +out_mountproto_mismatch: +printk (KERN_INFO "NFS: mount server address does not match mountproto= " +"option\n" ); +return 0 ; +out_proto_mismatch: +printk (KERN_INFO "NFS: server address does not match proto= option\n" ); +return 0 ; +out_invalid_address: +printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); +return 0 ; +out_invalid_value: +printk (KERN_INFO "NFS: bad mount option value specified: %s\n" , p); +return 0 ; +out_minorversion_mismatch: +printk (KERN_INFO "NFS: mount option vers=%u does not support " +"minorversion=%u\n" , mnt->version, mnt->minorversion); +return 0 ; +out_migration_misuse: +printk (KERN_INFO +"NFS: 'migration' not supported for this NFS version\n" ); +return 0 ; +out_nomem: +printk (KERN_INFO "NFS: not enough memory to parse option\n" ); +return 0 ; +out_security_failure: +printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); +return 0 ; +} + +/* +* Split "dev_name" into "hostname:export_path". +* +* The leftmost colon demarks the split between the server's hostname +* and the export path. If the hostname starts with a left square +* bracket, then it may contain colons. +* +* Note: caller frees hostname and export path, even on error. +*/ +static int nfs_parse_devname (const char *dev_name, +char **hostname,size_t maxnamlen, +char **export_path,size_t maxpathlen) +{ +size_t len; +char *end; + +if (unlikely (!dev_name || !*dev_name)) { +dfprintk (MOUNT ,"NFS: device name not specified\n" ); +return -EINVAL ; + } + +/* Is the host name protected with square brakcets? */ +if (*dev_name =='[' ) { + end =strchr (++dev_name,']' ); +if (end ==NULL || end[1 ] !=':' ) + goto out_bad_devname; + + len = end - dev_name; + end++; + }else { +char *comma; + + end =strchr (dev_name,':' ); +if (end ==NULL ) + goto out_bad_devname; + len = end - dev_name; + +/* kill possible hostname list: not supported */ + comma =strchr (dev_name,',' ); +if (comma !=NULL && comma < end) + len = comma - dev_name; + } + +if (len > maxnamlen) + goto out_hostname; + +/* N.B. caller will free nfs_server.hostname in all cases */ + *hostname =kstrndup (dev_name, len,GFP_KERNEL ); +if (*hostname ==NULL ) + goto out_nomem; + len =strlen (++end); +if (len > maxpathlen) + goto out_path; + *export_path =kstrndup (end, len,GFP_KERNEL ); +if (!*export_path) + goto out_nomem; + +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); +return 0 ; + +out_bad_devname: +dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); +return -EINVAL ; + +out_nomem: +dfprintk (MOUNT ,"NFS: not enough memory to parse device name\n" ); +return -ENOMEM ; + +out_hostname: +dfprintk (MOUNT ,"NFS: server hostname too long\n" ); +return -ENAMETOOLONG ; + +out_path: +dfprintk (MOUNT ,"NFS: export pathname too long\n" ); +return -ENAMETOOLONG ; +} + +/* +* Validate the NFS2/NFS3 mount data +* - fills in the mount root filehandle +* +* For option strings, user space handles the following behaviors: +* +* + DNS: mapping server host name to IP address ("addr=" option) +* +* + failure mode: how to behave if a mount request can't be handled +* immediately ("fg/bg" option) +* +* + retry: how often to retry a mount request ("retry=" option) +* +* + breaking back: trying proto=udp after proto=tcp, v2 after v3, +* mountproto=tcp after mountproto=udp, and so on +*/ +static int nfs23_validate_mount_data (void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +struct nfs_mount_data *data = (struct nfs_mount_data *)options; +struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; +int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; + +if (data ==NULL ) + goto out_no_data; + + args->version =NFS_DEFAULT_VERSION ; +switch (data->version) { +case 1 : + data->namlen =0 ;/* fall through */ +case 2 : + data->bsize =0 ;/* fall through */ +case 3 : +if (data->flags &NFS_MOUNT_VER3 ) + goto out_no_v3; + data->root.size =NFS2_FHSIZE ; +memcpy (data->root.data, data->old_root.data,NFS2_FHSIZE ); +/* Turn off security negotiation */ + extra_flags |=NFS_MOUNT_SECFLAVOUR ; +/* fall through */ +case 4 : +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + goto out_no_sec; +/* fall through */ +case 5 : +memset (data->context,0 ,sizeof (data->context)); +/* fall through */ +case 6 : +if (data->flags &NFS_MOUNT_VER3 ) { +if (data->root.size >NFS3_FHSIZE || data->root.size ==0 ) + goto out_invalid_fh; + mntfh->size = data->root.size; + args->version =3 ; + }else { + mntfh->size =NFS2_FHSIZE ; + args->version =2 ; + } + + +memcpy (mntfh->data, data->root.data, mntfh->size); +if (mntfh->size <sizeof (mntfh->data)) +memset (mntfh->data + mntfh->size,0 , +sizeof (mntfh->data) - mntfh->size); + +/* +* Translate to nfs_parsed_mount_data, which nfs_fill_super +* can deal with. +*/ + args->flags = data->flags &NFS_MOUNT_FLAGMASK ; + args->flags |= extra_flags; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->need_mount = false; + +memcpy (sap, &data->addr,sizeof (data->addr)); + args->nfs_server.addrlen =sizeof (data->addr); + args->nfs_server.port =ntohs (data->addr.sin_port); +if (sap->sa_family !=AF_INET || + !nfs_verify_server_address (sap)) + goto out_no_address; + +if (!(data->flags &NFS_MOUNT_TCP )) + args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +/* N.B. caller will free nfs_server.hostname in all cases */ + args->nfs_server.hostname =kstrdup (data->hostname,GFP_KERNEL ); + args->namlen = data->namlen; + args->bsize = data->bsize; + +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + args->selected_flavor = data->pseudoflavor; +else + args->selected_flavor =RPC_AUTH_UNIX ; +if (!args->nfs_server.hostname) + goto out_nomem; + +if (!(data->flags &NFS_MOUNT_NONLM )) + args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +else + args->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +/* +* The legacy version 6 binary mount data from userspace has a +* field used only to transport selinux information into the +* the kernel. To continue to support that functionality we +* have a touch of selinux knowledge here in the NFS code. The +* userspace code converted context=blah to just blah so we are +* converting back to the full string selinux understands. +*/ +if (data->context[0 ]){ +#ifdef CONFIG_SECURITY_SELINUX +int rc; + data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; + rc =security_add_mnt_opt ("context" , data->context, +strlen (data->context), &args->lsm_opts); +if (rc) +return rc; +#else +return -EINVAL ; +#endif + } + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: +dfprintk (MOUNT ,"NFS: mount program didn't pass any mount data\n" ); +return -EINVAL ; + +out_no_v3: +dfprintk (MOUNT ,"NFS: nfs_mount_data version %d does not support v3\n" , + data->version); +return -EINVAL ; + +out_no_sec: +dfprintk (MOUNT ,"NFS: nfs_mount_data version supports only AUTH_SYS\n" ); +return -EINVAL ; + +out_nomem: +dfprintk (MOUNT ,"NFS: not enough memory to handle mount options\n" ); +return -ENOMEM ; + +out_no_address: +dfprintk (MOUNT ,"NFS: mount program didn't pass remote address\n" ); +return -EINVAL ; + +out_invalid_fh: +dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); +return -EINVAL ; +} + +#if IS_ENABLED (CONFIG_NFS_V4 ) + +static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *args) +{ + args->flags &= ~(NFS_MOUNT_NONLM |NFS_MOUNT_NOACL |NFS_MOUNT_VER3 | +NFS_MOUNT_LOCAL_FLOCK |NFS_MOUNT_LOCAL_FCNTL ); +} + +/* +* Validate NFSv4 mount options +*/ +static int nfs4_validate_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ +struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; +struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; +char *c; + +if (data ==NULL ) + goto out_no_data; + + args->version =4 ; + +switch (data->version) { +case 1 : +if (data->host_addrlen >sizeof (args->nfs_server.address)) + goto out_no_address; +if (data->host_addrlen ==0 ) + goto out_no_address; + args->nfs_server.addrlen = data->host_addrlen; +if (copy_from_user (sap, data->host_addr, data->host_addrlen)) +return -EFAULT ; +if (!nfs_verify_server_address (sap)) + goto out_no_address; + args->nfs_server.port =ntohs (((struct sockaddr_in *)sap)->sin_port); + +if (data->auth_flavourlen) { +rpc_authflavor_t pseudoflavor; +if (data->auth_flavourlen >1 ) + goto out_inval_auth; +if (copy_from_user (&pseudoflavor, + data->auth_flavours, +sizeof (pseudoflavor))) +return -EFAULT ; + args->selected_flavor = pseudoflavor; + }else + args->selected_flavor =RPC_AUTH_UNIX ; + + c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.hostname = c; + + c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.export_path = c; +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); + + c =strndup_user (data->client_addr.data,16 ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->client_address = c; + +/* +* Translate to nfs_parsed_mount_data, which nfs4_fill_super +* can deal with. +*/ + + args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->nfs_server.protocol = data->proto; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: +dfprintk (MOUNT ,"NFS4: mount program didn't pass any mount data\n" ); +return -EINVAL ; + +out_inval_auth: +dfprintk (MOUNT ,"NFS4: Invalid number of RPC auth flavours %d\n" , + data->auth_flavourlen); +return -EINVAL ; + +out_no_address: +dfprintk (MOUNT ,"NFS4: mount program didn't pass remote address\n" ); +return -EINVAL ; + +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +} + +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +if (fs_type == &nfs_fs_type) +return nfs23_validate_mount_data (options, args, mntfh, dev_name); +return nfs4_validate_mount_data (options, args, dev_name); +} +#else +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +return nfs23_validate_mount_data (options, args, mntfh, dev_name); +} +#endif + +int nfs_validate_text_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ +int port =0 ; +int max_namelen =PAGE_SIZE ; +int max_pathlen =NFS_MAXPATHLEN ; +struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; + +if (nfs_parse_mount_options ((char *)options, args) ==0 ) +return -EINVAL ; + +if (!nfs_verify_server_address (sap)) + goto out_no_address; + +if (args->version ==4 ) { +#if IS_ENABLED (CONFIG_NFS_V4 ) +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; +else + port =NFS_PORT ; + max_namelen =NFS4_MAXNAMLEN ; + max_pathlen =NFS4_MAXPATHLEN ; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; +nfs4_validate_mount_flags (args); +#else + goto out_v4_not_compiled; +#endif /* CONFIG_NFS_V4 */ + }else { +nfs_set_mount_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; + } + +nfs_set_port (sap, &args->nfs_server.port, port); + +return nfs_parse_devname (dev_name, + &args->nfs_server.hostname, + max_namelen, + &args->nfs_server.export_path, + max_pathlen); + +#if !IS_ENABLED (CONFIG_NFS_V4 ) +out_v4_not_compiled: +dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); +return -EPROTONOSUPPORT ; +#else +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +#endif /* !CONFIG_NFS_V4 */ + +out_no_address: +dfprintk (MOUNT ,"NFS: mount program didn't pass remote address\n" ); +return -EINVAL ; +}fs/nfs/internal.h +29
-0@@ -7,6 +7,7 @@#include <linux/mount.h> #include <linux/security.h> #include <linux/crc32.h> +#include <linux/sunrpc/addr.h> #include <linux/nfs_page.h> #include <linux/wait_bit.h> @@ -232,6 +233,22 @@ extern const struct svc_version nfs4_callback_version1;extern const struct svc_version nfs4_callback_version4;struct nfs_pageio_descriptor ; + +/* mount.c */ +#define NFS_TEXT_DATA 1 + +extern struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ); +extern void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data); +extern int nfs_parse_mount_options (char *raw,struct nfs_parsed_mount_data *mnt); +extern int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name); +extern int nfs_validate_text_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name); +/* pagelist.c */ extern int __init nfs_init_nfspagecache (void );extern void nfs_destroy_nfspagecache (void );@@ -763,3 +780,15 @@ static inline bool nfs_error_is_fatal(int err) } } +/* +* Select between a default port value and a user-specified port value. +* If a zero value is set, then autobind will be used. +*/ +static inline void nfs_set_port (struct sockaddr *sap,int *port, +const unsigned short default_port) +{ +if (*port ==NFS_UNSPEC_PORT ) + *port = default_port; + +rpc_set_port (sap, *port); +}fs/nfs/super.c +0
-1411@@ -69,229 +69,6 @@#include "nfs.h" #define NFSDBG_FACILITY NFSDBG_VFS -#define NFS_TEXT_DATA 1 - -#if IS_ENABLED (CONFIG_NFS_V3 ) -#define NFS_DEFAULT_VERSION 3 -#else -#define NFS_DEFAULT_VERSION 2 -#endif - -#define NFS_MAX_CONNECTIONS 16 - -enum { -/* Mount options that take no arguments */ - Opt_soft, Opt_softerr, Opt_hard, - Opt_posix, Opt_noposix, - Opt_cto, Opt_nocto, - Opt_ac, Opt_noac, - Opt_lock, Opt_nolock, - Opt_udp, Opt_tcp, Opt_rdma, - Opt_acl, Opt_noacl, - Opt_rdirplus, Opt_nordirplus, - Opt_sharecache, Opt_nosharecache, - Opt_resvport, Opt_noresvport, - Opt_fscache, Opt_nofscache, - Opt_migration, Opt_nomigration, - -/* Mount options that take integer arguments */ - Opt_port, - Opt_rsize, Opt_wsize, Opt_bsize, - Opt_timeo, Opt_retrans, - Opt_acregmin, Opt_acregmax, - Opt_acdirmin, Opt_acdirmax, - Opt_actimeo, - Opt_namelen, - Opt_mountport, - Opt_mountvers, - Opt_minorversion, - -/* Mount options that take string arguments */ - Opt_nfsvers, - Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, - Opt_nconnect, - Opt_lookupcache, - Opt_fscache_uniq, - Opt_local_lock, - -/* Special mount options */ - Opt_userspace, Opt_deprecated, Opt_sloppy, - - Opt_err -}; - -static const match_table_t nfs_mount_option_tokens = { - { Opt_userspace,"bg" }, - { Opt_userspace,"fg" }, - { Opt_userspace,"retry=%s" }, - - { Opt_sloppy,"sloppy" }, - - { Opt_soft,"soft" }, - { Opt_softerr,"softerr" }, - { Opt_hard,"hard" }, - { Opt_deprecated,"intr" }, - { Opt_deprecated,"nointr" }, - { Opt_posix,"posix" }, - { Opt_noposix,"noposix" }, - { Opt_cto,"cto" }, - { Opt_nocto,"nocto" }, - { Opt_ac,"ac" }, - { Opt_noac,"noac" }, - { Opt_lock,"lock" }, - { Opt_nolock,"nolock" }, - { Opt_udp,"udp" }, - { Opt_tcp,"tcp" }, - { Opt_rdma,"rdma" }, - { Opt_acl,"acl" }, - { Opt_noacl,"noacl" }, - { Opt_rdirplus,"rdirplus" }, - { Opt_nordirplus,"nordirplus" }, - { Opt_sharecache,"sharecache" }, - { Opt_nosharecache,"nosharecache" }, - { Opt_resvport,"resvport" }, - { Opt_noresvport,"noresvport" }, - { Opt_fscache,"fsc" }, - { Opt_nofscache,"nofsc" }, - { Opt_migration,"migration" }, - { Opt_nomigration,"nomigration" }, - - { Opt_port,"port=%s" }, - { Opt_rsize,"rsize=%s" }, - { Opt_wsize,"wsize=%s" }, - { Opt_bsize,"bsize=%s" }, - { Opt_timeo,"timeo=%s" }, - { Opt_retrans,"retrans=%s" }, - { Opt_acregmin,"acregmin=%s" }, - { Opt_acregmax,"acregmax=%s" }, - { Opt_acdirmin,"acdirmin=%s" }, - { Opt_acdirmax,"acdirmax=%s" }, - { Opt_actimeo,"actimeo=%s" }, - { Opt_namelen,"namlen=%s" }, - { Opt_mountport,"mountport=%s" }, - { Opt_mountvers,"mountvers=%s" }, - { Opt_minorversion,"minorversion=%s" }, - - { Opt_nfsvers,"nfsvers=%s" }, - { Opt_nfsvers,"vers=%s" }, - - { Opt_sec,"sec=%s" }, - { Opt_proto,"proto=%s" }, - { Opt_mountproto,"mountproto=%s" }, - { Opt_addr,"addr=%s" }, - { Opt_clientaddr,"clientaddr=%s" }, - { Opt_mounthost,"mounthost=%s" }, - { Opt_mountaddr,"mountaddr=%s" }, - - { Opt_nconnect,"nconnect=%s" }, - - { Opt_lookupcache,"lookupcache=%s" }, - { Opt_fscache_uniq,"fsc=%s" }, - { Opt_local_lock,"local_lock=%s" }, - -/* The following needs to be listed after all other options */ - { Opt_nfsvers,"v%s" }, - - { Opt_err,NULL } -}; - -enum { - Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma, - Opt_xprt_rdma6, - - Opt_xprt_err -}; - -static const match_table_t nfs_xprt_protocol_tokens = { - { Opt_xprt_udp,"udp" }, - { Opt_xprt_udp6,"udp6" }, - { Opt_xprt_tcp,"tcp" }, - { Opt_xprt_tcp6,"tcp6" }, - { Opt_xprt_rdma,"rdma" }, - { Opt_xprt_rdma6,"rdma6" }, - - { Opt_xprt_err,NULL } -}; - -enum { - Opt_sec_none, Opt_sec_sys, - Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, - Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, - Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, - - Opt_sec_err -}; - -static const match_table_t nfs_secflavor_tokens = { - { Opt_sec_none,"none" }, - { Opt_sec_none,"null" }, - { Opt_sec_sys,"sys" }, - - { Opt_sec_krb5,"krb5" }, - { Opt_sec_krb5i,"krb5i" }, - { Opt_sec_krb5p,"krb5p" }, - - { Opt_sec_lkey,"lkey" }, - { Opt_sec_lkeyi,"lkeyi" }, - { Opt_sec_lkeyp,"lkeyp" }, - - { Opt_sec_spkm,"spkm3" }, - { Opt_sec_spkmi,"spkm3i" }, - { Opt_sec_spkmp,"spkm3p" }, - - { Opt_sec_err,NULL } -}; - -enum { - Opt_lookupcache_all, Opt_lookupcache_positive, - Opt_lookupcache_none, - - Opt_lookupcache_err -}; - -static match_table_t nfs_lookupcache_tokens = { - { Opt_lookupcache_all,"all" }, - { Opt_lookupcache_positive,"pos" }, - { Opt_lookupcache_positive,"positive" }, - { Opt_lookupcache_none,"none" }, - - { Opt_lookupcache_err,NULL } -}; - -enum { - Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, - Opt_local_lock_none, - - Opt_local_lock_err -}; - -static match_table_t nfs_local_lock_tokens = { - { Opt_local_lock_all,"all" }, - { Opt_local_lock_flock,"flock" }, - { Opt_local_lock_posix,"posix" }, - { Opt_local_lock_none,"none" }, - - { Opt_local_lock_err,NULL } -}; - -enum { - Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, - Opt_vers_4_1, Opt_vers_4_2, - - Opt_vers_err -}; - -static match_table_t nfs_vers_tokens = { - { Opt_vers_2,"2" }, - { Opt_vers_3,"3" }, - { Opt_vers_4,"4" }, - { Opt_vers_4_0,"4.0" }, - { Opt_vers_4_1,"4.1" }, - { Opt_vers_4_2,"4.2" }, - - { Opt_vers_err,NULL } -};static struct dentry *nfs_prepared_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *raw_data);@@ -332,10 +109,6 @@ const struct super_operations nfs_sops = {EXPORT_SYMBOL_GPL (nfs_sops);#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *); -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args,const char *dev_name); -struct file_system_type nfs4_fs_type = { .owner =THIS_MODULE , .name = "nfs4",@@ -932,141 +705,6 @@ void nfs_umount_begin(struct super_block *sb) }EXPORT_SYMBOL_GPL (nfs_umount_begin); -static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ) -{ -struct nfs_parsed_mount_data *data; - - data =kzalloc (sizeof (*data),GFP_KERNEL ); -if (data) { - data->timeo =NFS_UNSPEC_TIMEO ; - data->retrans =NFS_UNSPEC_RETRANS ; - data->acregmin =NFS_DEF_ACREGMIN ; - data->acregmax =NFS_DEF_ACREGMAX ; - data->acdirmin =NFS_DEF_ACDIRMIN ; - data->acdirmax =NFS_DEF_ACDIRMAX ; - data->mount_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - data->selected_flavor =RPC_AUTH_MAXFLAVOR ; - data->minorversion =0 ; - data->need_mount = true; - data->net = current->nsproxy->net_ns; - data->lsm_opts =NULL ; - } -return data; -} - -static void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data) -{ -if (data) { -kfree (data->client_address); -kfree (data->mount_server.hostname); -kfree (data->nfs_server.export_path); -kfree (data->nfs_server.hostname); -kfree (data->fscache_uniq); -security_free_mnt_opts (&data->lsm_opts); -kfree (data); - } -} - -/* -* Sanity-check a server address provided by the mount command. -* -* Address family must be initialized, and address must not be -* the ANY address for that family. -*/ -static int nfs_verify_server_address (struct sockaddr *addr) -{ -switch (addr->sa_family) { -case AF_INET : { -struct sockaddr_in *sa = (struct sockaddr_in *)addr; -return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); - } -case AF_INET6 : { -struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; -return !ipv6_addr_any (sa); - } - } - -dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); -return 0 ; -} - -/* -* Select between a default port value and a user-specified port value. -* If a zero value is set, then autobind will be used. -*/ -static void nfs_set_port (struct sockaddr *sap,int *port, -const unsigned short default_port) -{ -if (*port ==NFS_UNSPEC_PORT ) - *port = default_port; - -rpc_set_port (sap, *port); -} - -/* -* Sanity check the NFS transport protocol. -* -*/ -static void nfs_validate_transport_protocol (struct nfs_parsed_mount_data *mnt) -{ -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : -break ; -default : - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* For text based NFSv2/v3 mounts, the mount protocol transport default -* settings should depend upon the specified NFS transport. -*/ -static void nfs_set_mount_transport_protocol (struct nfs_parsed_mount_data *mnt) -{ -nfs_validate_transport_protocol (mnt); - -if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || - mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) -return ; -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : - mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : - mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* Add 'flavor' to 'auth_info' if not already present. -* Returns true if 'flavor' ends up in the list, false otherwise -*/ -static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, -rpc_authflavor_t flavor) -{ -unsigned int i; -unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); - -/* make sure this flavor isn't already in the list */ -for (i =0 ; i < auth_info->flavor_len; i++) { -if (flavor == auth_info->flavors[i]) -return true; - } - -if (auth_info->flavor_len +1 >= max_flavor_len) { -dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); -return false; - } - - auth_info->flavors[auth_info->flavor_len++] = flavor; -return true; -} -/* * Return true if 'match' is in auth_info or auth_info is empty. * Return false otherwise. @@ -1087,627 +725,6 @@ bool nfs_auth_info_match(const struct nfs_auth_info *auth_info, }EXPORT_SYMBOL_GPL (nfs_auth_info_match); -/* -* Parse the value of the 'sec=' option. -*/ -static int nfs_parse_security_flavors (char *value, -struct nfs_parsed_mount_data *mnt) -{ -substring_t args[MAX_OPT_ARGS ]; -rpc_authflavor_t pseudoflavor; -char *p; - -dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); - -while ((p =strsep (&value,":" )) !=NULL ) { -switch (match_token (p, nfs_secflavor_tokens, args)) { -case Opt_sec_none: - pseudoflavor =RPC_AUTH_NULL ; -break ; -case Opt_sec_sys: - pseudoflavor =RPC_AUTH_UNIX ; -break ; -case Opt_sec_krb5: - pseudoflavor =RPC_AUTH_GSS_KRB5 ; -break ; -case Opt_sec_krb5i: - pseudoflavor =RPC_AUTH_GSS_KRB5I ; -break ; -case Opt_sec_krb5p: - pseudoflavor =RPC_AUTH_GSS_KRB5P ; -break ; -case Opt_sec_lkey: - pseudoflavor =RPC_AUTH_GSS_LKEY ; -break ; -case Opt_sec_lkeyi: - pseudoflavor =RPC_AUTH_GSS_LKEYI ; -break ; -case Opt_sec_lkeyp: - pseudoflavor =RPC_AUTH_GSS_LKEYP ; -break ; -case Opt_sec_spkm: - pseudoflavor =RPC_AUTH_GSS_SPKM ; -break ; -case Opt_sec_spkmi: - pseudoflavor =RPC_AUTH_GSS_SPKMI ; -break ; -case Opt_sec_spkmp: - pseudoflavor =RPC_AUTH_GSS_SPKMP ; -break ; -default : -dfprintk (MOUNT , -"NFS: sec= option '%s' not recognized\n" , p); -return 0 ; - } - -if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) -return 0 ; - } - -return 1 ; -} - -static int nfs_parse_version_string (char *string, -struct nfs_parsed_mount_data *mnt, -substring_t *args) -{ - mnt->flags &= ~NFS_MOUNT_VER3 ; -switch (match_token (string, nfs_vers_tokens, args)) { -case Opt_vers_2: - mnt->version =2 ; -break ; -case Opt_vers_3: - mnt->flags |=NFS_MOUNT_VER3 ; - mnt->version =3 ; -break ; -case Opt_vers_4: -/* Backward compatibility option. In future, -* the mount program should always supply -* a NFSv4 minor version number. -*/ - mnt->version =4 ; -break ; -case Opt_vers_4_0: - mnt->version =4 ; - mnt->minorversion =0 ; -break ; -case Opt_vers_4_1: - mnt->version =4 ; - mnt->minorversion =1 ; -break ; -case Opt_vers_4_2: - mnt->version =4 ; - mnt->minorversion =2 ; -break ; -default : -return 0 ; - } -return 1 ; -} - -static int nfs_get_option_str (substring_t args[],char **option) -{ -kfree (*option); - *option =match_strdup (args); -return !*option; -} - -static int nfs_get_option_ul (substring_t args[],unsigned long *option) -{ -int rc; -char *string; - - string =match_strdup (args); -if (string ==NULL ) -return -ENOMEM ; - rc =kstrtoul (string,10 , option); -kfree (string); - -return rc; -} - -static int nfs_get_option_ul_bound (substring_t args[],unsigned long *option, -unsigned long l_bound,unsigned long u_bound) -{ -int ret; - - ret =nfs_get_option_ul (args, option); -if (ret !=0 ) -return ret; -if (*option < l_bound || *option > u_bound) -return -ERANGE ; -return 0 ; -} - -/* -* Error-check and convert a string of mount options from user space into -* a data structure. The whole mount string is processed; bad options are -* skipped as they are encountered. If there were no errors, return 1; -* otherwise return 0 (zero). -*/ -static int nfs_parse_mount_options (char *raw, -struct nfs_parsed_mount_data *mnt) -{ -char *p, *string; -int rc, sloppy =0 , invalid_option =0 ; -unsigned short protofamily =AF_UNSPEC ; -unsigned short mountfamily =AF_UNSPEC ; - -if (!raw) { -dfprintk (MOUNT ,"NFS: mount options string was NULL.\n" ); -return 1 ; - } -dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); - - rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); -if (rc) - goto out_security_failure; - -while ((p =strsep (&raw,"," )) !=NULL ) { -substring_t args[MAX_OPT_ARGS ]; -unsigned long option; -int token; - -if (!*p) -continue ; - -dfprintk (MOUNT ,"NFS: parsing nfs mount option '%s'\n" , p); - - token =match_token (p, nfs_mount_option_tokens, args); -switch (token) { - -/* -* boolean options: foo/nofoo -*/ -case Opt_soft: - mnt->flags |=NFS_MOUNT_SOFT ; - mnt->flags &= ~NFS_MOUNT_SOFTERR ; -break ; -case Opt_softerr: - mnt->flags |=NFS_MOUNT_SOFTERR ; - mnt->flags &= ~NFS_MOUNT_SOFT ; -break ; -case Opt_hard: - mnt->flags &= ~(NFS_MOUNT_SOFT |NFS_MOUNT_SOFTERR ); -break ; -case Opt_posix: - mnt->flags |=NFS_MOUNT_POSIX ; -break ; -case Opt_noposix: - mnt->flags &= ~NFS_MOUNT_POSIX ; -break ; -case Opt_cto: - mnt->flags &= ~NFS_MOUNT_NOCTO ; -break ; -case Opt_nocto: - mnt->flags |=NFS_MOUNT_NOCTO ; -break ; -case Opt_ac: - mnt->flags &= ~NFS_MOUNT_NOAC ; -break ; -case Opt_noac: - mnt->flags |=NFS_MOUNT_NOAC ; -break ; -case Opt_lock: - mnt->flags &= ~NFS_MOUNT_NONLM ; - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_nolock: - mnt->flags |=NFS_MOUNT_NONLM ; - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case Opt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; -break ; -case Opt_rdma: - mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */ - mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; -xprt_load_transport (p); -break ; -case Opt_acl: - mnt->flags &= ~NFS_MOUNT_NOACL ; -break ; -case Opt_noacl: - mnt->flags |=NFS_MOUNT_NOACL ; -break ; -case Opt_rdirplus: - mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_nordirplus: - mnt->flags |=NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_sharecache: - mnt->flags &= ~NFS_MOUNT_UNSHARED ; -break ; -case Opt_nosharecache: - mnt->flags |=NFS_MOUNT_UNSHARED ; -break ; -case Opt_resvport: - mnt->flags &= ~NFS_MOUNT_NORESVPORT ; -break ; -case Opt_noresvport: - mnt->flags |=NFS_MOUNT_NORESVPORT ; -break ; -case Opt_fscache: - mnt->options |=NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_nofscache: - mnt->options &= ~NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_migration: - mnt->options |=NFS_OPTION_MIGRATION ; -break ; -case Opt_nomigration: - mnt->options &= ~NFS_OPTION_MIGRATION ; -break ; - -/* -* options that take numeric values -*/ -case Opt_port: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->nfs_server.port = option; -break ; -case Opt_rsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->rsize = option; -break ; -case Opt_wsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->wsize = option; -break ; -case Opt_bsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->bsize = option; -break ; -case Opt_timeo: -if (nfs_get_option_ul_bound (args, &option,1 ,INT_MAX )) - goto out_invalid_value; - mnt->timeo = option; -break ; -case Opt_retrans: -if (nfs_get_option_ul_bound (args, &option,0 ,INT_MAX )) - goto out_invalid_value; - mnt->retrans = option; -break ; -case Opt_acregmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = option; -break ; -case Opt_acregmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmax = option; -break ; -case Opt_acdirmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmin = option; -break ; -case Opt_acdirmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmax = option; -break ; -case Opt_actimeo: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = mnt->acregmax = - mnt->acdirmin = mnt->acdirmax = option; -break ; -case Opt_namelen: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->namlen = option; -break ; -case Opt_mountport: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->mount_server.port = option; -break ; -case Opt_mountvers: -if (nfs_get_option_ul (args, &option) || - option <NFS_MNT_VERSION || - option >NFS_MNT3_VERSION ) - goto out_invalid_value; - mnt->mount_server.version = option; -break ; -case Opt_minorversion: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; -if (option >NFS4_MAX_MINOR_VERSION ) - goto out_invalid_value; - mnt->minorversion = option; -break ; - -/* -* options that take text values -*/ -case Opt_nfsvers: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc =nfs_parse_version_string (string, mnt, args); -kfree (string); -if (!rc) - goto out_invalid_value; -break ; -case Opt_sec: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc =nfs_parse_security_flavors (string, mnt); -kfree (string); -if (!rc) { -dfprintk (MOUNT ,"NFS: unrecognized " -"security flavor\n" ); -return 0 ; - } -break ; -case Opt_proto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_xprt_protocol_tokens, args); - - protofamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case Opt_xprt_tcp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; -break ; -case Opt_xprt_rdma6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_rdma: -/* vector side protocols to TCP */ - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; -xprt_load_transport (string); -break ; -default : -dfprintk (MOUNT ,"NFS: unrecognized " -"transport protocol\n" ); -kfree (string); -return 0 ; - } -kfree (string); -break ; -case Opt_mountproto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_xprt_protocol_tokens, args); -kfree (string); - - mountfamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case Opt_xprt_tcp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; -break ; -case Opt_xprt_rdma:/* not used for side protocols */ -default : -dfprintk (MOUNT ,"NFS: unrecognized " -"transport protocol\n" ); -return 0 ; - } -break ; -case Opt_addr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->nfs_server.addrlen = -rpc_pton (mnt->net, string,strlen (string), - (struct sockaddr *) - &mnt->nfs_server.address, -sizeof (mnt->nfs_server.address)); -kfree (string); -if (mnt->nfs_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_clientaddr: -if (nfs_get_option_str (args, &mnt->client_address)) - goto out_nomem; -break ; -case Opt_mounthost: -if (nfs_get_option_str (args, - &mnt->mount_server.hostname)) - goto out_nomem; -break ; -case Opt_mountaddr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->mount_server.addrlen = -rpc_pton (mnt->net, string,strlen (string), - (struct sockaddr *) - &mnt->mount_server.address, -sizeof (mnt->mount_server.address)); -kfree (string); -if (mnt->mount_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_nconnect: -if (nfs_get_option_ul_bound (args, &option,1 ,NFS_MAX_CONNECTIONS )) - goto out_invalid_value; - mnt->nfs_server.nconnect = option; -break ; -case Opt_lookupcache: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_lookupcache_tokens, args); -kfree (string); -switch (token) { -case Opt_lookupcache_all: - mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG |NFS_MOUNT_LOOKUP_CACHE_NONE ); -break ; -case Opt_lookupcache_positive: - mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE ; - mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG ; -break ; -case Opt_lookupcache_none: - mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG |NFS_MOUNT_LOOKUP_CACHE_NONE ; -break ; -default : -dfprintk (MOUNT ,"NFS: invalid " -"lookupcache argument\n" ); -return 0 ; - }; -break ; -case Opt_fscache_uniq: -if (nfs_get_option_str (args, &mnt->fscache_uniq)) - goto out_nomem; - mnt->options |=NFS_OPTION_FSCACHE ; -break ; -case Opt_local_lock: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, nfs_local_lock_tokens, - args); -kfree (string); -switch (token) { -case Opt_local_lock_all: - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_local_lock_flock: - mnt->flags |=NFS_MOUNT_LOCAL_FLOCK ; -break ; -case Opt_local_lock_posix: - mnt->flags |=NFS_MOUNT_LOCAL_FCNTL ; -break ; -case Opt_local_lock_none: - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -default : -dfprintk (MOUNT ,"NFS: invalid " -"local_lock argument\n" ); -return 0 ; - }; -break ; - -/* -* Special options -*/ -case Opt_sloppy: - sloppy =1 ; -dfprintk (MOUNT ,"NFS: relaxing parsing rules\n" ); -break ; -case Opt_userspace: -case Opt_deprecated: -dfprintk (MOUNT ,"NFS: ignoring mount option " -"'%s'\n" , p); -break ; - -default : - invalid_option =1 ; -dfprintk (MOUNT ,"NFS: unrecognized mount option " -"'%s'\n" , p); - } - } - -if (!sloppy && invalid_option) -return 0 ; - -if (mnt->minorversion && mnt->version !=4 ) - goto out_minorversion_mismatch; - -if (mnt->options &NFS_OPTION_MIGRATION && - (mnt->version !=4 || mnt->minorversion !=0 )) - goto out_migration_misuse; - -/* -* verify that any proto=/mountproto= options match the address -* families in the addr=/mountaddr= options. -*/ -if (protofamily !=AF_UNSPEC && - protofamily != mnt->nfs_server.address.ss_family) - goto out_proto_mismatch; - -if (mountfamily !=AF_UNSPEC ) { -if (mnt->mount_server.addrlen) { -if (mountfamily != mnt->mount_server.address.ss_family) - goto out_mountproto_mismatch; - }else { -if (mountfamily != mnt->nfs_server.address.ss_family) - goto out_mountproto_mismatch; - } - } - -return 1 ; - -out_mountproto_mismatch: -printk (KERN_INFO "NFS: mount server address does not match mountproto= " -"option\n" ); -return 0 ; -out_proto_mismatch: -printk (KERN_INFO "NFS: server address does not match proto= option\n" ); -return 0 ; -out_invalid_address: -printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); -return 0 ; -out_invalid_value: -printk (KERN_INFO "NFS: bad mount option value specified: %s\n" , p); -return 0 ; -out_minorversion_mismatch: -printk (KERN_INFO "NFS: mount option vers=%u does not support " -"minorversion=%u\n" , mnt->version, mnt->minorversion); -return 0 ; -out_migration_misuse: -printk (KERN_INFO -"NFS: 'migration' not supported for this NFS version\n" ); -return 0 ; -out_nomem: -printk (KERN_INFO "NFS: not enough memory to parse option\n" ); -return 0 ; -out_security_failure: -printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); -return 0 ; -} -/* * Ensure that a specified authtype in args->auth_info is supported by * the server. Returns 0 and sets args->selected_flavor if it's ok, and @@ -1908,327 +925,6 @@ struct dentry *nfs_try_mount(int flags, const char *dev_name, }EXPORT_SYMBOL_GPL (nfs_try_mount); -/* -* Split "dev_name" into "hostname:export_path". -* -* The leftmost colon demarks the split between the server's hostname -* and the export path. If the hostname starts with a left square -* bracket, then it may contain colons. -* -* Note: caller frees hostname and export path, even on error. -*/ -static int nfs_parse_devname (const char *dev_name, -char **hostname,size_t maxnamlen, -char **export_path,size_t maxpathlen) -{ -size_t len; -char *end; - -if (unlikely (!dev_name || !*dev_name)) { -dfprintk (MOUNT ,"NFS: device name not specified\n" ); -return -EINVAL ; - } - -/* Is the host name protected with square brakcets? */ -if (*dev_name =='[' ) { - end =strchr (++dev_name,']' ); -if (end ==NULL || end[1 ] !=':' ) - goto out_bad_devname; - - len = end - dev_name; - end++; - }else { -char *comma; - - end =strchr (dev_name,':' ); -if (end ==NULL ) - goto out_bad_devname; - len = end - dev_name; - -/* kill possible hostname list: not supported */ - comma =strchr (dev_name,',' ); -if (comma !=NULL && comma < end) - len = comma - dev_name; - } - -if (len > maxnamlen) - goto out_hostname; - -/* N.B. caller will free nfs_server.hostname in all cases */ - *hostname =kstrndup (dev_name, len,GFP_KERNEL ); -if (*hostname ==NULL ) - goto out_nomem; - len =strlen (++end); -if (len > maxpathlen) - goto out_path; - *export_path =kstrndup (end, len,GFP_KERNEL ); -if (!*export_path) - goto out_nomem; - -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); -return 0 ; - -out_bad_devname: -dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); -return -EINVAL ; - -out_nomem: -dfprintk (MOUNT ,"NFS: not enough memory to parse device name\n" ); -return -ENOMEM ; - -out_hostname: -dfprintk (MOUNT ,"NFS: server hostname too long\n" ); -return -ENAMETOOLONG ; - -out_path: -dfprintk (MOUNT ,"NFS: export pathname too long\n" ); -return -ENAMETOOLONG ; -} - -/* -* Validate the NFS2/NFS3 mount data -* - fills in the mount root filehandle -* -* For option strings, user space handles the following behaviors: -* -* + DNS: mapping server host name to IP address ("addr=" option) -* -* + failure mode: how to behave if a mount request can't be handled -* immediately ("fg/bg" option) -* -* + retry: how often to retry a mount request ("retry=" option) -* -* + breaking back: trying proto=udp after proto=tcp, v2 after v3, -* mountproto=tcp after mountproto=udp, and so on -*/ -static int nfs23_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args, -struct nfs_fh *mntfh, -const char *dev_name) -{ -struct nfs_mount_data *data = (struct nfs_mount_data *)options; -struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; -int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; - -if (data ==NULL ) - goto out_no_data; - - args->version =NFS_DEFAULT_VERSION ; -switch (data->version) { -case 1 : - data->namlen =0 ;/* fall through */ -case 2 : - data->bsize =0 ;/* fall through */ -case 3 : -if (data->flags &NFS_MOUNT_VER3 ) - goto out_no_v3; - data->root.size =NFS2_FHSIZE ; -memcpy (data->root.data, data->old_root.data,NFS2_FHSIZE ); -/* Turn off security negotiation */ - extra_flags |=NFS_MOUNT_SECFLAVOUR ; -/* fall through */ -case 4 : -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - goto out_no_sec; -/* fall through */ -case 5 : -memset (data->context,0 ,sizeof (data->context)); -/* fall through */ -case 6 : -if (data->flags &NFS_MOUNT_VER3 ) { -if (data->root.size >NFS3_FHSIZE || data->root.size ==0 ) - goto out_invalid_fh; - mntfh->size = data->root.size; - args->version =3 ; - }else { - mntfh->size =NFS2_FHSIZE ; - args->version =2 ; - } - - -memcpy (mntfh->data, data->root.data, mntfh->size); -if (mntfh->size <sizeof (mntfh->data)) -memset (mntfh->data + mntfh->size,0 , -sizeof (mntfh->data) - mntfh->size); - -/* -* Translate to nfs_parsed_mount_data, which nfs_fill_super -* can deal with. -*/ - args->flags = data->flags &NFS_MOUNT_FLAGMASK ; - args->flags |= extra_flags; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->need_mount = false; - -memcpy (sap, &data->addr,sizeof (data->addr)); - args->nfs_server.addrlen =sizeof (data->addr); - args->nfs_server.port =ntohs (data->addr.sin_port); -if (sap->sa_family !=AF_INET || - !nfs_verify_server_address (sap)) - goto out_no_address; - -if (!(data->flags &NFS_MOUNT_TCP )) - args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -/* N.B. caller will free nfs_server.hostname in all cases */ - args->nfs_server.hostname =kstrdup (data->hostname,GFP_KERNEL ); - args->namlen = data->namlen; - args->bsize = data->bsize; - -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - args->selected_flavor = data->pseudoflavor; -else - args->selected_flavor =RPC_AUTH_UNIX ; -if (!args->nfs_server.hostname) - goto out_nomem; - -if (!(data->flags &NFS_MOUNT_NONLM )) - args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -else - args->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -/* -* The legacy version 6 binary mount data from userspace has a -* field used only to transport selinux information into the -* the kernel. To continue to support that functionality we -* have a touch of selinux knowledge here in the NFS code. The -* userspace code converted context=blah to just blah so we are -* converting back to the full string selinux understands. -*/ -if (data->context[0 ]){ -#ifdef CONFIG_SECURITY_SELINUX -int rc; - data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; - rc =security_add_mnt_opt ("context" , data->context, -strlen (data->context), &args->lsm_opts); -if (rc) -return rc; -#else -return -EINVAL ; -#endif - } - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: -dfprintk (MOUNT ,"NFS: mount program didn't pass any mount data\n" ); -return -EINVAL ; - -out_no_v3: -dfprintk (MOUNT ,"NFS: nfs_mount_data version %d does not support v3\n" , - data->version); -return -EINVAL ; - -out_no_sec: -dfprintk (MOUNT ,"NFS: nfs_mount_data version supports only AUTH_SYS\n" ); -return -EINVAL ; - -out_nomem: -dfprintk (MOUNT ,"NFS: not enough memory to handle mount options\n" ); -return -ENOMEM ; - -out_no_address: -dfprintk (MOUNT ,"NFS: mount program didn't pass remote address\n" ); -return -EINVAL ; - -out_invalid_fh: -dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); -return -EINVAL ; -} - -#if IS_ENABLED (CONFIG_NFS_V4 ) -static int nfs_validate_mount_data (struct file_system_type *fs_type, -void *options, -struct nfs_parsed_mount_data *args, -struct nfs_fh *mntfh, -const char *dev_name) -{ -if (fs_type == &nfs_fs_type) -return nfs23_validate_mount_data (options, args, mntfh, dev_name); -return nfs4_validate_mount_data (options, args, dev_name); -} -#else -static int nfs_validate_mount_data (struct file_system_type *fs_type, -void *options, -struct nfs_parsed_mount_data *args, -struct nfs_fh *mntfh, -const char *dev_name) -{ -return nfs23_validate_mount_data (options, args, mntfh, dev_name); -} -#endif - -static int nfs_validate_text_mount_data (void *options, -struct nfs_parsed_mount_data *args, -const char *dev_name) -{ -int port =0 ; -int max_namelen =PAGE_SIZE ; -int max_pathlen =NFS_MAXPATHLEN ; -struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; - -if (nfs_parse_mount_options ((char *)options, args) ==0 ) -return -EINVAL ; - -if (!nfs_verify_server_address (sap)) - goto out_no_address; - -if (args->version ==4 ) { -#if IS_ENABLED (CONFIG_NFS_V4 ) -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; -else - port =NFS_PORT ; - max_namelen =NFS4_MAXNAMLEN ; - max_pathlen =NFS4_MAXPATHLEN ; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; -nfs4_validate_mount_flags (args); -#else - goto out_v4_not_compiled; -#endif /* CONFIG_NFS_V4 */ - }else { -nfs_set_mount_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; - } - -nfs_set_port (sap, &args->nfs_server.port, port); - -return nfs_parse_devname (dev_name, - &args->nfs_server.hostname, - max_namelen, - &args->nfs_server.export_path, - max_pathlen); - -#if !IS_ENABLED (CONFIG_NFS_V4 ) -out_v4_not_compiled: -dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); -return -EPROTONOSUPPORT ; -#else -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -#endif /* !CONFIG_NFS_V4 */ - -out_no_address: -dfprintk (MOUNT ,"NFS: mount program didn't pass remote address\n" ); -return -EINVAL ; -} -#define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \ | NFS_MOUNT_SECURE \ | NFS_MOUNT_TCP \@@ -2719,113 +1415,6 @@ nfs_prepared_mount(struct file_system_type *fs_type, int flags,#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *args) -{ - args->flags &= ~(NFS_MOUNT_NONLM |NFS_MOUNT_NOACL |NFS_MOUNT_VER3 | -NFS_MOUNT_LOCAL_FLOCK |NFS_MOUNT_LOCAL_FCNTL ); -} - -/* -* Validate NFSv4 mount options -*/ -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args, -const char *dev_name) -{ -struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; -struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; -char *c; - -if (data ==NULL ) - goto out_no_data; - - args->version =4 ; - -switch (data->version) { -case 1 : -if (data->host_addrlen >sizeof (args->nfs_server.address)) - goto out_no_address; -if (data->host_addrlen ==0 ) - goto out_no_address; - args->nfs_server.addrlen = data->host_addrlen; -if (copy_from_user (sap, data->host_addr, data->host_addrlen)) -return -EFAULT ; -if (!nfs_verify_server_address (sap)) - goto out_no_address; - args->nfs_server.port =ntohs (((struct sockaddr_in *)sap)->sin_port); - -if (data->auth_flavourlen) { -rpc_authflavor_t pseudoflavor; -if (data->auth_flavourlen >1 ) - goto out_inval_auth; -if (copy_from_user (&pseudoflavor, - data->auth_flavours, -sizeof (pseudoflavor))) -return -EFAULT ; - args->selected_flavor = pseudoflavor; - }else - args->selected_flavor =RPC_AUTH_UNIX ; - - c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.hostname = c; - - c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.export_path = c; -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); - - c =strndup_user (data->client_addr.data,16 ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->client_address = c; - -/* -* Translate to nfs_parsed_mount_data, which nfs4_fill_super -* can deal with. -*/ - - args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->nfs_server.protocol = data->proto; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: -dfprintk (MOUNT ,"NFS4: mount program didn't pass any mount data\n" ); -return -EINVAL ; - -out_inval_auth: -dfprintk (MOUNT ,"NFS4: Invalid number of RPC auth flavours %d\n" , - data->auth_flavourlen); -return -EINVAL ; - -out_no_address: -dfprintk (MOUNT ,"NFS4: mount program didn't pass remote address\n" ); -return -EINVAL ; - -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -} -/* * NFS v4 module parameters need to stay in the * NFS client for backwards compatibility Signature · 1 line
2.17.2
--
Chuck Lever
[email protected]
Re: [PATCH v3 16/26] NFS: Move mount parameterisation bits into their own file
Quoted 65 lines · Chuck Lever
Quoted 51 lines
On Sep 11, 2019, at 12:16 PM, Scott Mayhew <[email protected]> wrote:
From: David Howells <[email protected]>
Split various bits relating to mount parameterisation out from
fs/nfs/super.cinto their own file to form the basis of filesystem context
handling for NFS.No other changes are made to the code beyond removing 'static' qualifiers.
Signed-off-by David Howells <[email protected]>Signed-off-by Al Viro <[email protected]>---
fs/nfs/Makefile| 2 +-fs/nfs/fs_context.c| 1418
+++++++++++++++++++++++++++++++++++++++++++fs/nfs/internal.h| 29 +fs/nfs/super.c| 1411 ----------------------------------------
--4 files changed, 1448 insertions(+), 1412 deletions(-)create mode 100644
fs/nfs/fs_context.cfs/nfs/Makefile +0
-0@@ -9,7 +9,7 @@ CFLAGS_nfstrace.o += -I$(src)nfs-y := client.o dir.o file.o getroot.o
inode.o super.o \
io.o direct.o pagelist.o read.o symlink.o
unlink.o \
write.o namespace.o mount_clnt.o nfstrace.o
\fs/nfs/Makefile +1
-1- export.o sysfs.o + export.o sysfs.o fs_context.onfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.ofs/nfs/fs_context.c new file +4
-0@@ -0,0 +1,1418 @@ +/* NFS mount handling. +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) fs/nfs/fs_context.c line 14
Quoted 10 lines
fs/nfs/fs_context.c new file +10
-0+* +* Split from fs/nfs/super.c: +* +* Copyright (C) 1992 Rick Sladkey +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ New source files should have an SPDX tag instead of boilerplate. I suggest:
Quoted 2 lines
// SPDX-License-Identifier: GPL-2.0-only
Agreed. It is also quite a long stretch to claim authorship of the entire file as implied above. Given that this is mostly a copy-paste effort, then most of the actual copyrights belong to the people who've contributed to super.c (and to inode.c before it). David is one of those authors, but he is one of many.
Quoted 3,125 lines
Quoted 3,112 lines
fs/nfs/fs_context.c new file +136
-0+#include <linux/parser.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> +#include "nfs.h" +#include "internal.h" + +#define NFSDBG_FACILITY NFSDBG_MOUNT + +#if IS_ENABLED (CONFIG_NFS_V3 ) +#define NFS_DEFAULT_VERSION 3 +#else +#define NFS_DEFAULT_VERSION 2 +#endif + +#define NFS_MAX_CONNECTIONS 16 + +enum { +/* Mount options that take no arguments */ + Opt_soft, Opt_softerr, Opt_hard, + Opt_posix, Opt_noposix, + Opt_cto, Opt_nocto, + Opt_ac, Opt_noac, + Opt_lock, Opt_nolock, + Opt_udp, Opt_tcp, Opt_rdma, + Opt_acl, Opt_noacl, + Opt_rdirplus, Opt_nordirplus, + Opt_sharecache, Opt_nosharecache, + Opt_resvport, Opt_noresvport, + Opt_fscache, Opt_nofscache, + Opt_migration, Opt_nomigration, + +/* Mount options that take integer arguments */ + Opt_port, + Opt_rsize, Opt_wsize, Opt_bsize, + Opt_timeo, Opt_retrans, + Opt_acregmin, Opt_acregmax, + Opt_acdirmin, Opt_acdirmax, + Opt_actimeo, + Opt_namelen, + Opt_mountport, + Opt_mountvers, + Opt_minorversion, + +/* Mount options that take string arguments */ + Opt_nfsvers, + Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, + Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_nconnect, + Opt_lookupcache, + Opt_fscache_uniq, + Opt_local_lock, + +/* Special mount options */ + Opt_userspace, Opt_deprecated, Opt_sloppy, + + Opt_err +}; + +static const match_table_t nfs_mount_option_tokens = { + { Opt_userspace,"bg" }, + { Opt_userspace,"fg" }, + { Opt_userspace,"retry=%s" }, + + { Opt_sloppy,"sloppy" }, + + { Opt_soft,"soft" }, + { Opt_softerr,"softerr" }, + { Opt_hard,"hard" }, + { Opt_deprecated,"intr" }, + { Opt_deprecated,"nointr" }, + { Opt_posix,"posix" }, + { Opt_noposix,"noposix" }, + { Opt_cto,"cto" }, + { Opt_nocto,"nocto" }, + { Opt_ac,"ac" }, + { Opt_noac,"noac" }, + { Opt_lock,"lock" }, + { Opt_nolock,"nolock" }, + { Opt_udp,"udp" }, + { Opt_tcp,"tcp" }, + { Opt_rdma,"rdma" }, + { Opt_acl,"acl" }, + { Opt_noacl,"noacl" }, + { Opt_rdirplus,"rdirplus" }, + { Opt_nordirplus,"nordirplus" }, + { Opt_sharecache,"sharecache" }, + { Opt_nosharecache,"nosharecache" }, + { Opt_resvport,"resvport" }, + { Opt_noresvport,"noresvport" }, + { Opt_fscache,"fsc" }, + { Opt_nofscache,"nofsc" }, + { Opt_migration,"migration" }, + { Opt_nomigration,"nomigration" }, + + { Opt_port,"port=%s" }, + { Opt_rsize,"rsize=%s" }, + { Opt_wsize,"wsize=%s" }, + { Opt_bsize,"bsize=%s" }, + { Opt_timeo,"timeo=%s" }, + { Opt_retrans,"retrans=%s" }, + { Opt_acregmin,"acregmin=%s" }, + { Opt_acregmax,"acregmax=%s" }, + { Opt_acdirmin,"acdirmin=%s" }, + { Opt_acdirmax,"acdirmax=%s" }, + { Opt_actimeo,"actimeo=%s" }, + { Opt_namelen,"namlen=%s" }, + { Opt_mountport,"mountport=%s" }, + { Opt_mountvers,"mountvers=%s" }, + { Opt_minorversion,"minorversion=%s" }, + + { Opt_nfsvers,"nfsvers=%s" }, + { Opt_nfsvers,"vers=%s" }, + + { Opt_sec,"sec=%s" }, + { Opt_proto,"proto=%s" }, + { Opt_mountproto,"mountproto=%s" }, + { Opt_addr,"addr=%s" }, + { Opt_clientaddr,"clientaddr=%s" }, + { Opt_mounthost,"mounthost=%s" }, + { Opt_mountaddr,"mountaddr=%s" }, + + { Opt_nconnect,"nconnect=%s" }, + + { Opt_lookupcache,"lookupcache=%s" }, + { Opt_fscache_uniq,"fsc=%s" }, + { Opt_local_lock,"local_lock=%s" }, + +/* The following needs to be listed after all other options */ + { Opt_nfsvers,"v%s" }, + + { Opt_err,NULL } +}; + +enum { + Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6,
Opt_xprt_rdma,fs/nfs/fs_context.c new file +120
-0+ Opt_xprt_rdma6, + + Opt_xprt_err +}; + +static const match_table_t nfs_xprt_protocol_tokens = { + { Opt_xprt_udp,"udp" }, + { Opt_xprt_udp6,"udp6" }, + { Opt_xprt_tcp,"tcp" }, + { Opt_xprt_tcp6,"tcp6" }, + { Opt_xprt_rdma,"rdma" }, + { Opt_xprt_rdma6,"rdma6" }, + + { Opt_xprt_err,NULL } +}; + +enum { + Opt_sec_none, Opt_sec_sys, + Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, + Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, + Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, + + Opt_sec_err +}; + +static const match_table_t nfs_secflavor_tokens = { + { Opt_sec_none,"none" }, + { Opt_sec_none,"null" }, + { Opt_sec_sys,"sys" }, + + { Opt_sec_krb5,"krb5" }, + { Opt_sec_krb5i,"krb5i" }, + { Opt_sec_krb5p,"krb5p" }, + + { Opt_sec_lkey,"lkey" }, + { Opt_sec_lkeyi,"lkeyi" }, + { Opt_sec_lkeyp,"lkeyp" }, + + { Opt_sec_spkm,"spkm3" }, + { Opt_sec_spkmi,"spkm3i" }, + { Opt_sec_spkmp,"spkm3p" }, + + { Opt_sec_err,NULL } +}; + +enum { + Opt_lookupcache_all, Opt_lookupcache_positive, + Opt_lookupcache_none, + + Opt_lookupcache_err +}; + +static match_table_t nfs_lookupcache_tokens = { + { Opt_lookupcache_all,"all" }, + { Opt_lookupcache_positive,"pos" }, + { Opt_lookupcache_positive,"positive" }, + { Opt_lookupcache_none,"none" }, + + { Opt_lookupcache_err,NULL } +}; + +enum { + Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, + Opt_local_lock_none, + + Opt_local_lock_err +}; + +static match_table_t nfs_local_lock_tokens = { + { Opt_local_lock_all,"all" }, + { Opt_local_lock_flock,"flock" }, + { Opt_local_lock_posix,"posix" }, + { Opt_local_lock_none,"none" }, + + { Opt_local_lock_err,NULL } +}; + +enum { + Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, + Opt_vers_4_1, Opt_vers_4_2, + + Opt_vers_err +}; + +static match_table_t nfs_vers_tokens = { + { Opt_vers_2,"2" }, + { Opt_vers_3,"3" }, + { Opt_vers_4,"4" }, + { Opt_vers_4_0,"4.0" }, + { Opt_vers_4_1,"4.1" }, + { Opt_vers_4_2,"4.2" }, + + { Opt_vers_err,NULL } +}; + +struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ) +{ +struct nfs_parsed_mount_data *data; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (data) { + data->timeo =NFS_UNSPEC_TIMEO ; + data->retrans =NFS_UNSPEC_RETRANS ; + data->acregmin =NFS_DEF_ACREGMIN ; + data->acregmax =NFS_DEF_ACREGMAX ; + data->acdirmin =NFS_DEF_ACDIRMIN ; + data->acdirmax =NFS_DEF_ACDIRMAX ; + data->mount_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + data->selected_flavor =RPC_AUTH_MAXFLAVOR ; + data->minorversion =0 ; + data->need_mount = true; + data->net = current->nsproxy->net_ns; + data->lsm_opts =NULL ; + } +return data; +} + +void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data*data)
fs/nfs/fs_context.c new file +27
-0+{ +if (data) { +kfree (data->client_address); +kfree (data->mount_server.hostname); +kfree (data->nfs_server.export_path); +kfree (data->nfs_server.hostname); +kfree (data->fscache_uniq); +security_free_mnt_opts (&data->lsm_opts); +kfree (data); + } +} + +/* +* Sanity-check a server address provided by the mount command. +* +* Address family must be initialized, and address must not be +* the ANY address for that family. +*/ +static int nfs_verify_server_address (struct sockaddr *addr) +{ +switch (addr->sa_family) { +case AF_INET : { +struct sockaddr_in *sa = (struct sockaddr_in *)addr; +return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); + } +case AF_INET6 : { + struct in6_addr *sa = &((struct sockaddr_in6 *)addr)-Quoted 1 line
sin6_addr;fs/nfs/fs_context.c new file +13
-0+return !ipv6_addr_any (sa); + } + } + +dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); +return 0 ; +} + +/* +* Sanity check the NFS transport protocol. +* +*/ +static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/fs_context.c new file +13
-0+{ +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : +break ; +default : + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* For text based NFSv2/v3 mounts, the mount protocol transport default
+ * settings should depend upon the specified NFS transport.
+ */
+static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +46
-0+{ +nfs_validate_transport_protocol (mnt); + +if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || + mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) +return ; +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : + mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : + mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* Add 'flavor' to 'auth_info' if not already present. +* Returns true if 'flavor' ends up in the list, false otherwise +*/ +static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, +rpc_authflavor_t flavor) +{ +unsigned int i; +unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); + +/* make sure this flavor isn't already in the list */ +for (i =0 ; i < auth_info->flavor_len; i++) { +if (flavor == auth_info->flavors[i]) +return true; + } + +if (auth_info->flavor_len +1 >= max_flavor_len) { +dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); +return false; + } + + auth_info->flavors[auth_info->flavor_len++] = flavor; +return true; +} + +/* +* Parse the value of the 'sec=' option. +*/ +static int nfs_parse_security_flavors (char *value, + struct nfs_parsed_mount_data*mnt)
fs/nfs/fs_context.c new file +45
-0+{ +substring_t args[MAX_OPT_ARGS ]; +rpc_authflavor_t pseudoflavor; +char *p; + +dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); + +while ((p =strsep (&value,":" )) !=NULL ) { +switch (match_token (p, nfs_secflavor_tokens, args)) { +case Opt_sec_none: + pseudoflavor =RPC_AUTH_NULL ; +break ; +case Opt_sec_sys: + pseudoflavor =RPC_AUTH_UNIX ; +break ; +case Opt_sec_krb5: + pseudoflavor =RPC_AUTH_GSS_KRB5 ; +break ; +case Opt_sec_krb5i: + pseudoflavor =RPC_AUTH_GSS_KRB5I ; +break ; +case Opt_sec_krb5p: + pseudoflavor =RPC_AUTH_GSS_KRB5P ; +break ; +case Opt_sec_lkey: + pseudoflavor =RPC_AUTH_GSS_LKEY ; +break ; +case Opt_sec_lkeyi: + pseudoflavor =RPC_AUTH_GSS_LKEYI ; +break ; +case Opt_sec_lkeyp: + pseudoflavor =RPC_AUTH_GSS_LKEYP ; +break ; +case Opt_sec_spkm: + pseudoflavor =RPC_AUTH_GSS_SPKM ; +break ; +case Opt_sec_spkmi: + pseudoflavor =RPC_AUTH_GSS_SPKMI ; +break ; +case Opt_sec_spkmp: + pseudoflavor =RPC_AUTH_GSS_SPKMP ; +break ; +default : + dfprintk(MOUNT, + "NFS: sec= option '%s' notrecognized\n", p);
fs/nfs/fs_context.c new file +56
-0+return 0 ; + } + +if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) +return 0 ; + } + +return 1 ; +} + +static int nfs_parse_version_string (char *string, +struct nfs_parsed_mount_data *mnt, +substring_t *args) +{ + mnt->flags &= ~NFS_MOUNT_VER3 ; +switch (match_token (string, nfs_vers_tokens, args)) { +case Opt_vers_2: + mnt->version =2 ; +break ; +case Opt_vers_3: + mnt->flags |=NFS_MOUNT_VER3 ; + mnt->version =3 ; +break ; +case Opt_vers_4: +/* Backward compatibility option. In future, +* the mount program should always supply +* a NFSv4 minor version number. +*/ + mnt->version =4 ; +break ; +case Opt_vers_4_0: + mnt->version =4 ; + mnt->minorversion =0 ; +break ; +case Opt_vers_4_1: + mnt->version =4 ; + mnt->minorversion =1 ; +break ; +case Opt_vers_4_2: + mnt->version =4 ; + mnt->minorversion =2 ; +break ; +default : +return 0 ; + } +return 1 ; +} + +static int nfs_get_option_str (substring_t args[],char **option) +{ +kfree (*option); + *option =match_strdup (args); +return !*option; +} + +static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/fs_context.c new file +14
-0+{ +int rc; +char *string; + + string =match_strdup (args); +if (string ==NULL ) +return -ENOMEM ; + rc =kstrtoul (string,10 , option); +kfree (string); + +return rc; +} + +static int nfs_get_option_ul_bound(substring_t args[], unsignedlong *option,
fs/nfs/fs_context.c new file +14
-0+ unsigned long l_bound, unsigned long u_bound) +{ + int ret; + + ret =nfs_get_option_ul (args, option); +if (ret !=0 ) +return ret; +if (*option < l_bound || *option > u_bound) +return -ERANGE ; +return 0 ; +} + +/* +* Error-check and convert a string of mount options from user space into
+ * a data structure. The whole mount string is processed; bad options are
+ * skipped as they are encountered. If there were no errors, return 1;
+ * otherwise return 0 (zero).
+ */
+intnfs_parse_mount_options(char *raw, struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +8
-0+{ +char *p, *string; +int rc, sloppy =0 , invalid_option =0 ; +unsigned short protofamily =AF_UNSPEC ; +unsigned short mountfamily =AF_UNSPEC ; + +if (!raw) { + dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/fs_context.c new file +17
-0+return 1 ; + } +dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); + + rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); +if (rc) + goto out_security_failure; + +while ((p =strsep (&raw,"," )) !=NULL ) { +substring_t args[MAX_OPT_ARGS ]; +unsigned long option; +int token; + +if (!*p) +continue ; + + dfprintk(MOUNT, "NFS: parsing nfs mount option'%s'\n", p);
fs/nfs/fs_context.c new file +17
-0+ + token =match_token (p, nfs_mount_option_tokens, args); +switch (token) { + +/* +* boolean options: foo/nofoo +*/ +case Opt_soft: + mnt->flags |=NFS_MOUNT_SOFT ; + mnt->flags &= ~NFS_MOUNT_SOFTERR ; +break ; +case Opt_softerr: + mnt->flags |=NFS_MOUNT_SOFTERR ; + mnt->flags &= ~NFS_MOUNT_SOFT ; +break ; +case Opt_hard: + mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/fs_context.c new file +39
-0+break ; +case Opt_posix: + mnt->flags |=NFS_MOUNT_POSIX ; +break ; +case Opt_noposix: + mnt->flags &= ~NFS_MOUNT_POSIX ; +break ; +case Opt_cto: + mnt->flags &= ~NFS_MOUNT_NOCTO ; +break ; +case Opt_nocto: + mnt->flags |=NFS_MOUNT_NOCTO ; +break ; +case Opt_ac: + mnt->flags &= ~NFS_MOUNT_NOAC ; +break ; +case Opt_noac: + mnt->flags |=NFS_MOUNT_NOAC ; +break ; +case Opt_lock: + mnt->flags &= ~NFS_MOUNT_NONLM ; + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_nolock: + mnt->flags |=NFS_MOUNT_NONLM ; + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case Opt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; +break ; +case Opt_rdma: + mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */
fs/nfs/fs_context.c new file +70
-0+ mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; +xprt_load_transport (p); +break ; +case Opt_acl: + mnt->flags &= ~NFS_MOUNT_NOACL ; +break ; +case Opt_noacl: + mnt->flags |=NFS_MOUNT_NOACL ; +break ; +case Opt_rdirplus: + mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_nordirplus: + mnt->flags |=NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_sharecache: + mnt->flags &= ~NFS_MOUNT_UNSHARED ; +break ; +case Opt_nosharecache: + mnt->flags |=NFS_MOUNT_UNSHARED ; +break ; +case Opt_resvport: + mnt->flags &= ~NFS_MOUNT_NORESVPORT ; +break ; +case Opt_noresvport: + mnt->flags |=NFS_MOUNT_NORESVPORT ; +break ; +case Opt_fscache: + mnt->options |=NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_migration: + mnt->options |=NFS_OPTION_MIGRATION ; +break ; +case Opt_nomigration: + mnt->options &= ~NFS_OPTION_MIGRATION ; +break ; + +/* +* options that take numeric values +*/ +case Opt_port: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->nfs_server.port = option; +break ; +case Opt_rsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->rsize = option; +break ; +case Opt_wsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->wsize = option; +break ; +case Opt_bsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->bsize = option; +break ; +case Opt_timeo: + if (nfs_get_option_ul_bound(args, &option, 1,
INT_MAX))fs/nfs/fs_context.c new file +5
-0+ goto out_invalid_value; + mnt->timeo = option; +break ; +case Opt_retrans: + if (nfs_get_option_ul_bound(args, &option, 0,
INT_MAX))fs/nfs/fs_context.c new file +63
-0+ goto out_invalid_value; + mnt->retrans = option; +break ; +case Opt_acregmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = option; +break ; +case Opt_acregmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmax = option; +break ; +case Opt_acdirmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmin = option; +break ; +case Opt_acdirmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmax = option; +break ; +case Opt_actimeo: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = mnt->acregmax = + mnt->acdirmin = mnt->acdirmax = option; +break ; +case Opt_namelen: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->namlen = option; +break ; +case Opt_mountport: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->mount_server.port = option; +break ; +case Opt_mountvers: +if (nfs_get_option_ul (args, &option) || + option <NFS_MNT_VERSION || + option >NFS_MNT3_VERSION ) + goto out_invalid_value; + mnt->mount_server.version = option; +break ; +case Opt_minorversion: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; +if (option >NFS4_MAX_MINOR_VERSION ) + goto out_invalid_value; + mnt->minorversion = option; +break ; + +/* +* options that take text values +*/ +case Opt_nfsvers: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc = nfs_parse_version_string(string, mnt,args);
fs/nfs/fs_context.c new file +22
-0+kfree (string); +if (!rc) + goto out_invalid_value; +break ; +case Opt_sec: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc =nfs_parse_security_flavors (string, mnt); +kfree (string); +if (!rc) { +dfprintk (MOUNT ,"NFS: unrecognized " +"security flavor\n" ); +return 0 ; + } +break ; +case Opt_proto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string, + nfs_xprt_protocol_tokens,args);
fs/nfs/fs_context.c new file +9
-0+ + protofamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +7
-0+break ; +case Opt_xprt_tcp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +8
-0+break ; +case Opt_xprt_rdma6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_rdma: +/* vector side protocols to TCP */ + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/fs_context.c new file +5
-0+xprt_load_transport (string); +break ; +default : +dfprintk (MOUNT ,"NFS: unrecognized " + "transportprotocol\n");
fs/nfs/fs_context.c new file +11
-0+kfree (string); +return 0 ; + } +kfree (string); +break ; +case Opt_mountproto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string, + nfs_xprt_protocol_tokens,args);
fs/nfs/fs_context.c new file +9
-0+kfree (string); + + mountfamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +6
-0+break ; +case Opt_xprt_tcp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +2
-0+break ; +case Opt_xprt_rdma:/* not used for side protocols */
fs/nfs/fs_context.c new file +3
-0+default : +dfprintk (MOUNT ,"NFS: unrecognized " + "transportprotocol\n");
fs/nfs/fs_context.c new file +9
-0+return 0 ; + } +break ; +case Opt_addr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->nfs_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +3
-0+ (struct sockaddr *) + &mnt->nfs_server.address, + sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->nfs_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_clientaddr: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/fs_context.c new file +5
-0+ goto out_nomem; +break ; +case Opt_mounthost: + if (nfs_get_option_str(args, + &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; +break ; +case Opt_mountaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->mount_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +3
-0+ (struct sockaddr *) + &mnt->mount_server.address, + sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->mount_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_nconnect: + if (nfs_get_option_ul_bound(args, &option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/fs_context.c new file +13
-0+ goto out_invalid_value; + mnt->nfs_server.nconnect = option; +break ; +case Opt_lookupcache: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_lookupcache_tokens, args); +kfree (string); +switch (token) { +case Opt_lookupcache_all: + mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_positive: + mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +1
-0+ mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_none: + mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +3
-0+break ; +default : + dfprintk(MOUNT, "NFS: invalid"
fs/nfs/fs_context.c new file +1
-0+ "lookupcacheargument\n");
fs/nfs/fs_context.c new file +5
-0+return 0 ; + }; +break ; +case Opt_fscache_uniq: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; + mnt->options |=NFS_OPTION_FSCACHE ; +break ; +case Opt_local_lock: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string,
nfs_local_lock_tokens,fs/nfs/fs_context.c new file +20
-0+ args); +kfree (string); + switch (token) { + case Opt_local_lock_all: + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | + NFS_MOUNT_LOCAL_FCNTL); + break; + case Opt_local_lock_flock: + mnt->flags |= NFS_MOUNT_LOCAL_FLOCK; + break; + case Opt_local_lock_posix: + mnt->flags |= NFS_MOUNT_LOCAL_FCNTL; + break; + case Opt_local_lock_none: + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | + NFS_MOUNT_LOCAL_FCNTL); + break; + default: + dfprintk(MOUNT, "NFS: invalid " + "local_lockargument\n");
fs/nfs/fs_context.c new file +10
-0+return 0 ; + }; +break ; + +/* +* Special options +*/ +case Opt_sloppy: + sloppy =1 ; + dfprintk(MOUNT, "NFS: relaxing parsingrules\n");
fs/nfs/fs_context.c new file +10
-0+break ; +case Opt_userspace: +case Opt_deprecated: +dfprintk (MOUNT ,"NFS: ignoring mount option " +"'%s'\n" , p); +break ; + +default : + invalid_option =1 ; + dfprintk(MOUNT, "NFS: unrecognized mountoption "
fs/nfs/fs_context.c new file +25
-0+ "'%s'\n", p); + } + } + +if (!sloppy && invalid_option) +return 0 ; + +if (mnt->minorversion && mnt->version !=4 ) + goto out_minorversion_mismatch; + +if (mnt->options &NFS_OPTION_MIGRATION && + (mnt->version !=4 || mnt->minorversion !=0 )) + goto out_migration_misuse; + +/* +* verify that any proto=/mountproto= options match the address +* families in the addr=/mountaddr= options. +*/ +if (protofamily !=AF_UNSPEC && + protofamily != mnt->nfs_server.address.ss_family) + goto out_proto_mismatch; + + if (mountfamily != AF_UNSPEC) { + if (mnt->mount_server.addrlen) { + if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/fs_context.c new file +3
-0+ goto out_mountproto_mismatch; + } else { + if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/fs_context.c new file +8
-0+ goto out_mountproto_mismatch; + } + } + +return 1 ; + +out_mountproto_mismatch: + printk(KERN_INFO "NFS: mount server address does not matchmountproto= "
fs/nfs/fs_context.c new file +4
-0+ "option\n"); +return 0 ; +out_proto_mismatch: + printk(KERN_INFO "NFS: server address does not match proto=option\n");
fs/nfs/fs_context.c new file +6
-0+return 0 ; +out_invalid_address: +printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); +return 0 ; +out_invalid_value: + printk(KERN_INFO "NFS: bad mount option value specified: %s\n",p);
fs/nfs/fs_context.c new file +4
-0+return 0 ; +out_minorversion_mismatch: + printk(KERN_INFO "NFS: mount option vers=%u does not support " + "minorversion=%u\n", mnt->version, mnt-Quoted 1 line
minorversion);
fs/nfs/fs_context.c new file +4
-0+return 0 ; +out_migration_misuse: +printk (KERN_INFO + "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/fs_context.c new file +13
-0+return 0 ; +out_nomem: +printk (KERN_INFO "NFS: not enough memory to parse option\n" ); +return 0 ; +out_security_failure: +printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); +return 0 ; +} + +/* +* Split "dev_name" into "hostname:export_path". +* +* The leftmost colon demarks the split between the server's hostname
+ * and the export path. If the hostname starts with a left square
+ * bracket, then it may contain colons.
+ *
+ * Note: caller frees hostname and export path, even on error.
+ */fs/nfs/fs_context.c new file +57
-0+static int nfs_parse_devname (const char *dev_name, +char **hostname,size_t maxnamlen, +char **export_path,size_t maxpathlen) +{ +size_t len; +char *end; + +if (unlikely (!dev_name || !*dev_name)) { +dfprintk (MOUNT ,"NFS: device name not specified\n" ); +return -EINVAL ; + } + +/* Is the host name protected with square brakcets? */ +if (*dev_name =='[' ) { + end =strchr (++dev_name,']' ); +if (end ==NULL || end[1 ] !=':' ) + goto out_bad_devname; + + len = end - dev_name; + end++; + }else { +char *comma; + + end =strchr (dev_name,':' ); +if (end ==NULL ) + goto out_bad_devname; + len = end - dev_name; + +/* kill possible hostname list: not supported */ + comma =strchr (dev_name,',' ); +if (comma !=NULL && comma < end) + len = comma - dev_name; + } + +if (len > maxnamlen) + goto out_hostname; + +/* N.B. caller will free nfs_server.hostname in all cases */ + *hostname =kstrndup (dev_name, len,GFP_KERNEL ); +if (*hostname ==NULL ) + goto out_nomem; + len =strlen (++end); +if (len > maxpathlen) + goto out_path; + *export_path =kstrndup (end, len,GFP_KERNEL ); +if (!*export_path) + goto out_nomem; + +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); +return 0 ; + +out_bad_devname: +dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); +return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/fs_context.c new file +20
-0+return -ENOMEM ; + +out_hostname: +dfprintk (MOUNT ,"NFS: server hostname too long\n" ); +return -ENAMETOOLONG ; + +out_path: +dfprintk (MOUNT ,"NFS: export pathname too long\n" ); +return -ENAMETOOLONG ; +} + +/* +* Validate the NFS2/NFS3 mount data +* - fills in the mount root filehandle +* +* For option strings, user space handles the following behaviors: +* +* + DNS: mapping server host name to IP address ("addr=" option) +* +* + failure mode: how to behave if a mount request can't be handled
+ * immediately ("fg/bg" option)
+ *
+ * + retry: how often to retry a mount request ("retry=" option)
+ *
+ * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
+ * mountproto=tcp after mountproto=udp, and so on
+ */fs/nfs/fs_context.c new file +2
-0+static int nfs23_validate_mount_data (void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/fs_context.c new file +5
-0+struct nfs_fh *mntfh, + const char *dev_name) +{ + struct nfs_mount_data *data = (struct nfs_mount_data *)options; + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +16
-0+int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; + +if (data ==NULL ) + goto out_no_data; + + args->version =NFS_DEFAULT_VERSION ; +switch (data->version) { +case 1 : + data->namlen =0 ;/* fall through */ +case 2 : + data->bsize =0 ;/* fall through */ +case 3 : +if (data->flags &NFS_MOUNT_VER3 ) + goto out_no_v3; + data->root.size =NFS2_FHSIZE ; + memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/fs_context.c new file +13
-0+/* Turn off security negotiation */ + extra_flags |=NFS_MOUNT_SECFLAVOUR ; +/* fall through */ +case 4 : +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + goto out_no_sec; +/* fall through */ +case 5 : +memset (data->context,0 ,sizeof (data->context)); +/* fall through */ +case 6 : + if (data->flags & NFS_MOUNT_VER3) { + if (data->root.size > NFS3_FHSIZE || data-Quoted 1 line
root.size == 0)
fs/nfs/fs_context.c new file +16
-0+ goto out_invalid_fh; + mntfh->size = data->root.size; + args->version =3 ; + }else { + mntfh->size =NFS2_FHSIZE ; + args->version =2 ; + } + + +memcpy (mntfh->data, data->root.data, mntfh->size); +if (mntfh->size <sizeof (mntfh->data)) +memset (mntfh->data + mntfh->size,0 , +sizeof (mntfh->data) - mntfh->size); + +/* +* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/fs_context.c new file +24
-0+* can deal with. +*/ + args->flags = data->flags &NFS_MOUNT_FLAGMASK ; + args->flags |= extra_flags; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->need_mount = false; + +memcpy (sap, &data->addr,sizeof (data->addr)); + args->nfs_server.addrlen =sizeof (data->addr); + args->nfs_server.port =ntohs (data->addr.sin_port); +if (sap->sa_family !=AF_INET || + !nfs_verify_server_address (sap)) + goto out_no_address; + +if (!(data->flags &NFS_MOUNT_TCP )) + args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/fs_context.c new file +1
-0+ args->nfs_server.hostname = kstrdup(data->hostname,
GFP_KERNEL);fs/nfs/fs_context.c new file +18
-0+ args->namlen = data->namlen; + args->bsize = data->bsize; + +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + args->selected_flavor = data->pseudoflavor; +else + args->selected_flavor =RPC_AUTH_UNIX ; +if (!args->nfs_server.hostname) + goto out_nomem; + +if (!(data->flags &NFS_MOUNT_NONLM )) + args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +else + args->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +/* +* The legacy version 6 binary mount data from userspace has a
fs/nfs/fs_context.c new file +1
-0+* field used only to transport selinux information into the
fs/nfs/fs_context.c new file +1
-0+* the kernel. To continue to support that functionality we
fs/nfs/fs_context.c new file +1
-0+* have a touch of selinux knowledge here in the NFS code. The
fs/nfs/fs_context.c new file +1
-0+* userspace code converted context=blah to just blah so we are
fs/nfs/fs_context.c new file +1
-0+* converting back to the full string selinux understands.
fs/nfs/fs_context.c new file +6
-0+*/ +if (data->context[0 ]){ +#ifdef CONFIG_SECURITY_SELINUX +int rc; + data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; + rc = security_add_mnt_opt("context", data-Quoted 1 line
context,
fs/nfs/fs_context.c new file +1
-0+ strlen(data->context), &args-Quoted 1 line
lsm_opts);fs/nfs/fs_context.c new file +16
-0+if (rc) +return rc; +#else +return -EINVAL ; +#endif + } + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS: mount program didn't pass any mountdata\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_no_v3: + dfprintk(MOUNT, "NFS: nfs_mount_data version %d does notsupport v3\n",
fs/nfs/fs_context.c new file +5
-0+ data->version); +return -EINVAL ; + +out_no_sec: + dfprintk(MOUNT, "NFS: nfs_mount_data version supports onlyAUTH_SYS\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/fs_context.c new file +4
-0+return -ENOMEM ; + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +10
-0+return -EINVAL ; + +out_invalid_fh: +dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); +return -EINVAL ; +} + +#if IS_ENABLED (CONFIG_NFS_V4 ) + +static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data*args)
fs/nfs/fs_context.c new file +2
-0+{ + args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/fs_context.c new file +11
-0+ NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); +} + +/* +* Validate NFSv4 mount options +*/ +static int nfs4_validate_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +1
-0+ struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/fs_context.c new file +10
-0+char *c; + +if (data ==NULL ) + goto out_no_data; + + args->version =4 ; + +switch (data->version) { +case 1 : + if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/fs_context.c new file +5
-0+ goto out_no_address; +if (data->host_addrlen ==0 ) + goto out_no_address; + args->nfs_server.addrlen = data->host_addrlen; + if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/fs_context.c new file +4
-0+return -EFAULT ; +if (!nfs_verify_server_address (sap)) + goto out_no_address; + args->nfs_server.port = ntohs(((struct sockaddr_in*)sap)->sin_port);
fs/nfs/fs_context.c new file +31
-0+ +if (data->auth_flavourlen) { +rpc_authflavor_t pseudoflavor; +if (data->auth_flavourlen >1 ) + goto out_inval_auth; +if (copy_from_user (&pseudoflavor, + data->auth_flavours, +sizeof (pseudoflavor))) +return -EFAULT ; + args->selected_flavor = pseudoflavor; + }else + args->selected_flavor =RPC_AUTH_UNIX ; + + c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.hostname = c; + + c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.export_path = c; +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); + + c =strndup_user (data->client_addr.data,16 ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->client_address = c; + +/* +* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/fs_context.c new file +26
-0+* can deal with. +*/ + + args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->nfs_server.protocol = data->proto; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS4: mount program didn't pass any mountdata\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_inval_auth: + dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours%d\n",
fs/nfs/fs_context.c new file +5
-0+ data->auth_flavourlen); +return -EINVAL ; + +out_no_address: + dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +15
-0+return -EINVAL ; + +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +} + +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +if (fs_type == &nfs_fs_type) + return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/fs_context.c new file +10
-0+return nfs4_validate_mount_data (options, args, dev_name); +} +#else +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ + return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/fs_context.c new file +11
-0+} +#endif + +int nfs_validate_text_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ +int port =0 ; +int max_namelen =PAGE_SIZE ; +int max_pathlen =NFS_MAXPATHLEN ; + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +48
-0+ +if (nfs_parse_mount_options ((char *)options, args) ==0 ) +return -EINVAL ; + +if (!nfs_verify_server_address (sap)) + goto out_no_address; + +if (args->version ==4 ) { +#if IS_ENABLED (CONFIG_NFS_V4 ) +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; +else + port =NFS_PORT ; + max_namelen =NFS4_MAXNAMLEN ; + max_pathlen =NFS4_MAXPATHLEN ; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; +nfs4_validate_mount_flags (args); +#else + goto out_v4_not_compiled; +#endif /* CONFIG_NFS_V4 */ + }else { +nfs_set_mount_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; + } + +nfs_set_port (sap, &args->nfs_server.port, port); + +return nfs_parse_devname (dev_name, + &args->nfs_server.hostname, + max_namelen, + &args->nfs_server.export_path, + max_pathlen); + +#if !IS_ENABLED (CONFIG_NFS_V4 ) +out_v4_not_compiled: +dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); +return -EPROTONOSUPPORT ; +#else +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +#endif /* !CONFIG_NFS_V4 */ + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +2
-0+return -EINVAL ; +}fs/nfs/internal.h +8
-0@@ -7,6 +7,7 @@#include <linux/mount.h> #include <linux/security.h> #include <linux/crc32.h> +#include <linux/sunrpc/addr.h> #include <linux/nfs_page.h> #include <linux/wait_bit.h> @@ -232,6 +233,22 @@ extern const struct svc_version nfs4_callback_version1;extern const struct svc_version nfs4_callback_version4;struct nfs_pageio_descriptor ; + +/* mount.c */ +#define NFS_TEXT_DATA 1 + +extern struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ); +extern void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data); +extern int nfs_parse_mount_options(char *raw, struct
nfs_parsed_mount_data*mnt);
+extern int nfs_validate_mount_data(structfile_system_type*fs_type,fs/nfs/internal.h +6
-0+void *options, + struct nfs_parsed_mount_data *args, + struct nfs_fh *mntfh, + const char *dev_name); +extern int nfs_validate_text_mount_data (void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/internal.h +2
-0+ const char *dev_name); +/*
pagelist.c*/
extern int__initnfs_init_nfspagecache(void);
extern voidnfs_destroy_nfspagecache(void);fs/nfs/internal.h +2
-0@@ -763,3 +780,15 @@ static inline bool nfs_error_is_fatal(int err) } } +/* +* Select between a default port value and a user-specified port value.
+ * If a zero value is set, then autobind will be used.
+ */fs/nfs/internal.h +8
-0+static inline void nfs_set_port (struct sockaddr *sap,int *port, +const unsigned short default_port) +{ +if (*port ==NFS_UNSPEC_PORT ) + *port = default_port; + +rpc_set_port (sap, *port); +}fs/nfs/super.c +0
-223@@ -69,229 +69,6 @@#include "nfs.h" #define NFSDBG_FACILITY NFSDBG_VFS -#define NFS_TEXT_DATA 1 - -#if IS_ENABLED (CONFIG_NFS_V3 ) -#define NFS_DEFAULT_VERSION 3 -#else -#define NFS_DEFAULT_VERSION 2 -#endif - -#define NFS_MAX_CONNECTIONS 16 - -enum { -/* Mount options that take no arguments */ - Opt_soft, Opt_softerr, Opt_hard, - Opt_posix, Opt_noposix, - Opt_cto, Opt_nocto, - Opt_ac, Opt_noac, - Opt_lock, Opt_nolock, - Opt_udp, Opt_tcp, Opt_rdma, - Opt_acl, Opt_noacl, - Opt_rdirplus, Opt_nordirplus, - Opt_sharecache, Opt_nosharecache, - Opt_resvport, Opt_noresvport, - Opt_fscache, Opt_nofscache, - Opt_migration, Opt_nomigration, - -/* Mount options that take integer arguments */ - Opt_port, - Opt_rsize, Opt_wsize, Opt_bsize, - Opt_timeo, Opt_retrans, - Opt_acregmin, Opt_acregmax, - Opt_acdirmin, Opt_acdirmax, - Opt_actimeo, - Opt_namelen, - Opt_mountport, - Opt_mountvers, - Opt_minorversion, - -/* Mount options that take string arguments */ - Opt_nfsvers, - Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, - Opt_nconnect, - Opt_lookupcache, - Opt_fscache_uniq, - Opt_local_lock, - -/* Special mount options */ - Opt_userspace, Opt_deprecated, Opt_sloppy, - - Opt_err -}; - -static const match_table_t nfs_mount_option_tokens = { - { Opt_userspace,"bg" }, - { Opt_userspace,"fg" }, - { Opt_userspace,"retry=%s" }, - - { Opt_sloppy,"sloppy" }, - - { Opt_soft,"soft" }, - { Opt_softerr,"softerr" }, - { Opt_hard,"hard" }, - { Opt_deprecated,"intr" }, - { Opt_deprecated,"nointr" }, - { Opt_posix,"posix" }, - { Opt_noposix,"noposix" }, - { Opt_cto,"cto" }, - { Opt_nocto,"nocto" }, - { Opt_ac,"ac" }, - { Opt_noac,"noac" }, - { Opt_lock,"lock" }, - { Opt_nolock,"nolock" }, - { Opt_udp,"udp" }, - { Opt_tcp,"tcp" }, - { Opt_rdma,"rdma" }, - { Opt_acl,"acl" }, - { Opt_noacl,"noacl" }, - { Opt_rdirplus,"rdirplus" }, - { Opt_nordirplus,"nordirplus" }, - { Opt_sharecache,"sharecache" }, - { Opt_nosharecache,"nosharecache" }, - { Opt_resvport,"resvport" }, - { Opt_noresvport,"noresvport" }, - { Opt_fscache,"fsc" }, - { Opt_nofscache,"nofsc" }, - { Opt_migration,"migration" }, - { Opt_nomigration,"nomigration" }, - - { Opt_port,"port=%s" }, - { Opt_rsize,"rsize=%s" }, - { Opt_wsize,"wsize=%s" }, - { Opt_bsize,"bsize=%s" }, - { Opt_timeo,"timeo=%s" }, - { Opt_retrans,"retrans=%s" }, - { Opt_acregmin,"acregmin=%s" }, - { Opt_acregmax,"acregmax=%s" }, - { Opt_acdirmin,"acdirmin=%s" }, - { Opt_acdirmax,"acdirmax=%s" }, - { Opt_actimeo,"actimeo=%s" }, - { Opt_namelen,"namlen=%s" }, - { Opt_mountport,"mountport=%s" }, - { Opt_mountvers,"mountvers=%s" }, - { Opt_minorversion,"minorversion=%s" }, - - { Opt_nfsvers,"nfsvers=%s" }, - { Opt_nfsvers,"vers=%s" }, - - { Opt_sec,"sec=%s" }, - { Opt_proto,"proto=%s" }, - { Opt_mountproto,"mountproto=%s" }, - { Opt_addr,"addr=%s" }, - { Opt_clientaddr,"clientaddr=%s" }, - { Opt_mounthost,"mounthost=%s" }, - { Opt_mountaddr,"mountaddr=%s" }, - - { Opt_nconnect,"nconnect=%s" }, - - { Opt_lookupcache,"lookupcache=%s" }, - { Opt_fscache_uniq,"fsc=%s" }, - { Opt_local_lock,"local_lock=%s" }, - -/* The following needs to be listed after all other options */ - { Opt_nfsvers,"v%s" }, - - { Opt_err,NULL } -}; - -enum { - Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma, - Opt_xprt_rdma6, - - Opt_xprt_err -}; - -static const match_table_t nfs_xprt_protocol_tokens = { - { Opt_xprt_udp,"udp" }, - { Opt_xprt_udp6,"udp6" }, - { Opt_xprt_tcp,"tcp" }, - { Opt_xprt_tcp6,"tcp6" }, - { Opt_xprt_rdma,"rdma" }, - { Opt_xprt_rdma6,"rdma6" }, - - { Opt_xprt_err,NULL } -}; - -enum { - Opt_sec_none, Opt_sec_sys, - Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, - Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, - Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, - - Opt_sec_err -}; - -static const match_table_t nfs_secflavor_tokens = { - { Opt_sec_none,"none" }, - { Opt_sec_none,"null" }, - { Opt_sec_sys,"sys" }, - - { Opt_sec_krb5,"krb5" }, - { Opt_sec_krb5i,"krb5i" }, - { Opt_sec_krb5p,"krb5p" }, - - { Opt_sec_lkey,"lkey" }, - { Opt_sec_lkeyi,"lkeyi" }, - { Opt_sec_lkeyp,"lkeyp" }, - - { Opt_sec_spkm,"spkm3" }, - { Opt_sec_spkmi,"spkm3i" }, - { Opt_sec_spkmp,"spkm3p" }, - - { Opt_sec_err,NULL } -}; - -enum { - Opt_lookupcache_all, Opt_lookupcache_positive, - Opt_lookupcache_none, - - Opt_lookupcache_err -}; - -static match_table_t nfs_lookupcache_tokens = { - { Opt_lookupcache_all,"all" }, - { Opt_lookupcache_positive,"pos" }, - { Opt_lookupcache_positive,"positive" }, - { Opt_lookupcache_none,"none" }, - - { Opt_lookupcache_err,NULL } -}; - -enum { - Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, - Opt_local_lock_none, - - Opt_local_lock_err -}; - -static match_table_t nfs_local_lock_tokens = { - { Opt_local_lock_all,"all" }, - { Opt_local_lock_flock,"flock" }, - { Opt_local_lock_posix,"posix" }, - { Opt_local_lock_none,"none" }, - - { Opt_local_lock_err,NULL } -}; - -enum { - Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, - Opt_vers_4_1, Opt_vers_4_2, - - Opt_vers_err -}; - -static match_table_t nfs_vers_tokens = { - { Opt_vers_2,"2" }, - { Opt_vers_3,"3" }, - { Opt_vers_4,"4" }, - { Opt_vers_4_0,"4.0" }, - { Opt_vers_4_1,"4.1" }, - { Opt_vers_4_2,"4.2" }, - - { Opt_vers_err,NULL } -};static struct dentry *nfs_prepared_mount(struct
file_system_type*fs_type,int flags, const char *dev_name, void *raw_data);fs/nfs/super.c +0
-4@@ -332,10 +109,6 @@ const struct super_operations nfs_sops = {EXPORT_SYMBOL_GPL (nfs_sops);#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *); -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args,const char *dev_name); -struct file_system_type nfs4_fs_type = { .owner = THIS_MODULE,.name = "nfs4",fs/nfs/super.c +0
-62@@ -932,141 +705,6 @@ void nfs_umount_begin(struct super_block *sb) }EXPORT_SYMBOL_GPL (nfs_umount_begin); -static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void) -{ -struct nfs_parsed_mount_data *data; - - data =kzalloc (sizeof (*data),GFP_KERNEL ); -if (data) { - data->timeo =NFS_UNSPEC_TIMEO ; - data->retrans =NFS_UNSPEC_RETRANS ; - data->acregmin =NFS_DEF_ACREGMIN ; - data->acregmax =NFS_DEF_ACREGMAX ; - data->acdirmin =NFS_DEF_ACDIRMIN ; - data->acdirmax =NFS_DEF_ACDIRMAX ; - data->mount_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - data->selected_flavor =RPC_AUTH_MAXFLAVOR ; - data->minorversion =0 ; - data->need_mount = true; - data->net = current->nsproxy->net_ns; - data->lsm_opts =NULL ; - } -return data; -} - -static void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data) -{ -if (data) { -kfree (data->client_address); -kfree (data->mount_server.hostname); -kfree (data->nfs_server.export_path); -kfree (data->nfs_server.hostname); -kfree (data->fscache_uniq); -security_free_mnt_opts (&data->lsm_opts); -kfree (data); - } -} - -/* -* Sanity-check a server address provided by the mount command. -* -* Address family must be initialized, and address must not be -* the ANY address for that family. -*/ -static int nfs_verify_server_address (struct sockaddr *addr) -{ -switch (addr->sa_family) { -case AF_INET : { -struct sockaddr_in *sa = (struct sockaddr_in *)addr; -return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); - } -case AF_INET6 : { -struct in6_addr *sa = &((struct sockaddr_in6 *)addr)- >sin6_addr; -return !ipv6_addr_any (sa); - } - } - -dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); -return 0 ; -} - -/* -* Select between a default port value and a user-specified port value.
- * If a zero value is set, then autobind will be used.
- */fs/nfs/super.c +0
-14-static void nfs_set_port (struct sockaddr *sap,int *port, -const unsigned short default_port) -{ -if (*port ==NFS_UNSPEC_PORT ) - *port = default_port; - -rpc_set_port (sap, *port); -} - -/* -* Sanity check the NFS transport protocol. -* -*/ -static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/super.c +0
-13-{ -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : -break ; -default : - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* For text based NFSv2/v3 mounts, the mount protocol transport default
- * settings should depend upon the specified NFS transport.
- */
-static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/super.c +0
-41-{ -nfs_validate_transport_protocol (mnt); - -if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || - mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) -return ; -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : - mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : - mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* Add 'flavor' to 'auth_info' if not already present. -* Returns true if 'flavor' ends up in the list, false otherwise -*/ -static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, -rpc_authflavor_t flavor) -{ -unsigned int i; -unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); - -/* make sure this flavor isn't already in the list */ -for (i =0 ; i < auth_info->flavor_len; i++) { -if (flavor == auth_info->flavors[i]) -return true; - } - -if (auth_info->flavor_len +1 >= max_flavor_len) { -dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); -return false; - } - - auth_info->flavors[auth_info->flavor_len++] = flavor; -return true; -} -/*
* Return true if 'match' is inauth_infoorauth_infois empty.
* Return false otherwise.fs/nfs/super.c +0
-106@@ -1087,627 +725,6 @@ bool nfs_auth_info_match(const structnfs_auth_info *auth_info, }EXPORT_SYMBOL_GPL (nfs_auth_info_match ); -/* -* Parse the value of the 'sec=' option. -*/ -static int nfs_parse_security_flavors (char *value, -struct nfs_parsed_mount_data *mnt) -{ -substring_t args[MAX_OPT_ARGS ]; -rpc_authflavor_t pseudoflavor; -char *p; - -dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); - -while ((p =strsep (&value,":" )) !=NULL ) { -switch (match_token (p, nfs_secflavor_tokens, args)) { -case Opt_sec_none: - pseudoflavor =RPC_AUTH_NULL ; -break ; -case Opt_sec_sys: - pseudoflavor =RPC_AUTH_UNIX ; -break ; -case Opt_sec_krb5: - pseudoflavor =RPC_AUTH_GSS_KRB5 ; -break ; -case Opt_sec_krb5i: - pseudoflavor =RPC_AUTH_GSS_KRB5I ; -break ; -case Opt_sec_krb5p: - pseudoflavor =RPC_AUTH_GSS_KRB5P ; -break ; -case Opt_sec_lkey: - pseudoflavor =RPC_AUTH_GSS_LKEY ; -break ; -case Opt_sec_lkeyi: - pseudoflavor =RPC_AUTH_GSS_LKEYI ; -break ; -case Opt_sec_lkeyp: - pseudoflavor =RPC_AUTH_GSS_LKEYP ; -break ; -case Opt_sec_spkm: - pseudoflavor =RPC_AUTH_GSS_SPKM ; -break ; -case Opt_sec_spkmi: - pseudoflavor =RPC_AUTH_GSS_SPKMI ; -break ; -case Opt_sec_spkmp: - pseudoflavor =RPC_AUTH_GSS_SPKMP ; -break ; -default : -dfprintk (MOUNT , -"NFS: sec= option '%s' not recognized\n", p); -return 0 ; - } - -if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) -return 0 ; - } - -return 1 ; -} - -static int nfs_parse_version_string (char *string, -struct nfs_parsed_mount_data *mnt, -substring_t *args) -{ - mnt->flags &= ~NFS_MOUNT_VER3 ; -switch (match_token (string, nfs_vers_tokens, args)) { -case Opt_vers_2: - mnt->version =2 ; -break ; -case Opt_vers_3: - mnt->flags |=NFS_MOUNT_VER3 ; - mnt->version =3 ; -break ; -case Opt_vers_4: -/* Backward compatibility option. In future, -* the mount program should always supply -* a NFSv4 minor version number. -*/ - mnt->version =4 ; -break ; -case Opt_vers_4_0: - mnt->version =4 ; - mnt->minorversion =0 ; -break ; -case Opt_vers_4_1: - mnt->version =4 ; - mnt->minorversion =1 ; -break ; -case Opt_vers_4_2: - mnt->version =4 ; - mnt->minorversion =2 ; -break ; -default : -return 0 ; - } -return 1 ; -} - -static int nfs_get_option_str (substring_t args[],char **option) -{ -kfree (*option); - *option =match_strdup (args); -return !*option; -} - -static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/super.c +0
-14-{ -int rc; -char *string; - - string =match_strdup (args); -if (string ==NULL ) -return -ENOMEM ; - rc =kstrtoul (string,10 , option); -kfree (string); - -return rc; -} - -static int nfs_get_option_ul_bound(substring_t args[], unsignedlong *option,
fs/nfs/super.c +0
-14- unsigned long l_bound, unsigned long u_bound) -{ - int ret; - - ret =nfs_get_option_ul (args, option); -if (ret !=0 ) -return ret; -if (*option < l_bound || *option > u_bound) -return -ERANGE ; -return 0 ; -} - -/* -* Error-check and convert a string of mount options from user space into
- * a data structure. The whole mount string is processed; bad options are
- * skipped as they are encountered. If there were no errors, return 1;
- * otherwise return 0 (zero).
- */fs/nfs/super.c +0
-10-static int nfs_parse_mount_options (char *raw, -struct nfs_parsed_mount_data *mnt) -{ -char *p, *string; -int rc, sloppy =0 , invalid_option =0 ; -unsigned short protofamily =AF_UNSPEC ; -unsigned short mountfamily =AF_UNSPEC ; - -if (!raw) { - dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/super.c +0
-17-return 1 ; - } -dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); - - rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); -if (rc) - goto out_security_failure; - -while ((p =strsep (&raw,"," )) !=NULL ) { -substring_t args[MAX_OPT_ARGS ]; -unsigned long option; -int token; - -if (!*p) -continue ; - - dfprintk(MOUNT, "NFS: parsing nfs mount option'%s'\n", p);
fs/nfs/super.c +0
-17- - token =match_token (p, nfs_mount_option_tokens, args); -switch (token) { - -/* -* boolean options: foo/nofoo -*/ -case Opt_soft: - mnt->flags |=NFS_MOUNT_SOFT ; - mnt->flags &= ~NFS_MOUNT_SOFTERR ; -break ; -case Opt_softerr: - mnt->flags |=NFS_MOUNT_SOFTERR ; - mnt->flags &= ~NFS_MOUNT_SOFT ; -break ; -case Opt_hard: - mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/super.c +0
-39-break ; -case Opt_posix: - mnt->flags |=NFS_MOUNT_POSIX ; -break ; -case Opt_noposix: - mnt->flags &= ~NFS_MOUNT_POSIX ; -break ; -case Opt_cto: - mnt->flags &= ~NFS_MOUNT_NOCTO ; -break ; -case Opt_nocto: - mnt->flags |=NFS_MOUNT_NOCTO ; -break ; -case Opt_ac: - mnt->flags &= ~NFS_MOUNT_NOAC ; -break ; -case Opt_noac: - mnt->flags |=NFS_MOUNT_NOAC ; -break ; -case Opt_lock: - mnt->flags &= ~NFS_MOUNT_NONLM ; - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_nolock: - mnt->flags |=NFS_MOUNT_NONLM ; - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case Opt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; -break ; -case Opt_rdma: - mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */
fs/nfs/super.c +0
-70- mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; -xprt_load_transport (p); -break ; -case Opt_acl: - mnt->flags &= ~NFS_MOUNT_NOACL ; -break ; -case Opt_noacl: - mnt->flags |=NFS_MOUNT_NOACL ; -break ; -case Opt_rdirplus: - mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_nordirplus: - mnt->flags |=NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_sharecache: - mnt->flags &= ~NFS_MOUNT_UNSHARED ; -break ; -case Opt_nosharecache: - mnt->flags |=NFS_MOUNT_UNSHARED ; -break ; -case Opt_resvport: - mnt->flags &= ~NFS_MOUNT_NORESVPORT ; -break ; -case Opt_noresvport: - mnt->flags |=NFS_MOUNT_NORESVPORT ; -break ; -case Opt_fscache: - mnt->options |=NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_nofscache: - mnt->options &= ~NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_migration: - mnt->options |=NFS_OPTION_MIGRATION ; -break ; -case Opt_nomigration: - mnt->options &= ~NFS_OPTION_MIGRATION ; -break ; - -/* -* options that take numeric values -*/ -case Opt_port: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->nfs_server.port = option; -break ; -case Opt_rsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->rsize = option; -break ; -case Opt_wsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->wsize = option; -break ; -case Opt_bsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->bsize = option; -break ; -case Opt_timeo: - if (nfs_get_option_ul_bound(args, &option, 1,
INT_MAX))fs/nfs/super.c +0
-5- goto out_invalid_value; - mnt->timeo = option; -break ; -case Opt_retrans: - if (nfs_get_option_ul_bound(args, &option, 0,
INT_MAX))fs/nfs/super.c +0
-63- goto out_invalid_value; - mnt->retrans = option; -break ; -case Opt_acregmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = option; -break ; -case Opt_acregmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmax = option; -break ; -case Opt_acdirmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmin = option; -break ; -case Opt_acdirmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmax = option; -break ; -case Opt_actimeo: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = mnt->acregmax = - mnt->acdirmin = mnt->acdirmax = option; -break ; -case Opt_namelen: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->namlen = option; -break ; -case Opt_mountport: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->mount_server.port = option; -break ; -case Opt_mountvers: -if (nfs_get_option_ul (args, &option) || - option <NFS_MNT_VERSION || - option >NFS_MNT3_VERSION ) - goto out_invalid_value; - mnt->mount_server.version = option; -break ; -case Opt_minorversion: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; -if (option >NFS4_MAX_MINOR_VERSION ) - goto out_invalid_value; - mnt->minorversion = option; -break ; - -/* -* options that take text values -*/ -case Opt_nfsvers: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc = nfs_parse_version_string(string, mnt,args);
fs/nfs/super.c +0
-22-kfree (string); -if (!rc) - goto out_invalid_value; -break ; -case Opt_sec: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc =nfs_parse_security_flavors (string, mnt); -kfree (string); -if (!rc) { -dfprintk (MOUNT ,"NFS: unrecognized " -"security flavor\n" ); -return 0 ; - } -break ; -case Opt_proto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string, - nfs_xprt_protocol_tokens,args);
fs/nfs/super.c +0
-9- - protofamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-7-break ; -case Opt_xprt_tcp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-8-break ; -case Opt_xprt_rdma6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_rdma: -/* vector side protocols to TCP */ - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/super.c +0
-5-xprt_load_transport (string); -break ; -default : -dfprintk (MOUNT ,"NFS: unrecognized " - "transportprotocol\n");
fs/nfs/super.c +0
-11-kfree (string); -return 0 ; - } -kfree (string); -break ; -case Opt_mountproto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string, - nfs_xprt_protocol_tokens,args);
fs/nfs/super.c +0
-9-kfree (string); - - mountfamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-6-break ; -case Opt_xprt_tcp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-2-break ; -case Opt_xprt_rdma:/* not used for side protocols */
fs/nfs/super.c +0
-3-default : -dfprintk (MOUNT ,"NFS: unrecognized " - "transportprotocol\n");
fs/nfs/super.c +0
-9-return 0 ; - } -break ; -case Opt_addr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->nfs_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-3- (struct sockaddr *) - &mnt->nfs_server.address, - sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->nfs_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_clientaddr: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/super.c +0
-5- goto out_nomem; -break ; -case Opt_mounthost: - if (nfs_get_option_str(args, - &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/super.c +0
-8- goto out_nomem; -break ; -case Opt_mountaddr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->mount_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-3- (struct sockaddr *) - &mnt->mount_server.address, - sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->mount_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_nconnect: - if (nfs_get_option_ul_bound(args, &option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/super.c +0
-13- goto out_invalid_value; - mnt->nfs_server.nconnect = option; -break ; -case Opt_lookupcache: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_lookupcache_tokens, args); -kfree (string); -switch (token) { -case Opt_lookupcache_all: - mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_positive: - mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-1- mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_none: - mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-3-break ; -default : - dfprintk(MOUNT, "NFS: invalid"
fs/nfs/super.c +0
-1- "lookupcacheargument\n");
fs/nfs/super.c +0
-5-return 0 ; - }; -break ; -case Opt_fscache_uniq: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/super.c +0
-8- goto out_nomem; - mnt->options |=NFS_OPTION_FSCACHE ; -break ; -case Opt_local_lock: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string,
nfs_local_lock_tokens,fs/nfs/super.c +0
-20- args); -kfree (string); - switch (token) { - case Opt_local_lock_all: - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | - NFS_MOUNT_LOCAL_FCNTL); - break; - case Opt_local_lock_flock: - mnt->flags |= NFS_MOUNT_LOCAL_FLOCK; - break; - case Opt_local_lock_posix: - mnt->flags |= NFS_MOUNT_LOCAL_FCNTL; - break; - case Opt_local_lock_none: - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | - NFS_MOUNT_LOCAL_FCNTL); - break; - default: - dfprintk(MOUNT, "NFS: invalid " - "local_lockargument\n");
fs/nfs/super.c +0
-10-return 0 ; - }; -break ; - -/* -* Special options -*/ -case Opt_sloppy: - sloppy =1 ; - dfprintk(MOUNT, "NFS: relaxing parsingrules\n");
fs/nfs/super.c +0
-10-break ; -case Opt_userspace: -case Opt_deprecated: -dfprintk (MOUNT ,"NFS: ignoring mount option " -"'%s'\n" , p); -break ; - -default : - invalid_option =1 ; - dfprintk(MOUNT, "NFS: unrecognized mountoption "
fs/nfs/super.c +0
-25- "'%s'\n", p); - } - } - -if (!sloppy && invalid_option) -return 0 ; - -if (mnt->minorversion && mnt->version !=4 ) - goto out_minorversion_mismatch; - -if (mnt->options &NFS_OPTION_MIGRATION && - (mnt->version !=4 || mnt->minorversion !=0 )) - goto out_migration_misuse; - -/* -* verify that any proto=/mountproto= options match the address -* families in the addr=/mountaddr= options. -*/ -if (protofamily !=AF_UNSPEC && - protofamily != mnt->nfs_server.address.ss_family) - goto out_proto_mismatch; - - if (mountfamily != AF_UNSPEC) { - if (mnt->mount_server.addrlen) { - if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/super.c +0
-3- goto out_mountproto_mismatch; - } else { - if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/super.c +0
-8- goto out_mountproto_mismatch; - } - } - -return 1 ; - -out_mountproto_mismatch: - printk(KERN_INFO "NFS: mount server address does not matchmountproto= "
fs/nfs/super.c +0
-4- "option\n"); -return 0 ; -out_proto_mismatch: - printk(KERN_INFO "NFS: server address does not match proto=option\n");
fs/nfs/super.c +0
-6-return 0 ; -out_invalid_address: -printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); -return 0 ; -out_invalid_value: - printk(KERN_INFO "NFS: bad mount option value specified: %s\n",p);
fs/nfs/super.c +0
-4-return 0 ; -out_minorversion_mismatch: - printk(KERN_INFO "NFS: mount option vers=%u does not support " - "minorversion=%u\n", mnt->version, mnt-Quoted 1 line
minorversion);
fs/nfs/super.c +0
-4-return 0 ; -out_migration_misuse: -printk (KERN_INFO - "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/super.c +0
-9-return 0 ; -out_nomem: -printk (KERN_INFO "NFS: not enough memory to parse option\n" ); -return 0 ; -out_security_failure: -printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); -return 0 ; -} -/*
* Ensure that a specified authtype inargs->auth_infois supported
by
* the server. Returns 0 and setsargs->selected_flavorif it's ok,
andfs/nfs/super.c +0
-4@@ -1908,327 +925,6 @@ struct dentry *nfs_try_mount(int flags,const char *dev_name, }EXPORT_SYMBOL_GPL (nfs_try_mount ); -/* -* Split "dev_name" into "hostname:export_path". -* -* The leftmost colon demarks the split between the server's hostname
- * and the export path. If the hostname starts with a left square
- * bracket, then it may contain colons.
- *
- * Note: caller frees hostname and export path, even on error.
- */fs/nfs/super.c +0
-57-static int nfs_parse_devname (const char *dev_name, -char **hostname,size_t maxnamlen, -char **export_path,size_t maxpathlen) -{ -size_t len; -char *end; - -if (unlikely (!dev_name || !*dev_name)) { -dfprintk (MOUNT ,"NFS: device name not specified\n" ); -return -EINVAL ; - } - -/* Is the host name protected with square brakcets? */ -if (*dev_name =='[' ) { - end =strchr (++dev_name,']' ); -if (end ==NULL || end[1 ] !=':' ) - goto out_bad_devname; - - len = end - dev_name; - end++; - }else { -char *comma; - - end =strchr (dev_name,':' ); -if (end ==NULL ) - goto out_bad_devname; - len = end - dev_name; - -/* kill possible hostname list: not supported */ - comma =strchr (dev_name,',' ); -if (comma !=NULL && comma < end) - len = comma - dev_name; - } - -if (len > maxnamlen) - goto out_hostname; - -/* N.B. caller will free nfs_server.hostname in all cases */ - *hostname =kstrndup (dev_name, len,GFP_KERNEL ); -if (*hostname ==NULL ) - goto out_nomem; - len =strlen (++end); -if (len > maxpathlen) - goto out_path; - *export_path =kstrndup (end, len,GFP_KERNEL ); -if (!*export_path) - goto out_nomem; - -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); -return 0 ; - -out_bad_devname: -dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); -return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/super.c +0
-20-return -ENOMEM ; - -out_hostname: -dfprintk (MOUNT ,"NFS: server hostname too long\n" ); -return -ENAMETOOLONG ; - -out_path: -dfprintk (MOUNT ,"NFS: export pathname too long\n" ); -return -ENAMETOOLONG ; -} - -/* -* Validate the NFS2/NFS3 mount data -* - fills in the mount root filehandle -* -* For option strings, user space handles the following behaviors: -* -* + DNS: mapping server host name to IP address ("addr=" option) -* -* + failure mode: how to behave if a mount request can't be handled
- * immediately ("fg/bg" option)
- *
- * + retry: how often to retry a mount request ("retry=" option)
- *
- * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
- * mountproto=tcp after mountproto=udp, and so on
- */fs/nfs/super.c +0
-2-static int nfs23_validate_mount_data (void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-5-struct nfs_fh *mntfh, - const char *dev_name) -{ - struct nfs_mount_data *data = (struct nfs_mount_data *)options; - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-16-int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; - -if (data ==NULL ) - goto out_no_data; - - args->version =NFS_DEFAULT_VERSION ; -switch (data->version) { -case 1 : - data->namlen =0 ;/* fall through */ -case 2 : - data->bsize =0 ;/* fall through */ -case 3 : -if (data->flags &NFS_MOUNT_VER3 ) - goto out_no_v3; - data->root.size =NFS2_FHSIZE ; - memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/super.c +0
-13-/* Turn off security negotiation */ - extra_flags |=NFS_MOUNT_SECFLAVOUR ; -/* fall through */ -case 4 : -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - goto out_no_sec; -/* fall through */ -case 5 : -memset (data->context,0 ,sizeof (data->context)); -/* fall through */ -case 6 : - if (data->flags & NFS_MOUNT_VER3) { - if (data->root.size > NFS3_FHSIZE || data-Quoted 1 line
root.size == 0)
fs/nfs/super.c +0
-16- goto out_invalid_fh; - mntfh->size = data->root.size; - args->version =3 ; - }else { - mntfh->size =NFS2_FHSIZE ; - args->version =2 ; - } - - -memcpy (mntfh->data, data->root.data, mntfh->size); -if (mntfh->size <sizeof (mntfh->data)) -memset (mntfh->data + mntfh->size,0 , -sizeof (mntfh->data) - mntfh->size); - -/* -* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/super.c +0
-24-* can deal with. -*/ - args->flags = data->flags &NFS_MOUNT_FLAGMASK ; - args->flags |= extra_flags; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->need_mount = false; - -memcpy (sap, &data->addr,sizeof (data->addr)); - args->nfs_server.addrlen =sizeof (data->addr); - args->nfs_server.port =ntohs (data->addr.sin_port); -if (sap->sa_family !=AF_INET || - !nfs_verify_server_address (sap)) - goto out_no_address; - -if (!(data->flags &NFS_MOUNT_TCP )) - args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/super.c +0
-1- args->nfs_server.hostname = kstrdup(data->hostname,
GFP_KERNEL);fs/nfs/super.c +0
-18- args->namlen = data->namlen; - args->bsize = data->bsize; - -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - args->selected_flavor = data->pseudoflavor; -else - args->selected_flavor =RPC_AUTH_UNIX ; -if (!args->nfs_server.hostname) - goto out_nomem; - -if (!(data->flags &NFS_MOUNT_NONLM )) - args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -else - args->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -/* -* The legacy version 6 binary mount data from userspace has a
fs/nfs/super.c +0
-1-* field used only to transport selinux information into the
fs/nfs/super.c +0
-1-* the kernel. To continue to support that functionality we
fs/nfs/super.c +0
-1-* have a touch of selinux knowledge here in the NFS code. The
fs/nfs/super.c +0
-1-* userspace code converted context=blah to just blah so we are
fs/nfs/super.c +0
-1-* converting back to the full string selinux understands.
fs/nfs/super.c +0
-6-*/ -if (data->context[0 ]){ -#ifdef CONFIG_SECURITY_SELINUX -int rc; - data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; - rc = security_add_mnt_opt("context", data-Quoted 1 line
context,
fs/nfs/super.c +0
-1- strlen(data->context), &args-Quoted 1 line
lsm_opts);fs/nfs/super.c +0
-16-if (rc) -return rc; -#else -return -EINVAL ; -#endif - } - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS: mount program didn't pass any mountdata\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_no_v3: - dfprintk(MOUNT, "NFS: nfs_mount_data version %d does notsupport v3\n",
fs/nfs/super.c +0
-5- data->version); -return -EINVAL ; - -out_no_sec: - dfprintk(MOUNT, "NFS: nfs_mount_data version supports onlyAUTH_SYS\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/super.c +0
-4-return -ENOMEM ; - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-9-return -EINVAL ; - -out_invalid_fh: -dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); -return -EINVAL ; -} - -#if IS_ENABLED (CONFIG_NFS_V4 ) -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-7- void *options, - struct nfs_parsed_mount_data *args, - struct nfs_fh *mntfh, - const char *dev_name) -{ - if (fs_type == &nfs_fs_type) - return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/super.c +0
-4-return nfs4_validate_mount_data (options, args, dev_name); -} -#else -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-6- void *options, - struct nfs_parsed_mount_data *args, - struct nfs_fh *mntfh, - const char *dev_name) -{ - return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/super.c +0
-5-} -#endif - -static int nfs_validate_text_mount_data (void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-6- const char *dev_name) -{ -int port =0 ; -int max_namelen =PAGE_SIZE ; -int max_pathlen =NFS_MAXPATHLEN ; - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-48- -if (nfs_parse_mount_options ((char *)options, args) ==0 ) -return -EINVAL ; - -if (!nfs_verify_server_address (sap)) - goto out_no_address; - -if (args->version ==4 ) { -#if IS_ENABLED (CONFIG_NFS_V4 ) -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; -else - port =NFS_PORT ; - max_namelen =NFS4_MAXNAMLEN ; - max_pathlen =NFS4_MAXPATHLEN ; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; -nfs4_validate_mount_flags (args); -#else - goto out_v4_not_compiled; -#endif /* CONFIG_NFS_V4 */ - }else { -nfs_set_mount_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; - } - -nfs_set_port (sap, &args->nfs_server.port, port); - -return nfs_parse_devname (dev_name, - &args->nfs_server.hostname, - max_namelen, - &args->nfs_server.export_path, - max_pathlen); - -#if !IS_ENABLED (CONFIG_NFS_V4 ) -out_v4_not_compiled: -dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); -return -EPROTONOSUPPORT ; -#else -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -#endif /* !CONFIG_NFS_V4 */ - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-3-return -EINVAL ; -} -#define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \ | NFS_MOUNT_SECURE \ | NFS_MOUNT_TCP \fs/nfs/super.c +0
-3@@ -2719,113 +1415,6 @@ nfs_prepared_mount(struct file_system_type *fs_type, int flags,#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *args) -{ - args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/super.c +0
-11- NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); -} - -/* -* Validate NFSv4 mount options -*/ -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args, -const char *dev_name) -{ - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-1- struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/super.c +0
-10-char *c; - -if (data ==NULL ) - goto out_no_data; - - args->version =4 ; - -switch (data->version) { -case 1 : - if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/super.c +0
-5- goto out_no_address; -if (data->host_addrlen ==0 ) - goto out_no_address; - args->nfs_server.addrlen = data->host_addrlen; - if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/super.c +0
-4-return -EFAULT ; -if (!nfs_verify_server_address (sap)) - goto out_no_address; - args->nfs_server.port = ntohs(((struct sockaddr_in*)sap)->sin_port);
fs/nfs/super.c +0
-31- -if (data->auth_flavourlen) { -rpc_authflavor_t pseudoflavor; -if (data->auth_flavourlen >1 ) - goto out_inval_auth; -if (copy_from_user (&pseudoflavor, - data->auth_flavours, -sizeof (pseudoflavor))) -return -EFAULT ; - args->selected_flavor = pseudoflavor; - }else - args->selected_flavor =RPC_AUTH_UNIX ; - - c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.hostname = c; - - c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.export_path = c; -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); - - c =strndup_user (data->client_addr.data,16 ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->client_address = c; - -/* -* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/super.c +0
-26-* can deal with. -*/ - - args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->nfs_server.protocol = data->proto; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS4: mount program didn't pass any mountdata\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_inval_auth: - dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours%d\n",
fs/nfs/super.c +0
-5- data->auth_flavourlen); -return -EINVAL ; - -out_no_address: - dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-7-return -EINVAL ; - -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -} -Quoted 6 lines
/*
* NFS v4 module parameters need to stay in the
* NFS client for backwards compatibilitySignature · 1 line
2.17.2--
Chuck Lever
[email protected]
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v3 16/26] NFS: Move mount parameterisation bits into their own file
Quoted 66 lines · Trond Myklebust
Quoted 65 lines · Chuck Lever
Quoted 51 lines
On Sep 11, 2019, at 12:16 PM, Scott Mayhew <[email protected]> wrote:
From: David Howells <[email protected]>
Split various bits relating to mount parameterisation out from
fs/nfs/super.cinto their own file to form the basis of filesystem context
handling for NFS.No other changes are made to the code beyond removing 'static' qualifiers.
Signed-off-by David Howells <[email protected]>Signed-off-by Al Viro <[email protected]>---
fs/nfs/Makefile| 2 +-fs/nfs/fs_context.c| 1418
+++++++++++++++++++++++++++++++++++++++++++fs/nfs/internal.h| 29 +fs/nfs/super.c| 1411 ----------------------------------------
--4 files changed, 1448 insertions(+), 1412 deletions(-)create mode 100644
fs/nfs/fs_context.cfs/nfs/Makefile +0
-0@@ -9,7 +9,7 @@ CFLAGS_nfstrace.o += -I$(src)nfs-y := client.o dir.o file.o getroot.o
inode.o super.o \
io.o direct.o pagelist.o read.o symlink.o
unlink.o \
write.o namespace.o mount_clnt.o nfstrace.o
\fs/nfs/Makefile +1
-1- export.o sysfs.o + export.o sysfs.o fs_context.onfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.ofs/nfs/fs_context.c new file +4
-0@@ -0,0 +1,1418 @@ +/* NFS mount handling. +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) fs/nfs/fs_context.c line 14
Quoted 10 lines
fs/nfs/fs_context.c new file +10
-0+* +* Split from fs/nfs/super.c: +* +* Copyright (C) 1992 Rick Sladkey +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ New source files should have an SPDX tag instead of boilerplate. I suggest:
Quoted 8 lines
Quoted 2 lines
// SPDX-License-Identifier: GPL-2.0-only
Agreed. It is also quite a long stretch to claim authorship of the entire file as implied above. Given that this is mostly a copy-paste effort, then most of the actual copyrights belong to the people who've contributed to
super.c(and toinode.cbefore it). David is one of those authors, but he is one of many.
Okay, how about:
// SPDX-License-Identifier: GPL-2.0-only
/*
* linux/fs/nfs/fs_context.c
*
* Copyright (C) 1992 Rick Sladkey
*
* NFS mount handling.
*
* Split from fs/nfs/super.c by David Howells <[email protected]> */
and have patch 25/26 add a line
* Conversion to new mount api Copyright (C) David Howells
-Scott
Quoted 3,133 lines
Quoted 3,127 lines
Quoted 3,114 lines
fs/nfs/fs_context.c new file +136
-0+#include <linux/parser.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> +#include "nfs.h" +#include "internal.h" + +#define NFSDBG_FACILITY NFSDBG_MOUNT + +#if IS_ENABLED (CONFIG_NFS_V3 ) +#define NFS_DEFAULT_VERSION 3 +#else +#define NFS_DEFAULT_VERSION 2 +#endif + +#define NFS_MAX_CONNECTIONS 16 + +enum { +/* Mount options that take no arguments */ + Opt_soft, Opt_softerr, Opt_hard, + Opt_posix, Opt_noposix, + Opt_cto, Opt_nocto, + Opt_ac, Opt_noac, + Opt_lock, Opt_nolock, + Opt_udp, Opt_tcp, Opt_rdma, + Opt_acl, Opt_noacl, + Opt_rdirplus, Opt_nordirplus, + Opt_sharecache, Opt_nosharecache, + Opt_resvport, Opt_noresvport, + Opt_fscache, Opt_nofscache, + Opt_migration, Opt_nomigration, + +/* Mount options that take integer arguments */ + Opt_port, + Opt_rsize, Opt_wsize, Opt_bsize, + Opt_timeo, Opt_retrans, + Opt_acregmin, Opt_acregmax, + Opt_acdirmin, Opt_acdirmax, + Opt_actimeo, + Opt_namelen, + Opt_mountport, + Opt_mountvers, + Opt_minorversion, + +/* Mount options that take string arguments */ + Opt_nfsvers, + Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, + Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_nconnect, + Opt_lookupcache, + Opt_fscache_uniq, + Opt_local_lock, + +/* Special mount options */ + Opt_userspace, Opt_deprecated, Opt_sloppy, + + Opt_err +}; + +static const match_table_t nfs_mount_option_tokens = { + { Opt_userspace,"bg" }, + { Opt_userspace,"fg" }, + { Opt_userspace,"retry=%s" }, + + { Opt_sloppy,"sloppy" }, + + { Opt_soft,"soft" }, + { Opt_softerr,"softerr" }, + { Opt_hard,"hard" }, + { Opt_deprecated,"intr" }, + { Opt_deprecated,"nointr" }, + { Opt_posix,"posix" }, + { Opt_noposix,"noposix" }, + { Opt_cto,"cto" }, + { Opt_nocto,"nocto" }, + { Opt_ac,"ac" }, + { Opt_noac,"noac" }, + { Opt_lock,"lock" }, + { Opt_nolock,"nolock" }, + { Opt_udp,"udp" }, + { Opt_tcp,"tcp" }, + { Opt_rdma,"rdma" }, + { Opt_acl,"acl" }, + { Opt_noacl,"noacl" }, + { Opt_rdirplus,"rdirplus" }, + { Opt_nordirplus,"nordirplus" }, + { Opt_sharecache,"sharecache" }, + { Opt_nosharecache,"nosharecache" }, + { Opt_resvport,"resvport" }, + { Opt_noresvport,"noresvport" }, + { Opt_fscache,"fsc" }, + { Opt_nofscache,"nofsc" }, + { Opt_migration,"migration" }, + { Opt_nomigration,"nomigration" }, + + { Opt_port,"port=%s" }, + { Opt_rsize,"rsize=%s" }, + { Opt_wsize,"wsize=%s" }, + { Opt_bsize,"bsize=%s" }, + { Opt_timeo,"timeo=%s" }, + { Opt_retrans,"retrans=%s" }, + { Opt_acregmin,"acregmin=%s" }, + { Opt_acregmax,"acregmax=%s" }, + { Opt_acdirmin,"acdirmin=%s" }, + { Opt_acdirmax,"acdirmax=%s" }, + { Opt_actimeo,"actimeo=%s" }, + { Opt_namelen,"namlen=%s" }, + { Opt_mountport,"mountport=%s" }, + { Opt_mountvers,"mountvers=%s" }, + { Opt_minorversion,"minorversion=%s" }, + + { Opt_nfsvers,"nfsvers=%s" }, + { Opt_nfsvers,"vers=%s" }, + + { Opt_sec,"sec=%s" }, + { Opt_proto,"proto=%s" }, + { Opt_mountproto,"mountproto=%s" }, + { Opt_addr,"addr=%s" }, + { Opt_clientaddr,"clientaddr=%s" }, + { Opt_mounthost,"mounthost=%s" }, + { Opt_mountaddr,"mountaddr=%s" }, + + { Opt_nconnect,"nconnect=%s" }, + + { Opt_lookupcache,"lookupcache=%s" }, + { Opt_fscache_uniq,"fsc=%s" }, + { Opt_local_lock,"local_lock=%s" }, + +/* The following needs to be listed after all other options */ + { Opt_nfsvers,"v%s" }, + + { Opt_err,NULL } +}; + +enum { + Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6,
Opt_xprt_rdma,fs/nfs/fs_context.c new file +120
-0+ Opt_xprt_rdma6, + + Opt_xprt_err +}; + +static const match_table_t nfs_xprt_protocol_tokens = { + { Opt_xprt_udp,"udp" }, + { Opt_xprt_udp6,"udp6" }, + { Opt_xprt_tcp,"tcp" }, + { Opt_xprt_tcp6,"tcp6" }, + { Opt_xprt_rdma,"rdma" }, + { Opt_xprt_rdma6,"rdma6" }, + + { Opt_xprt_err,NULL } +}; + +enum { + Opt_sec_none, Opt_sec_sys, + Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, + Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, + Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, + + Opt_sec_err +}; + +static const match_table_t nfs_secflavor_tokens = { + { Opt_sec_none,"none" }, + { Opt_sec_none,"null" }, + { Opt_sec_sys,"sys" }, + + { Opt_sec_krb5,"krb5" }, + { Opt_sec_krb5i,"krb5i" }, + { Opt_sec_krb5p,"krb5p" }, + + { Opt_sec_lkey,"lkey" }, + { Opt_sec_lkeyi,"lkeyi" }, + { Opt_sec_lkeyp,"lkeyp" }, + + { Opt_sec_spkm,"spkm3" }, + { Opt_sec_spkmi,"spkm3i" }, + { Opt_sec_spkmp,"spkm3p" }, + + { Opt_sec_err,NULL } +}; + +enum { + Opt_lookupcache_all, Opt_lookupcache_positive, + Opt_lookupcache_none, + + Opt_lookupcache_err +}; + +static match_table_t nfs_lookupcache_tokens = { + { Opt_lookupcache_all,"all" }, + { Opt_lookupcache_positive,"pos" }, + { Opt_lookupcache_positive,"positive" }, + { Opt_lookupcache_none,"none" }, + + { Opt_lookupcache_err,NULL } +}; + +enum { + Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, + Opt_local_lock_none, + + Opt_local_lock_err +}; + +static match_table_t nfs_local_lock_tokens = { + { Opt_local_lock_all,"all" }, + { Opt_local_lock_flock,"flock" }, + { Opt_local_lock_posix,"posix" }, + { Opt_local_lock_none,"none" }, + + { Opt_local_lock_err,NULL } +}; + +enum { + Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, + Opt_vers_4_1, Opt_vers_4_2, + + Opt_vers_err +}; + +static match_table_t nfs_vers_tokens = { + { Opt_vers_2,"2" }, + { Opt_vers_3,"3" }, + { Opt_vers_4,"4" }, + { Opt_vers_4_0,"4.0" }, + { Opt_vers_4_1,"4.1" }, + { Opt_vers_4_2,"4.2" }, + + { Opt_vers_err,NULL } +}; + +struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ) +{ +struct nfs_parsed_mount_data *data; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (data) { + data->timeo =NFS_UNSPEC_TIMEO ; + data->retrans =NFS_UNSPEC_RETRANS ; + data->acregmin =NFS_DEF_ACREGMIN ; + data->acregmax =NFS_DEF_ACREGMAX ; + data->acdirmin =NFS_DEF_ACDIRMIN ; + data->acdirmax =NFS_DEF_ACDIRMAX ; + data->mount_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + data->selected_flavor =RPC_AUTH_MAXFLAVOR ; + data->minorversion =0 ; + data->need_mount = true; + data->net = current->nsproxy->net_ns; + data->lsm_opts =NULL ; + } +return data; +} + +void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data*data)
fs/nfs/fs_context.c new file +27
-0+{ +if (data) { +kfree (data->client_address); +kfree (data->mount_server.hostname); +kfree (data->nfs_server.export_path); +kfree (data->nfs_server.hostname); +kfree (data->fscache_uniq); +security_free_mnt_opts (&data->lsm_opts); +kfree (data); + } +} + +/* +* Sanity-check a server address provided by the mount command. +* +* Address family must be initialized, and address must not be +* the ANY address for that family. +*/ +static int nfs_verify_server_address (struct sockaddr *addr) +{ +switch (addr->sa_family) { +case AF_INET : { +struct sockaddr_in *sa = (struct sockaddr_in *)addr; +return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); + } +case AF_INET6 : { + struct in6_addr *sa = &((struct sockaddr_in6 *)addr)-Quoted 1 line
sin6_addr;fs/nfs/fs_context.c new file +13
-0+return !ipv6_addr_any (sa); + } + } + +dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); +return 0 ; +} + +/* +* Sanity check the NFS transport protocol. +* +*/ +static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/fs_context.c new file +13
-0+{ +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : +break ; +default : + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* For text based NFSv2/v3 mounts, the mount protocol transport default
+ * settings should depend upon the specified NFS transport.
+ */
+static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +46
-0+{ +nfs_validate_transport_protocol (mnt); + +if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || + mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) +return ; +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : + mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : + mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* Add 'flavor' to 'auth_info' if not already present. +* Returns true if 'flavor' ends up in the list, false otherwise +*/ +static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, +rpc_authflavor_t flavor) +{ +unsigned int i; +unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); + +/* make sure this flavor isn't already in the list */ +for (i =0 ; i < auth_info->flavor_len; i++) { +if (flavor == auth_info->flavors[i]) +return true; + } + +if (auth_info->flavor_len +1 >= max_flavor_len) { +dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); +return false; + } + + auth_info->flavors[auth_info->flavor_len++] = flavor; +return true; +} + +/* +* Parse the value of the 'sec=' option. +*/ +static int nfs_parse_security_flavors (char *value, + struct nfs_parsed_mount_data*mnt)
fs/nfs/fs_context.c new file +45
-0+{ +substring_t args[MAX_OPT_ARGS ]; +rpc_authflavor_t pseudoflavor; +char *p; + +dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); + +while ((p =strsep (&value,":" )) !=NULL ) { +switch (match_token (p, nfs_secflavor_tokens, args)) { +case Opt_sec_none: + pseudoflavor =RPC_AUTH_NULL ; +break ; +case Opt_sec_sys: + pseudoflavor =RPC_AUTH_UNIX ; +break ; +case Opt_sec_krb5: + pseudoflavor =RPC_AUTH_GSS_KRB5 ; +break ; +case Opt_sec_krb5i: + pseudoflavor =RPC_AUTH_GSS_KRB5I ; +break ; +case Opt_sec_krb5p: + pseudoflavor =RPC_AUTH_GSS_KRB5P ; +break ; +case Opt_sec_lkey: + pseudoflavor =RPC_AUTH_GSS_LKEY ; +break ; +case Opt_sec_lkeyi: + pseudoflavor =RPC_AUTH_GSS_LKEYI ; +break ; +case Opt_sec_lkeyp: + pseudoflavor =RPC_AUTH_GSS_LKEYP ; +break ; +case Opt_sec_spkm: + pseudoflavor =RPC_AUTH_GSS_SPKM ; +break ; +case Opt_sec_spkmi: + pseudoflavor =RPC_AUTH_GSS_SPKMI ; +break ; +case Opt_sec_spkmp: + pseudoflavor =RPC_AUTH_GSS_SPKMP ; +break ; +default : + dfprintk(MOUNT, + "NFS: sec= option '%s' notrecognized\n", p);
fs/nfs/fs_context.c new file +56
-0+return 0 ; + } + +if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) +return 0 ; + } + +return 1 ; +} + +static int nfs_parse_version_string (char *string, +struct nfs_parsed_mount_data *mnt, +substring_t *args) +{ + mnt->flags &= ~NFS_MOUNT_VER3 ; +switch (match_token (string, nfs_vers_tokens, args)) { +case Opt_vers_2: + mnt->version =2 ; +break ; +case Opt_vers_3: + mnt->flags |=NFS_MOUNT_VER3 ; + mnt->version =3 ; +break ; +case Opt_vers_4: +/* Backward compatibility option. In future, +* the mount program should always supply +* a NFSv4 minor version number. +*/ + mnt->version =4 ; +break ; +case Opt_vers_4_0: + mnt->version =4 ; + mnt->minorversion =0 ; +break ; +case Opt_vers_4_1: + mnt->version =4 ; + mnt->minorversion =1 ; +break ; +case Opt_vers_4_2: + mnt->version =4 ; + mnt->minorversion =2 ; +break ; +default : +return 0 ; + } +return 1 ; +} + +static int nfs_get_option_str (substring_t args[],char **option) +{ +kfree (*option); + *option =match_strdup (args); +return !*option; +} + +static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/fs_context.c new file +14
-0+{ +int rc; +char *string; + + string =match_strdup (args); +if (string ==NULL ) +return -ENOMEM ; + rc =kstrtoul (string,10 , option); +kfree (string); + +return rc; +} + +static int nfs_get_option_ul_bound(substring_t args[], unsignedlong *option,
fs/nfs/fs_context.c new file +14
-0+ unsigned long l_bound, unsigned long u_bound) +{ + int ret; + + ret =nfs_get_option_ul (args, option); +if (ret !=0 ) +return ret; +if (*option < l_bound || *option > u_bound) +return -ERANGE ; +return 0 ; +} + +/* +* Error-check and convert a string of mount options from user space into
+ * a data structure. The whole mount string is processed; bad options are
+ * skipped as they are encountered. If there were no errors, return 1;
+ * otherwise return 0 (zero).
+ */
+intnfs_parse_mount_options(char *raw, struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +8
-0+{ +char *p, *string; +int rc, sloppy =0 , invalid_option =0 ; +unsigned short protofamily =AF_UNSPEC ; +unsigned short mountfamily =AF_UNSPEC ; + +if (!raw) { + dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/fs_context.c new file +17
-0+return 1 ; + } +dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); + + rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); +if (rc) + goto out_security_failure; + +while ((p =strsep (&raw,"," )) !=NULL ) { +substring_t args[MAX_OPT_ARGS ]; +unsigned long option; +int token; + +if (!*p) +continue ; + + dfprintk(MOUNT, "NFS: parsing nfs mount option'%s'\n", p);
fs/nfs/fs_context.c new file +17
-0+ + token =match_token (p, nfs_mount_option_tokens, args); +switch (token) { + +/* +* boolean options: foo/nofoo +*/ +case Opt_soft: + mnt->flags |=NFS_MOUNT_SOFT ; + mnt->flags &= ~NFS_MOUNT_SOFTERR ; +break ; +case Opt_softerr: + mnt->flags |=NFS_MOUNT_SOFTERR ; + mnt->flags &= ~NFS_MOUNT_SOFT ; +break ; +case Opt_hard: + mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/fs_context.c new file +39
-0+break ; +case Opt_posix: + mnt->flags |=NFS_MOUNT_POSIX ; +break ; +case Opt_noposix: + mnt->flags &= ~NFS_MOUNT_POSIX ; +break ; +case Opt_cto: + mnt->flags &= ~NFS_MOUNT_NOCTO ; +break ; +case Opt_nocto: + mnt->flags |=NFS_MOUNT_NOCTO ; +break ; +case Opt_ac: + mnt->flags &= ~NFS_MOUNT_NOAC ; +break ; +case Opt_noac: + mnt->flags |=NFS_MOUNT_NOAC ; +break ; +case Opt_lock: + mnt->flags &= ~NFS_MOUNT_NONLM ; + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_nolock: + mnt->flags |=NFS_MOUNT_NONLM ; + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +break ; +case Opt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; +break ; +case Opt_rdma: + mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */
fs/nfs/fs_context.c new file +70
-0+ mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; +xprt_load_transport (p); +break ; +case Opt_acl: + mnt->flags &= ~NFS_MOUNT_NOACL ; +break ; +case Opt_noacl: + mnt->flags |=NFS_MOUNT_NOACL ; +break ; +case Opt_rdirplus: + mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_nordirplus: + mnt->flags |=NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_sharecache: + mnt->flags &= ~NFS_MOUNT_UNSHARED ; +break ; +case Opt_nosharecache: + mnt->flags |=NFS_MOUNT_UNSHARED ; +break ; +case Opt_resvport: + mnt->flags &= ~NFS_MOUNT_NORESVPORT ; +break ; +case Opt_noresvport: + mnt->flags |=NFS_MOUNT_NORESVPORT ; +break ; +case Opt_fscache: + mnt->options |=NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_migration: + mnt->options |=NFS_OPTION_MIGRATION ; +break ; +case Opt_nomigration: + mnt->options &= ~NFS_OPTION_MIGRATION ; +break ; + +/* +* options that take numeric values +*/ +case Opt_port: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->nfs_server.port = option; +break ; +case Opt_rsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->rsize = option; +break ; +case Opt_wsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->wsize = option; +break ; +case Opt_bsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->bsize = option; +break ; +case Opt_timeo: + if (nfs_get_option_ul_bound(args, &option, 1,
INT_MAX))fs/nfs/fs_context.c new file +5
-0+ goto out_invalid_value; + mnt->timeo = option; +break ; +case Opt_retrans: + if (nfs_get_option_ul_bound(args, &option, 0,
INT_MAX))fs/nfs/fs_context.c new file +63
-0+ goto out_invalid_value; + mnt->retrans = option; +break ; +case Opt_acregmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = option; +break ; +case Opt_acregmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmax = option; +break ; +case Opt_acdirmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmin = option; +break ; +case Opt_acdirmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmax = option; +break ; +case Opt_actimeo: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = mnt->acregmax = + mnt->acdirmin = mnt->acdirmax = option; +break ; +case Opt_namelen: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->namlen = option; +break ; +case Opt_mountport: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->mount_server.port = option; +break ; +case Opt_mountvers: +if (nfs_get_option_ul (args, &option) || + option <NFS_MNT_VERSION || + option >NFS_MNT3_VERSION ) + goto out_invalid_value; + mnt->mount_server.version = option; +break ; +case Opt_minorversion: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; +if (option >NFS4_MAX_MINOR_VERSION ) + goto out_invalid_value; + mnt->minorversion = option; +break ; + +/* +* options that take text values +*/ +case Opt_nfsvers: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc = nfs_parse_version_string(string, mnt,args);
fs/nfs/fs_context.c new file +22
-0+kfree (string); +if (!rc) + goto out_invalid_value; +break ; +case Opt_sec: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc =nfs_parse_security_flavors (string, mnt); +kfree (string); +if (!rc) { +dfprintk (MOUNT ,"NFS: unrecognized " +"security flavor\n" ); +return 0 ; + } +break ; +case Opt_proto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string, + nfs_xprt_protocol_tokens,args);
fs/nfs/fs_context.c new file +9
-0+ + protofamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +7
-0+break ; +case Opt_xprt_tcp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +8
-0+break ; +case Opt_xprt_rdma6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_rdma: +/* vector side protocols to TCP */ + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/fs_context.c new file +5
-0+xprt_load_transport (string); +break ; +default : +dfprintk (MOUNT ,"NFS: unrecognized " + "transportprotocol\n");
fs/nfs/fs_context.c new file +11
-0+kfree (string); +return 0 ; + } +kfree (string); +break ; +case Opt_mountproto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string, + nfs_xprt_protocol_tokens,args);
fs/nfs/fs_context.c new file +9
-0+kfree (string); + + mountfamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +6
-0+break ; +case Opt_xprt_tcp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +2
-0+break ; +case Opt_xprt_rdma:/* not used for side protocols */
fs/nfs/fs_context.c new file +3
-0+default : +dfprintk (MOUNT ,"NFS: unrecognized " + "transportprotocol\n");
fs/nfs/fs_context.c new file +9
-0+return 0 ; + } +break ; +case Opt_addr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->nfs_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +3
-0+ (struct sockaddr *) + &mnt->nfs_server.address, + sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->nfs_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_clientaddr: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/fs_context.c new file +5
-0+ goto out_nomem; +break ; +case Opt_mounthost: + if (nfs_get_option_str(args, + &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; +break ; +case Opt_mountaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->mount_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +3
-0+ (struct sockaddr *) + &mnt->mount_server.address, + sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->mount_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_nconnect: + if (nfs_get_option_ul_bound(args, &option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/fs_context.c new file +13
-0+ goto out_invalid_value; + mnt->nfs_server.nconnect = option; +break ; +case Opt_lookupcache: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_lookupcache_tokens, args); +kfree (string); +switch (token) { +case Opt_lookupcache_all: + mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_positive: + mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +1
-0+ mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_none: + mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +3
-0+break ; +default : + dfprintk(MOUNT, "NFS: invalid"
fs/nfs/fs_context.c new file +1
-0+ "lookupcacheargument\n");
fs/nfs/fs_context.c new file +5
-0+return 0 ; + }; +break ; +case Opt_fscache_uniq: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; + mnt->options |=NFS_OPTION_FSCACHE ; +break ; +case Opt_local_lock: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string,
nfs_local_lock_tokens,fs/nfs/fs_context.c new file +20
-0+ args); +kfree (string); + switch (token) { + case Opt_local_lock_all: + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | + NFS_MOUNT_LOCAL_FCNTL); + break; + case Opt_local_lock_flock: + mnt->flags |= NFS_MOUNT_LOCAL_FLOCK; + break; + case Opt_local_lock_posix: + mnt->flags |= NFS_MOUNT_LOCAL_FCNTL; + break; + case Opt_local_lock_none: + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | + NFS_MOUNT_LOCAL_FCNTL); + break; + default: + dfprintk(MOUNT, "NFS: invalid " + "local_lockargument\n");
fs/nfs/fs_context.c new file +10
-0+return 0 ; + }; +break ; + +/* +* Special options +*/ +case Opt_sloppy: + sloppy =1 ; + dfprintk(MOUNT, "NFS: relaxing parsingrules\n");
fs/nfs/fs_context.c new file +10
-0+break ; +case Opt_userspace: +case Opt_deprecated: +dfprintk (MOUNT ,"NFS: ignoring mount option " +"'%s'\n" , p); +break ; + +default : + invalid_option =1 ; + dfprintk(MOUNT, "NFS: unrecognized mountoption "
fs/nfs/fs_context.c new file +25
-0+ "'%s'\n", p); + } + } + +if (!sloppy && invalid_option) +return 0 ; + +if (mnt->minorversion && mnt->version !=4 ) + goto out_minorversion_mismatch; + +if (mnt->options &NFS_OPTION_MIGRATION && + (mnt->version !=4 || mnt->minorversion !=0 )) + goto out_migration_misuse; + +/* +* verify that any proto=/mountproto= options match the address +* families in the addr=/mountaddr= options. +*/ +if (protofamily !=AF_UNSPEC && + protofamily != mnt->nfs_server.address.ss_family) + goto out_proto_mismatch; + + if (mountfamily != AF_UNSPEC) { + if (mnt->mount_server.addrlen) { + if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/fs_context.c new file +3
-0+ goto out_mountproto_mismatch; + } else { + if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/fs_context.c new file +8
-0+ goto out_mountproto_mismatch; + } + } + +return 1 ; + +out_mountproto_mismatch: + printk(KERN_INFO "NFS: mount server address does not matchmountproto= "
fs/nfs/fs_context.c new file +4
-0+ "option\n"); +return 0 ; +out_proto_mismatch: + printk(KERN_INFO "NFS: server address does not match proto=option\n");
fs/nfs/fs_context.c new file +6
-0+return 0 ; +out_invalid_address: +printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); +return 0 ; +out_invalid_value: + printk(KERN_INFO "NFS: bad mount option value specified: %s\n",p);
fs/nfs/fs_context.c new file +4
-0+return 0 ; +out_minorversion_mismatch: + printk(KERN_INFO "NFS: mount option vers=%u does not support " + "minorversion=%u\n", mnt->version, mnt-Quoted 1 line
minorversion);
fs/nfs/fs_context.c new file +4
-0+return 0 ; +out_migration_misuse: +printk (KERN_INFO + "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/fs_context.c new file +13
-0+return 0 ; +out_nomem: +printk (KERN_INFO "NFS: not enough memory to parse option\n" ); +return 0 ; +out_security_failure: +printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); +return 0 ; +} + +/* +* Split "dev_name" into "hostname:export_path". +* +* The leftmost colon demarks the split between the server's hostname
+ * and the export path. If the hostname starts with a left square
+ * bracket, then it may contain colons.
+ *
+ * Note: caller frees hostname and export path, even on error.
+ */fs/nfs/fs_context.c new file +57
-0+static int nfs_parse_devname (const char *dev_name, +char **hostname,size_t maxnamlen, +char **export_path,size_t maxpathlen) +{ +size_t len; +char *end; + +if (unlikely (!dev_name || !*dev_name)) { +dfprintk (MOUNT ,"NFS: device name not specified\n" ); +return -EINVAL ; + } + +/* Is the host name protected with square brakcets? */ +if (*dev_name =='[' ) { + end =strchr (++dev_name,']' ); +if (end ==NULL || end[1 ] !=':' ) + goto out_bad_devname; + + len = end - dev_name; + end++; + }else { +char *comma; + + end =strchr (dev_name,':' ); +if (end ==NULL ) + goto out_bad_devname; + len = end - dev_name; + +/* kill possible hostname list: not supported */ + comma =strchr (dev_name,',' ); +if (comma !=NULL && comma < end) + len = comma - dev_name; + } + +if (len > maxnamlen) + goto out_hostname; + +/* N.B. caller will free nfs_server.hostname in all cases */ + *hostname =kstrndup (dev_name, len,GFP_KERNEL ); +if (*hostname ==NULL ) + goto out_nomem; + len =strlen (++end); +if (len > maxpathlen) + goto out_path; + *export_path =kstrndup (end, len,GFP_KERNEL ); +if (!*export_path) + goto out_nomem; + +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); +return 0 ; + +out_bad_devname: +dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); +return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/fs_context.c new file +20
-0+return -ENOMEM ; + +out_hostname: +dfprintk (MOUNT ,"NFS: server hostname too long\n" ); +return -ENAMETOOLONG ; + +out_path: +dfprintk (MOUNT ,"NFS: export pathname too long\n" ); +return -ENAMETOOLONG ; +} + +/* +* Validate the NFS2/NFS3 mount data +* - fills in the mount root filehandle +* +* For option strings, user space handles the following behaviors: +* +* + DNS: mapping server host name to IP address ("addr=" option) +* +* + failure mode: how to behave if a mount request can't be handled
+ * immediately ("fg/bg" option)
+ *
+ * + retry: how often to retry a mount request ("retry=" option)
+ *
+ * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
+ * mountproto=tcp after mountproto=udp, and so on
+ */fs/nfs/fs_context.c new file +2
-0+static int nfs23_validate_mount_data (void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/fs_context.c new file +5
-0+struct nfs_fh *mntfh, + const char *dev_name) +{ + struct nfs_mount_data *data = (struct nfs_mount_data *)options; + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +16
-0+int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; + +if (data ==NULL ) + goto out_no_data; + + args->version =NFS_DEFAULT_VERSION ; +switch (data->version) { +case 1 : + data->namlen =0 ;/* fall through */ +case 2 : + data->bsize =0 ;/* fall through */ +case 3 : +if (data->flags &NFS_MOUNT_VER3 ) + goto out_no_v3; + data->root.size =NFS2_FHSIZE ; + memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/fs_context.c new file +13
-0+/* Turn off security negotiation */ + extra_flags |=NFS_MOUNT_SECFLAVOUR ; +/* fall through */ +case 4 : +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + goto out_no_sec; +/* fall through */ +case 5 : +memset (data->context,0 ,sizeof (data->context)); +/* fall through */ +case 6 : + if (data->flags & NFS_MOUNT_VER3) { + if (data->root.size > NFS3_FHSIZE || data-Quoted 1 line
root.size == 0)
fs/nfs/fs_context.c new file +16
-0+ goto out_invalid_fh; + mntfh->size = data->root.size; + args->version =3 ; + }else { + mntfh->size =NFS2_FHSIZE ; + args->version =2 ; + } + + +memcpy (mntfh->data, data->root.data, mntfh->size); +if (mntfh->size <sizeof (mntfh->data)) +memset (mntfh->data + mntfh->size,0 , +sizeof (mntfh->data) - mntfh->size); + +/* +* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/fs_context.c new file +24
-0+* can deal with. +*/ + args->flags = data->flags &NFS_MOUNT_FLAGMASK ; + args->flags |= extra_flags; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->need_mount = false; + +memcpy (sap, &data->addr,sizeof (data->addr)); + args->nfs_server.addrlen =sizeof (data->addr); + args->nfs_server.port =ntohs (data->addr.sin_port); +if (sap->sa_family !=AF_INET || + !nfs_verify_server_address (sap)) + goto out_no_address; + +if (!(data->flags &NFS_MOUNT_TCP )) + args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; +/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/fs_context.c new file +1
-0+ args->nfs_server.hostname = kstrdup(data->hostname,
GFP_KERNEL);fs/nfs/fs_context.c new file +18
-0+ args->namlen = data->namlen; + args->bsize = data->bsize; + +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + args->selected_flavor = data->pseudoflavor; +else + args->selected_flavor =RPC_AUTH_UNIX ; +if (!args->nfs_server.hostname) + goto out_nomem; + +if (!(data->flags &NFS_MOUNT_NONLM )) + args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +else + args->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +/* +* The legacy version 6 binary mount data from userspace has a
fs/nfs/fs_context.c new file +1
-0+* field used only to transport selinux information into the
fs/nfs/fs_context.c new file +1
-0+* the kernel. To continue to support that functionality we
fs/nfs/fs_context.c new file +1
-0+* have a touch of selinux knowledge here in the NFS code. The
fs/nfs/fs_context.c new file +1
-0+* userspace code converted context=blah to just blah so we are
fs/nfs/fs_context.c new file +1
-0+* converting back to the full string selinux understands.
fs/nfs/fs_context.c new file +6
-0+*/ +if (data->context[0 ]){ +#ifdef CONFIG_SECURITY_SELINUX +int rc; + data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; + rc = security_add_mnt_opt("context", data-Quoted 1 line
context,
fs/nfs/fs_context.c new file +1
-0+ strlen(data->context), &args-Quoted 1 line
lsm_opts);fs/nfs/fs_context.c new file +16
-0+if (rc) +return rc; +#else +return -EINVAL ; +#endif + } + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS: mount program didn't pass any mountdata\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_no_v3: + dfprintk(MOUNT, "NFS: nfs_mount_data version %d does notsupport v3\n",
fs/nfs/fs_context.c new file +5
-0+ data->version); +return -EINVAL ; + +out_no_sec: + dfprintk(MOUNT, "NFS: nfs_mount_data version supports onlyAUTH_SYS\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/fs_context.c new file +4
-0+return -ENOMEM ; + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +10
-0+return -EINVAL ; + +out_invalid_fh: +dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); +return -EINVAL ; +} + +#if IS_ENABLED (CONFIG_NFS_V4 ) + +static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data*args)
fs/nfs/fs_context.c new file +2
-0+{ + args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/fs_context.c new file +11
-0+ NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); +} + +/* +* Validate NFSv4 mount options +*/ +static int nfs4_validate_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +1
-0+ struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/fs_context.c new file +10
-0+char *c; + +if (data ==NULL ) + goto out_no_data; + + args->version =4 ; + +switch (data->version) { +case 1 : + if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/fs_context.c new file +5
-0+ goto out_no_address; +if (data->host_addrlen ==0 ) + goto out_no_address; + args->nfs_server.addrlen = data->host_addrlen; + if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/fs_context.c new file +4
-0+return -EFAULT ; +if (!nfs_verify_server_address (sap)) + goto out_no_address; + args->nfs_server.port = ntohs(((struct sockaddr_in*)sap)->sin_port);
fs/nfs/fs_context.c new file +31
-0+ +if (data->auth_flavourlen) { +rpc_authflavor_t pseudoflavor; +if (data->auth_flavourlen >1 ) + goto out_inval_auth; +if (copy_from_user (&pseudoflavor, + data->auth_flavours, +sizeof (pseudoflavor))) +return -EFAULT ; + args->selected_flavor = pseudoflavor; + }else + args->selected_flavor =RPC_AUTH_UNIX ; + + c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.hostname = c; + + c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.export_path = c; +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); + + c =strndup_user (data->client_addr.data,16 ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->client_address = c; + +/* +* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/fs_context.c new file +26
-0+* can deal with. +*/ + + args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->nfs_server.protocol = data->proto; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS4: mount program didn't pass any mountdata\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_inval_auth: + dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours%d\n",
fs/nfs/fs_context.c new file +5
-0+ data->auth_flavourlen); +return -EINVAL ; + +out_no_address: + dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +15
-0+return -EINVAL ; + +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +} + +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +if (fs_type == &nfs_fs_type) + return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/fs_context.c new file +10
-0+return nfs4_validate_mount_data (options, args, dev_name); +} +#else +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ + return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/fs_context.c new file +11
-0+} +#endif + +int nfs_validate_text_mount_data (void *options, +struct nfs_parsed_mount_data *args, +const char *dev_name) +{ +int port =0 ; +int max_namelen =PAGE_SIZE ; +int max_pathlen =NFS_MAXPATHLEN ; + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +48
-0+ +if (nfs_parse_mount_options ((char *)options, args) ==0 ) +return -EINVAL ; + +if (!nfs_verify_server_address (sap)) + goto out_no_address; + +if (args->version ==4 ) { +#if IS_ENABLED (CONFIG_NFS_V4 ) +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; +else + port =NFS_PORT ; + max_namelen =NFS4_MAXNAMLEN ; + max_pathlen =NFS4_MAXPATHLEN ; +nfs_validate_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) + goto out_invalid_transport_udp; +nfs4_validate_mount_flags (args); +#else + goto out_v4_not_compiled; +#endif /* CONFIG_NFS_V4 */ + }else { +nfs_set_mount_transport_protocol (args); +if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) + port =NFS_RDMA_PORT ; + } + +nfs_set_port (sap, &args->nfs_server.port, port); + +return nfs_parse_devname (dev_name, + &args->nfs_server.hostname, + max_namelen, + &args->nfs_server.export_path, + max_pathlen); + +#if !IS_ENABLED (CONFIG_NFS_V4 ) +out_v4_not_compiled: +dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); +return -EPROTONOSUPPORT ; +#else +out_invalid_transport_udp: +dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); +return -EINVAL ; +#endif /* !CONFIG_NFS_V4 */ + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +2
-0+return -EINVAL ; +}fs/nfs/internal.h +8
-0@@ -7,6 +7,7 @@#include <linux/mount.h> #include <linux/security.h> #include <linux/crc32.h> +#include <linux/sunrpc/addr.h> #include <linux/nfs_page.h> #include <linux/wait_bit.h> @@ -232,6 +233,22 @@ extern const struct svc_version nfs4_callback_version1;extern const struct svc_version nfs4_callback_version4;struct nfs_pageio_descriptor ; + +/* mount.c */ +#define NFS_TEXT_DATA 1 + +extern struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ); +extern void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data); +extern int nfs_parse_mount_options(char *raw, struct
nfs_parsed_mount_data*mnt);
+extern int nfs_validate_mount_data(structfile_system_type*fs_type,fs/nfs/internal.h +6
-0+void *options, + struct nfs_parsed_mount_data *args, + struct nfs_fh *mntfh, + const char *dev_name); +extern int nfs_validate_text_mount_data (void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/internal.h +2
-0+ const char *dev_name); +/*
pagelist.c*/
extern int__initnfs_init_nfspagecache(void);
extern voidnfs_destroy_nfspagecache(void);fs/nfs/internal.h +2
-0@@ -763,3 +780,15 @@ static inline bool nfs_error_is_fatal(int err) } } +/* +* Select between a default port value and a user-specified port value.
+ * If a zero value is set, then autobind will be used.
+ */fs/nfs/internal.h +8
-0+static inline void nfs_set_port (struct sockaddr *sap,int *port, +const unsigned short default_port) +{ +if (*port ==NFS_UNSPEC_PORT ) + *port = default_port; + +rpc_set_port (sap, *port); +}fs/nfs/super.c +0
-223@@ -69,229 +69,6 @@#include "nfs.h" #define NFSDBG_FACILITY NFSDBG_VFS -#define NFS_TEXT_DATA 1 - -#if IS_ENABLED (CONFIG_NFS_V3 ) -#define NFS_DEFAULT_VERSION 3 -#else -#define NFS_DEFAULT_VERSION 2 -#endif - -#define NFS_MAX_CONNECTIONS 16 - -enum { -/* Mount options that take no arguments */ - Opt_soft, Opt_softerr, Opt_hard, - Opt_posix, Opt_noposix, - Opt_cto, Opt_nocto, - Opt_ac, Opt_noac, - Opt_lock, Opt_nolock, - Opt_udp, Opt_tcp, Opt_rdma, - Opt_acl, Opt_noacl, - Opt_rdirplus, Opt_nordirplus, - Opt_sharecache, Opt_nosharecache, - Opt_resvport, Opt_noresvport, - Opt_fscache, Opt_nofscache, - Opt_migration, Opt_nomigration, - -/* Mount options that take integer arguments */ - Opt_port, - Opt_rsize, Opt_wsize, Opt_bsize, - Opt_timeo, Opt_retrans, - Opt_acregmin, Opt_acregmax, - Opt_acdirmin, Opt_acdirmax, - Opt_actimeo, - Opt_namelen, - Opt_mountport, - Opt_mountvers, - Opt_minorversion, - -/* Mount options that take string arguments */ - Opt_nfsvers, - Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, - Opt_nconnect, - Opt_lookupcache, - Opt_fscache_uniq, - Opt_local_lock, - -/* Special mount options */ - Opt_userspace, Opt_deprecated, Opt_sloppy, - - Opt_err -}; - -static const match_table_t nfs_mount_option_tokens = { - { Opt_userspace,"bg" }, - { Opt_userspace,"fg" }, - { Opt_userspace,"retry=%s" }, - - { Opt_sloppy,"sloppy" }, - - { Opt_soft,"soft" }, - { Opt_softerr,"softerr" }, - { Opt_hard,"hard" }, - { Opt_deprecated,"intr" }, - { Opt_deprecated,"nointr" }, - { Opt_posix,"posix" }, - { Opt_noposix,"noposix" }, - { Opt_cto,"cto" }, - { Opt_nocto,"nocto" }, - { Opt_ac,"ac" }, - { Opt_noac,"noac" }, - { Opt_lock,"lock" }, - { Opt_nolock,"nolock" }, - { Opt_udp,"udp" }, - { Opt_tcp,"tcp" }, - { Opt_rdma,"rdma" }, - { Opt_acl,"acl" }, - { Opt_noacl,"noacl" }, - { Opt_rdirplus,"rdirplus" }, - { Opt_nordirplus,"nordirplus" }, - { Opt_sharecache,"sharecache" }, - { Opt_nosharecache,"nosharecache" }, - { Opt_resvport,"resvport" }, - { Opt_noresvport,"noresvport" }, - { Opt_fscache,"fsc" }, - { Opt_nofscache,"nofsc" }, - { Opt_migration,"migration" }, - { Opt_nomigration,"nomigration" }, - - { Opt_port,"port=%s" }, - { Opt_rsize,"rsize=%s" }, - { Opt_wsize,"wsize=%s" }, - { Opt_bsize,"bsize=%s" }, - { Opt_timeo,"timeo=%s" }, - { Opt_retrans,"retrans=%s" }, - { Opt_acregmin,"acregmin=%s" }, - { Opt_acregmax,"acregmax=%s" }, - { Opt_acdirmin,"acdirmin=%s" }, - { Opt_acdirmax,"acdirmax=%s" }, - { Opt_actimeo,"actimeo=%s" }, - { Opt_namelen,"namlen=%s" }, - { Opt_mountport,"mountport=%s" }, - { Opt_mountvers,"mountvers=%s" }, - { Opt_minorversion,"minorversion=%s" }, - - { Opt_nfsvers,"nfsvers=%s" }, - { Opt_nfsvers,"vers=%s" }, - - { Opt_sec,"sec=%s" }, - { Opt_proto,"proto=%s" }, - { Opt_mountproto,"mountproto=%s" }, - { Opt_addr,"addr=%s" }, - { Opt_clientaddr,"clientaddr=%s" }, - { Opt_mounthost,"mounthost=%s" }, - { Opt_mountaddr,"mountaddr=%s" }, - - { Opt_nconnect,"nconnect=%s" }, - - { Opt_lookupcache,"lookupcache=%s" }, - { Opt_fscache_uniq,"fsc=%s" }, - { Opt_local_lock,"local_lock=%s" }, - -/* The following needs to be listed after all other options */ - { Opt_nfsvers,"v%s" }, - - { Opt_err,NULL } -}; - -enum { - Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma, - Opt_xprt_rdma6, - - Opt_xprt_err -}; - -static const match_table_t nfs_xprt_protocol_tokens = { - { Opt_xprt_udp,"udp" }, - { Opt_xprt_udp6,"udp6" }, - { Opt_xprt_tcp,"tcp" }, - { Opt_xprt_tcp6,"tcp6" }, - { Opt_xprt_rdma,"rdma" }, - { Opt_xprt_rdma6,"rdma6" }, - - { Opt_xprt_err,NULL } -}; - -enum { - Opt_sec_none, Opt_sec_sys, - Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, - Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, - Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, - - Opt_sec_err -}; - -static const match_table_t nfs_secflavor_tokens = { - { Opt_sec_none,"none" }, - { Opt_sec_none,"null" }, - { Opt_sec_sys,"sys" }, - - { Opt_sec_krb5,"krb5" }, - { Opt_sec_krb5i,"krb5i" }, - { Opt_sec_krb5p,"krb5p" }, - - { Opt_sec_lkey,"lkey" }, - { Opt_sec_lkeyi,"lkeyi" }, - { Opt_sec_lkeyp,"lkeyp" }, - - { Opt_sec_spkm,"spkm3" }, - { Opt_sec_spkmi,"spkm3i" }, - { Opt_sec_spkmp,"spkm3p" }, - - { Opt_sec_err,NULL } -}; - -enum { - Opt_lookupcache_all, Opt_lookupcache_positive, - Opt_lookupcache_none, - - Opt_lookupcache_err -}; - -static match_table_t nfs_lookupcache_tokens = { - { Opt_lookupcache_all,"all" }, - { Opt_lookupcache_positive,"pos" }, - { Opt_lookupcache_positive,"positive" }, - { Opt_lookupcache_none,"none" }, - - { Opt_lookupcache_err,NULL } -}; - -enum { - Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix, - Opt_local_lock_none, - - Opt_local_lock_err -}; - -static match_table_t nfs_local_lock_tokens = { - { Opt_local_lock_all,"all" }, - { Opt_local_lock_flock,"flock" }, - { Opt_local_lock_posix,"posix" }, - { Opt_local_lock_none,"none" }, - - { Opt_local_lock_err,NULL } -}; - -enum { - Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, - Opt_vers_4_1, Opt_vers_4_2, - - Opt_vers_err -}; - -static match_table_t nfs_vers_tokens = { - { Opt_vers_2,"2" }, - { Opt_vers_3,"3" }, - { Opt_vers_4,"4" }, - { Opt_vers_4_0,"4.0" }, - { Opt_vers_4_1,"4.1" }, - { Opt_vers_4_2,"4.2" }, - - { Opt_vers_err,NULL } -};static struct dentry *nfs_prepared_mount(struct
file_system_type*fs_type,int flags, const char *dev_name, void *raw_data);fs/nfs/super.c +0
-4@@ -332,10 +109,6 @@ const struct super_operations nfs_sops = {EXPORT_SYMBOL_GPL (nfs_sops);#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *); -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args,const char *dev_name); -struct file_system_type nfs4_fs_type = { .owner = THIS_MODULE,.name = "nfs4",fs/nfs/super.c +0
-62@@ -932,141 +705,6 @@ void nfs_umount_begin(struct super_block *sb) }EXPORT_SYMBOL_GPL (nfs_umount_begin); -static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void) -{ -struct nfs_parsed_mount_data *data; - - data =kzalloc (sizeof (*data),GFP_KERNEL ); -if (data) { - data->timeo =NFS_UNSPEC_TIMEO ; - data->retrans =NFS_UNSPEC_RETRANS ; - data->acregmin =NFS_DEF_ACREGMIN ; - data->acregmax =NFS_DEF_ACREGMAX ; - data->acdirmin =NFS_DEF_ACDIRMIN ; - data->acdirmax =NFS_DEF_ACDIRMAX ; - data->mount_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - data->selected_flavor =RPC_AUTH_MAXFLAVOR ; - data->minorversion =0 ; - data->need_mount = true; - data->net = current->nsproxy->net_ns; - data->lsm_opts =NULL ; - } -return data; -} - -static void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data) -{ -if (data) { -kfree (data->client_address); -kfree (data->mount_server.hostname); -kfree (data->nfs_server.export_path); -kfree (data->nfs_server.hostname); -kfree (data->fscache_uniq); -security_free_mnt_opts (&data->lsm_opts); -kfree (data); - } -} - -/* -* Sanity-check a server address provided by the mount command. -* -* Address family must be initialized, and address must not be -* the ANY address for that family. -*/ -static int nfs_verify_server_address (struct sockaddr *addr) -{ -switch (addr->sa_family) { -case AF_INET : { -struct sockaddr_in *sa = (struct sockaddr_in *)addr; -return sa->sin_addr.s_addr !=htonl (INADDR_ANY ); - } -case AF_INET6 : { -struct in6_addr *sa = &((struct sockaddr_in6 *)addr)- >sin6_addr; -return !ipv6_addr_any (sa); - } - } - -dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); -return 0 ; -} - -/* -* Select between a default port value and a user-specified port value.
- * If a zero value is set, then autobind will be used.
- */fs/nfs/super.c +0
-14-static void nfs_set_port (struct sockaddr *sap,int *port, -const unsigned short default_port) -{ -if (*port ==NFS_UNSPEC_PORT ) - *port = default_port; - -rpc_set_port (sap, *port); -} - -/* -* Sanity check the NFS transport protocol. -* -*/ -static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/super.c +0
-13-{ -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : -break ; -default : - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* For text based NFSv2/v3 mounts, the mount protocol transport default
- * settings should depend upon the specified NFS transport.
- */
-static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/super.c +0
-41-{ -nfs_validate_transport_protocol (mnt); - -if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || - mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) -return ; -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : - mnt->mount_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : - mnt->mount_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* Add 'flavor' to 'auth_info' if not already present. -* Returns true if 'flavor' ends up in the list, false otherwise -*/ -static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, -rpc_authflavor_t flavor) -{ -unsigned int i; -unsigned int max_flavor_len =ARRAY_SIZE (auth_info->flavors); - -/* make sure this flavor isn't already in the list */ -for (i =0 ; i < auth_info->flavor_len; i++) { -if (flavor == auth_info->flavors[i]) -return true; - } - -if (auth_info->flavor_len +1 >= max_flavor_len) { -dfprintk (MOUNT ,"NFS: too many sec= flavors\n" ); -return false; - } - - auth_info->flavors[auth_info->flavor_len++] = flavor; -return true; -} -/*
* Return true if 'match' is inauth_infoorauth_infois empty.
* Return false otherwise.fs/nfs/super.c +0
-106@@ -1087,627 +725,6 @@ bool nfs_auth_info_match(const structnfs_auth_info *auth_info, }EXPORT_SYMBOL_GPL (nfs_auth_info_match ); -/* -* Parse the value of the 'sec=' option. -*/ -static int nfs_parse_security_flavors (char *value, -struct nfs_parsed_mount_data *mnt) -{ -substring_t args[MAX_OPT_ARGS ]; -rpc_authflavor_t pseudoflavor; -char *p; - -dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); - -while ((p =strsep (&value,":" )) !=NULL ) { -switch (match_token (p, nfs_secflavor_tokens, args)) { -case Opt_sec_none: - pseudoflavor =RPC_AUTH_NULL ; -break ; -case Opt_sec_sys: - pseudoflavor =RPC_AUTH_UNIX ; -break ; -case Opt_sec_krb5: - pseudoflavor =RPC_AUTH_GSS_KRB5 ; -break ; -case Opt_sec_krb5i: - pseudoflavor =RPC_AUTH_GSS_KRB5I ; -break ; -case Opt_sec_krb5p: - pseudoflavor =RPC_AUTH_GSS_KRB5P ; -break ; -case Opt_sec_lkey: - pseudoflavor =RPC_AUTH_GSS_LKEY ; -break ; -case Opt_sec_lkeyi: - pseudoflavor =RPC_AUTH_GSS_LKEYI ; -break ; -case Opt_sec_lkeyp: - pseudoflavor =RPC_AUTH_GSS_LKEYP ; -break ; -case Opt_sec_spkm: - pseudoflavor =RPC_AUTH_GSS_SPKM ; -break ; -case Opt_sec_spkmi: - pseudoflavor =RPC_AUTH_GSS_SPKMI ; -break ; -case Opt_sec_spkmp: - pseudoflavor =RPC_AUTH_GSS_SPKMP ; -break ; -default : -dfprintk (MOUNT , -"NFS: sec= option '%s' not recognized\n", p); -return 0 ; - } - -if (!nfs_auth_info_add (&mnt->auth_info, pseudoflavor)) -return 0 ; - } - -return 1 ; -} - -static int nfs_parse_version_string (char *string, -struct nfs_parsed_mount_data *mnt, -substring_t *args) -{ - mnt->flags &= ~NFS_MOUNT_VER3 ; -switch (match_token (string, nfs_vers_tokens, args)) { -case Opt_vers_2: - mnt->version =2 ; -break ; -case Opt_vers_3: - mnt->flags |=NFS_MOUNT_VER3 ; - mnt->version =3 ; -break ; -case Opt_vers_4: -/* Backward compatibility option. In future, -* the mount program should always supply -* a NFSv4 minor version number. -*/ - mnt->version =4 ; -break ; -case Opt_vers_4_0: - mnt->version =4 ; - mnt->minorversion =0 ; -break ; -case Opt_vers_4_1: - mnt->version =4 ; - mnt->minorversion =1 ; -break ; -case Opt_vers_4_2: - mnt->version =4 ; - mnt->minorversion =2 ; -break ; -default : -return 0 ; - } -return 1 ; -} - -static int nfs_get_option_str (substring_t args[],char **option) -{ -kfree (*option); - *option =match_strdup (args); -return !*option; -} - -static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/super.c +0
-14-{ -int rc; -char *string; - - string =match_strdup (args); -if (string ==NULL ) -return -ENOMEM ; - rc =kstrtoul (string,10 , option); -kfree (string); - -return rc; -} - -static int nfs_get_option_ul_bound(substring_t args[], unsignedlong *option,
fs/nfs/super.c +0
-14- unsigned long l_bound, unsigned long u_bound) -{ - int ret; - - ret =nfs_get_option_ul (args, option); -if (ret !=0 ) -return ret; -if (*option < l_bound || *option > u_bound) -return -ERANGE ; -return 0 ; -} - -/* -* Error-check and convert a string of mount options from user space into
- * a data structure. The whole mount string is processed; bad options are
- * skipped as they are encountered. If there were no errors, return 1;
- * otherwise return 0 (zero).
- */fs/nfs/super.c +0
-10-static int nfs_parse_mount_options (char *raw, -struct nfs_parsed_mount_data *mnt) -{ -char *p, *string; -int rc, sloppy =0 , invalid_option =0 ; -unsigned short protofamily =AF_UNSPEC ; -unsigned short mountfamily =AF_UNSPEC ; - -if (!raw) { - dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/super.c +0
-17-return 1 ; - } -dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); - - rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); -if (rc) - goto out_security_failure; - -while ((p =strsep (&raw,"," )) !=NULL ) { -substring_t args[MAX_OPT_ARGS ]; -unsigned long option; -int token; - -if (!*p) -continue ; - - dfprintk(MOUNT, "NFS: parsing nfs mount option'%s'\n", p);
fs/nfs/super.c +0
-17- - token =match_token (p, nfs_mount_option_tokens, args); -switch (token) { - -/* -* boolean options: foo/nofoo -*/ -case Opt_soft: - mnt->flags |=NFS_MOUNT_SOFT ; - mnt->flags &= ~NFS_MOUNT_SOFTERR ; -break ; -case Opt_softerr: - mnt->flags |=NFS_MOUNT_SOFTERR ; - mnt->flags &= ~NFS_MOUNT_SOFT ; -break ; -case Opt_hard: - mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/super.c +0
-39-break ; -case Opt_posix: - mnt->flags |=NFS_MOUNT_POSIX ; -break ; -case Opt_noposix: - mnt->flags &= ~NFS_MOUNT_POSIX ; -break ; -case Opt_cto: - mnt->flags &= ~NFS_MOUNT_NOCTO ; -break ; -case Opt_nocto: - mnt->flags |=NFS_MOUNT_NOCTO ; -break ; -case Opt_ac: - mnt->flags &= ~NFS_MOUNT_NOAC ; -break ; -case Opt_noac: - mnt->flags |=NFS_MOUNT_NOAC ; -break ; -case Opt_lock: - mnt->flags &= ~NFS_MOUNT_NONLM ; - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_nolock: - mnt->flags |=NFS_MOUNT_NONLM ; - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -break ; -case Opt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; -break ; -case Opt_rdma: - mnt->flags |=NFS_MOUNT_TCP ;/* for side protocols */
fs/nfs/super.c +0
-70- mnt->nfs_server.protocol =XPRT_TRANSPORT_RDMA ; -xprt_load_transport (p); -break ; -case Opt_acl: - mnt->flags &= ~NFS_MOUNT_NOACL ; -break ; -case Opt_noacl: - mnt->flags |=NFS_MOUNT_NOACL ; -break ; -case Opt_rdirplus: - mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_nordirplus: - mnt->flags |=NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_sharecache: - mnt->flags &= ~NFS_MOUNT_UNSHARED ; -break ; -case Opt_nosharecache: - mnt->flags |=NFS_MOUNT_UNSHARED ; -break ; -case Opt_resvport: - mnt->flags &= ~NFS_MOUNT_NORESVPORT ; -break ; -case Opt_noresvport: - mnt->flags |=NFS_MOUNT_NORESVPORT ; -break ; -case Opt_fscache: - mnt->options |=NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_nofscache: - mnt->options &= ~NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_migration: - mnt->options |=NFS_OPTION_MIGRATION ; -break ; -case Opt_nomigration: - mnt->options &= ~NFS_OPTION_MIGRATION ; -break ; - -/* -* options that take numeric values -*/ -case Opt_port: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->nfs_server.port = option; -break ; -case Opt_rsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->rsize = option; -break ; -case Opt_wsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->wsize = option; -break ; -case Opt_bsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->bsize = option; -break ; -case Opt_timeo: - if (nfs_get_option_ul_bound(args, &option, 1,
INT_MAX))fs/nfs/super.c +0
-5- goto out_invalid_value; - mnt->timeo = option; -break ; -case Opt_retrans: - if (nfs_get_option_ul_bound(args, &option, 0,
INT_MAX))fs/nfs/super.c +0
-63- goto out_invalid_value; - mnt->retrans = option; -break ; -case Opt_acregmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = option; -break ; -case Opt_acregmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmax = option; -break ; -case Opt_acdirmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmin = option; -break ; -case Opt_acdirmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmax = option; -break ; -case Opt_actimeo: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = mnt->acregmax = - mnt->acdirmin = mnt->acdirmax = option; -break ; -case Opt_namelen: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->namlen = option; -break ; -case Opt_mountport: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->mount_server.port = option; -break ; -case Opt_mountvers: -if (nfs_get_option_ul (args, &option) || - option <NFS_MNT_VERSION || - option >NFS_MNT3_VERSION ) - goto out_invalid_value; - mnt->mount_server.version = option; -break ; -case Opt_minorversion: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; -if (option >NFS4_MAX_MINOR_VERSION ) - goto out_invalid_value; - mnt->minorversion = option; -break ; - -/* -* options that take text values -*/ -case Opt_nfsvers: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc = nfs_parse_version_string(string, mnt,args);
fs/nfs/super.c +0
-22-kfree (string); -if (!rc) - goto out_invalid_value; -break ; -case Opt_sec: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc =nfs_parse_security_flavors (string, mnt); -kfree (string); -if (!rc) { -dfprintk (MOUNT ,"NFS: unrecognized " -"security flavor\n" ); -return 0 ; - } -break ; -case Opt_proto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string, - nfs_xprt_protocol_tokens,args);
fs/nfs/super.c +0
-9- - protofamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-7-break ; -case Opt_xprt_tcp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-8-break ; -case Opt_xprt_rdma6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_rdma: -/* vector side protocols to TCP */ - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/super.c +0
-5-xprt_load_transport (string); -break ; -default : -dfprintk (MOUNT ,"NFS: unrecognized " - "transportprotocol\n");
fs/nfs/super.c +0
-11-kfree (string); -return 0 ; - } -kfree (string); -break ; -case Opt_mountproto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string, - nfs_xprt_protocol_tokens,args);
fs/nfs/super.c +0
-9-kfree (string); - - mountfamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-6-break ; -case Opt_xprt_tcp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-2-break ; -case Opt_xprt_rdma:/* not used for side protocols */
fs/nfs/super.c +0
-3-default : -dfprintk (MOUNT ,"NFS: unrecognized " - "transportprotocol\n");
fs/nfs/super.c +0
-9-return 0 ; - } -break ; -case Opt_addr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->nfs_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-3- (struct sockaddr *) - &mnt->nfs_server.address, - sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->nfs_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_clientaddr: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/super.c +0
-5- goto out_nomem; -break ; -case Opt_mounthost: - if (nfs_get_option_str(args, - &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/super.c +0
-8- goto out_nomem; -break ; -case Opt_mountaddr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->mount_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-3- (struct sockaddr *) - &mnt->mount_server.address, - sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->mount_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_nconnect: - if (nfs_get_option_ul_bound(args, &option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/super.c +0
-13- goto out_invalid_value; - mnt->nfs_server.nconnect = option; -break ; -case Opt_lookupcache: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_lookupcache_tokens, args); -kfree (string); -switch (token) { -case Opt_lookupcache_all: - mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_positive: - mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-1- mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_none: - mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-3-break ; -default : - dfprintk(MOUNT, "NFS: invalid"
fs/nfs/super.c +0
-1- "lookupcacheargument\n");
fs/nfs/super.c +0
-5-return 0 ; - }; -break ; -case Opt_fscache_uniq: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/super.c +0
-8- goto out_nomem; - mnt->options |=NFS_OPTION_FSCACHE ; -break ; -case Opt_local_lock: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string,
nfs_local_lock_tokens,fs/nfs/super.c +0
-20- args); -kfree (string); - switch (token) { - case Opt_local_lock_all: - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | - NFS_MOUNT_LOCAL_FCNTL); - break; - case Opt_local_lock_flock: - mnt->flags |= NFS_MOUNT_LOCAL_FLOCK; - break; - case Opt_local_lock_posix: - mnt->flags |= NFS_MOUNT_LOCAL_FCNTL; - break; - case Opt_local_lock_none: - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | - NFS_MOUNT_LOCAL_FCNTL); - break; - default: - dfprintk(MOUNT, "NFS: invalid " - "local_lockargument\n");
fs/nfs/super.c +0
-10-return 0 ; - }; -break ; - -/* -* Special options -*/ -case Opt_sloppy: - sloppy =1 ; - dfprintk(MOUNT, "NFS: relaxing parsingrules\n");
fs/nfs/super.c +0
-10-break ; -case Opt_userspace: -case Opt_deprecated: -dfprintk (MOUNT ,"NFS: ignoring mount option " -"'%s'\n" , p); -break ; - -default : - invalid_option =1 ; - dfprintk(MOUNT, "NFS: unrecognized mountoption "
fs/nfs/super.c +0
-25- "'%s'\n", p); - } - } - -if (!sloppy && invalid_option) -return 0 ; - -if (mnt->minorversion && mnt->version !=4 ) - goto out_minorversion_mismatch; - -if (mnt->options &NFS_OPTION_MIGRATION && - (mnt->version !=4 || mnt->minorversion !=0 )) - goto out_migration_misuse; - -/* -* verify that any proto=/mountproto= options match the address -* families in the addr=/mountaddr= options. -*/ -if (protofamily !=AF_UNSPEC && - protofamily != mnt->nfs_server.address.ss_family) - goto out_proto_mismatch; - - if (mountfamily != AF_UNSPEC) { - if (mnt->mount_server.addrlen) { - if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/super.c +0
-3- goto out_mountproto_mismatch; - } else { - if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/super.c +0
-8- goto out_mountproto_mismatch; - } - } - -return 1 ; - -out_mountproto_mismatch: - printk(KERN_INFO "NFS: mount server address does not matchmountproto= "
fs/nfs/super.c +0
-4- "option\n"); -return 0 ; -out_proto_mismatch: - printk(KERN_INFO "NFS: server address does not match proto=option\n");
fs/nfs/super.c +0
-6-return 0 ; -out_invalid_address: -printk (KERN_INFO "NFS: bad IP address specified: %s\n" , p); -return 0 ; -out_invalid_value: - printk(KERN_INFO "NFS: bad mount option value specified: %s\n",p);
fs/nfs/super.c +0
-4-return 0 ; -out_minorversion_mismatch: - printk(KERN_INFO "NFS: mount option vers=%u does not support " - "minorversion=%u\n", mnt->version, mnt-Quoted 1 line
minorversion);
fs/nfs/super.c +0
-4-return 0 ; -out_migration_misuse: -printk (KERN_INFO - "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/super.c +0
-9-return 0 ; -out_nomem: -printk (KERN_INFO "NFS: not enough memory to parse option\n" ); -return 0 ; -out_security_failure: -printk (KERN_INFO "NFS: security options invalid: %d\n" , rc); -return 0 ; -} -/*
* Ensure that a specified authtype inargs->auth_infois supported
by
* the server. Returns 0 and setsargs->selected_flavorif it's ok,
andfs/nfs/super.c +0
-4@@ -1908,327 +925,6 @@ struct dentry *nfs_try_mount(int flags,const char *dev_name, }EXPORT_SYMBOL_GPL (nfs_try_mount ); -/* -* Split "dev_name" into "hostname:export_path". -* -* The leftmost colon demarks the split between the server's hostname
- * and the export path. If the hostname starts with a left square
- * bracket, then it may contain colons.
- *
- * Note: caller frees hostname and export path, even on error.
- */fs/nfs/super.c +0
-57-static int nfs_parse_devname (const char *dev_name, -char **hostname,size_t maxnamlen, -char **export_path,size_t maxpathlen) -{ -size_t len; -char *end; - -if (unlikely (!dev_name || !*dev_name)) { -dfprintk (MOUNT ,"NFS: device name not specified\n" ); -return -EINVAL ; - } - -/* Is the host name protected with square brakcets? */ -if (*dev_name =='[' ) { - end =strchr (++dev_name,']' ); -if (end ==NULL || end[1 ] !=':' ) - goto out_bad_devname; - - len = end - dev_name; - end++; - }else { -char *comma; - - end =strchr (dev_name,':' ); -if (end ==NULL ) - goto out_bad_devname; - len = end - dev_name; - -/* kill possible hostname list: not supported */ - comma =strchr (dev_name,',' ); -if (comma !=NULL && comma < end) - len = comma - dev_name; - } - -if (len > maxnamlen) - goto out_hostname; - -/* N.B. caller will free nfs_server.hostname in all cases */ - *hostname =kstrndup (dev_name, len,GFP_KERNEL ); -if (*hostname ==NULL ) - goto out_nomem; - len =strlen (++end); -if (len > maxpathlen) - goto out_path; - *export_path =kstrndup (end, len,GFP_KERNEL ); -if (!*export_path) - goto out_nomem; - -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); -return 0 ; - -out_bad_devname: -dfprintk (MOUNT ,"NFS: device name not in host:path format\n" ); -return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/super.c +0
-20-return -ENOMEM ; - -out_hostname: -dfprintk (MOUNT ,"NFS: server hostname too long\n" ); -return -ENAMETOOLONG ; - -out_path: -dfprintk (MOUNT ,"NFS: export pathname too long\n" ); -return -ENAMETOOLONG ; -} - -/* -* Validate the NFS2/NFS3 mount data -* - fills in the mount root filehandle -* -* For option strings, user space handles the following behaviors: -* -* + DNS: mapping server host name to IP address ("addr=" option) -* -* + failure mode: how to behave if a mount request can't be handled
- * immediately ("fg/bg" option)
- *
- * + retry: how often to retry a mount request ("retry=" option)
- *
- * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
- * mountproto=tcp after mountproto=udp, and so on
- */fs/nfs/super.c +0
-2-static int nfs23_validate_mount_data (void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-5-struct nfs_fh *mntfh, - const char *dev_name) -{ - struct nfs_mount_data *data = (struct nfs_mount_data *)options; - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-16-int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; - -if (data ==NULL ) - goto out_no_data; - - args->version =NFS_DEFAULT_VERSION ; -switch (data->version) { -case 1 : - data->namlen =0 ;/* fall through */ -case 2 : - data->bsize =0 ;/* fall through */ -case 3 : -if (data->flags &NFS_MOUNT_VER3 ) - goto out_no_v3; - data->root.size =NFS2_FHSIZE ; - memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/super.c +0
-13-/* Turn off security negotiation */ - extra_flags |=NFS_MOUNT_SECFLAVOUR ; -/* fall through */ -case 4 : -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - goto out_no_sec; -/* fall through */ -case 5 : -memset (data->context,0 ,sizeof (data->context)); -/* fall through */ -case 6 : - if (data->flags & NFS_MOUNT_VER3) { - if (data->root.size > NFS3_FHSIZE || data-Quoted 1 line
root.size == 0)
fs/nfs/super.c +0
-16- goto out_invalid_fh; - mntfh->size = data->root.size; - args->version =3 ; - }else { - mntfh->size =NFS2_FHSIZE ; - args->version =2 ; - } - - -memcpy (mntfh->data, data->root.data, mntfh->size); -if (mntfh->size <sizeof (mntfh->data)) -memset (mntfh->data + mntfh->size,0 , -sizeof (mntfh->data) - mntfh->size); - -/* -* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/super.c +0
-24-* can deal with. -*/ - args->flags = data->flags &NFS_MOUNT_FLAGMASK ; - args->flags |= extra_flags; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->need_mount = false; - -memcpy (sap, &data->addr,sizeof (data->addr)); - args->nfs_server.addrlen =sizeof (data->addr); - args->nfs_server.port =ntohs (data->addr.sin_port); -if (sap->sa_family !=AF_INET || - !nfs_verify_server_address (sap)) - goto out_no_address; - -if (!(data->flags &NFS_MOUNT_TCP )) - args->nfs_server.protocol =XPRT_TRANSPORT_UDP ; -/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/super.c +0
-1- args->nfs_server.hostname = kstrdup(data->hostname,
GFP_KERNEL);fs/nfs/super.c +0
-18- args->namlen = data->namlen; - args->bsize = data->bsize; - -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - args->selected_flavor = data->pseudoflavor; -else - args->selected_flavor =RPC_AUTH_UNIX ; -if (!args->nfs_server.hostname) - goto out_nomem; - -if (!(data->flags &NFS_MOUNT_NONLM )) - args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -else - args->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -/* -* The legacy version 6 binary mount data from userspace has a
fs/nfs/super.c +0
-1-* field used only to transport selinux information into the
fs/nfs/super.c +0
-1-* the kernel. To continue to support that functionality we
fs/nfs/super.c +0
-1-* have a touch of selinux knowledge here in the NFS code. The
fs/nfs/super.c +0
-1-* userspace code converted context=blah to just blah so we are
fs/nfs/super.c +0
-1-* converting back to the full string selinux understands.
fs/nfs/super.c +0
-6-*/ -if (data->context[0 ]){ -#ifdef CONFIG_SECURITY_SELINUX -int rc; - data->context[NFS_MAX_CONTEXT_LEN ] ='\0' ; - rc = security_add_mnt_opt("context", data-Quoted 1 line
context,
fs/nfs/super.c +0
-1- strlen(data->context), &args-Quoted 1 line
lsm_opts);fs/nfs/super.c +0
-16-if (rc) -return rc; -#else -return -EINVAL ; -#endif - } - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS: mount program didn't pass any mountdata\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_no_v3: - dfprintk(MOUNT, "NFS: nfs_mount_data version %d does notsupport v3\n",
fs/nfs/super.c +0
-5- data->version); -return -EINVAL ; - -out_no_sec: - dfprintk(MOUNT, "NFS: nfs_mount_data version supports onlyAUTH_SYS\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/super.c +0
-4-return -ENOMEM ; - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-9-return -EINVAL ; - -out_invalid_fh: -dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); -return -EINVAL ; -} - -#if IS_ENABLED (CONFIG_NFS_V4 ) -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-7- void *options, - struct nfs_parsed_mount_data *args, - struct nfs_fh *mntfh, - const char *dev_name) -{ - if (fs_type == &nfs_fs_type) - return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/super.c +0
-4-return nfs4_validate_mount_data (options, args, dev_name); -} -#else -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-6- void *options, - struct nfs_parsed_mount_data *args, - struct nfs_fh *mntfh, - const char *dev_name) -{ - return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/super.c +0
-5-} -#endif - -static int nfs_validate_text_mount_data (void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-6- const char *dev_name) -{ -int port =0 ; -int max_namelen =PAGE_SIZE ; -int max_pathlen =NFS_MAXPATHLEN ; - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-48- -if (nfs_parse_mount_options ((char *)options, args) ==0 ) -return -EINVAL ; - -if (!nfs_verify_server_address (sap)) - goto out_no_address; - -if (args->version ==4 ) { -#if IS_ENABLED (CONFIG_NFS_V4 ) -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; -else - port =NFS_PORT ; - max_namelen =NFS4_MAXNAMLEN ; - max_pathlen =NFS4_MAXPATHLEN ; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; -nfs4_validate_mount_flags (args); -#else - goto out_v4_not_compiled; -#endif /* CONFIG_NFS_V4 */ - }else { -nfs_set_mount_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_RDMA ) - port =NFS_RDMA_PORT ; - } - -nfs_set_port (sap, &args->nfs_server.port, port); - -return nfs_parse_devname (dev_name, - &args->nfs_server.hostname, - max_namelen, - &args->nfs_server.export_path, - max_pathlen); - -#if !IS_ENABLED (CONFIG_NFS_V4 ) -out_v4_not_compiled: -dfprintk (MOUNT ,"NFS: NFSv4 is not compiled into kernel\n" ); -return -EPROTONOSUPPORT ; -#else -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -#endif /* !CONFIG_NFS_V4 */ - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-3-return -EINVAL ; -} -#define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \ | NFS_MOUNT_SECURE \ | NFS_MOUNT_TCP \fs/nfs/super.c +0
-3@@ -2719,113 +1415,6 @@ nfs_prepared_mount(struct file_system_type *fs_type, int flags,#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags (struct nfs_parsed_mount_data *args) -{ - args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/super.c +0
-11- NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); -} - -/* -* Validate NFSv4 mount options -*/ -static int nfs4_validate_mount_data (void *options, -struct nfs_parsed_mount_data *args, -const char *dev_name) -{ - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-1- struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/super.c +0
-10-char *c; - -if (data ==NULL ) - goto out_no_data; - - args->version =4 ; - -switch (data->version) { -case 1 : - if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/super.c +0
-5- goto out_no_address; -if (data->host_addrlen ==0 ) - goto out_no_address; - args->nfs_server.addrlen = data->host_addrlen; - if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/super.c +0
-4-return -EFAULT ; -if (!nfs_verify_server_address (sap)) - goto out_no_address; - args->nfs_server.port = ntohs(((struct sockaddr_in*)sap)->sin_port);
fs/nfs/super.c +0
-31- -if (data->auth_flavourlen) { -rpc_authflavor_t pseudoflavor; -if (data->auth_flavourlen >1 ) - goto out_inval_auth; -if (copy_from_user (&pseudoflavor, - data->auth_flavours, -sizeof (pseudoflavor))) -return -EFAULT ; - args->selected_flavor = pseudoflavor; - }else - args->selected_flavor =RPC_AUTH_UNIX ; - - c =strndup_user (data->hostname.data,NFS4_MAXNAMLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.hostname = c; - - c =strndup_user (data->mnt_path.data,NFS4_MAXPATHLEN ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.export_path = c; -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); - - c =strndup_user (data->client_addr.data,16 ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->client_address = c; - -/* -* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/super.c +0
-26-* can deal with. -*/ - - args->flags = data->flags &NFS4_MOUNT_FLAGMASK ; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->nfs_server.protocol = data->proto; -nfs_validate_transport_protocol (args); -if (args->nfs_server.protocol ==XPRT_TRANSPORT_UDP ) - goto out_invalid_transport_udp; - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS4: mount program didn't pass any mountdata\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_inval_auth: - dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours%d\n",
fs/nfs/super.c +0
-5- data->auth_flavourlen); -return -EINVAL ; - -out_no_address: - dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-7-return -EINVAL ; - -out_invalid_transport_udp: -dfprintk (MOUNT ,"NFSv4: Unsupported transport protocol udp\n" ); -return -EINVAL ; -} -Quoted 6 lines
/*
* NFS v4 module parameters need to stay in the
* NFS client for backwards compatibilitySignature · 1 line
2.17.2--
Chuck Lever
[email protected]Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v3 16/26] NFS: Move mount parameterisation bits into their own file
Quoted 98 lines · Scott Mayhew
Quoted 75 lines · Trond Myklebust
Quoted 71 lines · Chuck Lever
Quoted 61 lines
On Sep 11, 2019, at 12:16 PM, Scott Mayhew <[email protected]> wrote:
From: David Howells <[email protected]>
Split various bits relating to mount parameterisation out from
fs/nfs/super.cinto their own file to form the basis of filesystem
context
handling for NFS.No other changes are made to the code beyond removing 'static' qualifiers.
Signed-off-by David Howells <[email protected]>Signed-off-by Al Viro <[email protected]>---
fs/nfs/Makefile| 2 +-fs/nfs/fs_context.c| 1418
+++++++++++++++++++++++++++++++++++++++++++fs/nfs/internal.h| 29 +fs/nfs/super.c| 1411 ------------------------------------
----
--4 files changed, 1448 insertions(+), 1412 deletions(-)create mode 100644
fs/nfs/fs_context.cfs/nfs/Makefile +0
-0@@ -9,7 +9,7 @@ CFLAGS_nfstrace.o += -I$(src)nfs-y := client.o dir.o file.o getroot.o
inode.o super.o \
io.o direct.o pagelist.o read.o
symlink.o
unlink.o \
write.o namespace.o mount_clnt.o
nfstrace.o
\fs/nfs/Makefile +1
-1- export.o sysfs.o + export.o sysfs.o fs_context.onfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.ofs/nfs/fs_context.c new file +10
-0@@ -0,0 +1,1418 @@ +/* NFS mount handling. +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* Split from fs/nfs/super.c: +* +* Copyright (C) 1992 Rick Sladkey +* +* This program is free software; you can redistribute it Quoted 6 lines
and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */New source files should have an SPDX tag instead of boilerplate. I suggest:
Quoted 2 lines
// SPDX-License-Identifier: GPL-2.0-only
Quoted 7 lines
Agreed. It is also quite a long stretch to claim authorship of the entire file as implied above. Given that this is mostly a copy- paste
effort, then most of the actual copyrights belong to the people who've
contributed tosuper.c(and toinode.cbefore it). David is one of those authors, but he is one of many.Okay, how about:
// SPDX-License-Identifier: GPL-2.0-only
/*
*linux/fs/nfs/fs_context.c
*
* Copyright (C) 1992 Rick Sladkey
*
* NFS mount handling.
*
* Split fromfs/nfs/super.cby David Howells <[email protected]> */
Quoted 3 lines
and have patch 25/26 add a line
* Conversion to new mount api Copyright (C) David Howells
That looks more reasonable to me.
Quoted 3,387 lines
-Scott
Quoted 3,385 lines
Quoted 3,379 lines
Quoted 3,366 lines
fs/nfs/fs_context.c new file +129
-0+#include <linux/parser.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> +#include "nfs.h" +#include "internal.h" + +#define NFSDBG_FACILITY NFSDBG_MOUNT + +#if IS_ENABLED (CONFIG_NFS_V3 ) +#define NFS_DEFAULT_VERSION 3 +#else +#define NFS_DEFAULT_VERSION 2 +#endif + +#define NFS_MAX_CONNECTIONS 16 + +enum { +/* Mount options that take no arguments */ + Opt_soft, Opt_softerr, Opt_hard, + Opt_posix, Opt_noposix, + Opt_cto, Opt_nocto, + Opt_ac, Opt_noac, + Opt_lock, Opt_nolock, + Opt_udp, Opt_tcp, Opt_rdma, + Opt_acl, Opt_noacl, + Opt_rdirplus, Opt_nordirplus, + Opt_sharecache, Opt_nosharecache, + Opt_resvport, Opt_noresvport, + Opt_fscache, Opt_nofscache, + Opt_migration, Opt_nomigration, + +/* Mount options that take integer arguments */ + Opt_port, + Opt_rsize, Opt_wsize, Opt_bsize, + Opt_timeo, Opt_retrans, + Opt_acregmin, Opt_acregmax, + Opt_acdirmin, Opt_acdirmax, + Opt_actimeo, + Opt_namelen, + Opt_mountport, + Opt_mountvers, + Opt_minorversion, + +/* Mount options that take string arguments */ + Opt_nfsvers, + Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, + Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_nconnect, + Opt_lookupcache, + Opt_fscache_uniq, + Opt_local_lock, + +/* Special mount options */ + Opt_userspace, Opt_deprecated, Opt_sloppy, + + Opt_err +}; + +static const match_table_t nfs_mount_option_tokens = { + { Opt_userspace,"bg" }, + { Opt_userspace,"fg" }, + { Opt_userspace,"retry=%s" }, + + { Opt_sloppy,"sloppy" }, + + { Opt_soft,"soft" }, + { Opt_softerr,"softerr" }, + { Opt_hard,"hard" }, + { Opt_deprecated,"intr" }, + { Opt_deprecated,"nointr" }, + { Opt_posix,"posix" }, + { Opt_noposix,"noposix" }, + { Opt_cto,"cto" }, + { Opt_nocto,"nocto" }, + { Opt_ac,"ac" }, + { Opt_noac,"noac" }, + { Opt_lock,"lock" }, + { Opt_nolock,"nolock" }, + { Opt_udp,"udp" }, + { Opt_tcp,"tcp" }, + { Opt_rdma,"rdma" }, + { Opt_acl,"acl" }, + { Opt_noacl,"noacl" }, + { Opt_rdirplus,"rdirplus" }, + { Opt_nordirplus,"nordirplus" }, + { Opt_sharecache,"sharecache" }, + { Opt_nosharecache,"nosharecache" }, + { Opt_resvport,"resvport" }, + { Opt_noresvport,"noresvport" }, + { Opt_fscache,"fsc" }, + { Opt_nofscache,"nofsc" }, + { Opt_migration,"migration" }, + { Opt_nomigration,"nomigration" }, + + { Opt_port,"port=%s" }, + { Opt_rsize,"rsize=%s" }, + { Opt_wsize,"wsize=%s" }, + { Opt_bsize,"bsize=%s" }, + { Opt_timeo,"timeo=%s" }, + { Opt_retrans,"retrans=%s" }, + { Opt_acregmin,"acregmin=%s" }, + { Opt_acregmax,"acregmax=%s" }, + { Opt_acdirmin,"acdirmin=%s" }, + { Opt_acdirmax,"acdirmax=%s" }, + { Opt_actimeo,"actimeo=%s" }, + { Opt_namelen,"namlen=%s" }, + { Opt_mountport,"mountport=%s" }, + { Opt_mountvers,"mountvers=%s" }, + { Opt_minorversion,"minorversion=%s" }, + + { Opt_nfsvers,"nfsvers=%s" }, + { Opt_nfsvers,"vers=%s" }, + + { Opt_sec,"sec=%s" }, + { Opt_proto,"proto=%s" }, + { Opt_mountproto,"mountproto=%s" }, + { Opt_addr,"addr=%s" }, + { Opt_clientaddr,"clientaddr=%s" }, + { Opt_mounthost,"mounthost=%s" }, + { Opt_mountaddr,"mountaddr=%s" }, + + { Opt_nconnect,"nconnect=%s" }, + + { Opt_lookupcache,"lookupcache=%s" }, + { Opt_fscache_uniq,"fsc=%s" }, + { Opt_local_lock,"local_lock=%s" }, + +/* The following needs to be listed after all other options */
fs/nfs/fs_context.c new file +7
-0+ { Opt_nfsvers, "v%s" }, + + { Opt_err, NULL } +}; + +enum { + Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp,
Opt_xprt_tcp6,Opt_xprt_rdma,fs/nfs/fs_context.c new file +63
-0+ Opt_xprt_rdma6, + + Opt_xprt_err +}; + +static const match_table_t nfs_xprt_protocol_tokens = { + { Opt_xprt_udp,"udp" }, + { Opt_xprt_udp6,"udp6" }, + { Opt_xprt_tcp,"tcp" }, + { Opt_xprt_tcp6,"tcp6" }, + { Opt_xprt_rdma,"rdma" }, + { Opt_xprt_rdma6,"rdma6" }, + + { Opt_xprt_err,NULL } +}; + +enum { + Opt_sec_none, Opt_sec_sys, + Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, + Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, + Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, + + Opt_sec_err +}; + +static const match_table_t nfs_secflavor_tokens = { + { Opt_sec_none,"none" }, + { Opt_sec_none,"null" }, + { Opt_sec_sys,"sys" }, + + { Opt_sec_krb5,"krb5" }, + { Opt_sec_krb5i,"krb5i" }, + { Opt_sec_krb5p,"krb5p" }, + + { Opt_sec_lkey,"lkey" }, + { Opt_sec_lkeyi,"lkeyi" }, + { Opt_sec_lkeyp,"lkeyp" }, + + { Opt_sec_spkm,"spkm3" }, + { Opt_sec_spkmi,"spkm3i" }, + { Opt_sec_spkmp,"spkm3p" }, + + { Opt_sec_err,NULL } +}; + +enum { + Opt_lookupcache_all, Opt_lookupcache_positive, + Opt_lookupcache_none, + + Opt_lookupcache_err +}; + +static match_table_t nfs_lookupcache_tokens = { + { Opt_lookupcache_all,"all" }, + { Opt_lookupcache_positive,"pos" }, + { Opt_lookupcache_positive,"positive" }, + { Opt_lookupcache_none,"none" }, + + { Opt_lookupcache_err,NULL } +}; + +enum { + Opt_local_lock_all, Opt_local_lock_flock,
Opt_local_lock_posix,fs/nfs/fs_context.c new file +33
-0+ Opt_local_lock_none, + + Opt_local_lock_err +}; + +static match_table_t nfs_local_lock_tokens = { + { Opt_local_lock_all,"all" }, + { Opt_local_lock_flock,"flock" }, + { Opt_local_lock_posix,"posix" }, + { Opt_local_lock_none,"none" }, + + { Opt_local_lock_err,NULL } +}; + +enum { + Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, + Opt_vers_4_1, Opt_vers_4_2, + + Opt_vers_err +}; + +static match_table_t nfs_vers_tokens = { + { Opt_vers_2,"2" }, + { Opt_vers_3,"3" }, + { Opt_vers_4,"4" }, + { Opt_vers_4_0,"4.0" }, + { Opt_vers_4_1,"4.1" }, + { Opt_vers_4_2,"4.2" }, + + { Opt_vers_err,NULL } +}; + +struct nfs_parsed_mount_data
*nfs_alloc_parsed_mount_data(void)fs/nfs/fs_context.c new file +18
-0+{ +struct nfs_parsed_mount_data *data; + + data =kzalloc (sizeof (*data),GFP_KERNEL ); +if (data) { + data->timeo =NFS_UNSPEC_TIMEO ; + data->retrans =NFS_UNSPEC_RETRANS ; + data->acregmin =NFS_DEF_ACREGMIN ; + data->acregmax =NFS_DEF_ACREGMAX ; + data->acdirmin =NFS_DEF_ACDIRMIN ; + data->acdirmax =NFS_DEF_ACDIRMAX ; + data->mount_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.port =NFS_UNSPEC_PORT ; + data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + data->selected_flavor =RPC_AUTH_MAXFLAVOR ; + data->minorversion =0 ; + data->need_mount = true; + data->net = current->nsproxy-Quoted 1 line
net_ns;fs/nfs/fs_context.c new file +6
-0+ data->lsm_opts =NULL ; + } +return data; +} + +void nfs_free_parsed_mount_data(struct nfs_parsed_mount_data*data)
fs/nfs/fs_context.c new file +14
-0+{ +if (data) { +kfree (data->client_address); +kfree (data->mount_server.hostname); +kfree (data->nfs_server.export_path); +kfree (data->nfs_server.hostname); +kfree (data->fscache_uniq); +security_free_mnt_opts (&data->lsm_opts); +kfree (data); + } +} + +/* +* Sanity-check a server address provided by the mount command.
+ *
+ * Address family must be initialized, and address must not be
+ * the ANY address for that family.
+ */fs/nfs/fs_context.c new file +5
-0+static int nfs_verify_server_address (struct sockaddr *addr) +{ +switch (addr->sa_family) { +case AF_INET : { + struct sockaddr_in *sa = (struct sockaddr_in*)addr;
fs/nfs/fs_context.c new file +1
-0+ return sa->sin_addr.s_addr !=
htonl(INADDR_ANY);fs/nfs/fs_context.c new file +3
-0+ } +case AF_INET6 : { + struct in6_addr *sa = &((struct sockaddr_in6*)addr)-
Quoted 1 line
sin6_addr;fs/nfs/fs_context.c new file +13
-0+return !ipv6_addr_any (sa); + } + } + +dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); +return 0 ; +} + +/* +* Sanity check the NFS transport protocol. +* +*/ +static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/fs_context.c new file +13
-0+{ +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : +break ; +default : + mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; + } +} + +/* +* For text based NFSv2/v3 mounts, the mount protocol transport
default
+ * settings should depend upon the specified NFS transport.
+ */
+static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +9
-0+{ +nfs_validate_transport_protocol (mnt); + +if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || + mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) +return ; +switch (mnt->nfs_server.protocol) { +case XPRT_TRANSPORT_UDP : + mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +4
-0+break ; +case XPRT_TRANSPORT_TCP : +case XPRT_TRANSPORT_RDMA : + mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +6
-0+ } +} + +/* +* Add 'flavor' to 'auth_info' if not already present. +* Returns true if 'flavor' ends up in the list, false otherwise
+ */fs/nfs/fs_context.c new file +5
-0+static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, +rpc_authflavor_t flavor) +{ +unsigned int i; + unsigned int max_flavor_len = ARRAY_SIZE(auth_info-Quoted 1 line
flavors);
fs/nfs/fs_context.c new file +9
-0+ +/* make sure this flavor isn't already in the list */ +for (i =0 ; i < auth_info->flavor_len; i++) { +if (flavor == auth_info->flavors[i]) +return true; + } + +if (auth_info->flavor_len +1 >= max_flavor_len) { + dfprintk(MOUNT, "NFS: too many sec=flavors\n");
fs/nfs/fs_context.c new file +12
-0+return false; + } + + auth_info->flavors[auth_info->flavor_len++] = flavor; +return true; +} + +/* +* Parse the value of the 'sec=' option. +*/ +static int nfs_parse_security_flavors(char *value, + struct
nfs_parsed_mount_data
*mnt)fs/nfs/fs_context.c new file +9
-0+{ +substring_t args[MAX_OPT_ARGS ]; +rpc_authflavor_t pseudoflavor; +char *p; + +dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); + +while ((p =strsep (&value,":" )) !=NULL ) { + switch (match_token(p, nfs_secflavor_tokens,args)) {
fs/nfs/fs_context.c new file +36
-0+case Opt_sec_none: + pseudoflavor =RPC_AUTH_NULL ; +break ; +case Opt_sec_sys: + pseudoflavor =RPC_AUTH_UNIX ; +break ; +case Opt_sec_krb5: + pseudoflavor =RPC_AUTH_GSS_KRB5 ; +break ; +case Opt_sec_krb5i: + pseudoflavor =RPC_AUTH_GSS_KRB5I ; +break ; +case Opt_sec_krb5p: + pseudoflavor =RPC_AUTH_GSS_KRB5P ; +break ; +case Opt_sec_lkey: + pseudoflavor =RPC_AUTH_GSS_LKEY ; +break ; +case Opt_sec_lkeyi: + pseudoflavor =RPC_AUTH_GSS_LKEYI ; +break ; +case Opt_sec_lkeyp: + pseudoflavor =RPC_AUTH_GSS_LKEYP ; +break ; +case Opt_sec_spkm: + pseudoflavor =RPC_AUTH_GSS_SPKM ; +break ; +case Opt_sec_spkmi: + pseudoflavor =RPC_AUTH_GSS_SPKMI ; +break ; +case Opt_sec_spkmp: + pseudoflavor =RPC_AUTH_GSS_SPKMP ; +break ; +default : + dfprintk(MOUNT, + "NFS: sec= option '%s' notrecognized\n", p);
fs/nfs/fs_context.c new file +4
-0+return 0 ; + } + + if (!nfs_auth_info_add(&mnt->auth_info,pseudoflavor))
fs/nfs/fs_context.c new file +45
-0+return 0 ; + } + +return 1 ; +} + +static int nfs_parse_version_string (char *string, +struct nfs_parsed_mount_data *mnt, +substring_t *args) +{ + mnt->flags &= ~NFS_MOUNT_VER3 ; +switch (match_token (string, nfs_vers_tokens, args)) { +case Opt_vers_2: + mnt->version =2 ; +break ; +case Opt_vers_3: + mnt->flags |=NFS_MOUNT_VER3 ; + mnt->version =3 ; +break ; +case Opt_vers_4: +/* Backward compatibility option. In future, +* the mount program should always supply +* a NFSv4 minor version number. +*/ + mnt->version =4 ; +break ; +case Opt_vers_4_0: + mnt->version =4 ; + mnt->minorversion =0 ; +break ; +case Opt_vers_4_1: + mnt->version =4 ; + mnt->minorversion =1 ; +break ; +case Opt_vers_4_2: + mnt->version =4 ; + mnt->minorversion =2 ; +break ; +default : +return 0 ; + } +return 1 ; +} + +static int nfs_get_option_str(substring_t args[], char**option)
fs/nfs/fs_context.c new file +7
-0+{ +kfree (*option); + *option =match_strdup (args); +return !*option; +} + +static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/fs_context.c new file +14
-0+{ +int rc; +char *string; + + string =match_strdup (args); +if (string ==NULL ) +return -ENOMEM ; + rc =kstrtoul (string,10 , option); +kfree (string); + +return rc; +} + +static int nfs_get_option_ul_bound(substring_t args[],unsigned
long *option,fs/nfs/fs_context.c new file +14
-0+ unsigned long l_bound, unsigned long u_bound) +{ + int ret; + + ret =nfs_get_option_ul (args, option); +if (ret !=0 ) +return ret; +if (*option < l_bound || *option > u_bound) +return -ERANGE ; +return 0 ; +} + +/* +* Error-check and convert a string of mount options from user space into
+ * a data structure. The whole mount string is processed; bad options are
+ * skipped as they are encountered. If there were no errors, return 1;
+ * otherwise return 0 (zero).
+ */
+intnfs_parse_mount_options(char *raw, struct nfs_parsed_mount_data *mnt)fs/nfs/fs_context.c new file +8
-0+{ +char *p, *string; +int rc, sloppy =0 , invalid_option =0 ; +unsigned short protofamily =AF_UNSPEC ; +unsigned short mountfamily =AF_UNSPEC ; + +if (!raw) { + dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/fs_context.c new file +17
-0+return 1 ; + } +dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); + + rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); +if (rc) + goto out_security_failure; + +while ((p =strsep (&raw,"," )) !=NULL ) { +substring_t args[MAX_OPT_ARGS ]; +unsigned long option; +int token; + +if (!*p) +continue ; + + dfprintk(MOUNT, "NFS: parsing nfs mountoption
'%s'\n", p);fs/nfs/fs_context.c new file +2
-0+ + token = match_token(p, nfs_mount_option_tokens,args);
fs/nfs/fs_context.c new file +15
-0+switch (token) { + +/* +* boolean options: foo/nofoo +*/ +case Opt_soft: + mnt->flags |=NFS_MOUNT_SOFT ; + mnt->flags &= ~NFS_MOUNT_SOFTERR ; +break ; +case Opt_softerr: + mnt->flags |=NFS_MOUNT_SOFTERR ; + mnt->flags &= ~NFS_MOUNT_SOFT ; +break ; +case Opt_hard: + mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/fs_context.c new file +32
-0+break ; +case Opt_posix: + mnt->flags |=NFS_MOUNT_POSIX ; +break ; +case Opt_noposix: + mnt->flags &= ~NFS_MOUNT_POSIX ; +break ; +case Opt_cto: + mnt->flags &= ~NFS_MOUNT_NOCTO ; +break ; +case Opt_nocto: + mnt->flags |=NFS_MOUNT_NOCTO ; +break ; +case Opt_ac: + mnt->flags &= ~NFS_MOUNT_NOAC ; +break ; +case Opt_noac: + mnt->flags |=NFS_MOUNT_NOAC ; +break ; +case Opt_lock: + mnt->flags &= ~NFS_MOUNT_NONLM ; + mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_nolock: + mnt->flags |=NFS_MOUNT_NONLM ; + mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +break ; +case Opt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +4
-0+break ; +case Opt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_rdma: + mnt->flags |=NFS_MOUNT_TCP ;/* for side
protocols */fs/nfs/fs_context.c new file +1
-0+ mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/fs_context.c new file +69
-0+xprt_load_transport (p); +break ; +case Opt_acl: + mnt->flags &= ~NFS_MOUNT_NOACL ; +break ; +case Opt_noacl: + mnt->flags |=NFS_MOUNT_NOACL ; +break ; +case Opt_rdirplus: + mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_nordirplus: + mnt->flags |=NFS_MOUNT_NORDIRPLUS ; +break ; +case Opt_sharecache: + mnt->flags &= ~NFS_MOUNT_UNSHARED ; +break ; +case Opt_nosharecache: + mnt->flags |=NFS_MOUNT_UNSHARED ; +break ; +case Opt_resvport: + mnt->flags &= ~NFS_MOUNT_NORESVPORT ; +break ; +case Opt_noresvport: + mnt->flags |=NFS_MOUNT_NORESVPORT ; +break ; +case Opt_fscache: + mnt->options |=NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ; +kfree (mnt->fscache_uniq); + mnt->fscache_uniq =NULL ; +break ; +case Opt_migration: + mnt->options |=NFS_OPTION_MIGRATION ; +break ; +case Opt_nomigration: + mnt->options &= ~NFS_OPTION_MIGRATION ; +break ; + +/* +* options that take numeric values +*/ +case Opt_port: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->nfs_server.port = option; +break ; +case Opt_rsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->rsize = option; +break ; +case Opt_wsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->wsize = option; +break ; +case Opt_bsize: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->bsize = option; +break ; +case Opt_timeo: + if (nfs_get_option_ul_bound(args,&option, 1,
INT_MAX))fs/nfs/fs_context.c new file +5
-0+ goto out_invalid_value; + mnt->timeo = option; +break ; +case Opt_retrans: + if (nfs_get_option_ul_bound(args,&option, 0,
INT_MAX))fs/nfs/fs_context.c new file +63
-0+ goto out_invalid_value; + mnt->retrans = option; +break ; +case Opt_acregmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = option; +break ; +case Opt_acregmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmax = option; +break ; +case Opt_acdirmin: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmin = option; +break ; +case Opt_acdirmax: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acdirmax = option; +break ; +case Opt_actimeo: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->acregmin = mnt->acregmax = + mnt->acdirmin = mnt->acdirmax = option; +break ; +case Opt_namelen: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; + mnt->namlen = option; +break ; +case Opt_mountport: +if (nfs_get_option_ul (args, &option) || + option >USHRT_MAX ) + goto out_invalid_value; + mnt->mount_server.port = option; +break ; +case Opt_mountvers: +if (nfs_get_option_ul (args, &option) || + option <NFS_MNT_VERSION || + option >NFS_MNT3_VERSION ) + goto out_invalid_value; + mnt->mount_server.version = option; +break ; +case Opt_minorversion: +if (nfs_get_option_ul (args, &option)) + goto out_invalid_value; +if (option >NFS4_MAX_MINOR_VERSION ) + goto out_invalid_value; + mnt->minorversion = option; +break ; + +/* +* options that take text values +*/ +case Opt_nfsvers: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc = nfs_parse_version_string(string,mnt,
args);fs/nfs/fs_context.c new file +9
-0+kfree (string); +if (!rc) + goto out_invalid_value; +break ; +case Opt_sec: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + rc = nfs_parse_security_flavors(string,mnt);
fs/nfs/fs_context.c new file +3
-0+kfree (string); +if (!rc) { + dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/fs_context.c new file +1
-0+ "securityflavor\n");
fs/nfs/fs_context.c new file +9
-0+return 0 ; + } +break ; +case Opt_proto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_xprt_protocol_tokens,
args);fs/nfs/fs_context.c new file +9
-0+ + protofamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->flags &= ~NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +7
-0+break ; +case Opt_xprt_tcp6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +6
-0+break ; +case Opt_xprt_rdma6: + protofamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_rdma: +/* vector side protocols to TCP */
fs/nfs/fs_context.c new file +2
-0+ mnt->flags |=NFS_MOUNT_TCP ; + mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/fs_context.c new file +4
-0+xprt_load_transport (string); +break ; +default : + dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/fs_context.c new file +1
-0+ "transportprotocol\n");
fs/nfs/fs_context.c new file +11
-0+kfree (string); +return 0 ; + } +kfree (string); +break ; +case Opt_mountproto: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token =match_token (string, + nfs_xprt_protocol_tokens,
args);fs/nfs/fs_context.c new file +9
-0+kfree (string); + + mountfamily =AF_INET ; +switch (token) { +case Opt_xprt_udp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_udp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +6
-0+break ; +case Opt_xprt_tcp6: + mountfamily =AF_INET6 ; +/* fall through */ +case Opt_xprt_tcp: + mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/fs_context.c new file +2
-0+break ; +case Opt_xprt_rdma:/* not used for side
protocols */fs/nfs/fs_context.c new file +2
-0+default : + dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/fs_context.c new file +1
-0+ "transportprotocol\n");
fs/nfs/fs_context.c new file +9
-0+return 0 ; + } +break ; +case Opt_addr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->nfs_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +2
-0+ (struct sockaddr *) + &mnt-Quoted 1 line
nfs_server.address,
fs/nfs/fs_context.c new file +1
-0+ sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->nfs_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_clientaddr: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/fs_context.c new file +5
-0+ goto out_nomem; +break ; +case Opt_mounthost: + if (nfs_get_option_str(args, + &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; +break ; +case Opt_mountaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->mount_server.addrlen = + rpc_pton(mnt->net, string,strlen(string),
fs/nfs/fs_context.c new file +2
-0+ (struct sockaddr *) + &mnt-Quoted 1 line
mount_server.address,
fs/nfs/fs_context.c new file +1
-0+ sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/fs_context.c new file +6
-0+kfree (string); +if (mnt->mount_server.addrlen ==0 ) + goto out_invalid_address; +break ; +case Opt_nconnect: + if (nfs_get_option_ul_bound(args,&option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/fs_context.c new file +9
-0+ goto out_invalid_value; + mnt->nfs_server.nconnect = option; +break ; +case Opt_lookupcache: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string, + nfs_lookupcache_tokens,args);
fs/nfs/fs_context.c new file +4
-0+kfree (string); +switch (token) { +case Opt_lookupcache_all: + mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_positive: + mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +1
-0+ mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_lookupcache_none: + mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/fs_context.c new file +3
-0+break ; +default : + dfprintk(MOUNT,"NFS: invalid
"fs/nfs/fs_context.c new file +1
-0+ "lookupcache
argument\n");fs/nfs/fs_context.c new file +5
-0+return 0 ; + }; +break ; +case Opt_fscache_uniq: + if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/fs_context.c new file +8
-0+ goto out_nomem; + mnt->options |=NFS_OPTION_FSCACHE ; +break ; +case Opt_local_lock: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + token = match_token(string,
nfs_local_lock_tokens,fs/nfs/fs_context.c new file +5
-0+ args); +kfree (string); +switch (token) { +case Opt_local_lock_all: + mnt->flags |=(
NFS_MOUNT_LOCAL_FLOCK|fs/nfs/fs_context.c new file +1
-0+NFS_MOUNT_LOCAL_ FCNTL);
fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_local_lock_flock: + mnt->flags |=
NFS_MOUNT_LOCAL_FLOCK;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_local_lock_posix: + mnt->flags |=
NFS_MOUNT_LOCAL_FCNTL;fs/nfs/fs_context.c new file +3
-0+break ; +case Opt_local_lock_none: + mnt->flags &=~(NFS_MOUNT_LOCAL_FLOCK |
fs/nfs/fs_context.c new file +1
-0+NFS_MOUNT_LOCAL
_FCNTL);fs/nfs/fs_context.c new file +3
-0+break ; +default : + dfprintk(MOUNT, "NFS: invalid"fs/nfs/fs_context.c new file +1
-0+ "local_lockargument\n");
fs/nfs/fs_context.c new file +10
-0+return 0 ; + }; +break ; + +/* +* Special options +*/ +case Opt_sloppy: + sloppy =1 ; + dfprintk(MOUNT, "NFS: relaxingparsing
rules\n");fs/nfs/fs_context.c new file +4
-0+break ; +case Opt_userspace: +case Opt_deprecated: + dfprintk(MOUNT, "NFS: ignoring mountoption "
fs/nfs/fs_context.c new file +6
-0+ "'%s'\n", p); +break ; + +default : + invalid_option =1 ; + dfprintk(MOUNT, "NFS: unrecognizedmount
option "fs/nfs/fs_context.c new file +16
-0+ "'%s'\n", p); + } + } + +if (!sloppy && invalid_option) +return 0 ; + +if (mnt->minorversion && mnt->version !=4 ) + goto out_minorversion_mismatch; + +if (mnt->options &NFS_OPTION_MIGRATION && + (mnt->version !=4 || mnt->minorversion !=0 )) + goto out_migration_misuse; + +/* +* verify that any proto=/mountproto= options match the address
fs/nfs/fs_context.c new file +9
-0+* families in the addr=/mountaddr= options. +*/ +if (protofamily !=AF_UNSPEC && + protofamily != mnt->nfs_server.address.ss_family) + goto out_proto_mismatch; + + if (mountfamily != AF_UNSPEC) { + if (mnt->mount_server.addrlen) { + if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/fs_context.c new file +3
-0+ goto out_mountproto_mismatch; + } else { + if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/fs_context.c new file +8
-0+ goto out_mountproto_mismatch; + } + } + +return 1 ; + +out_mountproto_mismatch: + printk(KERN_INFO "NFS: mount server address does notmatch
mountproto= "fs/nfs/fs_context.c new file +4
-0+ "option\n"); +return 0 ; +out_proto_mismatch: + printk(KERN_INFO "NFS: server address does not matchproto=
option\n");fs/nfs/fs_context.c new file +3
-0+return 0 ; +out_invalid_address: + printk(KERN_INFO "NFS: bad IP address specified: %s\n",p);
fs/nfs/fs_context.c new file +3
-0+return 0 ; +out_invalid_value: + printk(KERN_INFO "NFS: bad mount option valuespecified: %s\n",
p);fs/nfs/fs_context.c new file +3
-0+return 0 ; +out_minorversion_mismatch: + printk(KERN_INFO "NFS: mount option vers=%u does notsupport "
fs/nfs/fs_context.c new file +1
-0+ "minorversion=%u\n", mnt->version,mnt-
Quoted 1 line
minorversion);
fs/nfs/fs_context.c new file +4
-0+return 0 ; +out_migration_misuse: +printk (KERN_INFO + "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/fs_context.c new file +3
-0+return 0 ; +out_nomem: + printk(KERN_INFO "NFS: not enough memory to parseoption\n");
fs/nfs/fs_context.c new file +3
-0+return 0 ; +out_security_failure: + printk(KERN_INFO "NFS: security options invalid: %d\n",rc);
fs/nfs/fs_context.c new file +7
-0+return 0 ; +} + +/* +* Split "dev_name" into "hostname:export_path". +* +* The leftmost colon demarks the split between the server's hostname
+ * and the export path. If the hostname starts with a left square
+ * bracket, then it may contain colons.
+ *
+ * Note: caller frees hostname and export path, even on error.
+ */fs/nfs/fs_context.c new file +3
-0+static int nfs_parse_devname (const char *dev_name, +char **hostname,size_t maxnamlen, + char **export_path, size_tmaxpathlen)
fs/nfs/fs_context.c new file +6
-0+{ +size_t len; +char *end; + +if (unlikely (!dev_name || !*dev_name)) { + dfprintk(MOUNT, "NFS: device name notspecified\n");
fs/nfs/fs_context.c new file +20
-0+return -EINVAL ; + } + +/* Is the host name protected with square brakcets? */ +if (*dev_name =='[' ) { + end =strchr (++dev_name,']' ); +if (end ==NULL || end[1 ] !=':' ) + goto out_bad_devname; + + len = end - dev_name; + end++; + }else { +char *comma; + + end =strchr (dev_name,':' ); +if (end ==NULL ) + goto out_bad_devname; + len = end - dev_name; + +/* kill possible hostname list: not supported */
fs/nfs/fs_context.c new file +9
-0+ comma =strchr (dev_name,',' ); +if (comma !=NULL && comma < end) + len = comma - dev_name; + } + +if (len > maxnamlen) + goto out_hostname; + +/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/fs_context.c new file +15
-0+ *hostname =kstrndup (dev_name, len,GFP_KERNEL ); +if (*hostname ==NULL ) + goto out_nomem; + len =strlen (++end); +if (len > maxpathlen) + goto out_path; + *export_path =kstrndup (end, len,GFP_KERNEL ); +if (!*export_path) + goto out_nomem; + +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); +return 0 ; + +out_bad_devname: + dfprintk(MOUNT, "NFS: device name not in host:pathformat\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/fs_context.c new file +16
-0+return -ENOMEM ; + +out_hostname: +dfprintk (MOUNT ,"NFS: server hostname too long\n" ); +return -ENAMETOOLONG ; + +out_path: +dfprintk (MOUNT ,"NFS: export pathname too long\n" ); +return -ENAMETOOLONG ; +} + +/* +* Validate the NFS2/NFS3 mount data +* - fills in the mount root filehandle +* +* For option strings, user space handles the following behaviors:
+ *
+ * + DNS: mapping server host name to IP address ("addr=" option)
+ *
+ * + failure mode: how to behave if a mount request can't be handled
+ * immediately ("fg/bg" option)
+ *
+ * + retry: how often to retry a mount request ("retry=" option)
+ *
+ * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
+ * mountproto=tcp after mountproto=udp, and so on
+ */fs/nfs/fs_context.c new file +2
-0+static int nfs23_validate_mount_data(void *options, + struct
nfs_parsed_mount_data
*args,fs/nfs/fs_context.c new file +4
-0+ struct nfs_fh *mntfh, + const char *dev_name) +{ + struct nfs_mount_data *data = (struct nfs_mount_data*)options;
fs/nfs/fs_context.c new file +1
-0+ struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +16
-0+int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; + +if (data ==NULL ) + goto out_no_data; + + args->version =NFS_DEFAULT_VERSION ; +switch (data->version) { +case 1 : + data->namlen =0 ;/* fall through */ +case 2 : + data->bsize =0 ;/* fall through */ +case 3 : +if (data->flags &NFS_MOUNT_VER3 ) + goto out_no_v3; + data->root.size =NFS2_FHSIZE ; + memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/fs_context.c new file +9
-0+/* Turn off security negotiation */ + extra_flags |=NFS_MOUNT_SECFLAVOUR ; +/* fall through */ +case 4 : +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + goto out_no_sec; +/* fall through */ +case 5 : + memset(data->context, 0, sizeof(data-Quoted 1 line
context));
fs/nfs/fs_context.c new file +4
-0+/* fall through */ +case 6 : +if (data->flags &NFS_MOUNT_VER3 ) { + if (data->root.size > NFS3_FHSIZE ||data-
Quoted 1 line
root.size == 0)
fs/nfs/fs_context.c new file +10
-0+ goto out_invalid_fh; + mntfh->size = data->root.size; + args->version =3 ; + }else { + mntfh->size =NFS2_FHSIZE ; + args->version =2 ; + } + + + memcpy(mntfh->data, data->root.data, mntfh-Quoted 1 line
size);
fs/nfs/fs_context.c new file +3
-0+if (mntfh->size <sizeof (mntfh->data)) + memset(mntfh->data + mntfh->size, 0, + sizeof(mntfh->data) - mntfh-Quoted 1 line
size);
fs/nfs/fs_context.c new file +3
-0+ +/* +* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/fs_context.c new file +3
-0+* can deal with. +*/ + args->flags = data->flags &
NFS_MOUNT_FLAGMASK;fs/nfs/fs_context.c new file +14
-0+ args->flags |= extra_flags; + args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->need_mount = false; + +memcpy (sap, &data->addr,sizeof (data->addr)); + args->nfs_server.addrlen =sizeof (data->addr); + args->nfs_server.port = ntohs(data-Quoted 1 line
addr.sin_port);
fs/nfs/fs_context.c new file +6
-0+if (sap->sa_family !=AF_INET || + !nfs_verify_server_address (sap)) + goto out_no_address; + +if (!(data->flags &NFS_MOUNT_TCP )) + args->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/fs_context.c new file +1
-0+/* N.B. caller will free nfs_server.hostname in all
cases */fs/nfs/fs_context.c new file +1
-0+ args->nfs_server.hostname = kstrdup(data-Quoted 1 line
hostname,
GFP_KERNEL);fs/nfs/fs_context.c new file +5
-0+ args->namlen = data->namlen; + args->bsize = data->bsize; + +if (data->flags &NFS_MOUNT_SECFLAVOUR ) + args->selected_flavor = data-Quoted 1 line
pseudoflavor;
fs/nfs/fs_context.c new file +8
-0+else + args->selected_flavor =RPC_AUTH_UNIX ; +if (!args->nfs_server.hostname) + goto out_nomem; + +if (!(data->flags &NFS_MOUNT_NONLM )) + args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL );
fs/nfs/fs_context.c new file +5
-0+else + args->flags |= (NFS_MOUNT_LOCAL_FLOCK | +NFS_MOUNT_LOCAL_FCNTL ); +/* +* The legacy version 6 binary mount data from userspace has a
fs/nfs/fs_context.c new file +1
-0+* field used only to transport selinux information
into thefs/nfs/fs_context.c new file +1
-0+* the kernel. To continue to support that functionality we
fs/nfs/fs_context.c new file +1
-0+* have a touch of selinux knowledge here in the NFS
code. Thefs/nfs/fs_context.c new file +1
-0+* userspace code converted context=blah to just blah
so we arefs/nfs/fs_context.c new file +1
-0+* converting back to the full string selinux understands.
fs/nfs/fs_context.c new file +5
-0+*/ +if (data->context[0 ]){ +#ifdef CONFIG_SECURITY_SELINUX +int rc; + data->context[NFS_MAX_CONTEXT_LEN] ='\0';
fs/nfs/fs_context.c new file +1
-0+ rc = security_add_mnt_opt("context",data-
Quoted 1 line
context,
fs/nfs/fs_context.c new file +1
-0+ strlen(data->context),&args-
Quoted 1 line
lsm_opts);fs/nfs/fs_context.c new file +16
-0+if (rc) +return rc; +#else +return -EINVAL ; +#endif + } + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS: mount program didn't pass anymount
data\n");fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_no_v3: + dfprintk(MOUNT, "NFS: nfs_mount_data version %d doesnot
support v3\n",fs/nfs/fs_context.c new file +5
-0+ data->version); +return -EINVAL ; + +out_no_sec: + dfprintk(MOUNT, "NFS: nfs_mount_data version supportsonly
AUTH_SYS\n");fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_nomem: + dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/fs_context.c new file +4
-0+return -ENOMEM ; + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +10
-0+return -EINVAL ; + +out_invalid_fh: +dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); +return -EINVAL ; +} + +#if IS_ENABLED (CONFIG_NFS_V4 ) + +static void nfs4_validate_mount_flags(struct
nfs_parsed_mount_data
*args)fs/nfs/fs_context.c new file +2
-0+{ + args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/fs_context.c new file +1
-0+NFS_MOUNT_LOCAL_FLOCK |NFS_MOUNT_LOCAL_ FCNTL);
fs/nfs/fs_context.c new file +7
-0+} + +/* +* Validate NFSv4 mount options +*/ +static int nfs4_validate_mount_data(void *options, + struct
nfs_parsed_mount_data*args,fs/nfs/fs_context.c new file +3
-0+ const char *dev_name) +{ + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +1
-0+ struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/fs_context.c new file +10
-0+char *c; + +if (data ==NULL ) + goto out_no_data; + + args->version =4 ; + +switch (data->version) { +case 1 : + if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/fs_context.c new file +5
-0+ goto out_no_address; +if (data->host_addrlen ==0 ) + goto out_no_address; + args->nfs_server.addrlen = data->host_addrlen; + if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/fs_context.c new file +4
-0+return -EFAULT ; +if (!nfs_verify_server_address (sap)) + goto out_no_address; + args->nfs_server.port = ntohs(((struct
sockaddr_in
*)sap)->sin_port);fs/nfs/fs_context.c new file +8
-0+ +if (data->auth_flavourlen) { +rpc_authflavor_t pseudoflavor; +if (data->auth_flavourlen >1 ) + goto out_inval_auth; + if (copy_from_user(&pseudoflavor, + data->auth_flavours, + sizeof(pseudoflavor)))
fs/nfs/fs_context.c new file +6
-0+return -EFAULT ; + args->selected_flavor = pseudoflavor; + }else + args->selected_flavor =RPC_AUTH_UNIX ; + + c = strndup_user(data->hostname.data,
NFS4_MAXNAMLEN);fs/nfs/fs_context.c new file +5
-0+if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.hostname = c; + + c = strndup_user(data->mnt_path.data,
NFS4_MAXPATHLEN);fs/nfs/fs_context.c new file +12
-0+if (IS_ERR (c)) +return PTR_ERR (c); + args->nfs_server.export_path = c; +dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); + + c =strndup_user (data->client_addr.data,16 ); +if (IS_ERR (c)) +return PTR_ERR (c); + args->client_address = c; + +/* +* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/fs_context.c new file +4
-0+* can deal with. +*/ + + args->flags = data->flags &
NFS4_MOUNT_FLAGMASK;fs/nfs/fs_context.c new file +11
-0+ args->rsize = data->rsize; + args->wsize = data->wsize; + args->timeo = data->timeo; + args->retrans = data->retrans; + args->acregmin = data->acregmin; + args->acregmax = data->acregmax; + args->acdirmin = data->acdirmin; + args->acdirmax = data->acdirmax; + args->nfs_server.protocol = data->proto; +nfs_validate_transport_protocol (args); + if (args->nfs_server.protocol ==
XPRT_TRANSPORT_UDP)fs/nfs/fs_context.c new file +11
-0+ goto out_invalid_transport_udp; + +break ; +default : +return NFS_TEXT_DATA ; + } + +return 0 ; + +out_no_data: + dfprintk(MOUNT, "NFS4: mount program didn't pass anymount
data\n");fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_inval_auth: + dfprintk(MOUNT, "NFS4: Invalid number of RPC authflavours
%d\n",fs/nfs/fs_context.c new file +5
-0+ data->auth_flavourlen); +return -EINVAL ; + +out_no_address: + dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +4
-0+return -EINVAL ; + +out_invalid_transport_udp: + dfprintk(MOUNT, "NFSv4: Unsupported transport protocoludp\n");
fs/nfs/fs_context.c new file +11
-0+return -EINVAL ; +} + +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ +if (fs_type == &nfs_fs_type) + return nfs23_validate_mount_data(options, args,mntfh,
dev_name);fs/nfs/fs_context.c new file +1
-0+ return nfs4_validate_mount_data(options, args,
dev_name);fs/nfs/fs_context.c new file +9
-0+} +#else +int nfs_validate_mount_data (struct file_system_type *fs_type, +void *options, +struct nfs_parsed_mount_data *args, +struct nfs_fh *mntfh, +const char *dev_name) +{ + return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/fs_context.c new file +5
-0+} +#endif + +int nfs_validate_text_mount_data (void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/fs_context.c new file +6
-0+ const char *dev_name) +{ +int port =0 ; +int max_namelen =PAGE_SIZE ; +int max_pathlen =NFS_MAXPATHLEN ; + struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/fs_context.c new file +2
-0+ + if (nfs_parse_mount_options((char *)options, args) ==0)
fs/nfs/fs_context.c new file +8
-0+return -EINVAL ; + +if (!nfs_verify_server_address (sap)) + goto out_no_address; + +if (args->version ==4 ) { +#if IS_ENABLED (CONFIG_NFS_V4 ) + if (args->nfs_server.protocol ==
XPRT_TRANSPORT_RDMA)fs/nfs/fs_context.c new file +7
-0+ port =NFS_RDMA_PORT ; + else + port =NFS_PORT ; + max_namelen =NFS4_MAXNAMLEN ; + max_pathlen =NFS4_MAXPATHLEN ; +nfs_validate_transport_protocol (args); + if (args->nfs_server.protocol ==
XPRT_TRANSPORT_UDP)fs/nfs/fs_context.c new file +8
-0+ goto out_invalid_transport_udp; +nfs4_validate_mount_flags (args); +#else + goto out_v4_not_compiled; +#endif /* CONFIG_NFS_V4 */ + }else { +nfs_set_mount_transport_protocol (args); + if (args->nfs_server.protocol ==
XPRT_TRANSPORT_RDMA)fs/nfs/fs_context.c new file +9
-0+ port =NFS_RDMA_PORT ; + } + +nfs_set_port (sap, &args->nfs_server.port, port); + + return nfs_parse_devname(dev_name, + &args->nfs_server.hostname, + max_namelen, + &args-Quoted 1 line
nfs_server.export_path,
fs/nfs/fs_context.c new file +5
-0+ max_pathlen); + +#if !IS_ENABLED (CONFIG_NFS_V4 ) +out_v4_not_compiled: + dfprintk(MOUNT, "NFS: NFSv4 is not compiled intokernel\n");
fs/nfs/fs_context.c new file +4
-0+return -EPROTONOSUPPORT ; +#else +out_invalid_transport_udp: + dfprintk(MOUNT, "NFSv4: Unsupported transport protocoludp\n");
fs/nfs/fs_context.c new file +5
-0+return -EINVAL ; +#endif /* !CONFIG_NFS_V4 */ + +out_no_address: + dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/fs_context.c new file +2
-0+return -EINVAL ; +}fs/nfs/internal.h +8
-0@@ -7,6 +7,7 @@#include <linux/mount.h> #include <linux/security.h> #include <linux/crc32.h> +#include <linux/sunrpc/addr.h> #include <linux/nfs_page.h> #include <linux/wait_bit.h> @@ -232,6 +233,22 @@ extern const struct svc_version nfs4_callback_version1;extern const struct svc_version nfs4_callback_version4;struct nfs_pageio_descriptor ; + +/* mount.c */ +#define NFS_TEXT_DATA 1 + +extern struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void ); +extern void nfs_free_parsed_mount_data (struct nfs_parsed_mount_data *data); +extern int nfs_parse_mount_options(char *raw, struct
nfs_parsed_mount_data*mnt);
+extern int nfs_validate_mount_data(structfile_system_type*fs_type,fs/nfs/internal.h +2
-0+void *options, + struct nfs_parsed_mount_data*args,
fs/nfs/internal.h +4
-0+struct nfs_fh *mntfh, + const char *dev_name); +extern int nfs_validate_text_mount_data(void *options, + struct
nfs_parsed_mount_data
*args,fs/nfs/internal.h +2
-0+ const char *dev_name); +/*
pagelist.c*/
extern int__initnfs_init_nfspagecache(void);
extern voidnfs_destroy_nfspagecache(void);fs/nfs/internal.h +2
-0@@ -763,3 +780,15 @@ static inline bool nfs_error_is_fatal(int err) } } +/* +* Select between a default port value and a user-specified port
value.
+ * If a zero value is set, then autobind will be used.
+ */
+static inline void nfs_set_port(struct sockaddr *sap, int *port,fs/nfs/internal.h +1
-0+ const unsigned short
default_port)fs/nfs/internal.h +6
-0+{ +if (*port ==NFS_UNSPEC_PORT ) + *port = default_port; + +rpc_set_port (sap, *port); +}fs/nfs/super.c +0
-122@@ -69,229 +69,6 @@#include "nfs.h" #define NFSDBG_FACILITY NFSDBG_VFS -#define NFS_TEXT_DATA 1 - -#if IS_ENABLED (CONFIG_NFS_V3 ) -#define NFS_DEFAULT_VERSION 3 -#else -#define NFS_DEFAULT_VERSION 2 -#endif - -#define NFS_MAX_CONNECTIONS 16 - -enum { -/* Mount options that take no arguments */ - Opt_soft, Opt_softerr, Opt_hard, - Opt_posix, Opt_noposix, - Opt_cto, Opt_nocto, - Opt_ac, Opt_noac, - Opt_lock, Opt_nolock, - Opt_udp, Opt_tcp, Opt_rdma, - Opt_acl, Opt_noacl, - Opt_rdirplus, Opt_nordirplus, - Opt_sharecache, Opt_nosharecache, - Opt_resvport, Opt_noresvport, - Opt_fscache, Opt_nofscache, - Opt_migration, Opt_nomigration, - -/* Mount options that take integer arguments */ - Opt_port, - Opt_rsize, Opt_wsize, Opt_bsize, - Opt_timeo, Opt_retrans, - Opt_acregmin, Opt_acregmax, - Opt_acdirmin, Opt_acdirmax, - Opt_actimeo, - Opt_namelen, - Opt_mountport, - Opt_mountvers, - Opt_minorversion, - -/* Mount options that take string arguments */ - Opt_nfsvers, - Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, - Opt_nconnect, - Opt_lookupcache, - Opt_fscache_uniq, - Opt_local_lock, - -/* Special mount options */ - Opt_userspace, Opt_deprecated, Opt_sloppy, - - Opt_err -}; - -static const match_table_t nfs_mount_option_tokens = { - { Opt_userspace,"bg" }, - { Opt_userspace,"fg" }, - { Opt_userspace,"retry=%s" }, - - { Opt_sloppy,"sloppy" }, - - { Opt_soft,"soft" }, - { Opt_softerr,"softerr" }, - { Opt_hard,"hard" }, - { Opt_deprecated,"intr" }, - { Opt_deprecated,"nointr" }, - { Opt_posix,"posix" }, - { Opt_noposix,"noposix" }, - { Opt_cto,"cto" }, - { Opt_nocto,"nocto" }, - { Opt_ac,"ac" }, - { Opt_noac,"noac" }, - { Opt_lock,"lock" }, - { Opt_nolock,"nolock" }, - { Opt_udp,"udp" }, - { Opt_tcp,"tcp" }, - { Opt_rdma,"rdma" }, - { Opt_acl,"acl" }, - { Opt_noacl,"noacl" }, - { Opt_rdirplus,"rdirplus" }, - { Opt_nordirplus,"nordirplus" }, - { Opt_sharecache,"sharecache" }, - { Opt_nosharecache,"nosharecache" }, - { Opt_resvport,"resvport" }, - { Opt_noresvport,"noresvport" }, - { Opt_fscache,"fsc" }, - { Opt_nofscache,"nofsc" }, - { Opt_migration,"migration" }, - { Opt_nomigration,"nomigration" }, - - { Opt_port,"port=%s" }, - { Opt_rsize,"rsize=%s" }, - { Opt_wsize,"wsize=%s" }, - { Opt_bsize,"bsize=%s" }, - { Opt_timeo,"timeo=%s" }, - { Opt_retrans,"retrans=%s" }, - { Opt_acregmin,"acregmin=%s" }, - { Opt_acregmax,"acregmax=%s" }, - { Opt_acdirmin,"acdirmin=%s" }, - { Opt_acdirmax,"acdirmax=%s" }, - { Opt_actimeo,"actimeo=%s" }, - { Opt_namelen,"namlen=%s" }, - { Opt_mountport,"mountport=%s" }, - { Opt_mountvers,"mountvers=%s" }, - { Opt_minorversion,"minorversion=%s" }, - - { Opt_nfsvers,"nfsvers=%s" }, - { Opt_nfsvers,"vers=%s" }, - - { Opt_sec,"sec=%s" }, - { Opt_proto,"proto=%s" }, - { Opt_mountproto,"mountproto=%s" }, - { Opt_addr,"addr=%s" }, - { Opt_clientaddr,"clientaddr=%s" }, - { Opt_mounthost,"mounthost=%s" }, - { Opt_mountaddr,"mountaddr=%s" }, - - { Opt_nconnect,"nconnect=%s" }, - - { Opt_lookupcache,"lookupcache=%s" }, - { Opt_fscache_uniq,"fsc=%s" }, - { Opt_local_lock,"local_lock=%s" }, - -/* The following needs to be listed after all other options */
fs/nfs/super.c +0
-7- { Opt_nfsvers, "v%s" }, - - { Opt_err, NULL } -}; - -enum { - Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp,
Opt_xprt_tcp6,Opt_xprt_rdma,fs/nfs/super.c +0
-63- Opt_xprt_rdma6, - - Opt_xprt_err -}; - -static const match_table_t nfs_xprt_protocol_tokens = { - { Opt_xprt_udp,"udp" }, - { Opt_xprt_udp6,"udp6" }, - { Opt_xprt_tcp,"tcp" }, - { Opt_xprt_tcp6,"tcp6" }, - { Opt_xprt_rdma,"rdma" }, - { Opt_xprt_rdma6,"rdma6" }, - - { Opt_xprt_err,NULL } -}; - -enum { - Opt_sec_none, Opt_sec_sys, - Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, - Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, - Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, - - Opt_sec_err -}; - -static const match_table_t nfs_secflavor_tokens = { - { Opt_sec_none,"none" }, - { Opt_sec_none,"null" }, - { Opt_sec_sys,"sys" }, - - { Opt_sec_krb5,"krb5" }, - { Opt_sec_krb5i,"krb5i" }, - { Opt_sec_krb5p,"krb5p" }, - - { Opt_sec_lkey,"lkey" }, - { Opt_sec_lkeyi,"lkeyi" }, - { Opt_sec_lkeyp,"lkeyp" }, - - { Opt_sec_spkm,"spkm3" }, - { Opt_sec_spkmi,"spkm3i" }, - { Opt_sec_spkmp,"spkm3p" }, - - { Opt_sec_err,NULL } -}; - -enum { - Opt_lookupcache_all, Opt_lookupcache_positive, - Opt_lookupcache_none, - - Opt_lookupcache_err -}; - -static match_table_t nfs_lookupcache_tokens = { - { Opt_lookupcache_all,"all" }, - { Opt_lookupcache_positive,"pos" }, - { Opt_lookupcache_positive,"positive" }, - { Opt_lookupcache_none,"none" }, - - { Opt_lookupcache_err,NULL } -}; - -enum { - Opt_local_lock_all, Opt_local_lock_flock,
Opt_local_lock_posix,fs/nfs/super.c +0
-31- Opt_local_lock_none, - - Opt_local_lock_err -}; - -static match_table_t nfs_local_lock_tokens = { - { Opt_local_lock_all,"all" }, - { Opt_local_lock_flock,"flock" }, - { Opt_local_lock_posix,"posix" }, - { Opt_local_lock_none,"none" }, - - { Opt_local_lock_err,NULL } -}; - -enum { - Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0, - Opt_vers_4_1, Opt_vers_4_2, - - Opt_vers_err -}; - -static match_table_t nfs_vers_tokens = { - { Opt_vers_2,"2" }, - { Opt_vers_3,"3" }, - { Opt_vers_4,"4" }, - { Opt_vers_4_0,"4.0" }, - { Opt_vers_4_1,"4.1" }, - { Opt_vers_4_2,"4.2" }, - - { Opt_vers_err,NULL } -};static struct dentry *nfs_prepared_mount(struct
file_system_type*fs_type,
int flags, const char*dev_name, void*raw_data);fs/nfs/super.c +0
-1@@ -332,10 +109,6 @@ const struct super_operations nfs_sops = {EXPORT_SYMBOL_GPL (nfs_sops);#if IS_ENABLED (CONFIG_NFS_V4 ) -static void nfs4_validate_mount_flags(struct
nfs_parsed_mount_data
*);fs/nfs/super.c +0
-2-static int nfs4_validate_mount_data (void *options, - struct nfs_parsed_mount_data *args, const char
*dev_name);
-struct file_system_type nfs4_fs_type = { .owner = THIS_MODULE, .name = "nfs4",fs/nfs/super.c +0
-25@@ -932,141 +705,6 @@ void nfs_umount_begin(struct super_block *sb) }EXPORT_SYMBOL_GPL (nfs_umount_begin); -static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data (void) -{ -struct nfs_parsed_mount_data *data; - - data =kzalloc (sizeof (*data),GFP_KERNEL ); -if (data) { - data->timeo =NFS_UNSPEC_TIMEO ; - data->retrans =NFS_UNSPEC_RETRANS ; - data->acregmin =NFS_DEF_ACREGMIN ; - data->acregmax =NFS_DEF_ACREGMAX ; - data->acdirmin =NFS_DEF_ACDIRMIN ; - data->acdirmax =NFS_DEF_ACDIRMAX ; - data->mount_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.port =NFS_UNSPEC_PORT ; - data->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - data->selected_flavor =RPC_AUTH_MAXFLAVOR ; - data->minorversion =0 ; - data->need_mount = true; - data->net = current->nsproxy- >net_ns; - data->lsm_opts =NULL ; - } -return data; -} - -static void nfs_free_parsed_mount_data(struct
nfs_parsed_mount_data*data)fs/nfs/super.c +0
-14-{ -if (data) { -kfree (data->client_address); -kfree (data->mount_server.hostname); -kfree (data->nfs_server.export_path); -kfree (data->nfs_server.hostname); -kfree (data->fscache_uniq); -security_free_mnt_opts (&data->lsm_opts); -kfree (data); - } -} - -/* -* Sanity-check a server address provided by the mount command.
- *
- * Address family must be initialized, and address must not be
- * the ANY address for that family.
- */fs/nfs/super.c +0
-5-static int nfs_verify_server_address (struct sockaddr *addr) -{ -switch (addr->sa_family) { -case AF_INET : { - struct sockaddr_in *sa = (struct sockaddr_in*)addr;
fs/nfs/super.c +0
-1- return sa->sin_addr.s_addr !=
htonl(INADDR_ANY);fs/nfs/super.c +0
-3- } -case AF_INET6 : { - struct in6_addr *sa = &((struct sockaddr_in6*)addr)-
Quoted 1 line
sin6_addr;fs/nfs/super.c +0
-10-return !ipv6_addr_any (sa); - } - } - -dfprintk (MOUNT ,"NFS: Invalid IP address specified\n" ); -return 0 ; -} - -/* -* Select between a default port value and a user-specified port
value.
- * If a zero value is set, then autobind will be used.
- */fs/nfs/super.c +0
-2-static void nfs_set_port (struct sockaddr *sap,int *port, - const unsigned short
default_port)fs/nfs/super.c +0
-12-{ -if (*port ==NFS_UNSPEC_PORT ) - *port = default_port; - -rpc_set_port (sap, *port); -} - -/* -* Sanity check the NFS transport protocol. -* -*/ -static void nfs_validate_transport_protocol(struct
nfs_parsed_mount_data*mnt)fs/nfs/super.c +0
-13-{ -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : -break ; -default : - mnt->nfs_server.protocol =XPRT_TRANSPORT_TCP ; - } -} - -/* -* For text based NFSv2/v3 mounts, the mount protocol transport
default
- * settings should depend upon the specified NFS transport.
- */
-static voidnfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)fs/nfs/super.c +0
-9-{ -nfs_validate_transport_protocol (mnt); - -if (mnt->mount_server.protocol ==XPRT_TRANSPORT_UDP || - mnt->mount_server.protocol ==XPRT_TRANSPORT_TCP ) -return ; -switch (mnt->nfs_server.protocol) { -case XPRT_TRANSPORT_UDP : - mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-4-break ; -case XPRT_TRANSPORT_TCP : -case XPRT_TRANSPORT_RDMA : - mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-6- } -} - -/* -* Add 'flavor' to 'auth_info' if not already present. -* Returns true if 'flavor' ends up in the list, false otherwise
- */fs/nfs/super.c +0
-5-static bool nfs_auth_info_add (struct nfs_auth_info *auth_info, -rpc_authflavor_t flavor) -{ -unsigned int i; - unsigned int max_flavor_len = ARRAY_SIZE(auth_info-Quoted 1 line
flavors);
fs/nfs/super.c +0
-9- -/* make sure this flavor isn't already in the list */ -for (i =0 ; i < auth_info->flavor_len; i++) { -if (flavor == auth_info->flavors[i]) -return true; - } - -if (auth_info->flavor_len +1 >= max_flavor_len) { - dfprintk(MOUNT, "NFS: too many sec=flavors\n");
fs/nfs/super.c +0
-7-return false; - } - - auth_info->flavors[auth_info->flavor_len++] = flavor; -return true; -} -/*
* Return true if 'match' is inauth_infoorauth_infois
empty.
* Return false otherwise.fs/nfs/super.c +0
-5@@ -1087,627 +725,6 @@ bool nfs_auth_info_match(const structnfs_auth_info *auth_info, }EXPORT_SYMBOL_GPL (nfs_auth_info_match ); -/* -* Parse the value of the 'sec=' option. -*/ -static int nfs_parse_security_flavors(char *value, - struct
nfs_parsed_mount_data
*mnt)fs/nfs/super.c +0
-9-{ -substring_t args[MAX_OPT_ARGS ]; -rpc_authflavor_t pseudoflavor; -char *p; - -dfprintk (MOUNT ,"NFS: parsing sec=%s option\n" , value); - -while ((p =strsep (&value,":" )) !=NULL ) { - switch (match_token(p, nfs_secflavor_tokens,args)) {
fs/nfs/super.c +0
-36-case Opt_sec_none: - pseudoflavor =RPC_AUTH_NULL ; -break ; -case Opt_sec_sys: - pseudoflavor =RPC_AUTH_UNIX ; -break ; -case Opt_sec_krb5: - pseudoflavor =RPC_AUTH_GSS_KRB5 ; -break ; -case Opt_sec_krb5i: - pseudoflavor =RPC_AUTH_GSS_KRB5I ; -break ; -case Opt_sec_krb5p: - pseudoflavor =RPC_AUTH_GSS_KRB5P ; -break ; -case Opt_sec_lkey: - pseudoflavor =RPC_AUTH_GSS_LKEY ; -break ; -case Opt_sec_lkeyi: - pseudoflavor =RPC_AUTH_GSS_LKEYI ; -break ; -case Opt_sec_lkeyp: - pseudoflavor =RPC_AUTH_GSS_LKEYP ; -break ; -case Opt_sec_spkm: - pseudoflavor =RPC_AUTH_GSS_SPKM ; -break ; -case Opt_sec_spkmi: - pseudoflavor =RPC_AUTH_GSS_SPKMI ; -break ; -case Opt_sec_spkmp: - pseudoflavor =RPC_AUTH_GSS_SPKMP ; -break ; -default : - dfprintk(MOUNT, - "NFS: sec= option '%s' notrecognized\n", p);
fs/nfs/super.c +0
-4-return 0 ; - } - - if (!nfs_auth_info_add(&mnt->auth_info,pseudoflavor))
fs/nfs/super.c +0
-45-return 0 ; - } - -return 1 ; -} - -static int nfs_parse_version_string (char *string, -struct nfs_parsed_mount_data *mnt, -substring_t *args) -{ - mnt->flags &= ~NFS_MOUNT_VER3 ; -switch (match_token (string, nfs_vers_tokens, args)) { -case Opt_vers_2: - mnt->version =2 ; -break ; -case Opt_vers_3: - mnt->flags |=NFS_MOUNT_VER3 ; - mnt->version =3 ; -break ; -case Opt_vers_4: -/* Backward compatibility option. In future, -* the mount program should always supply -* a NFSv4 minor version number. -*/ - mnt->version =4 ; -break ; -case Opt_vers_4_0: - mnt->version =4 ; - mnt->minorversion =0 ; -break ; -case Opt_vers_4_1: - mnt->version =4 ; - mnt->minorversion =1 ; -break ; -case Opt_vers_4_2: - mnt->version =4 ; - mnt->minorversion =2 ; -break ; -default : -return 0 ; - } -return 1 ; -} - -static int nfs_get_option_str(substring_t args[], char**option)
fs/nfs/super.c +0
-7-{ -kfree (*option); - *option =match_strdup (args); -return !*option; -} - -static int nfs_get_option_ul(substring_t args[], unsigned long*option)
fs/nfs/super.c +0
-14-{ -int rc; -char *string; - - string =match_strdup (args); -if (string ==NULL ) -return -ENOMEM ; - rc =kstrtoul (string,10 , option); -kfree (string); - -return rc; -} - -static int nfs_get_option_ul_bound(substring_t args[],unsigned
long *option,fs/nfs/super.c +0
-14- unsigned long l_bound, unsigned long u_bound) -{ - int ret; - - ret =nfs_get_option_ul (args, option); -if (ret !=0 ) -return ret; -if (*option < l_bound || *option > u_bound) -return -ERANGE ; -return 0 ; -} - -/* -* Error-check and convert a string of mount options from user space into
- * a data structure. The whole mount string is processed; bad options are
- * skipped as they are encountered. If there were no errors, return 1;
- * otherwise return 0 (zero).
- */fs/nfs/super.c +0
-2-static int nfs_parse_mount_options (char *raw, - struct nfs_parsed_mount_data*mnt)
fs/nfs/super.c +0
-8-{ -char *p, *string; -int rc, sloppy =0 , invalid_option =0 ; -unsigned short protofamily =AF_UNSPEC ; -unsigned short mountfamily =AF_UNSPEC ; - -if (!raw) { - dfprintk(MOUNT, "NFS: mount options string wasNULL.\n");
fs/nfs/super.c +0
-17-return 1 ; - } -dfprintk (MOUNT ,"NFS: nfs mount opts='%s'\n" , raw); - - rc =security_sb_eat_lsm_opts (raw, &mnt->lsm_opts); -if (rc) - goto out_security_failure; - -while ((p =strsep (&raw,"," )) !=NULL ) { -substring_t args[MAX_OPT_ARGS ]; -unsigned long option; -int token; - -if (!*p) -continue ; - - dfprintk(MOUNT, "NFS: parsing nfs mountoption
'%s'\n", p);fs/nfs/super.c +0
-2- - token = match_token(p, nfs_mount_option_tokens,args);
fs/nfs/super.c +0
-15-switch (token) { - -/* -* boolean options: foo/nofoo -*/ -case Opt_soft: - mnt->flags |=NFS_MOUNT_SOFT ; - mnt->flags &= ~NFS_MOUNT_SOFTERR ; -break ; -case Opt_softerr: - mnt->flags |=NFS_MOUNT_SOFTERR ; - mnt->flags &= ~NFS_MOUNT_SOFT ; -break ; -case Opt_hard: - mnt->flags &=~(NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR);
fs/nfs/super.c +0
-32-break ; -case Opt_posix: - mnt->flags |=NFS_MOUNT_POSIX ; -break ; -case Opt_noposix: - mnt->flags &= ~NFS_MOUNT_POSIX ; -break ; -case Opt_cto: - mnt->flags &= ~NFS_MOUNT_NOCTO ; -break ; -case Opt_nocto: - mnt->flags |=NFS_MOUNT_NOCTO ; -break ; -case Opt_ac: - mnt->flags &= ~NFS_MOUNT_NOAC ; -break ; -case Opt_noac: - mnt->flags |=NFS_MOUNT_NOAC ; -break ; -case Opt_lock: - mnt->flags &= ~NFS_MOUNT_NONLM ; - mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_nolock: - mnt->flags |=NFS_MOUNT_NONLM ; - mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -break ; -case Opt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-4-break ; -case Opt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-3-break ; -case Opt_rdma: - mnt->flags |=NFS_MOUNT_TCP ;/* for side
protocols */fs/nfs/super.c +0
-1- mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/super.c +0
-69-xprt_load_transport (p); -break ; -case Opt_acl: - mnt->flags &= ~NFS_MOUNT_NOACL ; -break ; -case Opt_noacl: - mnt->flags |=NFS_MOUNT_NOACL ; -break ; -case Opt_rdirplus: - mnt->flags &= ~NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_nordirplus: - mnt->flags |=NFS_MOUNT_NORDIRPLUS ; -break ; -case Opt_sharecache: - mnt->flags &= ~NFS_MOUNT_UNSHARED ; -break ; -case Opt_nosharecache: - mnt->flags |=NFS_MOUNT_UNSHARED ; -break ; -case Opt_resvport: - mnt->flags &= ~NFS_MOUNT_NORESVPORT ; -break ; -case Opt_noresvport: - mnt->flags |=NFS_MOUNT_NORESVPORT ; -break ; -case Opt_fscache: - mnt->options |=NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_nofscache: - mnt->options &= ~NFS_OPTION_FSCACHE ; -kfree (mnt->fscache_uniq); - mnt->fscache_uniq =NULL ; -break ; -case Opt_migration: - mnt->options |=NFS_OPTION_MIGRATION ; -break ; -case Opt_nomigration: - mnt->options &= ~NFS_OPTION_MIGRATION ; -break ; - -/* -* options that take numeric values -*/ -case Opt_port: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->nfs_server.port = option; -break ; -case Opt_rsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->rsize = option; -break ; -case Opt_wsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->wsize = option; -break ; -case Opt_bsize: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->bsize = option; -break ; -case Opt_timeo: - if (nfs_get_option_ul_bound(args,&option, 1,
INT_MAX))fs/nfs/super.c +0
-5- goto out_invalid_value; - mnt->timeo = option; -break ; -case Opt_retrans: - if (nfs_get_option_ul_bound(args,&option, 0,
INT_MAX))fs/nfs/super.c +0
-63- goto out_invalid_value; - mnt->retrans = option; -break ; -case Opt_acregmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = option; -break ; -case Opt_acregmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmax = option; -break ; -case Opt_acdirmin: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmin = option; -break ; -case Opt_acdirmax: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acdirmax = option; -break ; -case Opt_actimeo: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->acregmin = mnt->acregmax = - mnt->acdirmin = mnt->acdirmax = option; -break ; -case Opt_namelen: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; - mnt->namlen = option; -break ; -case Opt_mountport: -if (nfs_get_option_ul (args, &option) || - option >USHRT_MAX ) - goto out_invalid_value; - mnt->mount_server.port = option; -break ; -case Opt_mountvers: -if (nfs_get_option_ul (args, &option) || - option <NFS_MNT_VERSION || - option >NFS_MNT3_VERSION ) - goto out_invalid_value; - mnt->mount_server.version = option; -break ; -case Opt_minorversion: -if (nfs_get_option_ul (args, &option)) - goto out_invalid_value; -if (option >NFS4_MAX_MINOR_VERSION ) - goto out_invalid_value; - mnt->minorversion = option; -break ; - -/* -* options that take text values -*/ -case Opt_nfsvers: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc = nfs_parse_version_string(string,mnt,
args);fs/nfs/super.c +0
-9-kfree (string); -if (!rc) - goto out_invalid_value; -break ; -case Opt_sec: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - rc = nfs_parse_security_flavors(string,mnt);
fs/nfs/super.c +0
-3-kfree (string); -if (!rc) { - dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/super.c +0
-1- "securityflavor\n");
fs/nfs/super.c +0
-9-return 0 ; - } -break ; -case Opt_proto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_xprt_protocol_tokens,
args);fs/nfs/super.c +0
-9- - protofamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->flags &= ~NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-7-break ; -case Opt_xprt_tcp6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-6-break ; -case Opt_xprt_rdma6: - protofamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_rdma: -/* vector side protocols to TCP */
fs/nfs/super.c +0
-2- mnt->flags |=NFS_MOUNT_TCP ; - mnt->nfs_server.protocol =
XPRT_TRANSPORT_RDMA;fs/nfs/super.c +0
-4-xprt_load_transport (string); -break ; -default : - dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/super.c +0
-1- "transportprotocol\n");
fs/nfs/super.c +0
-11-kfree (string); -return 0 ; - } -kfree (string); -break ; -case Opt_mountproto: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token =match_token (string, - nfs_xprt_protocol_tokens,
args);fs/nfs/super.c +0
-9-kfree (string); - - mountfamily =AF_INET ; -switch (token) { -case Opt_xprt_udp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_udp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-6-break ; -case Opt_xprt_tcp6: - mountfamily =AF_INET6 ; -/* fall through */ -case Opt_xprt_tcp: - mnt->mount_server.protocol =
XPRT_TRANSPORT_TCP;fs/nfs/super.c +0
-2-break ; -case Opt_xprt_rdma:/* not used for side
protocols */fs/nfs/super.c +0
-2-default : - dfprintk(MOUNT,"NFS: unrecognized "
fs/nfs/super.c +0
-1- "transportprotocol\n");
fs/nfs/super.c +0
-9-return 0 ; - } -break ; -case Opt_addr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->nfs_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-2- (struct sockaddr *) - &mnt-Quoted 1 line
nfs_server.address,
fs/nfs/super.c +0
-1- sizeof(mnt-Quoted 1 line
nfs_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->nfs_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_clientaddr: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
client_address))fs/nfs/super.c +0
-5- goto out_nomem; -break ; -case Opt_mounthost: - if (nfs_get_option_str(args, - &mnt-Quoted 1 line
mount_server.hostname))
fs/nfs/super.c +0
-8- goto out_nomem; -break ; -case Opt_mountaddr: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - mnt->mount_server.addrlen = - rpc_pton(mnt->net, string,strlen(string),
fs/nfs/super.c +0
-2- (struct sockaddr *) - &mnt-Quoted 1 line
mount_server.address,
fs/nfs/super.c +0
-1- sizeof(mnt-Quoted 1 line
mount_server.address));
fs/nfs/super.c +0
-6-kfree (string); -if (mnt->mount_server.addrlen ==0 ) - goto out_invalid_address; -break ; -case Opt_nconnect: - if (nfs_get_option_ul_bound(args,&option, 1,
NFS_MAX_CONNECTIONS))fs/nfs/super.c +0
-9- goto out_invalid_value; - mnt->nfs_server.nconnect = option; -break ; -case Opt_lookupcache: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string, - nfs_lookupcache_tokens,args);
fs/nfs/super.c +0
-4-kfree (string); -switch (token) { -case Opt_lookupcache_all: - mnt->flags &=~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_positive: - mnt->flags &=~NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-1- mnt->flags |=
NFS_MOUNT_LOOKUP_CACHE_NONEG;fs/nfs/super.c +0
-3-break ; -case Opt_lookupcache_none: - mnt->flags |=NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
fs/nfs/super.c +0
-3-break ; -default : - dfprintk(MOUNT,"NFS: invalid
"fs/nfs/super.c +0
-1- "lookupcache
argument\n");fs/nfs/super.c +0
-5-return 0 ; - }; -break ; -case Opt_fscache_uniq: - if (nfs_get_option_str(args, &mnt-Quoted 1 line
fscache_uniq))fs/nfs/super.c +0
-8- goto out_nomem; - mnt->options |=NFS_OPTION_FSCACHE ; -break ; -case Opt_local_lock: - string =match_strdup (args); -if (string ==NULL ) - goto out_nomem; - token = match_token(string,
nfs_local_lock_tokens,fs/nfs/super.c +0
-5- args); -kfree (string); -switch (token) { -case Opt_local_lock_all: - mnt->flags |=(
NFS_MOUNT_LOCAL_FLOCK|fs/nfs/super.c +0
-1-NFS_MOUNT_LOCAL_ FCNTL);
fs/nfs/super.c +0
-3-break ; -case Opt_local_lock_flock: - mnt->flags |=
NFS_MOUNT_LOCAL_FLOCK;fs/nfs/super.c +0
-3-break ; -case Opt_local_lock_posix: - mnt->flags |=
NFS_MOUNT_LOCAL_FCNTL;fs/nfs/super.c +0
-3-break ; -case Opt_local_lock_none: - mnt->flags &=~(NFS_MOUNT_LOCAL_FLOCK |
fs/nfs/super.c +0
-1-NFS_MOUNT_LOCAL
_FCNTL);fs/nfs/super.c +0
-3-break ; -default : - dfprintk(MOUNT, "NFS: invalid"fs/nfs/super.c +0
-1- "local_lockargument\n");
fs/nfs/super.c +0
-10-return 0 ; - }; -break ; - -/* -* Special options -*/ -case Opt_sloppy: - sloppy =1 ; - dfprintk(MOUNT, "NFS: relaxingparsing
rules\n");fs/nfs/super.c +0
-4-break ; -case Opt_userspace: -case Opt_deprecated: - dfprintk(MOUNT, "NFS: ignoring mountoption "
fs/nfs/super.c +0
-6- "'%s'\n", p); -break ; - -default : - invalid_option =1 ; - dfprintk(MOUNT, "NFS: unrecognizedmount
option "fs/nfs/super.c +0
-16- "'%s'\n", p); - } - } - -if (!sloppy && invalid_option) -return 0 ; - -if (mnt->minorversion && mnt->version !=4 ) - goto out_minorversion_mismatch; - -if (mnt->options &NFS_OPTION_MIGRATION && - (mnt->version !=4 || mnt->minorversion !=0 )) - goto out_migration_misuse; - -/* -* verify that any proto=/mountproto= options match the address
fs/nfs/super.c +0
-9-* families in the addr=/mountaddr= options. -*/ -if (protofamily !=AF_UNSPEC && - protofamily != mnt->nfs_server.address.ss_family) - goto out_proto_mismatch; - - if (mountfamily != AF_UNSPEC) { - if (mnt->mount_server.addrlen) { - if (mountfamily != mnt-Quoted 1 line
mount_server.address.ss_family)
fs/nfs/super.c +0
-3- goto out_mountproto_mismatch; - } else { - if (mountfamily != mnt-Quoted 1 line
nfs_server.address.ss_family)
fs/nfs/super.c +0
-8- goto out_mountproto_mismatch; - } - } - -return 1 ; - -out_mountproto_mismatch: - printk(KERN_INFO "NFS: mount server address does notmatch
mountproto= "fs/nfs/super.c +0
-4- "option\n"); -return 0 ; -out_proto_mismatch: - printk(KERN_INFO "NFS: server address does not matchproto=
option\n");fs/nfs/super.c +0
-3-return 0 ; -out_invalid_address: - printk(KERN_INFO "NFS: bad IP address specified: %s\n",p);
fs/nfs/super.c +0
-3-return 0 ; -out_invalid_value: - printk(KERN_INFO "NFS: bad mount option valuespecified: %s\n",
p);fs/nfs/super.c +0
-3-return 0 ; -out_minorversion_mismatch: - printk(KERN_INFO "NFS: mount option vers=%u does notsupport "
fs/nfs/super.c +0
-1- "minorversion=%u\n", mnt->version,mnt-
Quoted 1 line
minorversion);
fs/nfs/super.c +0
-4-return 0 ; -out_migration_misuse: -printk (KERN_INFO - "NFS: 'migration' not supported for this NFSversion\n");
fs/nfs/super.c +0
-3-return 0 ; -out_nomem: - printk(KERN_INFO "NFS: not enough memory to parseoption\n");
fs/nfs/super.c +0
-3-return 0 ; -out_security_failure: - printk(KERN_INFO "NFS: security options invalid: %d\n",rc);
fs/nfs/super.c +0
-3-return 0 ; -} -/*
* Ensure that a specified authtype inargs->auth_infois
supported
by
* the server. Returns 0 and setsargs->selected_flavorif it's
ok,
andfs/nfs/super.c +0
-4@@ -1908,327 +925,6 @@ struct dentry *nfs_try_mount(int flags,const char *dev_name, }EXPORT_SYMBOL_GPL (nfs_try_mount ); -/* -* Split "dev_name" into "hostname:export_path". -* -* The leftmost colon demarks the split between the server's hostname
- * and the export path. If the hostname starts with a left square
- * bracket, then it may contain colons.
- *
- * Note: caller frees hostname and export path, even on error.
- */fs/nfs/super.c +0
-3-static int nfs_parse_devname (const char *dev_name, -char **hostname,size_t maxnamlen, - char **export_path, size_tmaxpathlen)
fs/nfs/super.c +0
-6-{ -size_t len; -char *end; - -if (unlikely (!dev_name || !*dev_name)) { - dfprintk(MOUNT, "NFS: device name notspecified\n");
fs/nfs/super.c +0
-20-return -EINVAL ; - } - -/* Is the host name protected with square brakcets? */ -if (*dev_name =='[' ) { - end =strchr (++dev_name,']' ); -if (end ==NULL || end[1 ] !=':' ) - goto out_bad_devname; - - len = end - dev_name; - end++; - }else { -char *comma; - - end =strchr (dev_name,':' ); -if (end ==NULL ) - goto out_bad_devname; - len = end - dev_name; - -/* kill possible hostname list: not supported */
fs/nfs/super.c +0
-9- comma =strchr (dev_name,',' ); -if (comma !=NULL && comma < end) - len = comma - dev_name; - } - -if (len > maxnamlen) - goto out_hostname; - -/* N.B. caller will free nfs_server.hostname in all cases */
fs/nfs/super.c +0
-15- *hostname =kstrndup (dev_name, len,GFP_KERNEL ); -if (*hostname ==NULL ) - goto out_nomem; - len =strlen (++end); -if (len > maxpathlen) - goto out_path; - *export_path =kstrndup (end, len,GFP_KERNEL ); -if (!*export_path) - goto out_nomem; - -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , *export_path); -return 0 ; - -out_bad_devname: - dfprintk(MOUNT, "NFS: device name not in host:pathformat\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to parse devicename\n");
fs/nfs/super.c +0
-16-return -ENOMEM ; - -out_hostname: -dfprintk (MOUNT ,"NFS: server hostname too long\n" ); -return -ENAMETOOLONG ; - -out_path: -dfprintk (MOUNT ,"NFS: export pathname too long\n" ); -return -ENAMETOOLONG ; -} - -/* -* Validate the NFS2/NFS3 mount data -* - fills in the mount root filehandle -* -* For option strings, user space handles the following behaviors:
- *
- * + DNS: mapping server host name to IP address ("addr=" option)
- *
- * + failure mode: how to behave if a mount request can't be handled
- * immediately ("fg/bg" option)
- *
- * + retry: how often to retry a mount request ("retry=" option)
- *
- * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
- * mountproto=tcp after mountproto=udp, and so on
- */fs/nfs/super.c +0
-2-static int nfs23_validate_mount_data(void *options, - struct
nfs_parsed_mount_data
*args,fs/nfs/super.c +0
-4- struct nfs_fh *mntfh, - const char *dev_name) -{ - struct nfs_mount_data *data = (struct nfs_mount_data*)options;
fs/nfs/super.c +0
-1- struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-16-int extra_flags =NFS_MOUNT_LEGACY_INTERFACE ; - -if (data ==NULL ) - goto out_no_data; - - args->version =NFS_DEFAULT_VERSION ; -switch (data->version) { -case 1 : - data->namlen =0 ;/* fall through */ -case 2 : - data->bsize =0 ;/* fall through */ -case 3 : -if (data->flags &NFS_MOUNT_VER3 ) - goto out_no_v3; - data->root.size =NFS2_FHSIZE ; - memcpy(data->root.data, data->old_root.data,
NFS2_FHSIZE);fs/nfs/super.c +0
-9-/* Turn off security negotiation */ - extra_flags |=NFS_MOUNT_SECFLAVOUR ; -/* fall through */ -case 4 : -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - goto out_no_sec; -/* fall through */ -case 5 : - memset(data->context, 0, sizeof(data-Quoted 1 line
context));
fs/nfs/super.c +0
-4-/* fall through */ -case 6 : -if (data->flags &NFS_MOUNT_VER3 ) { - if (data->root.size > NFS3_FHSIZE ||data-
Quoted 1 line
root.size == 0)
fs/nfs/super.c +0
-10- goto out_invalid_fh; - mntfh->size = data->root.size; - args->version =3 ; - }else { - mntfh->size =NFS2_FHSIZE ; - args->version =2 ; - } - - - memcpy(mntfh->data, data->root.data, mntfh-Quoted 1 line
size);
fs/nfs/super.c +0
-3-if (mntfh->size <sizeof (mntfh->data)) - memset(mntfh->data + mntfh->size, 0, - sizeof(mntfh->data) - mntfh-Quoted 1 line
size);
fs/nfs/super.c +0
-3- -/* -* Translate to nfs_parsed_mount_data, which
nfs_fill_superfs/nfs/super.c +0
-3-* can deal with. -*/ - args->flags = data->flags &
NFS_MOUNT_FLAGMASK;fs/nfs/super.c +0
-14- args->flags |= extra_flags; - args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->need_mount = false; - -memcpy (sap, &data->addr,sizeof (data->addr)); - args->nfs_server.addrlen =sizeof (data->addr); - args->nfs_server.port = ntohs(data-Quoted 1 line
addr.sin_port);
fs/nfs/super.c +0
-6-if (sap->sa_family !=AF_INET || - !nfs_verify_server_address (sap)) - goto out_no_address; - -if (!(data->flags &NFS_MOUNT_TCP )) - args->nfs_server.protocol =
XPRT_TRANSPORT_UDP;fs/nfs/super.c +0
-1-/* N.B. caller will free nfs_server.hostname in all
cases */fs/nfs/super.c +0
-1- args->nfs_server.hostname = kstrdup(data-Quoted 1 line
hostname,
GFP_KERNEL);fs/nfs/super.c +0
-5- args->namlen = data->namlen; - args->bsize = data->bsize; - -if (data->flags &NFS_MOUNT_SECFLAVOUR ) - args->selected_flavor = data-Quoted 1 line
pseudoflavor;
fs/nfs/super.c +0
-8-else - args->selected_flavor =RPC_AUTH_UNIX ; -if (!args->nfs_server.hostname) - goto out_nomem; - -if (!(data->flags &NFS_MOUNT_NONLM )) - args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL );
fs/nfs/super.c +0
-5-else - args->flags |= (NFS_MOUNT_LOCAL_FLOCK | -NFS_MOUNT_LOCAL_FCNTL ); -/* -* The legacy version 6 binary mount data from userspace has a
fs/nfs/super.c +0
-1-* field used only to transport selinux information
into thefs/nfs/super.c +0
-1-* the kernel. To continue to support that functionality we
fs/nfs/super.c +0
-1-* have a touch of selinux knowledge here in the NFS
code. Thefs/nfs/super.c +0
-1-* userspace code converted context=blah to just blah
so we arefs/nfs/super.c +0
-1-* converting back to the full string selinux understands.
fs/nfs/super.c +0
-5-*/ -if (data->context[0 ]){ -#ifdef CONFIG_SECURITY_SELINUX -int rc; - data->context[NFS_MAX_CONTEXT_LEN] ='\0';
fs/nfs/super.c +0
-1- rc = security_add_mnt_opt("context",data-
Quoted 1 line
context,
fs/nfs/super.c +0
-1- strlen(data->context),&args-
Quoted 1 line
lsm_opts);fs/nfs/super.c +0
-16-if (rc) -return rc; -#else -return -EINVAL ; -#endif - } - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS: mount program didn't pass anymount
data\n");fs/nfs/super.c +0
-4-return -EINVAL ; - -out_no_v3: - dfprintk(MOUNT, "NFS: nfs_mount_data version %d doesnot
support v3\n",fs/nfs/super.c +0
-5- data->version); -return -EINVAL ; - -out_no_sec: - dfprintk(MOUNT, "NFS: nfs_mount_data version supportsonly
AUTH_SYS\n");fs/nfs/super.c +0
-4-return -EINVAL ; - -out_nomem: - dfprintk(MOUNT, "NFS: not enough memory to handle mountoptions\n");
fs/nfs/super.c +0
-4-return -ENOMEM ; - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-9-return -EINVAL ; - -out_invalid_fh: -dfprintk (MOUNT ,"NFS: invalid root filehandle\n" ); -return -EINVAL ; -} - -#if IS_ENABLED (CONFIG_NFS_V4 ) -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-2-void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-5- struct nfs_fh *mntfh, - const char *dev_name) -{ -if (fs_type == &nfs_fs_type) - return nfs23_validate_mount_data(options, args,mntfh,
dev_name);fs/nfs/super.c +0
-1- return nfs4_validate_mount_data(options, args,
dev_name);fs/nfs/super.c +0
-3-} -#else -static int nfs_validate_mount_data(struct file_system_type
*fs_type,fs/nfs/super.c +0
-2-void *options, - struct nfs_parsed_mount_data*args,
fs/nfs/super.c +0
-4- struct nfs_fh *mntfh, - const char *dev_name) -{ - return nfs23_validate_mount_data(options, args, mntfh,
dev_name);fs/nfs/super.c +0
-5-} -#endif - -static int nfs_validate_text_mount_data(void *options, - struct
nfs_parsed_mount_data
*args,fs/nfs/super.c +0
-6- const char *dev_name) -{ -int port =0 ; -int max_namelen =PAGE_SIZE ; -int max_pathlen =NFS_MAXPATHLEN ; - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-2- - if (nfs_parse_mount_options((char *)options, args) ==0)
fs/nfs/super.c +0
-8-return -EINVAL ; - -if (!nfs_verify_server_address (sap)) - goto out_no_address; - -if (args->version ==4 ) { -#if IS_ENABLED (CONFIG_NFS_V4 ) - if (args->nfs_server.protocol ==
XPRT_TRANSPORT_RDMA)fs/nfs/super.c +0
-7- port =NFS_RDMA_PORT ; - else - port =NFS_PORT ; - max_namelen =NFS4_MAXNAMLEN ; - max_pathlen =NFS4_MAXPATHLEN ; -nfs_validate_transport_protocol (args); - if (args->nfs_server.protocol ==
XPRT_TRANSPORT_UDP)fs/nfs/super.c +0
-8- goto out_invalid_transport_udp; -nfs4_validate_mount_flags (args); -#else - goto out_v4_not_compiled; -#endif /* CONFIG_NFS_V4 */ - }else { -nfs_set_mount_transport_protocol (args); - if (args->nfs_server.protocol ==
XPRT_TRANSPORT_RDMA)fs/nfs/super.c +0
-9- port =NFS_RDMA_PORT ; - } - -nfs_set_port (sap, &args->nfs_server.port, port); - - return nfs_parse_devname(dev_name, - &args->nfs_server.hostname, - max_namelen, - &args-Quoted 1 line
nfs_server.export_path,
fs/nfs/super.c +0
-5- max_pathlen); - -#if !IS_ENABLED (CONFIG_NFS_V4 ) -out_v4_not_compiled: - dfprintk(MOUNT, "NFS: NFSv4 is not compiled intokernel\n");
fs/nfs/super.c +0
-4-return -EPROTONOSUPPORT ; -#else -out_invalid_transport_udp: - dfprintk(MOUNT, "NFSv4: Unsupported transport protocoludp\n");
fs/nfs/super.c +0
-5-return -EINVAL ; -#endif /* !CONFIG_NFS_V4 */ - -out_no_address: - dfprintk(MOUNT, "NFS: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-3-return -EINVAL ; -} -#define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \ | NFS_MOUNT_SECURE \ | NFS_MOUNT_TCP \fs/nfs/super.c +0
-0@@ -2719,113 +1415,6 @@ nfs_prepared_mount(struct
file_system_type*fs_type, int flags,#if
IS_ENABLED(CONFIG_NFS_V4)-static void nfs4_validate_mount_flags(struct
nfs_parsed_mount_data
*args)fs/nfs/super.c +0
-2-{ - args->flags &=~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
fs/nfs/super.c +0
-1-NFS_MOUNT_LOCAL_FLOCK |NFS_MOUNT_LOCAL_ FCNTL);
fs/nfs/super.c +0
-7-} - -/* -* Validate NFSv4 mount options -*/ -static int nfs4_validate_mount_data(void *options, - struct
nfs_parsed_mount_data*args,fs/nfs/super.c +0
-3- const char *dev_name) -{ - struct sockaddr *sap = (struct sockaddr *)&args-Quoted 1 line
nfs_server.address;
fs/nfs/super.c +0
-1- struct nfs4_mount_data *data = (struct nfs4_mount_data*)options;
fs/nfs/super.c +0
-10-char *c; - -if (data ==NULL ) - goto out_no_data; - - args->version =4 ; - -switch (data->version) { -case 1 : - if (data->host_addrlen > sizeof(args-Quoted 1 line
nfs_server.address))
fs/nfs/super.c +0
-5- goto out_no_address; -if (data->host_addrlen ==0 ) - goto out_no_address; - args->nfs_server.addrlen = data->host_addrlen; - if (copy_from_user(sap, data->host_addr, data-Quoted 1 line
host_addrlen))fs/nfs/super.c +0
-4-return -EFAULT ; -if (!nfs_verify_server_address (sap)) - goto out_no_address; - args->nfs_server.port = ntohs(((struct
sockaddr_in
*)sap)->sin_port);fs/nfs/super.c +0
-8- -if (data->auth_flavourlen) { -rpc_authflavor_t pseudoflavor; -if (data->auth_flavourlen >1 ) - goto out_inval_auth; - if (copy_from_user(&pseudoflavor, - data->auth_flavours, - sizeof(pseudoflavor)))
fs/nfs/super.c +0
-6-return -EFAULT ; - args->selected_flavor = pseudoflavor; - }else - args->selected_flavor =RPC_AUTH_UNIX ; - - c = strndup_user(data->hostname.data,
NFS4_MAXNAMLEN);fs/nfs/super.c +0
-5-if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.hostname = c; - - c = strndup_user(data->mnt_path.data,
NFS4_MAXPATHLEN);fs/nfs/super.c +0
-12-if (IS_ERR (c)) -return PTR_ERR (c); - args->nfs_server.export_path = c; -dfprintk (MOUNT ,"NFS: MNTPATH: '%s'\n" , c); - - c =strndup_user (data->client_addr.data,16 ); -if (IS_ERR (c)) -return PTR_ERR (c); - args->client_address = c; - -/* -* Translate to nfs_parsed_mount_data, which
nfs4_fill_superfs/nfs/super.c +0
-4-* can deal with. -*/ - - args->flags = data->flags &
NFS4_MOUNT_FLAGMASK;fs/nfs/super.c +0
-11- args->rsize = data->rsize; - args->wsize = data->wsize; - args->timeo = data->timeo; - args->retrans = data->retrans; - args->acregmin = data->acregmin; - args->acregmax = data->acregmax; - args->acdirmin = data->acdirmin; - args->acdirmax = data->acdirmax; - args->nfs_server.protocol = data->proto; -nfs_validate_transport_protocol (args); - if (args->nfs_server.protocol ==
XPRT_TRANSPORT_UDP)fs/nfs/super.c +0
-11- goto out_invalid_transport_udp; - -break ; -default : -return NFS_TEXT_DATA ; - } - -return 0 ; - -out_no_data: - dfprintk(MOUNT, "NFS4: mount program didn't pass anymount
data\n");fs/nfs/super.c +0
-4-return -EINVAL ; - -out_inval_auth: - dfprintk(MOUNT, "NFS4: Invalid number of RPC authflavours
%d\n",fs/nfs/super.c +0
-5- data->auth_flavourlen); -return -EINVAL ; - -out_no_address: - dfprintk(MOUNT, "NFS4: mount program didn't pass remoteaddress\n");
fs/nfs/super.c +0
-4-return -EINVAL ; - -out_invalid_transport_udp: - dfprintk(MOUNT, "NFSv4: Unsupported transport protocoludp\n");
fs/nfs/super.c +0
-3-return -EINVAL ; -} -Quoted 6 lines
/*
* NFS v4 module parameters need to stay in the
* NFS client for backwards compatibilitySignature · 1 line
2.17.2--
Chuck Lever
[email protected]Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]