Skip to content

Commit f2aedb7

Browse files
dhowellsamschuma-ntap
authored andcommitted
NFS: Add fs_context support.
Add filesystem context support to NFS, parsing the options in advance and attaching the information to struct nfs_fs_context. The highlights are: (*) Merge nfs_mount_info and nfs_clone_mount into nfs_fs_context. This structure represents NFS's superblock config. (*) Make use of the VFS's parsing support to split comma-separated lists (*) Pin the NFS protocol module in the nfs_fs_context. (*) Attach supplementary error information to fs_context. This has the downside that these strings must be static and can't be formatted. (*) Remove the auxiliary file_system_type structs since the information necessary can be conveyed in the nfs_fs_context struct instead. (*) Root mounts are made by duplicating the config for the requested mount so as to have the same parameters. Submounts pick up their parameters from the parent superblock. [AV -- retrans is u32, not string] [SM -- Renamed cfg to ctx in a few functions in an earlier patch] [SM -- Moved fs_context mount option parsing to an earlier patch] [SM -- Moved fs_context error logging to a later patch] [SM -- Fixed printks in nfs4_try_get_tree() and nfs4_get_referral_tree()] [SM -- Added is_remount_fc() helper] [SM -- Deferred some refactoring to a later patch] [SM -- Fixed referral mounts, which were broken in the original patch] [SM -- Fixed leak of nfs_fattr when fs_context is freed] Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Scott Mayhew <smayhew@redhat.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent e38bb23 commit f2aedb7

12 files changed

Lines changed: 773 additions & 659 deletions

File tree

‎fs/nfs/fs_context.c‎

Lines changed: 316 additions & 154 deletions
Large diffs are not rendered by default.

‎fs/nfs/internal.h‎

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
#include "nfs4_fs.h"
7-
#include <linux/mount.h>
7+
#include <linux/fs_context.h>
88
#include <linux/security.h>
99
#include <linux/crc32.h>
1010
#include <linux/sunrpc/addr.h>
@@ -16,6 +16,7 @@
1616
extern const struct export_operations nfs_export_ops;
1717

1818
struct nfs_string;
19+
struct nfs_pageio_descriptor;
1920

