Skip to content

Commit

Permalink
Btrfs: fix infinite loop in btrfs_shrink_device()
Browse files Browse the repository at this point in the history
If relocate of block group 0 fails with ENOSPC we end up infinitely
looping because key.offset -= 1 statement in that case brings us back to
where we started.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
  • Loading branch information
Ilya Dryomov committed Mar 27, 2012
1 parent 5eb56d2 commit 213e64d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
key.offset = (u64)-1;
key.type = BTRFS_DEV_EXTENT_KEY;

while (1) {
do {
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0)
goto done;
Expand Down Expand Up @@ -3029,8 +3029,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
goto done;
if (ret == -ENOSPC)
failed++;
key.offset -= 1;
}
} while (key.offset-- > 0);

if (failed && !retried) {
failed = 0;
Expand Down

0 comments on commit 213e64d

Please sign in to comment.