From 293c259e5e1719ab20eb7d9976f1daf16a7a779a Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Fri, 7 Jul 2023 16:07:09 -0700 Subject: [PATCH] UPSTREAM: ANDROID: fuse-bpf: Add partial flock support This adds passthrough support for flock on fuse-bpf files. It does not give any control via a bpf filter. The flock will act as though it was taken on the lower file. Bug: 289882899 Test: fuse_test -t32 (flock_test) Change-Id: Iba0b9630766cedbd3195532c5e929891593cfe30 Signed-off-by: Daniel Rosenberg --- fs/fuse/backing.c | 14 ++++++++++++++ fs/fuse/file.c | 8 +++++++- fs/fuse/fuse_i.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index aad46ab272f7..8db2a0c87f75 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -1016,6 +1016,20 @@ void *fuse_file_write_iter_finalize(struct fuse_bpf_args *fa, return ERR_PTR(fwio->ret); } +int fuse_file_flock_backing(struct file *file, int cmd, struct file_lock *fl) +{ + struct fuse_file *ff = file->private_data; + struct file *backing_file = ff->backing_file; + int error; + + fl->fl_file = backing_file; + if (backing_file->f_op->flock) + error = backing_file->f_op->flock(backing_file, cmd, fl); + else + error = locks_lock_file_wait(backing_file, fl); + return error; +} + ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma) { int ret; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 26dd29c54cfb..781f5fe3ab0e 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2697,12 +2697,18 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl) { struct inode *inode = file_inode(file); struct fuse_conn *fc = get_fuse_conn(inode); + struct fuse_file *ff = file->private_data; int err; +#ifdef CONFIG_FUSE_BPF + /* TODO - this is simply passthrough, not a proper BPF filter */ + if (ff->backing_file) + return fuse_file_flock_backing(file, cmd, fl); +#endif + if (fc->no_flock) { err = locks_lock_file_wait(file, fl); } else { - struct fuse_file *ff = file->private_data; /* emulate flock with POSIX locks */ ff->flock = true; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 7e4a24b2d5f7..05e43ad2215e 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1580,6 +1580,7 @@ int fuse_file_write_iter_backing(struct fuse_bpf_args *fa, void *fuse_file_write_iter_finalize(struct fuse_bpf_args *fa, struct kiocb *iocb, struct iov_iter *from); +int fuse_file_flock_backing(struct file *file, int cmd, struct file_lock *fl); ssize_t fuse_backing_mmap(struct file *file, struct vm_area_struct *vma); int fuse_file_fallocate_initialize(struct fuse_bpf_args *fa,