Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 0d86dc02 authored by Alessio Balsini's avatar Alessio Balsini Committed by Hridaya Prajapati
Browse files

FROMLIST: fuse: Definitions and ioctl for passthrough

Expose the FUSE_PASSTHROUGH interface to user space and declare all the
basic data structures and functions as the skeleton on top of which the
FUSE passthrough functionality will be built.

As part of this, introduce the new FUSE passthrough ioctl, which allows
the FUSE daemon to specify a direct connection between a FUSE file and a
lower file system file. Such ioctl requires user space to pass the file
descriptor of one of its opened files through the fuse_passthrough_out
data structure introduced in this patch. This structure includes extra
fields for possible future extensions.
Also, add the passthrough functions for the set-up and tear-down of the
data structures and locks that will be used both when fuse_conns and
fuse_files are created/deleted.

Bug: 179164095
Link: https://lore.kernel.org/lkml/20210125153057.3623715-4-balsini@android.com/


Signed-off-by: default avatarAlessio Balsini <balsini@android.com>
Change-Id: I732532581348adadda5b5048a9346c2b0868d539
Signed-off-by: default avatarAlessio Balsini <balsini@google.com>
parent 759f0722
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,3 +6,4 @@ obj-$(CONFIG_FUSE_FS) += fuse.o
obj-$(CONFIG_CUSE) += cuse.o

fuse-objs := dev.o dir.o file.o inode.o control.o xattr.o acl.o
fuse-objs += passthrough.o
+12 −0
Original line number Diff line number Diff line
@@ -2293,6 +2293,7 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
	int res;
	int oldfd;
	struct fuse_dev *fud = NULL;
	struct fuse_passthrough_out pto;

	if (_IOC_TYPE(cmd) != FUSE_DEV_IOC_MAGIC)
		return -EINVAL;
@@ -2323,6 +2324,17 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd,
			}
		}
		break;
	case _IOC_NR(FUSE_DEV_IOC_PASSTHROUGH_OPEN):
		res = -EFAULT;
		if (!copy_from_user(&pto,
				    (struct fuse_passthrough_out __user *)arg,
				    sizeof(pto))) {
			res = -EINVAL;
			fud = fuse_get_dev(file);
			if (fud)
				res = fuse_passthrough_open(fud, &pto);
		}
		break;
	default:
		res = -ENOTTY;
		break;
+1 −0
Original line number Diff line number Diff line
@@ -508,6 +508,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
	ff->fh = outopen.fh;
	ff->nodeid = outentry.nodeid;
	ff->open_flags = outopen.open_flags;
	fuse_passthrough_setup(fc, ff, &outopen);
	inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
			  &outentry.attr, entry_attr_timeout(&outentry), 0);
	if (!inode) {
+3 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
		if (!err) {
			ff->fh = outarg.fh;
			ff->open_flags = outarg.open_flags;

			fuse_passthrough_setup(fc, ff, &outarg);
		} else if (err != -ENOSYS || isdir) {
			fuse_file_free(ff);
			return err;
@@ -264,6 +264,8 @@ void fuse_release_common(struct file *file, bool isdir)
	struct fuse_req *req = ff->reserved_req;
	int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;

	fuse_passthrough_release(&ff->passthrough);

	fuse_prepare_release(ff, file->f_flags, opcode);

	if (ff->flock) {
+27 −0
Original line number Diff line number Diff line
@@ -124,6 +124,14 @@ enum {

struct fuse_conn;

/**
 * Reference to lower filesystem file for read/write operations handled in
 * passthrough mode
 */
struct fuse_passthrough {
	struct file *filp;
};

/** FUSE specific file data */
struct fuse_file {
	/** Fuse connection for this file */
@@ -150,6 +158,9 @@ struct fuse_file {
	/** Entry on inode's write_files list */
	struct list_head write_entry;

	/** Container for data related to the passthrough functionality */
	struct fuse_passthrough passthrough;

	/** RB node to be linked on fuse_conn->polled_files */
	struct rb_node polled_node;

@@ -650,6 +661,9 @@ struct fuse_conn {
	/** Allow other than the mounter user to access the filesystem ? */
	unsigned allow_other:1;

	/** Passthrough mode for read/write IO */
	unsigned int passthrough:1;

	/** The number of requests waiting for completion */
	atomic_t num_waiting;

@@ -688,6 +702,12 @@ struct fuse_conn {

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

	/** IDR for passthrough requests */
	struct idr passthrough_req;

	/** Protects passthrough_req */
	spinlock_t passthrough_req_lock;
};

static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -1019,4 +1039,11 @@ struct posix_acl;
struct posix_acl *fuse_get_acl(struct inode *inode, int type);
int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);

/* passthrough.c */
int fuse_passthrough_open(struct fuse_dev *fud,
			  struct fuse_passthrough_out *pto);
int fuse_passthrough_setup(struct fuse_conn *fc, struct fuse_file *ff,
			   struct fuse_open_out *openarg);
void fuse_passthrough_release(struct fuse_passthrough *passthrough);

#endif /* _FS_FUSE_I_H */
Loading