Skip to content

Commit

Permalink
ANDROID: fuse-bpf: Simplify and fix setting bpf program
Browse files Browse the repository at this point in the history
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
Change-Id: If0e682f43cbeb62764a7a2be543b90cb974b0aa0
Signed-off-by: Paul Lawrence <[email protected]>
  • Loading branch information
PaulLawrenceGoogle authored and bengris32 committed Jun 22, 2024
1 parent ee2be78 commit c5202ff
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions fs/fuse/backing.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,39 +1235,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 (IS_ERR(bpf_prog))
return PTR_ERR(bpf_prog);
if (!bpf_file)
return -EINVAL;
if (IS_ERR(bpf_file))
return PTR_ERR(bpf_file);

new_bpf = bpf_prog;
new_bpf = fuse_get_bpf_prog(bpf_file);
if (IS_ERR(new_bpf))
return PTR_ERR(new_bpf);
break;
}

Expand All @@ -1276,11 +1273,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;
}
Expand Down

0 comments on commit c5202ff

Please sign in to comment.