2021
static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
2122
{
@@ -34,12 +35,13 @@ static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
3435

3536
struct nfs_clone_mount {
3637
const struct super_block *sb;
37-
const struct dentry *dentry;
38+
struct dentry *dentry;
3839
char *hostname;
3940
char *mnt_path;
4041
struct sockaddr *addr;
4142
size_t addrlen;
4243
rpc_authflavor_t authflavor;
44+
struct nfs_fattr *fattr;
4345
};
4446

4547
/*
@@ -78,10 +80,23 @@ struct nfs_client_initdata {
7880
const struct cred *cred;
7981
};
8082

83+
struct nfs_mount_info {
84+
unsigned int inherited_bsize;
85+
struct nfs_fs_context *ctx;
86+
struct nfs_clone_mount *cloned;
87+
struct nfs_server *server;
88+
struct nfs_fh *mntfh;
89+
struct nfs_subversion *nfs_mod;
90+
};
91+
8192
/*
8293
* In-kernel mount arguments
8394
*/
8495
struct nfs_fs_context {
96+
bool internal;
97+
bool skip_reconfig_option_check;
98+
bool need_mount;
99+
bool sloppy;
85100
unsigned int flags; /* NFS{,4}_MOUNT_* flags */
86101
unsigned int rsize, wsize;
87102
unsigned int timeo, retrans;
@@ -98,8 +113,6 @@ struct nfs_fs_context {
98113
char *fscache_uniq;
99114
unsigned short protofamily;
100115
unsigned short mountfamily;
101-
bool need_mount;
102-
bool sloppy;
103116

104117
struct {
105118
union {
@@ -124,14 +137,23 @@ struct nfs_fs_context {
124137
int port;
125138
unsigned short protocol;
126139
unsigned short nconnect;
140+
unsigned short export_path_len;
127141
} nfs_server;
128142

129143
void *lsm_opts;
130144
struct net *net;
131145

132146
char buf[32]; /* Parse buffer */
147+
148+
struct nfs_mount_info mount_info;
149+
struct nfs_clone_mount clone_data;
133150
};
134151

152+
static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
153+
{
154+
return fc->fs_private;
155+
}
156+
135157
/* mount_clnt.c */
136158
struct nfs_mount_request {
137159
struct sockaddr *sap;
@@ -147,15 +169,6 @@ struct nfs_mount_request {
147169
struct net *net;
148170
};
149171

150-
struct nfs_mount_info {
151-
unsigned int inherited_bsize;
152-
struct nfs_fs_context *ctx;
153-
struct nfs_clone_mount *cloned;
154-
struct nfs_server *server;
155-
struct nfs_fh *mntfh;
156-
struct nfs_subversion *nfs_mod;
157-
};
158-
159172
extern int nfs_mount(struct nfs_mount_request *info);
160173
extern void nfs_umount(const struct nfs_mount_request *info);
161174

@@ -235,22 +248,8 @@ static inline void nfs_fs_proc_exit(void)
235248
extern const struct svc_version nfs4_callback_version1;
236249
extern const struct svc_version nfs4_callback_version4;
237250

238-
struct nfs_pageio_descriptor;
239-
240-
/* mount.c */
241-
#define NFS_TEXT_DATA 1
242-
243-
extern struct nfs_fs_context *nfs_alloc_parsed_mount_data(void);
244-
extern void nfs_free_parsed_mount_data(struct nfs_fs_context *ctx);
245-
extern int nfs_parse_mount_options(char *raw, struct nfs_fs_context *ctx);
246-
extern int nfs_validate_mount_data(struct file_system_type *fs_type,
247-
void *options,
248-
struct nfs_fs_context *ctx,
249-
struct nfs_fh *mntfh,
250-
const char *dev_name);
251-
extern int nfs_validate_text_mount_data(void *options,
252-
struct nfs_fs_context *ctx,
253-
const char *dev_name);
251+
/* fs_context.c */
252+
extern struct file_system_type nfs_fs_type;
254253

255254
/* pagelist.c */
256255
extern int __init nfs_init_nfspagecache(void);
@@ -411,14 +410,9 @@ extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);
411410

412411
/* super.c */
413412
extern const struct super_operations nfs_sops;
414-
extern struct file_system_type nfs_fs_type;
415-
extern struct file_system_type nfs_prepared_fs_type;
416-
#if IS_ENABLED(CONFIG_NFS_V4)
417-
extern struct file_system_type nfs4_referral_fs_type;
418-
#endif
419413
bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
420-
struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *);
421-
struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
414+
int nfs_try_get_tree(struct fs_context *);
415+
int nfs_get_tree_common(struct fs_context *);
422416
void nfs_kill_super(struct super_block *);
423417

424418
extern struct rpc_stat nfs_rpcstat;
@@ -446,10 +440,8 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
446440
extern char *nfs_path(char **p, struct dentry *dentry,
447441
char *buffer, ssize_t buflen, unsigned flags);
448442
extern struct vfsmount *nfs_d_automount(struct path *path);
449-
struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
450-
struct nfs_fh *, struct nfs_fattr *);
451-
struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
452-
struct nfs_fattr *, rpc_authflavor_t);
443+
int nfs_submount(struct fs_context *, struct nfs_server *);
444+
int nfs_do_submount(struct fs_context *);
453445

454446
/* getroot.c */
455447
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
@@ -476,7 +468,7 @@ int nfs_show_options(struct seq_file *, struct dentry *);
476468
int nfs_show_devname(struct seq_file *, struct dentry *);
477469
int nfs_show_path(struct seq_file *, struct dentry *);
478470
int nfs_show_stats(struct seq_file *, struct dentry *);
479-
int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
471+
int nfs_reconfigure(struct fs_context *);
480472

481473
/* write.c */
482474
extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,

‎fs/nfs/namespace.c‎

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,65 @@ EXPORT_SYMBOL_GPL(nfs_path);
140140
*/
141141
struct vfsmount *nfs_d_automount(struct path *path)
142142
{
143-
struct vfsmount *mnt;
143+
struct nfs_fs_context *ctx;
144+
struct fs_context *fc;
145+
struct vfsmount *mnt = ERR_PTR(-ENOMEM);
144146
struct nfs_server *server = NFS_SERVER(d_inode(path->dentry));
145-
struct nfs_fh *fh = NULL;
146-
struct nfs_fattr *fattr = NULL;
147+
struct nfs_client *client = server->nfs_client;
148+
int ret;
147149

148150
if (IS_ROOT(path->dentry))
149151
return ERR_PTR(-ESTALE);
150152

151-
mnt = ERR_PTR(-ENOMEM);
152-
fh = nfs_alloc_fhandle();
153-
fattr = nfs_alloc_fattr();
154-
if (fh == NULL || fattr == NULL)
155-
goto out;
153+
/* Open a new filesystem context, transferring parameters from the
154+
* parent superblock, including the network namespace.
155+
*/
156+
fc = fs_context_for_submount(&nfs_fs_type, path->dentry);
157+
if (IS_ERR(fc))
158+
return ERR_CAST(fc);
156159

157-
mnt = server->nfs_client->rpc_ops->submount(server, path->dentry, fh, fattr);
160+
ctx = nfs_fc2context(fc);
161+
ctx->clone_data.dentry = path->dentry;
162+
ctx->clone_data.sb = path->dentry->d_sb;
163+
ctx->clone_data.fattr = nfs_alloc_fattr();
164+
if (!ctx->clone_data.fattr)
165+
goto out_fc;
166+
167+
if (fc->net_ns != client->cl_net) {
168+
put_net(fc->net_ns);
169+
fc->net_ns = get_net(client->cl_net);
170+
}
171+
172+
/* for submounts we want the same server; referrals will reassign */
173+
memcpy(&ctx->nfs_server.address, &client->cl_addr, client->cl_addrlen);
174+
ctx->nfs_server.addrlen = client->cl_addrlen;
175+
ctx->nfs_server.port = server->port;
176+
177+
ctx->version = client->rpc_ops->version;
178+
ctx->minorversion = client->cl_minorversion;
179+
ctx->mount_info.nfs_mod = client->cl_nfs_mod;
180+
__module_get(ctx->mount_info.nfs_mod->owner);
181+
182+
ret = client->rpc_ops->submount(fc, server);
183+
if (ret < 0) {
184+
mnt = ERR_PTR(ret);
185+
goto out_fc;
186+
}
187+
188+
up_write(&fc->root->d_sb->s_umount);
189+
mnt = vfs_create_mount(fc);
158190
if (IS_ERR(mnt))
159-
goto out;
191+
goto out_fc;
160192

161193
if (nfs_mountpoint_expiry_timeout < 0)
162-
goto out;
194+
goto out_fc;
163195

164196
mntget(mnt); /* prevent immediate expiration */
165197
mnt_set_expiry(mnt, &nfs_automount_list);
166198
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
167199

168-
out:
169-
nfs_free_fattr(fattr);
170-
nfs_free_fhandle(fh);
200+
out_fc:
201+
put_fs_context(fc);
171202
return mnt;
172203
}
173204

@@ -222,61 +253,62 @@ void nfs_release_automount_timer(void)
222253
* @authflavor: security flavor to use when performing the mount
223254
*
224255
*/
225-
struct vfsmount *nfs_do_submount(struct dentry *dentry, struct nfs_fh *fh,
226-
struct nfs_fattr *fattr, rpc_authflavor_t authflavor)
256+
int nfs_do_submount(struct fs_context *fc)
227257
{
228-
struct super_block *sb = dentry->d_sb;
229-
struct nfs_clone_mount mountdata = {
230-
.sb = sb,
231-
.dentry = dentry,
232-
.authflavor = authflavor,
233-
};
234-
struct nfs_mount_info mount_info = {
235-
.inherited_bsize = sb->s_blocksize_bits,
236-
.cloned = &mountdata,
237-
.mntfh = fh,
238-
.nfs_mod = NFS_SB(sb)->nfs_client->cl_nfs_mod,
239-
};
258+
struct nfs_fs_context *ctx = nfs_fc2context(fc);
259+
struct dentry *dentry = ctx->clone_data.dentry;
240260
struct nfs_server *server;
241-
struct vfsmount *mnt;
242-
char *page = (char *) __get_free_page(GFP_USER);
243-
char *devname;
261+
char *buffer, *p;
262+
int ret;
244263

245-
if (page == NULL)
246-
return ERR_PTR(-ENOMEM);
264+
/* create a new volume representation */
265+
server = ctx->mount_info.nfs_mod->rpc_ops->clone_server(NFS_SB(ctx->clone_data.sb),
266+
ctx->mount_info.mntfh,
267+
ctx->clone_data.fattr,
268+
ctx->selected_flavor);
247269

248-
server = mount_info.nfs_mod->rpc_ops->clone_server(NFS_SB(sb), fh,
249-
fattr, authflavor);
250270
if (IS_ERR(server))
251-
return ERR_CAST(server);
271+
return PTR_ERR(server);
252272

253-
mount_info.server = server;
273+
ctx->mount_info.server = server;
254274

255-
devname = nfs_devname(dentry, page, PAGE_SIZE);
256-
if (IS_ERR(devname))
257-
mnt = ERR_CAST(devname);
258-
else
259-
mnt = vfs_submount(dentry, &nfs_prepared_fs_type, devname, &mount_info);
275+
buffer = kmalloc(4096, GFP_USER);
276+
if (!buffer)
277+
return -ENOMEM;
260278

261-
if (mount_info.server)
262-
nfs_free_server(mount_info.server);
263-
free_page((unsigned long)page);
264-
return mnt;
279+
ctx->internal = true;
280+
ctx->mount_info.inherited_bsize = ctx->clone_data.sb->s_blocksize_bits;
281+
282+
p = nfs_devname(dentry, buffer, 4096);
283+
if (IS_ERR(p)) {
284+
dprintk("NFS: Couldn't determine submount pathname\n");
285+
ret = PTR_ERR(p);
286+
} else {
287+
ret = vfs_parse_fs_string(fc, "source", p, buffer + 4096 - p);
288+
if (!ret)
289+
ret = vfs_get_tree(fc);
290+
}
291+
kfree(buffer);
292+
return ret;
265293
}
266294
EXPORT_SYMBOL_GPL(nfs_do_submount);
267295

268-
struct vfsmount *nfs_submount(struct nfs_server *server, struct dentry *dentry,
269-
struct nfs_fh *fh, struct nfs_fattr *fattr)
296+
int nfs_submount(struct fs_context *fc, struct nfs_server *server)
270297
{
271-
int err;
298+
struct nfs_fs_context *ctx = nfs_fc2context(fc);
299+
struct dentry *dentry = ctx->clone_data.dentry;
272300
struct dentry *parent = dget_parent(dentry);
301+
int err;
273302

274303
/* Look it up again to get its attributes */
275-
err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name, fh, fattr, NULL);
304+
err = server->nfs_client->rpc_ops->lookup(d_inode(parent), &dentry->d_name,
305+
ctx->mount_info.mntfh, ctx->clone_data.fattr,
306+
NULL);
276307
dput(parent);
277308
if (err != 0)
278-
return ERR_PTR(err);
309+
return err;
279310

280-
return nfs_do_submount(dentry, fh, fattr, server->client->cl_auth->au_flavor);
311+
ctx->selected_flavor = server->client->cl_auth->au_flavor;
312+
return nfs_do_submount(fc);
281313
}
282314
EXPORT_SYMBOL_GPL(nfs_submount);

