ANDROID: fuse-bpf: Simplify and fix setting bpf program

Fix case when an existing bpf prog is being removed
Tidy up code

Bug: 279363668
Test: Boots, can copy file to /sdcardfs/Android/data, fuse_test passes
Signed-off-by: Paul Lawrence <paullawrence@google.com>
(cherry picked from https://android-review.googlesource.com/q/commit:64366661e8a9a6d691e5ab6499872d495aed5266)
Merged-In: If0e682f43cbeb62764a7a2be543b90cb974b0aa0
Change-Id: If0e682f43cbeb62764a7a2be543b90cb974b0aa0
This commit is contained in:
Paul Lawrence 2023-04-26 14:11:58 -07:00 committed by Cherrypicker Worker
parent f138bad25e
commit bb9c6d4116

View File

@ -1186,39 +1186,36 @@ int fuse_handle_backing(struct fuse_entry_bpf *feb, struct inode **backing_inode
int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent,
struct bpf_prog **bpf)
{
struct bpf_prog *new_bpf;
/* Parent isn't presented, but we want to keep
* Don't touch bpf program at all in this case
*/
if (feb->out.bpf_action == FUSE_ACTION_KEEP && !parent)
return 0;
struct bpf_prog *new_bpf = NULL;
switch (feb->out.bpf_action) {
case FUSE_ACTION_KEEP: {
struct fuse_inode *pi = get_fuse_inode(parent);
/* Parent isn't presented, but we want to keep
* Don't touch bpf program at all in this case
*/
if (!parent)
return 0;
new_bpf = pi->bpf;
new_bpf = get_fuse_inode(parent)->bpf;
if (new_bpf)
bpf_prog_inc(new_bpf);
break;
}
case FUSE_ACTION_REMOVE:
new_bpf = NULL;
break;
case FUSE_ACTION_REPLACE: {
struct file *bpf_file = feb->bpf_file;
struct bpf_prog *bpf_prog = ERR_PTR(-EINVAL);
if (bpf_file && !IS_ERR(bpf_file))
bpf_prog = fuse_get_bpf_prog(bpf_file);
if (!bpf_file)
return -EINVAL;
if (IS_ERR(bpf_file))
return PTR_ERR(bpf_file);
if (IS_ERR(bpf_prog))
return PTR_ERR(bpf_prog);
new_bpf = bpf_prog;
new_bpf = fuse_get_bpf_prog(bpf_file);
if (IS_ERR(new_bpf))
return PTR_ERR(new_bpf);
break;
}
@ -1227,11 +1224,14 @@ int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent,
}
/* Cannot change existing program */
if (*bpf) {
if (*bpf && new_bpf) {
bpf_prog_put(new_bpf);
return new_bpf == *bpf ? 0 : -EINVAL;
}
if (*bpf)
bpf_prog_put(*bpf);
*bpf = new_bpf;
return 0;
}