From 37966b8d2463bb0262b8ccff223ad821e811eca4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Mon, 7 Feb 2022 16:01:56 -0800 Subject: [PATCH] UPSTREAM: ANDROID: fuse: add bpf support for removexattr Bug: 218393120 Test: fuse_test#bpf_test_xattr Signed-off-by: Daniel Rosenberg Change-Id: Idf69b5b70c5dc5f09270146fe8c574ac1bde7be6 --- fs/fuse/backing.c | 33 +++++++++++++++++++++++++++++++++ fs/fuse/fuse_i.h | 8 ++++++++ fs/fuse/xattr.c | 9 ++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 98f65cde6bdc..8da15a080c8f 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -661,6 +661,39 @@ void *fuse_setxattr_finalize(struct fuse_args *fa, struct dentry *dentry, return NULL; } +int fuse_removexattr_initialize(struct fuse_args *fa, + struct fuse_dummy_io *unused, + struct dentry *dentry, const char *name) +{ + *fa = (struct fuse_args) { + .nodeid = get_fuse_inode(dentry->d_inode)->nodeid, + .opcode = FUSE_REMOVEXATTR, + .in_numargs = 1, + .in_args[0] = (struct fuse_in_arg) { + .size = strlen(name) + 1, + .value = name, + }, + }; + + return 0; +} + +int fuse_removexattr_backing(struct fuse_args *fa, + struct dentry *dentry, const char *name) +{ + struct path *backing_path = + &get_fuse_dentry(dentry)->backing_path; + + /* TODO account for changes of the name by prefilter */ + return vfs_removexattr(backing_path->dentry, name); +} + +void *fuse_removexattr_finalize(struct fuse_args *fa, + struct dentry *dentry, const char *name) +{ + return NULL; +} + int fuse_file_read_iter_initialize( struct fuse_args *fa, struct fuse_read_in *fri, struct kiocb *iocb, struct iov_iter *to) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 47bcd722a88b..f4b6f4366ff7 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1474,6 +1474,14 @@ void *fuse_setxattr_finalize(struct fuse_args *fa, struct dentry *dentry, const char *name, const void *value, size_t size, int flags); +int fuse_removexattr_initialize(struct fuse_args *fa, + struct fuse_dummy_io *unused, + struct dentry *dentry, const char *name); +int fuse_removexattr_backing(struct fuse_args *fa, + struct dentry *dentry, const char *name); +void *fuse_removexattr_finalize(struct fuse_args *fa, + struct dentry *dentry, const char *name); + int fuse_file_read_iter_initialize( struct fuse_args *fa, struct fuse_read_in *fri, struct kiocb *iocb, struct iov_iter *to); diff --git a/fs/fuse/xattr.c b/fs/fuse/xattr.c index 3f09fa38d412..3abdf0e2be89 100644 --- a/fs/fuse/xattr.c +++ b/fs/fuse/xattr.c @@ -217,10 +217,17 @@ static int fuse_xattr_set(const struct xattr_handler *handler, #ifdef CONFIG_FUSE_BPF struct fuse_err_ret fer; - fer = fuse_bpf_backing(inode, struct fuse_setxattr_in, + if (value) + fer = fuse_bpf_backing(inode, struct fuse_setxattr_in, fuse_setxattr_initialize, fuse_setxattr_backing, fuse_setxattr_finalize, dentry, name, value, size, flags); + else + fer = fuse_bpf_backing(inode, struct fuse_dummy_io, + fuse_removexattr_initialize, + fuse_removexattr_backing, + fuse_removexattr_finalize, + dentry, name); if (fer.ret) return PTR_ERR(fer.result); #endif