Commit 005d6712 authored by Su Yue's avatar Su Yue Committed by David Sterba

btrfs: adjust return values of btrfs_inode_by_name

Previously, btrfs_inode_by_name() returned 0 which left caller to check
objectid of location even location if the type was invalid.

Let btrfs_inode_by_name() return -EUCLEAN if a corrupted location of a
dir entry is found.  Removal of label out_err also simplifies the
function.
Signed-off-by: default avatarSu Yue <suy.fnst@cn.fujitsu.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ drop unlikely ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9b99b115
...@@ -5489,7 +5489,8 @@ void btrfs_evict_inode(struct inode *inode) ...@@ -5489,7 +5489,8 @@ void btrfs_evict_inode(struct inode *inode)
/* /*
* this returns the key found in the dir entry in the location pointer. * this returns the key found in the dir entry in the location pointer.
* If no dir entries were found, location->objectid is 0. * If no dir entries were found, returns -ENOENT.
* If found a corrupted location in dir entry, returns -EUCLEAN.
*/ */
static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
struct btrfs_key *location) struct btrfs_key *location)
...@@ -5507,27 +5508,27 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, ...@@ -5507,27 +5508,27 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry,
di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(BTRFS_I(dir)), di = btrfs_lookup_dir_item(NULL, root, path, btrfs_ino(BTRFS_I(dir)),
name, namelen, 0); name, namelen, 0);
if (IS_ERR(di)) if (!di) {
ret = -ENOENT;
goto out;
}
if (IS_ERR(di)) {
ret = PTR_ERR(di); ret = PTR_ERR(di);
goto out;
if (IS_ERR_OR_NULL(di)) }
goto out_err;
btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); btrfs_dir_item_key_to_cpu(path->nodes[0], di, location);
if (location->type != BTRFS_INODE_ITEM_KEY && if (location->type != BTRFS_INODE_ITEM_KEY &&
location->type != BTRFS_ROOT_ITEM_KEY) { location->type != BTRFS_ROOT_ITEM_KEY) {
ret = -EUCLEAN;
btrfs_warn(root->fs_info, btrfs_warn(root->fs_info,
"%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, location(%llu %u %llu))", "%s gets something invalid in DIR_ITEM (name %s, directory ino %llu, location(%llu %u %llu))",
__func__, name, btrfs_ino(BTRFS_I(dir)), __func__, name, btrfs_ino(BTRFS_I(dir)),
location->objectid, location->type, location->offset); location->objectid, location->type, location->offset);
goto out_err;
} }
out: out:
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
out_err:
location->objectid = 0;
goto out;
} }
/* /*
...@@ -5830,9 +5831,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) ...@@ -5830,9 +5831,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
if (ret < 0) if (ret < 0)
return ERR_PTR(ret); return ERR_PTR(ret);
if (location.objectid == 0)
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);
return inode; return inode;
......
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