Commit 30265117 authored by Jan Kara's avatar Jan Kara Committed by Dave Chinner

xfs: Fix rounding in xfs_alloc_fix_len()

Rounding in xfs_alloc_fix_len() is wrong. As the comment states, the
result should be a number of a form (k*prod+mod) however due to sign
mistake the result is different. As a result allocations on raid arrays
could be misaligned in some cases.

This also seems to fix occasional assertion failure:
	XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
in xfs_alloc_ag_vextent_size().

Also add an assertion that the result of xfs_alloc_fix_len() is of
expected form.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent 448011e2
...@@ -257,16 +257,14 @@ xfs_alloc_fix_len( ...@@ -257,16 +257,14 @@ xfs_alloc_fix_len(
k = rlen % args->prod; k = rlen % args->prod;
if (k == args->mod) if (k == args->mod)
return; return;
if (k > args->mod) { if (k > args->mod)
if ((int)(rlen = rlen - k - args->mod) < (int)args->minlen) rlen = rlen - (k - args->mod);
return; else
} else { rlen = rlen - args->prod + (args->mod - k);
if ((int)(rlen = rlen - args->prod - (args->mod - k)) < if ((int)rlen < (int)args->minlen)
(int)args->minlen) return;
return; ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
} ASSERT(rlen % args->prod == args->mod);
ASSERT(rlen >= args->minlen);
ASSERT(rlen <= args->maxlen);
args->len = rlen; args->len = rlen;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment