btrfs: handle errors in walk_down_tree properly
authorJosef Bacik <josef@toxicpanda.com>
Tue, 7 Feb 2023 16:57:24 +0000 (11:57 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:13 +0000 (18:01 +0200)
We can get errors in walk_down_proc as we try and lookup extent info for
the snapshot dropping to act on.  However if we get an error we simply
return 1 which indicates we're done with walking down, which will lead
us to improperly continue with the snapshot drop with the incorrect
information.  Instead break if we get any error from walk_down_proc or
do_walk_down, and handle the case of ret == 1 by returning 0, otherwise
return the ret value that we have.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 824c657f59e8887b157e1c3672e6c1f3ae5b3373..30720ea94a82af4dffd3f55db84e017a59b65d08 100644 (file)
@@ -5509,11 +5509,11 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
 {
        int level = wc->level;
        int lookup_info = 1;
-       int ret;
+       int ret = 0;
 
        while (level >= 0) {
                ret = walk_down_proc(trans, root, path, wc, lookup_info);
-               if (ret > 0)
+               if (ret)
                        break;
 
                if (level == 0)
@@ -5528,10 +5528,10 @@ static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
                        path->slots[level]++;
                        continue;
                } else if (ret < 0)
-                       return ret;
+                       break;
                level = wc->level;
        }
-       return 0;
+       return (ret == 1) ? 0 : ret;
 }
 
 static noinline int walk_up_tree(struct btrfs_trans_handle *trans,