1313#include <linux/virtio_fs.h>
1414#include <linux/delay.h>
1515#include <linux/fs_context.h>
16+ #include <linux/fs_parser.h>
1617#include <linux/highmem.h>
1718#include <linux/uio.h>
1819#include "fuse_i.h"
@@ -81,6 +82,44 @@ struct virtio_fs_req_work {
8182static int virtio_fs_enqueue_req (struct virtio_fs_vq * fsvq ,
8283 struct fuse_req * req , bool in_flight );
8384
85+ enum {
86+ OPT_DAX ,
87+ };
88+
89+ static const struct fs_parameter_spec virtio_fs_parameters [] = {
90+ fsparam_flag ("dax" , OPT_DAX ),
91+ {}
92+ };
93+
94+ static int virtio_fs_parse_param (struct fs_context * fc ,
95+ struct fs_parameter * param )
96+ {
97+ struct fs_parse_result result ;
98+ struct fuse_fs_context * ctx = fc -> fs_private ;
99+ int opt ;
100+
101+ opt = fs_parse (fc , virtio_fs_parameters , param , & result );
102+ if (opt < 0 )
103+ return opt ;
104+
105+ switch (opt ) {
106+ case OPT_DAX :
107+ ctx -> dax = 1 ;
108+ break ;
109+ default :
110+ return - EINVAL ;
111+ }
112+
113+ return 0 ;
114+ }
115+
116+ static void virtio_fs_free_fc (struct fs_context * fc )
117+ {
118+ struct fuse_fs_context * ctx = fc -> fs_private ;
119+
120+ kfree (ctx );
121+ }
122+
84123static inline struct virtio_fs_vq * vq_to_fsvq (struct virtqueue * vq )
85124{
86125 struct virtio_fs * fs = vq -> vdev -> priv ;
@@ -1219,23 +1258,27 @@ static const struct fuse_iqueue_ops virtio_fs_fiq_ops = {
12191258 .release = virtio_fs_fiq_release ,
12201259};
12211260
1222- static int virtio_fs_fill_super (struct super_block * sb )
1261+ static inline void virtio_fs_ctx_set_defaults (struct fuse_fs_context * ctx )
1262+ {
1263+ ctx -> rootmode = S_IFDIR ;
1264+ ctx -> default_permissions = 1 ;
1265+ ctx -> allow_other = 1 ;
1266+ ctx -> max_read = UINT_MAX ;
1267+ ctx -> blksize = 512 ;
1268+ ctx -> destroy = true;
1269+ ctx -> no_control = true;
1270+ ctx -> no_force_umount = true;
1271+ }
1272+
1273+ static int virtio_fs_fill_super (struct super_block * sb , struct fs_context * fsc )
12231274{
12241275 struct fuse_conn * fc = get_fuse_conn_super (sb );
12251276 struct virtio_fs * fs = fc -> iq .priv ;
1277+ struct fuse_fs_context * ctx = fsc -> fs_private ;
12261278 unsigned int i ;
12271279 int err ;
1228- struct fuse_fs_context ctx = {
1229- .rootmode = S_IFDIR ,
1230- .default_permissions = 1 ,
1231- .allow_other = 1 ,
1232- .max_read = UINT_MAX ,
1233- .blksize = 512 ,
1234- .destroy = true,
1235- .no_control = true,
1236- .no_force_umount = true,
1237- };
12381280
1281+ virtio_fs_ctx_set_defaults (ctx );
12391282 mutex_lock (& virtio_fs_mutex );
12401283
12411284 /* After holding mutex, make sure virtiofs device is still there.
@@ -1259,8 +1302,10 @@ static int virtio_fs_fill_super(struct super_block *sb)
12591302 }
12601303
12611304 /* virtiofs allocates and installs its own fuse devices */
1262- ctx .fudptr = NULL ;
1263- err = fuse_fill_super_common (sb , & ctx );
1305+ ctx -> fudptr = NULL ;
1306+ if (ctx -> dax )
1307+ ctx -> dax_dev = fs -> dax_dev ;
1308+ err = fuse_fill_super_common (sb , ctx );
12641309 if (err < 0 )
12651310 goto err_free_fuse_devs ;
12661311
@@ -1371,7 +1416,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
13711416 return PTR_ERR (sb );
13721417
13731418 if (!sb -> s_root ) {
1374- err = virtio_fs_fill_super (sb );
1419+ err = virtio_fs_fill_super (sb , fsc );
13751420 if (err ) {
13761421 deactivate_locked_super (sb );
13771422 return err ;
@@ -1386,11 +1431,19 @@ static int virtio_fs_get_tree(struct fs_context *fsc)
13861431}
13871432
13881433static const struct fs_context_operations virtio_fs_context_ops = {
1434+ .free = virtio_fs_free_fc ,
1435+ .parse_param = virtio_fs_parse_param ,
13891436 .get_tree = virtio_fs_get_tree ,
13901437};
13911438
13921439static int virtio_fs_init_fs_context (struct fs_context * fsc )
13931440{
1441+ struct fuse_fs_context * ctx ;
1442+
1443+ ctx = kzalloc (sizeof (struct fuse_fs_context ), GFP_KERNEL );
1444+ if (!ctx )
1445+ return - ENOMEM ;
1446+ fsc -> fs_private = ctx ;
13941447 fsc -> ops = & virtio_fs_context_ops ;
13951448 return 0 ;
13961449}
0 commit comments