[PATCH 14/52] fuse: add fuse_conn->dax_dev field

From: Vivek Goyal
Date: Mon Dec 10 2018 - 12:16:32 EST


From: Stefan Hajnoczi <stefanha@xxxxxxxxxx>

A struct dax_device instance is a prerequisite for the DAX filesystem
APIs. Let virtio_fs associate a dax_device with a fuse_conn. Classic
FUSE and CUSE set the pointer to NULL, disabling DAX.

Signed-off-by: Stefan Hajnoczi <stefanha@xxxxxxxxxx>
---
fs/fuse/cuse.c | 3 ++-
fs/fuse/fuse_i.h | 8 +++++++-
fs/fuse/inode.c | 9 ++++++---
fs/fuse/virtio_fs.c | 3 ++-
4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
index 98dc780cbafa..bf8c1c470e8c 100644
--- a/fs/fuse/cuse.c
+++ b/fs/fuse/cuse.c
@@ -503,7 +503,8 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
* Limit the cuse channel to requests that can
* be represented in file->f_cred->user_ns.
*/
- fuse_conn_init(&cc->fc, file->f_cred->user_ns, &fuse_dev_fiq_ops, NULL);
+ fuse_conn_init(&cc->fc, file->f_cred->user_ns, NULL, &fuse_dev_fiq_ops,
+ NULL);

fud = fuse_dev_alloc(&cc->fc);
if (!fud) {
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index f463586f2c9e..b5a6a12e67d6 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -803,6 +803,9 @@ struct fuse_conn {

/** List of device instances belonging to this connection */
struct list_head devices;
+
+ /** DAX device, non-NULL if DAX is supported */
+ struct dax_device *dax_dev;
};

static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -1025,7 +1028,8 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
* Initialize fuse_conn
*/
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
- const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
+ struct dax_device *dax_dev,
+ const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);

/**
* Release reference to fuse_conn
@@ -1045,12 +1049,14 @@ int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev,
* Fill in superblock and initialize fuse connection
* @sb: partially-initialized superblock to fill in
* @mount_data: mount parameters
+ * @dax_dev: DAX device, may be NULL
* @fiq_ops: fuse input queue operations
* @fiq_priv: device-specific state for fuse_iqueue
* @fudptr: fuse_dev pointer to fill in, should contain NULL on entry
*/
int fuse_fill_super_common(struct super_block *sb,
struct fuse_mount_data *mount_data,
+ struct dax_device *dax_dev,
const struct fuse_iqueue_ops *fiq_ops,
void *fiq_priv,
void **fudptr);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 31bb817575c4..10e4a39318c4 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -600,7 +600,8 @@ static void fuse_pqueue_init(struct fuse_pqueue *fpq)
}

void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
- const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv)
+ struct dax_device *dax_dev,
+ const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv)
{
memset(fc, 0, sizeof(*fc));
spin_lock_init(&fc->lock);
@@ -625,6 +626,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
fc->attr_version = 1;
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
+ fc->dax_dev = dax_dev;
fc->user_ns = get_user_ns(user_ns);
}
EXPORT_SYMBOL_GPL(fuse_conn_init);
@@ -1072,6 +1074,7 @@ EXPORT_SYMBOL_GPL(fuse_dev_free);

int fuse_fill_super_common(struct super_block *sb,
struct fuse_mount_data *mount_data,
+ struct dax_device *dax_dev,
const struct fuse_iqueue_ops *fiq_ops,
void *fiq_priv,
void **fudptr)
@@ -1122,7 +1125,7 @@ int fuse_fill_super_common(struct super_block *sb,
if (!fc)
goto err;

- fuse_conn_init(fc, sb->s_user_ns, fiq_ops, fiq_priv);
+ fuse_conn_init(fc, sb->s_user_ns, dax_dev, fiq_ops, fiq_priv);
fc->release = fuse_free_conn;

fud = fuse_dev_alloc(fc);
@@ -1233,7 +1236,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
(file->f_cred->user_ns != sb->s_user_ns))
goto err_fput;

- err = fuse_fill_super_common(sb, &d, &fuse_dev_fiq_ops, NULL,
+ err = fuse_fill_super_common(sb, &d, NULL, &fuse_dev_fiq_ops, NULL,
&file->private_data);
err_fput:
fput(file);
diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index fd914f2c6209..ba615ec2603e 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -844,7 +844,8 @@ static int virtio_fs_fill_super(struct super_block *sb, void *data,
/* TODO this sends FUSE_INIT and could cause hiprio or notifications
* virtqueue races since they haven't been set up yet!
*/
- err = fuse_fill_super_common(sb, &d, &virtio_fs_fiq_ops, fs,
+ err = fuse_fill_super_common(sb, &d, fs->dax_dev,
+ &virtio_fs_fiq_ops, fs,
(void **)&fs->vqs[2].fud);
if (err < 0)
goto err_fud;
--
2.13.6