btrfs: unify lookup return value when dir entry is missing
authorFilipe Manana <fdmanana@suse.com>
Fri, 1 Oct 2021 12:52:33 +0000 (13:52 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 7 Oct 2021 20:06:32 +0000 (22:06 +0200)
commit8dcbc26194eb872cc3430550fb70bb461424d267
tree85b0a431c2c67c2fbcd8138dd490d3388e648a9d
parent52db77791fe24538c8aa2a183248399715f6b380
btrfs: unify lookup return value when dir entry is missing

btrfs_lookup_dir_index_item() and btrfs_lookup_dir_item() lookup for dir
entries and both are used during log replay or when updating a log tree
during an unlink.

However when the dir item does not exists, btrfs_lookup_dir_item() returns
NULL while btrfs_lookup_dir_index_item() returns PTR_ERR(-ENOENT), and if
the dir item exists but there is no matching entry for a given name or
index, both return NULL. This makes the call sites during log replay to
be more verbose than necessary and it makes it easy to miss this slight
difference. Since we don't need to distinguish between those two cases,
make btrfs_lookup_dir_index_item() always return NULL when there is no
matching directory entry - either because there isn't any dir entry or
because there is one but it does not match the given name and index.

Also rename the argument 'objectid' of btrfs_lookup_dir_index_item() to
'index' since it is supposed to match an index number, and the name
'objectid' is not very good because it can easily be confused with an
inode number (like the inode number a dir entry points to).

CC: stable@vger.kernel.org # 4.14+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/dir-item.c
fs/btrfs/tree-log.c