Btrfs: add missing error handling after doing leaf/node binary search
authorFilipe Manana <fdmanana@suse.com>
Mon, 18 Feb 2019 16:57:26 +0000 (16:57 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Feb 2019 13:19:23 +0000 (14:19 +0100)
The function map_private_extent_buffer() can return an -EINVAL error, and
it is called by generic_bin_search() which will return back the error. The
btrfs_bin_search() function in turn calls generic_bin_search() and the
key_search() function calls btrfs_bin_search(), so both can return the
-EINVAL error coming from the map_private_extent_buffer() function. Some
callers of these functions were ignoring that these functions can return
an error, so fix them to deal with error return values.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
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.c
fs/btrfs/relocation.c
fs/btrfs/tree-log.c

index 4fac5cc2e648b0e057ad719097f393b704f941a4..399b9c5182d5564f0749eca179afce26f7e39f0c 100644 (file)
@@ -3020,6 +3020,8 @@ again:
                 */
                prev_cmp = -1;
                ret = key_search(b, key, level, &prev_cmp, &slot);
+               if (ret < 0)
+                       goto done;
 
                if (level != 0) {
                        int dec = 0;
@@ -5171,6 +5173,10 @@ again:
                nritems = btrfs_header_nritems(cur);
                level = btrfs_header_level(cur);
                sret = btrfs_bin_search(cur, min_key, level, &slot);
+               if (sret < 0) {
+                       ret = sret;
+                       goto out;
+               }
 
                /* at the lowest level, we're done, setup the path and exit */
                if (level == path->lowest_level) {
index 70b85a593b7b11570b0457a900d1cad31b13f9c6..ddf028509931289ab54c6a6feab771e6ed36f2d5 100644 (file)
@@ -1806,6 +1806,8 @@ again:
                BUG_ON(level < lowest_level);
 
                ret = btrfs_bin_search(parent, &key, level, &slot);
+               if (ret < 0)
+                       break;
                if (ret && slot > 0)
                        slot--;
 
@@ -2730,6 +2732,10 @@ static int do_relocation(struct btrfs_trans_handle *trans,
                        if (!lowest) {
                                ret = btrfs_bin_search(upper->eb, key,
                                                       upper->level, &slot);
+                               if (ret < 0) {
+                                       err = ret;
+                                       goto next;
+                               }
                                BUG_ON(ret);
                                bytenr = btrfs_node_blockptr(upper->eb, slot);
                                if (node->eb->start == bytenr)
@@ -2765,6 +2771,10 @@ static int do_relocation(struct btrfs_trans_handle *trans,
                } else {
                        ret = btrfs_bin_search(upper->eb, key, upper->level,
                                               &slot);
+                       if (ret < 0) {
+                               err = ret;
+                               goto next;
+                       }
                        BUG_ON(ret);
                }
 
index e76345f52beb52b822491ebbef233103fd65afef..f06454a55e00cb4df0f71f03eb0013adbae1e4f4 100644 (file)
@@ -3767,6 +3767,8 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,
                found_key.type = 0;
                ret = btrfs_bin_search(path->nodes[0], &found_key, 0,
                                       &start_slot);
+               if (ret < 0)
+                       break;
 
                ret = btrfs_del_items(trans, log, path, start_slot,
                                      path->slots[0] - start_slot + 1);