ANDROID: fuse-bpf: Adjust backing handle funcs

Cleaned up some args, and adjusted so we can choose to not update the
actual values for the next patch.

Test: fuse_test
Bug: 219958836
Change-Id: I025b7026357b119e2cd588f25f0976f5d4b68090
Signed-off-by: Daniel Rosenberg <drosen@google.com>
This commit is contained in:
Daniel Rosenberg
2022-07-14 18:16:16 -07:00
parent a06f77a0dd
commit a8b1cff534
3 changed files with 41 additions and 52 deletions

View File

@@ -1172,23 +1172,17 @@ int fuse_lookup_backing(struct fuse_bpf_args *fa, struct inode *dir,
return 0;
}
int handle_inode_backing_fd(struct inode *inode, struct dentry *entry,
struct fuse_entry_bpf_out *febo,
struct fuse_entry_bpf *feb)
{
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_dentry *fd = get_fuse_dentry(entry);
int ret = 0;
switch (febo->backing_action) {
int fuse_handle_backing(struct fuse_entry_bpf *feb, struct inode **backing_inode,
struct path *backing_path) {
switch (feb->out.backing_action) {
case FUSE_ACTION_KEEP:
/* backing inode/path are added in fuse_lookup_backing */
break;
case FUSE_ACTION_REMOVE:
iput(fi->backing_inode);
fi->backing_inode = NULL;
path_put_init(&fd->backing_path);
iput(*backing_inode);
*backing_inode = NULL;
path_put_init(backing_path);
break;
case FUSE_ACTION_REPLACE: {
@@ -1199,14 +1193,14 @@ int handle_inode_backing_fd(struct inode *inode, struct dentry *entry,
if (IS_ERR(backing_file))
return PTR_ERR(backing_file);
if (fi->backing_inode)
iput(fi->backing_inode);
fi->backing_inode = backing_file->f_inode;
ihold(fi->backing_inode);
if (backing_inode)
iput(*backing_inode);
*backing_inode = backing_file->f_inode;
ihold(*backing_inode);
path_put(&fd->backing_path);
fd->backing_path = backing_file->f_path;
path_get(&fd->backing_path);
path_put(backing_path);
*backing_path = backing_file->f_path;
path_get(backing_path);
fput(backing_file);
break;
@@ -1216,34 +1210,31 @@ int handle_inode_backing_fd(struct inode *inode, struct dentry *entry,
return -EINVAL;
}
return ret;
return 0;
}
int handle_inode_bpf(struct inode *inode, struct inode *parent,
struct fuse_entry_bpf_out *febo,
struct fuse_entry_bpf *feb)
int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent,
struct bpf_prog **bpf)
{
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_inode *pi;
int ret = 0;
// Parent isn't presented, but we want to keep
// Don't touch bpf program at all in this case
if (febo->bpf_action == FUSE_ACTION_KEEP && !parent) {
if (feb->out.bpf_action == FUSE_ACTION_KEEP && !parent) {
goto out;
}
if (fi->bpf) {
bpf_prog_put(fi->bpf);
fi->bpf = NULL;
if (*bpf) {
bpf_prog_put(*bpf);
*bpf = NULL;
}
switch (febo->bpf_action) {
switch (feb->out.bpf_action) {
case FUSE_ACTION_KEEP:
pi = get_fuse_inode(parent);
fi->bpf = pi->bpf;
if (fi->bpf)
bpf_prog_inc(fi->bpf);
*bpf = pi->bpf;
if (*bpf)
bpf_prog_inc(*bpf);
break;
case FUSE_ACTION_REMOVE:
@@ -1259,7 +1250,7 @@ int handle_inode_bpf(struct inode *inode, struct inode *parent,
if (IS_ERR(bpf_prog))
return PTR_ERR(bpf_prog);
fi->bpf = bpf_prog;
*bpf = bpf_prog;
break;
}
@@ -1268,7 +1259,7 @@ int handle_inode_bpf(struct inode *inode, struct inode *parent,
}
out:
return ret;
return 0;
}
struct dentry *fuse_lookup_finalize(struct fuse_bpf_args *fa, struct inode *dir,
@@ -1302,11 +1293,11 @@ struct dentry *fuse_lookup_finalize(struct fuse_bpf_args *fa, struct inode *dir,
if (IS_ERR(inode))
return ERR_PTR(PTR_ERR(inode));
error = handle_inode_bpf(inode, dir, febo, feb);
error = fuse_handle_bpf_prog(feb, dir, &get_fuse_inode(inode)->bpf);
if (error)
return ERR_PTR(error);
error = handle_inode_backing_fd(inode, entry, febo, feb);
error = fuse_handle_backing(feb, &get_fuse_inode(inode)->backing_inode, &fd->backing_path);
if (error)
return ERR_PTR(error);

View File

@@ -236,7 +236,6 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)),
&entry->d_name, &outarg, &bpf_arg.out);
ret = fuse_simple_request(fm, &args);
dput(parent);
#ifdef CONFIG_FUSE_BPF
if (ret == sizeof(bpf_arg.out)) {
@@ -244,17 +243,18 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
if (!entry)
goto out;
ret = handle_inode_backing_fd(inode, entry,
&bpf_arg.out, &bpf_arg);
ret = fuse_handle_backing(&bpf_arg, &get_fuse_inode(inode)->backing_inode,
&get_fuse_dentry(entry)->backing_path);
if (ret)
goto out;
ret = handle_inode_bpf(inode, entry->d_parent->d_inode,
&bpf_arg.out, &bpf_arg);
ret = fuse_handle_bpf_prog(&bpf_arg, parent->d_inode,
&get_fuse_inode(inode)->bpf);
if (ret)
goto out;
}
#endif
dput(parent);
/* Zero nodeid is same as -ENOENT */
if (!ret && !outarg.nodeid)
ret = -ENOENT;
@@ -548,13 +548,13 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name
if (!*inode)
goto bpf_arg_out;
err = handle_inode_backing_fd(*inode, entry,
&bpf_arg.out, &bpf_arg);
err = fuse_handle_backing(&bpf_arg,
&get_fuse_inode(*inode)->backing_inode,
&get_fuse_dentry(entry)->backing_path);
if (err)
goto out;
err = handle_inode_bpf(*inode, NULL,
&bpf_arg.out, &bpf_arg);
err = fuse_handle_bpf_prog(&bpf_arg, NULL, &get_fuse_inode(*inode)->bpf);
if (err)
goto out;
bpf_arg_out:

View File

@@ -1597,12 +1597,10 @@ struct fuse_lookup_io {
struct fuse_entry_bpf feb;
};
int handle_inode_backing_fd(struct inode *inode, struct dentry *entry,
struct fuse_entry_bpf_out *febo,
struct fuse_entry_bpf *feb);
int handle_inode_bpf(struct inode *inode, struct inode *parent,
struct fuse_entry_bpf_out *febo,
struct fuse_entry_bpf *feb);
int fuse_handle_backing(struct fuse_entry_bpf *feb, struct inode **backing_inode,
struct path *backing_path);
int fuse_handle_bpf_prog(struct fuse_entry_bpf *feb, struct inode *parent,
struct bpf_prog **bpf);
int fuse_lookup_initialize(struct fuse_bpf_args *fa, struct fuse_lookup_io *feo,
struct inode *dir, struct dentry *entry, unsigned int flags);