]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Btrfs: fix max chunk size check in chunk allocator
authorIlya Dryomov <idryomov@gmail.com>
Fri, 13 Apr 2012 14:05:08 +0000 (17:05 +0300)
committerDavid Sterba <dsterba@suse.cz>
Wed, 18 Apr 2012 17:22:25 +0000 (19:22 +0200)
Fix a bug, where in case we need to adjust stripe_size so that the
length of the resulting chunk is less than or equal to max_chunk_size,
DUP chunks turn out to be only half as big as they could be.

Cc: Arne Jansen <sensille@gmx.net>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/btrfs/volumes.c

index 759d02486d7ccb2dcb2ff1b1334396cc219880ca..ce289af526f086e812f345e7d0a2984e5b9f7812 100644 (file)
@@ -3324,12 +3324,14 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
        stripe_size = devices_info[ndevs-1].max_avail;
        num_stripes = ndevs * dev_stripes;
 
-       if (stripe_size * num_stripes > max_chunk_size * ncopies) {
+       if (stripe_size * ndevs > max_chunk_size * ncopies) {
                stripe_size = max_chunk_size * ncopies;
-               do_div(stripe_size, num_stripes);
+               do_div(stripe_size, ndevs);
        }
 
        do_div(stripe_size, dev_stripes);
+
+       /* align to BTRFS_STRIPE_LEN */
        do_div(stripe_size, BTRFS_STRIPE_LEN);
        stripe_size *= BTRFS_STRIPE_LEN;