Btrfs: fix infinite loop in btrfs_shrink_device()
authorIlya Dryomov <idryomov@gmail.com>
Tue, 27 Mar 2012 14:09:18 +0000 (17:09 +0300)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 27 Mar 2012 14:09:18 +0000 (17:09 +0300)
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>
fs/btrfs/volumes.c

index bcc0acda86910de915fe6a01a318f7b5a8a42d75..be2d4e0e6cfbc2946796c12e8c120c8f72286b96 100644 (file)
@@ -2987,7 +2987,7 @@ again:
        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;
@@ -3029,8 +3029,7 @@ again:
                        goto done;
                if (ret == -ENOSPC)
                        failed++;
-               key.offset -= 1;
-       }
+       } while (key.offset-- > 0);
 
        if (failed && !retried) {
                failed = 0;