Skip to content

Commit 1f3e414

Browse files
Eric Sandeenmartinetd
authored andcommitted
9p: convert to the new mount API
Convert 9p to the new mount API. This patch consolidates all parsing into fs/9p/v9fs.c, which stores all results into a filesystem context which can be passed to the various transports as needed. Some of the parsing helper functions such as get_cache_mode() have been eliminated in favor of using the new mount API's enum param type, for simplicity. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Message-ID: <20251010214222.1347785-5-sandeen@redhat.com> [ Dominique: handled source explicitly as per follow-up discussion ] Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent 075e8bd commit 1f3e414

12 files changed

Lines changed: 424 additions & 652 deletions

File tree

fs/9p/v9fs.c

Lines changed: 283 additions & 269 deletions
Large diffs are not rendered by default.

fs/9p/v9fs.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
#include <linux/backing-dev.h>
1212
#include <linux/netfs.h>
13+
#include <linux/fs_parser.h>
14+
#include <net/9p/client.h>
15+
#include <net/9p/transport.h>
1316

1417
/**
1518
* enum p9_session_flags - option flags for each 9P session
@@ -163,11 +166,13 @@ static inline struct fscache_volume *v9fs_session_cache(struct v9fs_session_info
163166
#endif
164167
}
165168

169+
extern const struct fs_parameter_spec v9fs_param_spec[];
166170

171+
extern int v9fs_parse_param(struct fs_context *fc, struct fs_parameter *param);
167172
extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
168173

169174
struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
170-
const char *dev_name, char *data);
175+
struct fs_context *fc);
171176
extern void v9fs_session_close(struct v9fs_session_info *v9ses);
172177
extern void v9fs_session_cancel(struct v9fs_session_info *v9ses);
173178
extern void v9fs_session_begin_cancel(struct v9fs_session_info *v9ses);

fs/9p/vfs_super.c

Lines changed: 91 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/statfs.h>
2020
#include <linux/magic.h>
2121
#include <linux/fscache.h>
22+
#include <linux/fs_context.h>
2223
#include <net/9p/9p.h>
2324
#include <net/9p/client.h>
2425

@@ -30,32 +31,10 @@
3031

3132
static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl;
3233

33-
/**
34-
* v9fs_set_super - set the superblock
35-
* @s: super block
36-
* @data: file system specific data
37-
*
38-
*/
39-
40-
static int v9fs_set_super(struct super_block *s, void *data)
41-
{
42-
s->s_fs_info = data;
43-
return set_anon_super(s, data);
44-
}
45-
46-
/**
47-
* v9fs_fill_super - populate superblock with info
48-
* @sb: superblock
49-
* @v9ses: session information
50-
* @flags: flags propagated from v9fs_mount()
51-
*
52-
*/
53-
54-
static int
55-
v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
56-
int flags)
34+
static int v9fs_fill_super(struct super_block *sb)
5735
{
5836
int ret;
37+
struct v9fs_session_info *v9ses = v9ses = sb->s_fs_info;
5938

6039
sb->s_maxbytes = MAX_LFS_FILESIZE;
6140
sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
@@ -95,16 +74,12 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
9574
}
9675

9776
/**
98-
* v9fs_mount - mount a superblock
99-
* @fs_type: file system type
100-
* @flags: mount flags
101-
* @dev_name: device name that was mounted
102-
* @data: mount options
77+
* v9fs_get_tree - create the mountable root and superblock
78+
* @fc: the filesystem context
10379
*
10480
*/
10581

106-
static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
107-
const char *dev_name, void *data)
82+
static int v9fs_get_tree(struct fs_context *fc)
10883
{
10984
struct super_block *sb = NULL;
11085
struct inode *inode = NULL;
@@ -117,20 +92,21 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
11792

11893
v9ses = kzalloc(sizeof(struct v9fs_session_info), GFP_KERNEL);
11994
if (!v9ses)
120-
return ERR_PTR(-ENOMEM);
95+
return -ENOMEM;
12196

122-
fid = v9fs_session_init(v9ses, dev_name, data);
97+
fid = v9fs_session_init(v9ses, fc);
12398
if (IS_ERR(fid)) {
12499
retval = PTR_ERR(fid);
125100
goto free_session;
126101
}
127102

128-
sb = sget(fs_type, NULL, v9fs_set_super, flags, v9ses);
103+
fc->s_fs_info = v9ses;
104+
sb = sget_fc(fc, NULL, set_anon_super_fc);
129105
if (IS_ERR(sb)) {
130106
retval = PTR_ERR(sb);
131107
goto clunk_fid;
132108
}
133-
retval = v9fs_fill_super(sb, v9ses, flags);
109+
retval = v9fs_fill_super(sb);
134110
if (retval)
135111
goto release_sb;
136112

@@ -159,14 +135,15 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
159135
v9fs_fid_add(root, &fid);
160136

161137
p9_debug(P9_DEBUG_VFS, " simple set mount, return 0\n");
162-
return dget(sb->s_root);
138+
fc->root = dget(sb->s_root);
139+
return 0;
163140

164141
clunk_fid:
165142
p9_fid_put(fid);
166143
v9fs_session_close(v9ses);
167144
free_session:
168145
kfree(v9ses);
169-
return ERR_PTR(retval);
146+
return retval;
170147

171148
release_sb:
172149
/*
@@ -177,7 +154,7 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags,
177154
*/
178155
p9_fid_put(fid);
179156
deactivate_locked_super(sb);
180-
return ERR_PTR(retval);
157+
return retval;
181158
}
182159

