Commit 5662344b authored by Tsutomu Itoh's avatar Tsutomu Itoh Committed by Chris Mason

Btrfs: fix error check of btrfs_lookup_dentry()

Clean up btrfs_lookup_dentry() to never return NULL, but PTR_ERR(-ENOENT)
instead. This keeps the return value convention consistent.

Callers who use btrfs_lookup_dentry() require a trivial update.

create_snapshot() in particular looks like it can also lose a BUG_ON(!inode)
which is not really needed - there seems less harm in returning ENOENT to
userspace at that point in the stack than there is to crash the machine.
Signed-off-by: default avatarTsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 78357766
...@@ -4992,7 +4992,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) ...@@ -4992,7 +4992,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
return ERR_PTR(ret); return ERR_PTR(ret);
if (location.objectid == 0) if (location.objectid == 0)
return NULL; return ERR_PTR(-ENOENT);
if (location.type == BTRFS_INODE_ITEM_KEY) { if (location.type == BTRFS_INODE_ITEM_KEY) {
inode = btrfs_iget(dir->i_sb, &location, root, NULL); inode = btrfs_iget(dir->i_sb, &location, root, NULL);
...@@ -5056,10 +5056,17 @@ static void btrfs_dentry_release(struct dentry *dentry) ...@@ -5056,10 +5056,17 @@ static void btrfs_dentry_release(struct dentry *dentry)
static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags) unsigned int flags)
{ {
struct dentry *ret; struct inode *inode;
ret = d_splice_alias(btrfs_lookup_dentry(dir, dentry), dentry); inode = btrfs_lookup_dentry(dir, dentry);
return ret; if (IS_ERR(inode)) {
if (PTR_ERR(inode) == -ENOENT)
inode = NULL;
else
return ERR_CAST(inode);
}
return d_splice_alias(inode, dentry);
} }
unsigned char btrfs_filetype_table[] = { unsigned char btrfs_filetype_table[] = {
......
...@@ -393,6 +393,7 @@ static noinline int create_subvol(struct inode *dir, ...@@ -393,6 +393,7 @@ static noinline int create_subvol(struct inode *dir,
struct btrfs_root *new_root; struct btrfs_root *new_root;
struct btrfs_block_rsv block_rsv; struct btrfs_block_rsv block_rsv;
struct timespec cur_time = CURRENT_TIME; struct timespec cur_time = CURRENT_TIME;
struct inode *inode;
int ret; int ret;
int err; int err;
u64 objectid; u64 objectid;
...@@ -554,8 +555,14 @@ static noinline int create_subvol(struct inode *dir, ...@@ -554,8 +555,14 @@ static noinline int create_subvol(struct inode *dir,
if (err && !ret) if (err && !ret)
ret = err; ret = err;
if (!ret) if (!ret) {
d_instantiate(dentry, btrfs_lookup_dentry(dir, dentry)); inode = btrfs_lookup_dentry(dir, dentry);
if (IS_ERR(inode)) {
ret = PTR_ERR(inode);
goto out;
}
d_instantiate(dentry, inode);
}
out: out:
btrfs_subvolume_release_metadata(root, &block_rsv, qgroup_reserved); btrfs_subvolume_release_metadata(root, &block_rsv, qgroup_reserved);
return ret; return ret;
...@@ -643,7 +650,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir, ...@@ -643,7 +650,7 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
ret = PTR_ERR(inode); ret = PTR_ERR(inode);
goto fail; goto fail;
} }
BUG_ON(!inode);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
ret = 0; ret = 0;
fail: fail:
......
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