diff options
author | Daniel Rosenberg <drosen@google.com> | 2023-07-07 16:07:09 -0700 |
---|---|---|
committer | Akilesh Kailash <akailash@google.com> | 2023-08-19 00:01:40 +0000 |
commit | 4ba55c9ec77a26109caab84a44037170188b5c7a (patch) | |
tree | 0790de2bec8abf021892629292ee046dce4cfaff | |
parent | 5b9b31a2c5ae949fb23cb6720635fcfcd7f028d3 (diff) | |
download | common-deprecated/android13-5.10-2022-11.tar.gz |
ANDROID: fuse-bpf: Add partial flock supportdeprecated/android13-5.10-2022-11android13-5.10-2022-11
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
Bug: 296641006
Test: fuse_test -t32 (flock_test)
Signed-off-by: Daniel Rosenberg <drosen@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:914d854f85754ce5ce22fe91b8ab2a23526ff48e)
Merged-In: Iba0b9630766cedbd3195532c5e929891593cfe30
Change-Id: Iba0b9630766cedbd3195532c5e929891593cfe30
-rw-r--r-- | fs/fuse/backing.c | 14 | ||||
-rw-r--r-- | fs/fuse/file.c | 8 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 1 | ||||
-rw-r--r-- | tools/testing/selftests/filesystems/fuse/fuse_test.c | 46 |
4 files changed, 68 insertions, 1 deletions
diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 9f78384b021f..de905e18bbbb 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -1042,6 +1042,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 d492898b33f5..b7b97c078c7b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2646,12 +2646,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 87de62763a6c..3dc7771e5b7c 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1582,6 +1582,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, diff --git a/tools/testing/selftests/filesystems/fuse/fuse_test.c b/tools/testing/selftests/filesystems/fuse/fuse_test.c index 461b79656973..9c5f3c987c90 100644 --- a/tools/testing/selftests/filesystems/fuse/fuse_test.c +++ b/tools/testing/selftests/filesystems/fuse/fuse_test.c @@ -12,6 +12,7 @@ #include <string.h> #include <unistd.h> +#include <sys/file.h> #include <sys/inotify.h> #include <sys/mman.h> #include <sys/mount.h> @@ -1343,6 +1344,50 @@ out: return result; } +static int flock_test(const char *mount_dir) +{ + const char *file = "file"; + int result = TEST_FAILURE; + int src_fd = -1; + int fuse_dev = -1; + int fd = -1, fd2 = -1; + int backing_fd = -1; + char *addr = NULL; + + TEST(src_fd = open(ft_src, O_DIRECTORY | O_RDONLY | O_CLOEXEC), + src_fd != -1); + TESTEQUAL(mount_fuse(mount_dir, -1, src_fd, &fuse_dev), 0); + TEST(fd = s_open(s_path(s(mount_dir), s(file)), + O_CREAT | O_RDWR | O_CLOEXEC, 0777), + fd != -1); + TEST(fd2 = s_open(s_path(s(mount_dir), s(file)), + O_RDWR | O_CLOEXEC, 0777), + fd2 != -1); + TESTSYSCALL(flock(fd, LOCK_EX | LOCK_NB)); + TESTCONDERR((flock(fd2, LOCK_EX | LOCK_NB)) == -1); + TESTCOND(errno == EAGAIN); + TESTSYSCALL(flock(fd, LOCK_UN)); + TESTSYSCALL(flock(fd2, LOCK_EX | LOCK_NB)); + TEST(backing_fd = s_open(s_path(s(ft_src), s(file)), + O_RDONLY | O_CLOEXEC), + backing_fd != -1); + TESTCONDERR((flock(backing_fd, LOCK_EX | LOCK_NB)) == -1); + TESTCOND(errno == EAGAIN); + close(fd2); + fd2 = 0; + TESTSYSCALL(flock(backing_fd, LOCK_EX | LOCK_NB)); + + result = TEST_SUCCESS; +out: + close(fd); + close(fd2); + close(backing_fd); + umount(mount_dir); + close(fuse_dev); + close(src_fd); + return result; +} + static int readdir_perms_test(const char *mount_dir) { int result = TEST_FAILURE; @@ -2104,6 +2149,7 @@ int main(int argc, char *argv[]) MAKE_TEST(bpf_test_no_readdirplus_without_nodeid), MAKE_TEST(bpf_test_revalidate_handle_backing_fd), MAKE_TEST(bpf_test_lookup_postfilter), + MAKE_TEST(flock_test), }; #undef MAKE_TEST |