183160
/**
@@ -303,11 +280,86 @@ static const struct super_operations v9fs_super_ops_dotl = {
303280
.write_inode = v9fs_write_inode_dotl,
304281
};
305282

283+
static void v9fs_free_fc(struct fs_context *fc)
284+
{
285+
struct v9fs_context *ctx = fc->fs_private;
286+
287+
if (!ctx)
288+
return;
289+
290+
/* These should be NULL by now but guard against leaks */
291+
kfree(ctx->session_opts.uname);
292+
kfree(ctx->session_opts.aname);
293+
#ifdef CONFIG_9P_FSCACHE
294+
kfree(ctx->session_opts.cachetag);
295+
#endif
296+
if (ctx->client_opts.trans_mod)
297+
v9fs_put_trans(ctx->client_opts.trans_mod);
298+
kfree(ctx);
299+
}
300+
301+
static const struct fs_context_operations v9fs_context_ops = {
302+
.parse_param = v9fs_parse_param,
303+
.get_tree = v9fs_get_tree,
304+
.free = v9fs_free_fc,
305+
};
306+
307+
static int v9fs_init_fs_context(struct fs_context *fc)
308+
{
309+
struct v9fs_context *ctx;
310+
311+
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
312+
if (!ctx)
313+
return -ENOMEM;
314+
315+
/* initialize core options */
316+
ctx->session_opts.afid = ~0;
317+
ctx->session_opts.cache = CACHE_NONE;
318+
ctx->session_opts.session_lock_timeout = P9_LOCK_TIMEOUT;
319+
ctx->session_opts.uname = kstrdup(V9FS_DEFUSER, GFP_KERNEL);
320+
if (!ctx->session_opts.uname)
321+
goto error;
322+
323+
ctx->session_opts.aname = kstrdup(V9FS_DEFANAME, GFP_KERNEL);
324+
if (!ctx->session_opts.aname)
325+
goto error;
326+
327+
ctx->session_opts.uid = INVALID_UID;
328+
ctx->session_opts.dfltuid = V9FS_DEFUID;
329+
ctx->session_opts.dfltgid = V9FS_DEFGID;
330+
331+
/* initialize client options */
332+
ctx->client_opts.proto_version = p9_proto_2000L;
333+
ctx->client_opts.msize = DEFAULT_MSIZE;
334+
335+
/* initialize fd transport options */
336+
ctx->fd_opts.port = P9_FD_PORT;
337+
ctx->fd_opts.rfd = ~0;
338+
ctx->fd_opts.wfd = ~0;
339+
ctx->fd_opts.privport = false;
340+
341+
/* initialize rdma transport options */
342+
ctx->rdma_opts.port = P9_RDMA_PORT;
343+
ctx->rdma_opts.sq_depth = P9_RDMA_SQ_DEPTH;
344+
ctx->rdma_opts.rq_depth = P9_RDMA_RQ_DEPTH;
345+
ctx->rdma_opts.timeout = P9_RDMA_TIMEOUT;
346+
ctx->rdma_opts.privport = false;
347+
348+
fc->ops = &v9fs_context_ops;
349+
fc->fs_private = ctx;
350+
351+
return 0;
352+
error:
353+
fc->need_free = 1;
354+
return -ENOMEM;
355+
}
356+
306357
struct file_system_type v9fs_fs_type = {
307358
.name = "9p",
308-
.mount = v9fs_mount,
309359
.kill_sb = v9fs_kill_super,
310360
.owner = THIS_MODULE,
311361
.fs_flags = FS_RENAME_DOES_D_MOVE,
362+
.init_fs_context = v9fs_init_fs_context,
363+
.parameters = v9fs_param_spec,
312364
};
313365
MODULE_ALIAS_FS("9p");

include/net/9p/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
279279
const char *name);
280280
int p9_client_renameat(struct p9_fid *olddirfid, const char *old_name,
281281
struct p9_fid *newdirfid, const char *new_name);
282-
struct p9_client *p9_client_create(const char *dev_name, char *options);
282+
struct p9_client *p9_client_create(struct fs_context *fc);
283283
void p9_client_destroy(struct p9_client *clnt);
284284
void p9_client_disconnect(struct p9_client *clnt);
285285
void p9_client_begin_disconnect(struct p9_client *clnt);

include/net/9p/transport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct p9_trans_module {
5757
bool supports_vmalloc; /* can work with vmalloc'd buffers */
5858
struct module *owner;
5959
int (*create)(struct p9_client *client,
60-
const char *devname, char *args);
60+
struct fs_context *fc);
6161
void (*close)(struct p9_client *client);
6262
int (*request)(struct p9_client *client, struct p9_req_t *req);
6363
int (*cancel)(struct p9_client *client, struct p9_req_t *req);

0 commit comments

Comments
 (0)