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

Unverified Commit 2fa6e18b authored by Alessio Balsini's avatar Alessio Balsini Committed by Michael Bestas
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: 168023149
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 626cbfbb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8,4 +8,5 @@ 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
fuse-objs += passthrough.o
virtiofs-y += virtio_fs.o
+12 −0
Original line number Diff line number Diff line
@@ -2268,6 +2268,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;
@@ -2298,6 +2299,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
@@ -529,6 +529,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
@@ -151,7 +151,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) {
			fuse_file_free(ff);
			return err;
@@ -287,6 +287,8 @@ void fuse_release_common(struct file *file, bool isdir)
	struct fuse_release_args *ra = ff->release_args;
	int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;

	fuse_passthrough_release(&ff->passthrough);

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

	if (ff->flock) {
+27 −0
Original line number Diff line number Diff line
@@ -165,6 +165,14 @@ enum {
struct fuse_conn;
struct fuse_release_args;

/**
 * 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 */
@@ -210,6 +218,9 @@ struct fuse_file {

	} readdir;

	/** 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;

@@ -726,6 +737,9 @@ struct fuse_conn {
	/* Do not show mount options */
	unsigned int no_mount_options:1;

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

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

@@ -761,6 +775,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)
@@ -1111,4 +1131,11 @@ 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);

/* 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