xfs: Fix rounding in xfs_alloc_fix_len()
PATCH 1/1 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().
--- fs/xfs/xfs_alloc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
fs/xfs/xfs_alloc.c +6 -8
@@ -257,14 +257,12 @@ xfs_alloc_fix_len( k = rlen % args->prod;if (k == args->mod)return ; -if (k > args->mod) { -if ((int )(rlen = rlen - k - args->mod) < (int )args->minlen) -return ; - }else { -if ((int )(rlen = rlen - args->prod - (args->mod - k)) < - (int )args->minlen) -return ; - } +if (k > args->mod) + rlen = rlen - (k - args->mod); +else + rlen = rlen - args->prod + (args->mod - k); +if ((int )rlen < (int )args->minlen) +return ;ASSERT (rlen >= args->minlen);ASSERT (rlen <= args->maxlen); args->len = rlen;
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 9 lines · Jan Kara
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)
inxfs_alloc_ag_vextent_size().
Do you happen to have a reproducer for this?
The meaning of args->prod (the structure definition comment calls it the prod value) is not clear to me. I see that we set it to an extent size hint if one exists (in xfs_bmap_btalloc()), so I'll go with that. args->mod then becomes the modulo of the file offset against that alignment hint.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len(
Quoted 10 lines
Signed-off-by Jan Kara <[email protected]>--- fs/xfs/xfs_alloc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/xfs/xfs_alloc.c +0
-0@@ -257,14 +257,12 @@ xfs_alloc_fix_len(
We get here and take the extent length, mod against the alignment and compare to the mod of the offset.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 261
Quoted 13 lines
fs/xfs/xfs_alloc.c +2
-8k = rlen % args->prod;if (k == args->mod)return ; -if (k > args->mod) { -if ((int )(rlen = rlen - k - args->mod) < (int )args->minlen) -return ; - }else { -if ((int )(rlen = rlen - args->prod - (args->mod - k)) < - (int )args->minlen) -return ; - } +if (k > args->mod) + rlen = rlen - (k - args->mod);
If the length mod is greater than the offset mod, reduce the length by the delta of the mods.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 263
Quoted 2 lines
fs/xfs/xfs_alloc.c +2
-0+else + rlen = rlen - args->prod + (args->mod - k);
Otherwise (length mod is less than offset mod), reduce by a full alignment size and add back the difference to match the offset mod.
This seems correct to me.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 267
Quoted 4 lines
fs/xfs/xfs_alloc.c +2
-0+if ((int )rlen < (int )args->minlen) +return ;ASSERT (rlen >= args->minlen);ASSERT (rlen <= args->maxlen);
The rlen >= minlen assert seems kind of pointless here, but what about changing both instances of these two asserts to the following:
ASSERT(rlen >= args->minlen && rlen <= args->maxlen);
... and add a new one after the length adjustment along the lines of:
ASSERT((rlen % args->prod) == args->mod);
Thoughts? Would this have caught the problem you've found earlier?
Brian
Quoted 8 lines
fs/xfs/xfs_alloc.c +0
-0args->len = rlen;Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · Brian Foster
Quoted 8 lines · Jan Kara
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)
inxfs_alloc_ag_vextent_size().Do you happen to have a reproducer for this?
No, IBM triggered this during their testing on powerPC. I can ask them if
they can share the test if you are interested.
Quoted 45 lines
The meaning of
args->prod(the structure definition comment calls it the prod value) is not clear to me. I see that we set it to an extent size hint if one exists (inxfs_bmap_btalloc()), so I'll go with that.args->modthen becomes the modulo of the file offset against that alignment hint.fs/xfs/xfs_alloc.c xfs_alloc_fix_len(
Quoted 10 lines
Signed-off-by Jan Kara <[email protected]>--- fs/xfs/xfs_alloc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/xfs/xfs_alloc.c +0
-0@@ -257,14 +257,12 @@ xfs_alloc_fix_len(We get here and take the extent length, mod against the alignment and compare to the mod of the offset.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 261
Quoted 13 lines
fs/xfs/xfs_alloc.c +2
-8k = rlen % args->prod;if (k == args->mod)return ; -if (k > args->mod) { -if ((int )(rlen = rlen - k - args->mod) < (int )args->minlen) -return ; - }else { -if ((int )(rlen = rlen - args->prod - (args->mod - k)) < - (int )args->minlen) -return ; - } +if (k > args->mod) + rlen = rlen - (k - args->mod);If the length mod is greater than the offset mod, reduce the length by the delta of the mods.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 263
Quoted 2 lines
fs/xfs/xfs_alloc.c +2
-0+else + rlen = rlen - args->prod + (args->mod - k);Otherwise (length mod is less than offset mod), reduce by a full alignment size and add back the difference to match the offset mod.
This seems correct to me.
Quoted 7 lines
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 267
Quoted 4 lines
fs/xfs/xfs_alloc.c +2
-0+if ((int )rlen < (int )args->minlen) +return ;ASSERT (rlen >= args->minlen);ASSERT (rlen <= args->maxlen);The rlen >= minlen assert seems kind of pointless here, but what about changing both instances of these two asserts to the following:
Well, rlen has been decreased so rlen >= minlen makes sense. rlen <=
maxlen seems to be the obvious one to me.
Quoted 7 lines
ASSERT(rlen >= args->minlen && rlen <= args->maxlen);... and add a new one after the length adjustment along the lines of:
ASSERT((rlen % args->prod) == args->mod);Thoughts? Would this have caught the problem you've found earlier?
Yes, this would have caught the bug. Should I add this assertion an
resend?
Honza
Signature · 7 lines
Jan Kara <[email protected]> SUSE Labs, CR _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 7 lines · Jan Kara
Quoted 6 lines · Brian Foster
Quoted 5 lines · Jan Kara
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.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
This also seems to fix occasional assertion failure:
XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0)
inxfs_alloc_ag_vextent_size().Do you happen to have a reproducer for this?
No, IBM triggered this during their testing on powerPC. I can ask them if
they can share the test if you are interested.
I think it would be generally interesting, particularly to see if we could create an xfstests test..?
Quoted 52 lines
Quoted 45 lines
The meaning of
args->prod(the structure definition comment calls it the prod value) is not clear to me. I see that we set it to an extent size hint if one exists (inxfs_bmap_btalloc()), so I'll go with that.args->modthen becomes the modulo of the file offset against that alignment hint.fs/xfs/xfs_alloc.c xfs_alloc_fix_len(
Quoted 10 lines
Signed-off-by Jan Kara <[email protected]>--- fs/xfs/xfs_alloc.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/xfs/xfs_alloc.c +0
-0@@ -257,14 +257,12 @@ xfs_alloc_fix_len(We get here and take the extent length, mod against the alignment and compare to the mod of the offset.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 261
Quoted 13 lines
fs/xfs/xfs_alloc.c +2
-8k = rlen % args->prod;if (k == args->mod)return ; -if (k > args->mod) { -if ((int )(rlen = rlen - k - args->mod) < (int )args->minlen) -return ; - }else { -if ((int )(rlen = rlen - args->prod - (args->mod - k)) < - (int )args->minlen) -return ; - } +if (k > args->mod) + rlen = rlen - (k - args->mod);If the length mod is greater than the offset mod, reduce the length by the delta of the mods.
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 263
Quoted 2 lines
fs/xfs/xfs_alloc.c +2
-0+else + rlen = rlen - args->prod + (args->mod - k);Otherwise (length mod is less than offset mod), reduce by a full alignment size and add back the difference to match the offset mod.
This seems correct to me.
Quoted 7 lines
fs/xfs/xfs_alloc.c xfs_alloc_fix_len( · line 267
Quoted 4 lines
fs/xfs/xfs_alloc.c +2
-0+if ((int )rlen < (int )args->minlen) +return ;ASSERT (rlen >= args->minlen);ASSERT (rlen <= args->maxlen);The rlen >= minlen assert seems kind of pointless here, but what about changing both instances of these two asserts to the following:
Quoted 3 lines
Well, rlen has been decreased so rlen >= minlen makes sense. rlen <=
maxlen seems to be the obvious one to me.
That was more a commentary on the fact that the assert now immediately follows a check for the negation of the assert, where we return. The assert below seems a bit more generic and just makes it stand out a little less (to me). Not really a big deal.
Quoted 9 lines
Quoted 7 lines
ASSERT(rlen >= args->minlen && rlen <= args->maxlen);... and add a new one after the length adjustment along the lines of:
ASSERT((rlen % args->prod) == args->mod);Thoughts? Would this have caught the problem you've found earlier?
Yes, this would have caught the bug. Should I add this assertion an
resend?
Yeah, if you don't mind. I think that one is definitely beneficial.
Brian
Quoted 6 lines
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs