Btrfs-progs: fix infinite loop in find_free_extent
authorLiu Bo <bo.li.liu@oracle.com>
Mon, 26 Jun 2017 17:34:41 +0000 (11:34 -0600)
committerDavid Sterba <dsterba@suse.com>
Thu, 20 Jul 2017 15:43:43 +0000 (17:43 +0200)
If the found %ins is crossing a stripe len, ie. BTRFS_STRIPE_LEN, we'd
search again with a stripe-aligned %search_start.  The current code
calculates %search_start by adding a wrong offset, in order to fix it, the
start position of the block group should be taken, otherwise, it'll end up
with looking at the same block group forever.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
extent-tree.c

index 75ed94f..46b8a05 100644 (file)
@@ -2611,8 +2611,9 @@ check_failed:
                                goto no_bg_cache;
                        bg_offset = ins->objectid - bg_cache->key.objectid;
 
-                       search_start = round_up(bg_offset + num_bytes,
-                                               BTRFS_STRIPE_LEN) + bg_offset;
+                       search_start = round_up(
+                               bg_offset + num_bytes, BTRFS_STRIPE_LEN) +
+                               bg_cache->key.objectid;
                        goto new_group;
                }
 no_bg_cache: