Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 00c93450 authored by Filipe Manana's avatar Filipe Manana Committed by Greg Kroah-Hartman
Browse files

btrfs: deal with errors when adding inode reference during log replay



commit 52db77791fe24538c8aa2a183248399715f6b380 upstream.

At __inode_add_ref(), we treating any error returned from
btrfs_lookup_dir_item() or from btrfs_lookup_dir_index_item() as meaning
that there is no existing directory entry in the fs/subvolume tree.
This is not correct since we can get errors such as, for example, -EIO
when reading extent buffers while searching the fs/subvolume's btree.

So fix that and return the error to the caller when it is not -ENOENT.

CC: stable@vger.kernel.org # 4.14+
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>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8d733c5d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -1141,7 +1141,10 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
	/* look for a conflicting sequence number */
	di = btrfs_lookup_dir_index_item(trans, root, path, btrfs_ino(dir),
					 ref_index, name, namelen, 0);
	if (di && !IS_ERR(di)) {
	if (IS_ERR(di)) {
		if (PTR_ERR(di) != -ENOENT)
			return PTR_ERR(di);
	} else if (di) {
		ret = drop_one_dir_item(trans, root, path, dir, di);
		if (ret)
			return ret;
@@ -1151,7 +1154,9 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
	/* look for a conflicing name */
	di = btrfs_lookup_dir_item(trans, root, path, btrfs_ino(dir),
				   name, namelen, 0);
	if (di && !IS_ERR(di)) {
	if (IS_ERR(di)) {
		return PTR_ERR(di);
	} else if (di) {
		ret = drop_one_dir_item(trans, root, path, dir, di);
		if (ret)
			return ret;