Skip to content

Commit 37db63a

Browse files
idryomovkdave
authored andcommitted
Btrfs: fix max chunk size check in chunk allocator
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>
1 parent b916a59 commit 37db63a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/btrfs/volumes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,12 +3324,14 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
33243324
stripe_size = devices_info[ndevs-1].max_avail;
33253325
num_stripes = ndevs * dev_stripes;
33263326

3327-
if (stripe_size * num_stripes > max_chunk_size * ncopies) {
3327+
if (stripe_size * ndevs > max_chunk_size * ncopies) {
33283328
stripe_size = max_chunk_size * ncopies;
3329-
do_div(stripe_size, num_stripes);
3329+
do_div(stripe_size, ndevs);
33303330
}
33313331

33323332
do_div(stripe_size, dev_stripes);
3333+
3334+
/* align to BTRFS_STRIPE_LEN */
33333335
do_div(stripe_size, BTRFS_STRIPE_LEN);
33343336
stripe_size *= BTRFS_STRIPE_LEN;
33353337

0 commit comments

Comments
 (0)