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 <drosen@google.com>
This commit is contained in:
Daniel Rosenberg 2023-07-07 16:07:09 -07:00 • committed by Alexander Martinz
commit 293c259e5e
No known key found for this signature in database
GPG key ID: CF15BDD9A321A9B2
3 changed files with 22 additions and 1 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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,