Btrfs: fix a regression in balance usage filter
authorIlya Dryomov <idryomov@gmail.com>
Mon, 21 Jan 2013 13:15:56 +0000 (15:15 +0200)
committerChris Mason <chris.mason@fusionio.com>
Tue, 22 Jan 2013 01:40:27 +0000 (20:40 -0500)
Commit 3fed40cc ("Btrfs: cleanup duplicated division functions"), which
was merged into 3.8-rc1, has introduced a regression by removing logic
that was guarding us against bad user input.  Bring it back.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
fs/btrfs/volumes.c

index 9c84dbe64f187ab5c3ebf13bc1e5be97a2816da9..46960983891333163eaddaadcbabccf5cd8f5e20 100644 (file)
@@ -2614,7 +2614,14 @@ static int chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset,
        cache = btrfs_lookup_block_group(fs_info, chunk_offset);
        chunk_used = btrfs_block_group_used(&cache->item);
 
-       user_thresh = div_factor_fine(cache->key.offset, bargs->usage);
+       if (bargs->usage == 0)
+               user_thresh = 0;
+       else if (bargs->usage > 100)
+               user_thresh = cache->key.offset;
+       else
+               user_thresh = div_factor_fine(cache->key.offset,
+                                             bargs->usage);
+
        if (chunk_used < user_thresh)
                ret = 0;