‎fs/nfs/nfs3proc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
990990
.nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
991991
.getroot = nfs3_proc_get_root,
992992
.submount = nfs_submount,
993-
.try_mount = nfs_try_mount,
993+
.try_get_tree = nfs_try_get_tree,
994994
.getattr = nfs3_proc_getattr,
995995
.setattr = nfs3_proc_setattr,
996996
.lookup = nfs3_proc_lookup,

‎fs/nfs/nfs4_fs.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,13 @@ extern const struct dentry_operations nfs4_dentry_operations;
268268
int nfs_atomic_open(struct inode *, struct dentry *, struct file *,
269269
unsigned, umode_t);
270270

271-
/* super.c */
271+
/* fs_context.c */
272272
extern struct file_system_type nfs4_fs_type;
273273

274274
/* nfs4namespace.c */
275275
struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *,
276276
const struct qstr *);
277-
struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *,
278-
struct nfs_fh *, struct nfs_fattr *);
277+
int nfs4_submount(struct fs_context *, struct nfs_server *);
279278
int nfs4_replace_transport(struct nfs_server *server,
280279
const struct nfs4_fs_locations *locations);
281280

@@ -526,7 +525,6 @@ extern const nfs4_stateid invalid_stateid;
526525
/* nfs4super.c */
527526
struct nfs_mount_info;
528527
extern struct nfs_subversion nfs_v4;
529-
struct dentry *nfs4_try_mount(int, const char *, struct nfs_mount_info *);
530528
extern bool nfs4_disable_idmapping;
531529
extern unsigned short max_session_slots;
532530
extern unsigned short max_session_cb_slots;
@@ -536,6 +534,9 @@ extern bool recover_lost_locks;
536534
#define NFS4_CLIENT_ID_UNIQ_LEN (64)
537535
extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
538536

537+
extern int nfs4_try_get_tree(struct fs_context *);
538+
extern int nfs4_get_referral_tree(struct fs_context *);
539+
539540
/* nfs4sysctl.c */
540541
#ifdef CONFIG_SYSCTL
541542
int nfs4_register_sysctl(void);

0 commit comments

Comments
 (0)