Skip to content

Commit bbbf7f3

Browse files
committed
Merge tag '9p-for-6.19-rc1' of https://github.com/martinetd/linux
Pull 9p updates from Dominique Martinet: - fix a bug with O_APPEND in cached mode causing data to be written multiple times on server - use kvmalloc for trans_fd to avoid problems with large msize and fragmented memory This should hopefully be used in more transports when time allows - convert to new mount API - minor cleanups * tag '9p-for-6.19-rc1' of https://github.com/martinetd/linux: 9p: fix new mount API cache option handling 9p: fix cache/debug options printing in v9fs_show_options 9p: convert to the new mount API 9p: create a v9fs_context structure to hold parsed options net/9p: move structures and macros to header files fs/fs_parse: add back fsparam_u32hex fs/9p: delete unnnecessary condition fs/9p: Don't open remote file with APPEND mode when writeback cache is used net/9p: cleanup: change p9_trans_module->def to bool 9p: Use kvmalloc for message buffers on supported transports
2 parents 9e906a9 + 3e28111 commit bbbf7f3

17 files changed

Lines changed: 564 additions & 689 deletions

fs/9p/v9fs.c

Lines changed: 279 additions & 245 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_dentry.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ static int __v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
109109
p9_debug(P9_DEBUG_VFS,
110110
"refresh inode: dentry = %pd (%p), got error %pe\n",
111111
dentry, dentry, ERR_PTR(retval));
112-
if (retval < 0)
113112
return retval;
114113
}
115114
}

fs/9p/vfs_file.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,29 @@ int v9fs_file_open(struct inode *inode, struct file *file)
4343
struct v9fs_session_info *v9ses;
4444
struct p9_fid *fid;
4545
int omode;
46+
int o_append;
4647

4748
p9_debug(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
4849
v9ses = v9fs_inode2v9ses(inode);
49-
if (v9fs_proto_dotl(v9ses))
50+
if (v9fs_proto_dotl(v9ses)) {
5051
omode = v9fs_open_to_dotl_flags(file->f_flags);
51-
else
52+
o_append = P9_DOTL_APPEND;
53+
} else {
5254
omode = v9fs_uflags2omode(file->f_flags,
5355
v9fs_proto_dotu(v9ses));
56+
o_append = P9_OAPPEND;
57+
}
5458
fid = file->private_data;
5559
if (!fid) {
5660
fid = v9fs_fid_clone(file_dentry(file));
5761
if (IS_ERR(fid))
5862
return PTR_ERR(fid);
5963

6064
if ((v9ses->cache & CACHE_WRITEBACK) && (omode & P9_OWRITE)) {
61-
int writeback_omode = (omode & ~P9_OWRITE) | P9_ORDWR;
65+
int writeback_omode = (omode & ~(P9_OWRITE | o_append)) | P9_ORDWR;
6266

6367
p9_debug(P9_DEBUG_CACHE, "write-only file with writeback enabled, try opening O_RDWR\n");
68+
6469
err = p9_client_open(fid, writeback_omode);
6570
if (err < 0) {
6671
p9_debug(P9_DEBUG_CACHE, "could not open O_RDWR, disabling caches\n");

fs/9p/vfs_inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
786786
p9_omode = v9fs_uflags2omode(flags, v9fs_proto_dotu(v9ses));
787787

788788
if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
789-
p9_omode = (p9_omode & ~P9_OWRITE) | P9_ORDWR;
789+
p9_omode = (p9_omode & ~(P9_OWRITE | P9_OAPPEND)) | P9_ORDWR;
790790
p9_debug(P9_DEBUG_CACHE,
791791
"write-only file with writeback enabled, creating w/ O_RDWR\n");
792792
}
@@ -1393,4 +1393,3 @@ static const struct inode_operations v9fs_symlink_inode_operations = {
13931393
.getattr = v9fs_vfs_getattr,
13941394
.setattr = v9fs_vfs_setattr,
13951395
};
1396-

fs/9p/vfs_inode_dotl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
282282
}
283283

284284
if ((v9ses->cache & CACHE_WRITEBACK) && (p9_omode & P9_OWRITE)) {
285-
p9_omode = (p9_omode & ~P9_OWRITE) | P9_ORDWR;
285+
p9_omode = (p9_omode & ~(P9_OWRITE | P9_DOTL_APPEND)) | P9_ORDWR;
286286
p9_debug(P9_DEBUG_CACHE,
287287
"write-only file with writeback enabled, creating w/ O_RDWR\n");
288288
}

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/linux/fs_parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ static inline bool fs_validate_description(const char *name,
120120
#define fsparam_u32(NAME, OPT) __fsparam(fs_param_is_u32, NAME, OPT, 0, NULL)
121121
#define fsparam_u32oct(NAME, OPT) \
122122
__fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)8)
123+
#define fsparam_u32hex(NAME, OPT) \
124+
__fsparam(fs_param_is_u32, NAME, OPT, 0, (void *)16)
123125
#define fsparam_s32(NAME, OPT) __fsparam(fs_param_is_s32, NAME, OPT, 0, NULL)
124126
#define fsparam_u64(NAME, OPT) __fsparam(fs_param_is_u64, NAME, OPT, 0, NULL)
125127
#define fsparam_enum(NAME, OPT, array) __fsparam(fs_param_is_enum, NAME, OPT, 0, array)

0 commit comments

Comments
 (0)