Commit 1dd53957 authored by Vivek Goyal's avatar Vivek Goyal Committed by Miklos Szeredi
Browse files

virtiofs: add a mount option to enable dax



Add a mount option to allow using dax with virtio_fs.

Signed-off-by: default avatarVivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 22f3787e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -38,3 +38,16 @@ config VIRTIO_FS

	  If you want to share files between guests or with the host, answer Y
	  or M.

config FUSE_DAX
	bool "Virtio Filesystem Direct Host Memory Access support"
	default y
	depends on VIRTIO_FS
	depends on FS_DAX
	depends on DAX_DRIVER
	help
	  This allows bypassing guest page cache and allows mapping host page
	  cache directly in guest address space.

	  If you want to allow mounting a Virtio Filesystem with the "dax"
	  option, answer Y.
+4 −2
Original line number Diff line number Diff line
@@ -7,5 +7,7 @@ obj-$(CONFIG_FUSE_FS) += fuse.o
obj-$(CONFIG_CUSE) += cuse.o
obj-$(CONFIG_VIRTIO_FS) += virtiofs.o

fuse-objs := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o
virtiofs-y += virtio_fs.o
fuse-y := dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o
fuse-$(CONFIG_FUSE_DAX) += dax.o

virtiofs-y := virtio_fs.o

fs/fuse/dax.c

0 → 100644
+36 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * dax: direct host memory access
 * Copyright (C) 2020 Red Hat, Inc.
 */

#include "fuse_i.h"

#include <linux/dax.h>

struct fuse_conn_dax {
	/* DAX device */
	struct dax_device *dev;
};

void fuse_dax_conn_free(struct fuse_conn *fc)
{
	kfree(fc->dax);
}

int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev)
{
	struct fuse_conn_dax *fcd;

	if (!dax_dev)
		return 0;

	fcd = kzalloc(sizeof(*fcd), GFP_KERNEL);
	if (!fcd)
		return -ENOMEM;

	fcd->dev = dax_dev;

	fc->dax = fcd;
	return 0;
}
+14 −0
Original line number Diff line number Diff line
@@ -483,10 +483,14 @@ struct fuse_fs_context {
	bool no_control:1;
	bool no_force_umount:1;
	bool legacy_opts_show:1;
	bool dax:1;
	unsigned int max_read;
	unsigned int blksize;
	const char *subtype;

	/* DAX device, may be NULL */
	struct dax_device *dax_dev;

	/* fuse_dev pointer to fill in, should contain NULL on entry */
	void **fudptr;
};
@@ -755,6 +759,11 @@ struct fuse_conn {

	/** List of device instances belonging to this connection */
	struct list_head devices;

#ifdef CONFIG_FUSE_DAX
	/* Dax specific conn data, non-NULL if DAX is enabled */
	struct fuse_conn_dax *dax;
#endif
};

static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -1093,4 +1102,9 @@ unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args);
u64 fuse_get_unique(struct fuse_iqueue *fiq);
void fuse_free_conn(struct fuse_conn *fc);

/* dax.c */

int fuse_dax_conn_alloc(struct fuse_conn *fc, struct dax_device *dax_dev);
void fuse_dax_conn_free(struct fuse_conn *fc);

#endif /* _FS_FUSE_I_H */
+17 −1
Original line number Diff line number Diff line
@@ -587,6 +587,11 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)
		if (sb->s_bdev && sb->s_blocksize != FUSE_DEFAULT_BLKSIZE)
			seq_printf(m, ",blksize=%lu", sb->s_blocksize);
	}
#ifdef CONFIG_FUSE_DAX
	if (fc->dax)
		seq_puts(m, ",dax");
#endif

	return 0;
}

@@ -651,6 +656,8 @@ void fuse_conn_put(struct fuse_conn *fc)
	if (refcount_dec_and_test(&fc->count)) {
		struct fuse_iqueue *fiq = &fc->iq;

		if (IS_ENABLED(CONFIG_FUSE_DAX))
			fuse_dax_conn_free(fc);
		if (fiq->ops->release)
			fiq->ops->release(fiq);
		put_pid_ns(fc->pid_ns);
@@ -1175,11 +1182,17 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
	if (sb->s_user_ns != &init_user_ns)
		sb->s_xattr = fuse_no_acl_xattr_handlers;

	if (IS_ENABLED(CONFIG_FUSE_DAX)) {
		err = fuse_dax_conn_alloc(fc, ctx->dax_dev);
		if (err)
			goto err;
	}

	if (ctx->fudptr) {
		err = -ENOMEM;
		fud = fuse_dev_alloc_install(fc);
		if (!fud)
			goto err;
			goto err_free_dax;
	}

	fc->dev = sb->s_dev;
@@ -1234,6 +1247,9 @@ int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
 err_dev_free:
	if (fud)
		fuse_dev_free(fud);
 err_free_dax:
	if (IS_ENABLED(CONFIG_FUSE_DAX))
		fuse_dax_conn_free(fc);
 err:
	return err;
}
Loading