btrfs-progs: avoid looping forever when a bad blockgroup key is found
authorJeff Mahoney <jeffm@suse.com>
Fri, 9 Sep 2016 13:22:19 +0000 (15:22 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Sep 2016 09:49:36 +0000 (11:49 +0200)
If we discover a bad BLOCK_GROUP_ITEM_KEY with offset = 0, we'll end up looping
forever when we read the block groups in.  This is due to the search for the
next block group starting at the current object + the offset.  If offset is 0,
we'll just get the same key over and over and never advance.  This patch
ensures that we'll advance at least one objectid per iteration.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
extent-tree.c

index 6cc8d3f..0607be6 100644 (file)
@@ -3259,6 +3259,8 @@ int btrfs_read_block_groups(struct btrfs_root *root)
                cache->cached = 0;
                cache->pinned = 0;
                key.objectid = found_key.objectid + found_key.offset;
+               if (found_key.offset == 0)
+                       key.objectid++;
                btrfs_release_path(path);
                cache->flags = btrfs_block_group_flags(&cache->item);
                bit = 0;