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
3031
3132static 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
164141clunk_fid :
165142 p9_fid_put (fid );
166143 v9fs_session_close (v9ses );
167144free_session :
168145 kfree (v9ses );
169- return ERR_PTR ( retval ) ;
146+ return retval ;
170147
171148release_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+
306357struct 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};
313365MODULE_ALIAS_FS ("9p" );
0 commit comments