Skip to content

Commit 4ed6847

Browse files
fdmananagregkh
authored andcommitted
btrfs: deal with errors when adding inode reference during log replay
commit 52db777 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: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 95d3aba commit 4ed6847

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎fs/btrfs/tree-log.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,10 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
11371137
/* look for a conflicting sequence number */
11381138
di = btrfs_lookup_dir_index_item(trans, root, path, btrfs_ino(dir),
11391139
ref_index, name, namelen, 0);
1140-
if (di && !IS_ERR(di)) {
1140+
if (IS_ERR(di)) {
1141+
if (PTR_ERR(di) != -ENOENT)
1142+
return PTR_ERR(di);
1143+
} else if (di) {
11411144
ret = drop_one_dir_item(trans, root, path, dir, di);
11421145
if (ret)
11431146
return ret;
@@ -1147,7 +1150,9 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
11471150
/* look for a conflicting name */
11481151
di = btrfs_lookup_dir_item(trans, root, path, btrfs_ino(dir),
11491152
name, namelen, 0);
1150-
if (di && !IS_ERR(di)) {
1153+
if (IS_ERR(di)) {
1154+
return PTR_ERR(di);
1155+
} else if (di) {
11511156
ret = drop_one_dir_item(trans, root, path, dir, di);
11521157
if (ret)
11531158
return ret;

0 commit comments

Comments
 (0)