From: Richard Weinberger <rich…@nod.at>
A driver which implements a userspace backed device on top of the FUSE
transport does not have to live in fs/fuse/. So far such a driver would
need fuse_i.h, and with it every internal data structure of FUSE.
Add <net/fuse.h> and move the bare minimum to it: the request arguments
(struct fuse_args), the device file operations, fuse_dev_release(),
fuse_dev_put(), reference counting of struct fuse_conn, and
fuse_kv_parse_one(). struct fuse_conn and struct fuse_dev are opaque to
users of this header.
No functional change, the private headers include the new one.
Signed-off-by: Richard Weinberger <rich…@nod.at>
---
MAINTAINERS | 1 +
fs/fuse/args.h | 44 +----------------------
fs/fuse/dev.h | 12 +------
fs/fuse/fuse_dev_i.h | 3 +-
fs/fuse/fuse_i.h | 9 -----
include/net/fuse.h | 85 ++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 89 insertions(+), 65 deletions(-)
create mode 100644 include/net/fuse.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..6626e026deea 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11039,6 +11039,7 @@ W: https://github.com/libfuse/
T: git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git
F: Documentation/filesystems/fuse/*
F: fs/fuse/
+F: include/net/fuse.h
F: include/uapi/linux/fuse.h
F: tools/testing/selftests/filesystems/fuse/
diff --git a/fs/fuse/args.h b/fs/fuse/args.h
index 36ef0c6d5999..d9c4fb1a19b3 100644
--- a/fs/fuse/args.h
+++ b/fs/fuse/args.h
@@ -4,52 +4,10 @@
#define _FS_FUSE_ARGS_H
#include <linux/types.h>
+#include <net/fuse.h>
struct fuse_mount;
-/** One input argument of a request */
-struct fuse_in_arg {
- unsigned size;
- const void *value;
-};
-
-/** One output argument of a request */
-struct fuse_arg {
- unsigned size;
- void *value;
-};
-
-struct fuse_args {
- u64 nodeid;
- u32 opcode;
- u32 uid;
- u32 gid;
- u32 pid;
- u8 in_numargs;
- u8 out_numargs;
- u8 ext_idx;
- bool force:1;
- bool noreply:1;
- bool nocreds:1;
- bool in_pages:1;
- bool out_pages:1;
- bool user_pages:1;
- bool out_argvar:1;
- bool page_zeroing:1;
- bool may_block:1;
- bool is_ext:1;
- bool is_pinned:1;
- bool invalidate_vmap:1;
- bool abort_on_kill:1;
- /* server requested io-uring zero-copy for this op */
- bool zero_copy:1;
- struct fuse_in_arg in_args[4];
- struct fuse_arg out_args[2];
- void (*end)(struct fuse_args *args, int error);
- /* Used for kvec iter backed by vmalloc address */
- void *vmap_base;
-};
-
/** FUSE folio descriptor */
struct fuse_folio_desc {
unsigned int length;
diff --git a/fs/fuse/dev.h b/fs/fuse/dev.h
index dbffd5bed2f5..3e4838b32c79 100644
--- a/fs/fuse/dev.h
+++ b/fs/fuse/dev.h
@@ -4,6 +4,7 @@
#define _FS_FUSE_DEV_H
#include <linux/cleanup.h>
+#include <net/fuse.h>
/** Maximum number of outstanding background requests */
#define FUSE_DEFAULT_MAX_BACKGROUND 12
@@ -59,7 +60,6 @@ void fuse_dev_cleanup(void);
void fuse_dev_install(struct fuse_dev *fud, struct fuse_chan *fch);
bool fuse_dev_verify(struct fuse_dev *fud, struct fuse_chan *fch);
-void fuse_dev_put(struct fuse_dev *fud);
bool fuse_dev_is_installed(struct fuse_dev *fud);
bool fuse_dev_is_sync_init(struct fuse_dev *fud);
struct fuse_dev *fuse_dev_grab(struct file *file);
@@ -70,16 +70,6 @@ void fuse_init_server_timeout(struct fuse_chan *fch, unsigned int timeout);
void fuse_chan_abort(struct fuse_chan *fch, bool abort_with_err);
void fuse_chan_wait_aborted(struct fuse_chan *fch);
-/**
- * Acquire reference to fuse_conn
- */
-struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
-
-/**
- * Release reference to fuse_conn
- */
-void fuse_conn_put(struct fuse_conn *fc);
-
dev_t fuse_conn_get_id(struct fuse_conn *fc);
void fuse_end_polls(struct fuse_conn *fc);
diff --git a/fs/fuse/fuse_dev_i.h b/fs/fuse/fuse_dev_i.h
index a8eba46a3e51..82621b8d41e6 100644
--- a/fs/fuse/fuse_dev_i.h
+++ b/fs/fuse/fuse_dev_i.h
@@ -12,6 +12,7 @@
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <linux/fs.h>
+#include <net/fuse.h>
/* Ordinary requests have even IDs, while interrupts IDs are odd */
#define FUSE_INT_REQ_BIT (1ULL << 0)
@@ -411,8 +412,6 @@ u64 fuse_get_unique(struct fuse_iqueue *fiq);
struct fuse_dev *fuse_dev_alloc_install(struct fuse_chan *fch);
struct fuse_dev *fuse_dev_alloc(void);
-int fuse_dev_release(struct inode *inode, struct file *file);
-
struct list_head *fuse_pqueue_alloc(void);
/*
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index b6153db7e76a..8bceab59c1ca 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -365,8 +365,6 @@ union fuse_file_args {
struct fuse_release_args release_args;
};
-#define FUSE_ARGS(args) struct fuse_args args = {}
-
/** The request IO state (for asynchronous processing) */
struct fuse_io_priv {
struct kref refcnt;
@@ -959,9 +957,6 @@ static inline void fuse_sync_bucket_dec(struct fuse_sync_bucket *bucket)
rcu_read_unlock();
}
-/** Device operations */
-extern const struct file_operations fuse_dev_operations;
-
extern const struct dentry_operations fuse_dentry_operations;
/*
@@ -1410,8 +1405,4 @@ int fuse_ext_map_mmap(struct file *file, struct vm_area_struct *vma);
bool fuse_ext_map_is_dax(struct fuse_backing *fb);
int fuse_ext_map_populate(struct fuse_conn *fc, struct fuse_notify_backing_map_out *arg,
struct fuse_extent *ext);
-
-/* helper.c */
-int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp);
-
#endif /* _FS_FUSE_I_H */
diff --git a/include/net/fuse.h b/include/net/fuse.h
new file mode 100644
index 000000000000..206193f4653a
--- /dev/null
+++ b/include/net/fuse.h
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * FUSE transport interface for users outside of fs/fuse/.
+ *
+ * This is the bare minimum a driver needs to implement a device which is
+ * backed by a userspace server.
+ */
+
+#ifndef _NET_FUSE_H
+#define _NET_FUSE_H
+
+#include <linux/types.h>
+
+struct file;
+struct file_operations;
+struct fuse_conn;
+struct fuse_dev;
+struct inode;
+struct user_namespace;
+
+/** One input argument of a request */
+struct fuse_in_arg {
+ unsigned size;
+ const void *value;
+};
+
+/** One output argument of a request */
+struct fuse_arg {
+ unsigned size;
+ void *value;
+};
+
+struct fuse_args {
+ u64 nodeid;
+ u32 opcode;
+ u32 uid;
+ u32 gid;
+ u32 pid;
+ u8 in_numargs;
+ u8 out_numargs;
+ u8 ext_idx;
+ bool force:1;
+ bool noreply:1;
+ bool nocreds:1;
+ bool in_pages:1;
+ bool out_pages:1;
+ bool user_pages:1;
+ bool out_argvar:1;
+ bool page_zeroing:1;
+ bool may_block:1;
+ bool is_ext:1;
+ bool is_pinned:1;
+ bool invalidate_vmap:1;
+ bool abort_on_kill:1;
+ /* server requested io-uring zero-copy for this op */
+ bool zero_copy:1;
+ struct fuse_in_arg in_args[4];
+ struct fuse_arg out_args[2];
+ void (*end)(struct fuse_args *args, int error);
+ /* Used for kvec iter backed by vmalloc address */
+ void *vmap_base;
+};
+
+#define FUSE_ARGS(args) struct fuse_args args = {}
+
+/** Device operations */
+extern const struct file_operations fuse_dev_operations;
+
+int fuse_dev_release(struct inode *inode, struct file *file);
+void fuse_dev_put(struct fuse_dev *fud);
+
+/**
+ * Acquire reference to fuse_conn
+ */
+struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
+
+/**
+ * Release reference to fuse_conn
+ */
+void fuse_conn_put(struct fuse_conn *fc);
+
+/* Helpers for userspace backed devices, see fs/fuse/helper.c */
+int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp);
+
+#endif /* _NET_FUSE_H */
--
2.55.0