Skip to contentSkip to conversation

btrfs: tree-log: Check btrfs_lookup_data_extent return value

PATCH In review Marcos Paulo de Souza 3 participants 3 messages Aug 2, 2021 – Aug 16, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: tree-log: Check btrfs_lookup_data_extent return value

Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return values bellow zero if an error happened.

Function replay_one_extent currently check if the search found something (0 returned) and increments the reference, and if not, it seems to evaluate as 'not found'.

Fix the condition by checking if the value was bellow zero and return early.

---

Found while inspecting some btrfs_search_slot call sites.

 fs/btrfs/tree-log.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/tree-log.c +3 -1
index 567adc3de11a..867ea0be0665 100644
@@ -753,7 +753,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
 			 */
 			ret = btrfs_lookup_data_extent(fs_info, ins.objectid,
 						ins.offset);
-			if (ret == 0) {
+			if (ret < 0) {
+				goto out;
+			} else if (ret == 0) {
 				btrfs_init_generic_ref(&ref,
 						BTRFS_ADD_DELAYED_REF,
 						ins.objectid, ins.offset, 0);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Marcos Paulo de Souza

Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return values bellow zero if an error happened.

Quoted 7 lines

Function replay_one_extent currently check if the search found something (0 returned) and increments the reference, and if not, it seems to evaluate as 'not found'.

Fix the condition by checking if the value was bellow zero and return early.

That's fine, thanks.

Quoted 25 lines

---

Found while inspecting some btrfs_search_slot call sites.

 fs/btrfs/tree-log.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/tree-log.c +3 -2
index 567adc3de11a..867ea0be0665 100644
@@ -753,7 +753,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
                         */
                        ret = btrfs_lookup_data_extent(fs_info, ins.objectid,
                                                ins.offset);
-                       if (ret == 0) {
+                       if (ret < 0) {
+                               goto out;
+                       } else if (ret == 0) {
                                btrfs_init_generic_ref(&ref,
                                                BTRFS_ADD_DELAYED_REF,
                                                ins.objectid, ins.offset, 0);
--

2.26.2

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#2 lore raw
In reply to Marcos Paulo de Souza
Quoted 11 lines · Marcos Paulo de Souza

Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return values bellow zero if an error happened.

Function replay_one_extent currently check if the search found something (0 returned) and increments the reference, and if not, it seems to evaluate as 'not found'.

Fix the condition by checking if the value was bellow zero and return early.

Added to misc-next, thanks.