Skip to content

Commit 780b1b9

Browse files
lostjeffleMiklos Szeredi
authored andcommitted
fuse: make DAX mount option a tri-state
We add 'always', 'never', and 'inode' (default). '-o dax' continues to operate the same which is equivalent to 'always'. The following behavior is consistent with that on ext4/xfs: - The default behavior (when neither '-o dax' nor '-o dax=always|never|inode' option is specified) is equal to 'inode' mode, while 'dax=inode' won't be printed among the mount option list. - The 'inode' mode is only advisory. It will silently fallback to 'never' mode if fuse server doesn't support that. Also noted that by the time of this commit, 'inode' mode is actually equal to 'always' mode, before the per inode DAX flag is introduced in the following patch. Signed-off-by: Jeffle Xu <[email protected]> Reviewed-by: Vivek Goyal <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent cecd491 commit 780b1b9

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

fs/fuse/dax.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,14 @@ static int fuse_dax_mem_range_init(struct fuse_conn_dax *fcd)
12791279
return ret;
12801280
}
12811281

1282-
int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev)
1282+
int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode dax_mode,
1283+
struct dax_device *dax_dev)
12831284
{
12841285
struct fuse_conn_dax *fcd;
12851286
int err;
12861287

1288+
fc->dax_mode = dax_mode;
1289+
12871290
if (!dax_dev)
12881291
return 0;
12891292

@@ -1330,7 +1333,15 @@ static const struct address_space_operations fuse_dax_file_aops = {
13301333
static bool fuse_should_enable_dax(struct inode *inode)
13311334
{
13321335
struct fuse_conn *fc = get_fuse_conn(inode);
1336+
enum fuse_dax_mode dax_mode = fc->dax_mode;
1337+
1338+
if (dax_mode == FUSE_DAX_NEVER)
1339+
return false;
13331340

1341+
/*
1342+
* fc->dax may be NULL in 'inode' mode when filesystem device doesn't
1343+
* support DAX, in which case it will silently fallback to 'never' mode.
1344+
*/
13341345
if (!fc->dax)
13351346
return false;
13361347

fs/fuse/fuse_i.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ struct fuse_dev {
480480
struct list_head entry;
481481
};
482482

483+
enum fuse_dax_mode {
484+
FUSE_DAX_INODE_DEFAULT, /* default */
485+
FUSE_DAX_ALWAYS, /* "-o dax=always" */
486+
FUSE_DAX_NEVER, /* "-o dax=never" */
487+
FUSE_DAX_INODE_USER, /* "-o dax=inode" */
488+
};
489+
490+
static inline bool fuse_is_inode_dax_mode(enum fuse_dax_mode mode)
491+
{
492+
return mode == FUSE_DAX_INODE_DEFAULT || mode == FUSE_DAX_INODE_USER;
493+
}
494+
483495
struct fuse_fs_context {
484496
int fd;
485497
struct file *file;
@@ -497,7 +509,7 @@ struct fuse_fs_context {
497509
bool no_control:1;
498510
bool no_force_umount:1;
499511
bool legacy_opts_show:1;
500-
bool dax:1;
512+
enum fuse_dax_mode dax_mode;
501513
unsigned int max_read;
502514
unsigned int blksize;
503515
const char *subtype;
@@ -805,6 +817,9 @@ struct fuse_conn {
805817
struct list_head devices;
806818

807819
#ifdef CONFIG_FUSE_DAX
820+
/* Dax mode */
821+
enum fuse_dax_mode dax_mode;
822+
808823
/* Dax specific conn data, non-NULL if DAX is enabled */
809824
struct fuse_conn_dax *dax;
810825
#endif
@@ -1272,7 +1287,8 @@ ssize_t fuse_dax_read_iter(struct kiocb *iocb, struct iov_iter *to);
12721287
ssize_t fuse_dax_write_iter(struct kiocb *iocb, struct iov_iter *from);
12731288
int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma);
12741289
int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end);
1275-
int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
1290+
int fuse_dax_conn_alloc(struct fuse_conn *fc, enum fuse_dax_mode mode,
1291+
struct dax_device *dax_dev);
12761292
void fuse_dax_conn_free(struct fuse_conn *fc);
12771293
bool fuse_dax_inode_alloc(struct super_block *sb, struct fuse_inode *fi);
12781294
void fuse_dax_inode_init(struct inode *inode);

fs/fuse/inode.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,12 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)
767767
seq_printf(m, ",blksize=%lu", sb->s_blocksize);
768768
}
769769
#ifdef CONFIG_FUSE_DAX
770-
if (fc->dax)
771-
seq_puts(m, ",dax");
770+
if (fc->dax_mode == FUSE_DAX_ALWAYS)
771+
seq_puts(m, ",dax=always");
772+
else if (fc->dax_mode == FUSE_DAX_NEVER)
773+
seq_puts(m, ",dax=never");
774+
else if (fc->dax_mode == FUSE_DAX_INODE_USER)
775+
seq_puts(m, ",dax=inode");
772776
#endif
773777

774778
return 0;
@@ -1523,7 +1527,7 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
15231527
sb->s_subtype = ctx->subtype;
15241528
ctx->subtype = NULL;
15251529
if (IS_ENABLED(CONFIG_FUSE_DAX)) {
1526-
err = fuse_dax_conn_alloc(fc, ctx->dax_dev);
1530+
err = fuse_dax_conn_alloc(fc, ctx->dax_mode, ctx->dax_dev);
15271531
if (err)
15281532
goto err;
15291533
}

fs/fuse/virtio_fs.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,21 @@ struct virtio_fs_req_work {
8888
static int virtio_fs_enqueue_req(struct virtio_fs_vq *fsvq,
8989
struct fuse_req *req, bool in_flight);
9090

91+
static const struct constant_table dax_param_enums[] = {
92+
{"always", FUSE_DAX_ALWAYS },
93+
{"never", FUSE_DAX_NEVER },
94+
{"inode", FUSE_DAX_INODE_USER },
95+
{}
96+
};
97+
9198
enum {
9299
OPT_DAX,
100+
OPT_DAX_ENUM,
93101
};
94102

95103
static const struct fs_parameter_spec virtio_fs_parameters[] = {
96104
fsparam_flag("dax", OPT_DAX),
105+
fsparam_enum("dax", OPT_DAX_ENUM, dax_param_enums),
97106
{}
98107
};
99108

@@ -110,7 +119,10 @@ static int virtio_fs_parse_param(struct fs_context *fsc,
110119

111120
switch (opt) {
112121
case OPT_DAX:
113-
ctx->dax = 1;
122+
ctx->dax_mode = FUSE_DAX_ALWAYS;
123+
break;
124+
case OPT_DAX_ENUM:
125+
ctx->dax_mode = result.uint_32;
114126
break;
115127
default:
116128
return -EINVAL;
@@ -1326,8 +1338,8 @@ static int virtio_fs_fill_super(struct super_block *sb, struct fs_context *fsc)
13261338

13271339
/* virtiofs allocates and installs its own fuse devices */
13281340
ctx->fudptr = NULL;
1329-
if (ctx->dax) {
1330-
if (!fs->dax_dev) {
1341+
if (ctx->dax_mode != FUSE_DAX_NEVER) {
1342+
if (ctx->dax_mode == FUSE_DAX_ALWAYS && !fs->dax_dev) {
13311343
err = -EINVAL;
13321344
pr_err("virtio-fs: dax can't be enabled as filesystem"
13331345
" device does not support it.\n");

0 commit comments

Comments
 (0)