Commit d25f4ec1 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: reduce nesting and deduplicate error handling at btrfs_iget_path()

Make btrfs_iget_path() simpler and easier to read by avoiding nesting of
if-then-else statements and having an error label to do all the error
handling instead of repeating it a couple times.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 061ea858
...@@ -5598,37 +5598,35 @@ struct inode *btrfs_iget_path(struct super_block *s, u64 ino, ...@@ -5598,37 +5598,35 @@ struct inode *btrfs_iget_path(struct super_block *s, u64 ino,
struct btrfs_root *root, struct btrfs_path *path) struct btrfs_root *root, struct btrfs_path *path)
{ {
struct inode *inode; struct inode *inode;
int ret;
inode = btrfs_iget_locked(s, ino, root); inode = btrfs_iget_locked(s, ino, root);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (inode->i_state & I_NEW) { if (!(inode->i_state & I_NEW))
int ret; return inode;
ret = btrfs_read_locked_inode(inode, path); ret = btrfs_read_locked_inode(inode, path);
if (!ret) {
ret = btrfs_add_inode_to_root(BTRFS_I(inode), true);
if (ret) {
iget_failed(inode);
inode = ERR_PTR(ret);
} else {
unlock_new_inode(inode);
}
} else {
iget_failed(inode);
/* /*
* ret > 0 can come from btrfs_search_slot called by * ret > 0 can come from btrfs_search_slot called by
* btrfs_read_locked_inode, this means the inode item * btrfs_read_locked_inode(), this means the inode item was not found.
* was not found.
*/ */
if (ret > 0) if (ret > 0)
ret = -ENOENT; ret = -ENOENT;
inode = ERR_PTR(ret); if (ret < 0)
} goto error;
}
ret = btrfs_add_inode_to_root(BTRFS_I(inode), true);
if (ret < 0)
goto error;
unlock_new_inode(inode);
return inode; return inode;
error:
iget_failed(inode);
return ERR_PTR(ret);
} }
struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root) struct inode *btrfs_iget(struct super_block *s, u64 ino, struct btrfs_root *root)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment