* [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
@ 2014-06-04 16:53 Jan Kara
2014-06-04 18:44 ` Brian Foster
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2014-06-04 16:53 UTC (permalink / raw)
To: xfs; +Cc: Brian Foster, 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)
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: Jan Kara <jack@suse.cz>
---
fs/xfs/xfs_alloc.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c
index c1cf6a336a72..1351a24d3cdc 100644
--- a/fs/xfs/xfs_alloc.c
+++ b/fs/xfs/xfs_alloc.c
@@ -257,16 +257,14 @@ 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;
- }
- ASSERT(rlen >= args->minlen);
- ASSERT(rlen <= args->maxlen);
+ 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 && rlen <= args->maxlen);
+ ASSERT(rlen % args->prod == args->mod);
args->len = rlen;
}
--
1.8.1.4
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
2014-06-04 16:53 [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len() Jan Kara
@ 2014-06-04 18:44 ` Brian Foster
2014-06-13 15:02 ` Jan Kara
0 siblings, 1 reply; 5+ messages in thread
From: Brian Foster @ 2014-06-04 18:44 UTC (permalink / raw)
To: Jan Kara; +Cc: xfs
On Wed, Jun 04, 2014 at 06:53:53PM +0200, Jan Kara wrote:
> 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: Jan Kara <jack@suse.cz>
> ---
Looks good to me. Thanks Jan.
Reviewed-by: Brian Foster <bfoster@redhat.com>
> fs/xfs/xfs_alloc.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c
> index c1cf6a336a72..1351a24d3cdc 100644
> --- a/fs/xfs/xfs_alloc.c
> +++ b/fs/xfs/xfs_alloc.c
> @@ -257,16 +257,14 @@ 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;
> - }
> - ASSERT(rlen >= args->minlen);
> - ASSERT(rlen <= args->maxlen);
> + 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 && rlen <= args->maxlen);
> + ASSERT(rlen % args->prod == args->mod);
> args->len = rlen;
> }
>
> --
> 1.8.1.4
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
2014-06-04 18:44 ` Brian Foster
@ 2014-06-13 15:02 ` Jan Kara
2014-06-13 23:56 ` Dave Chinner
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kara @ 2014-06-13 15:02 UTC (permalink / raw)
To: Brian Foster; +Cc: dchinner, Jan Kara, xfs
On Wed 04-06-14 14:44:40, Brian Foster wrote:
> On Wed, Jun 04, 2014 at 06:53:53PM +0200, Jan Kara wrote:
> > 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: Jan Kara <jack@suse.cz>
> > ---
>
> Looks good to me. Thanks Jan.
>
> Reviewed-by: Brian Foster <bfoster@redhat.com>
Ping Dave? Are you going to pick up this patch?
Honza
> > fs/xfs/xfs_alloc.c | 18 ++++++++----------
> > 1 file changed, 8 insertions(+), 10 deletions(-)
> >
> > diff --git a/fs/xfs/xfs_alloc.c b/fs/xfs/xfs_alloc.c
> > index c1cf6a336a72..1351a24d3cdc 100644
> > --- a/fs/xfs/xfs_alloc.c
> > +++ b/fs/xfs/xfs_alloc.c
> > @@ -257,16 +257,14 @@ 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;
> > - }
> > - ASSERT(rlen >= args->minlen);
> > - ASSERT(rlen <= args->maxlen);
> > + 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 && rlen <= args->maxlen);
> > + ASSERT(rlen % args->prod == args->mod);
> > args->len = rlen;
> > }
> >
> > --
> > 1.8.1.4
> >
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
2014-06-13 15:02 ` Jan Kara
@ 2014-06-13 23:56 ` Dave Chinner
2014-06-16 9:00 ` Jan Kara
0 siblings, 1 reply; 5+ messages in thread
From: Dave Chinner @ 2014-06-13 23:56 UTC (permalink / raw)
To: Jan Kara; +Cc: Brian Foster, xfs, dchinner
On Fri, Jun 13, 2014 at 05:02:07PM +0200, Jan Kara wrote:
> On Wed 04-06-14 14:44:40, Brian Foster wrote:
> > On Wed, Jun 04, 2014 at 06:53:53PM +0200, Jan Kara wrote:
> > > 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: Jan Kara <jack@suse.cz>
> > > ---
> >
> > Looks good to me. Thanks Jan.
> >
> > Reviewed-by: Brian Foster <bfoster@redhat.com>
> Ping Dave? Are you going to pick up this patch?
I did - it's already in Linus' tree for 3.16:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/xfs/xfs_alloc.c?id=30265117ee1e23fa91920f337a3ea91207f700dc
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
2014-06-13 23:56 ` Dave Chinner
@ 2014-06-16 9:00 ` Jan Kara
0 siblings, 0 replies; 5+ messages in thread
From: Jan Kara @ 2014-06-16 9:00 UTC (permalink / raw)
To: Dave Chinner; +Cc: Brian Foster, xfs, Jan Kara, dchinner
On Sat 14-06-14 09:56:22, Dave Chinner wrote:
> On Fri, Jun 13, 2014 at 05:02:07PM +0200, Jan Kara wrote:
> > On Wed 04-06-14 14:44:40, Brian Foster wrote:
> > > On Wed, Jun 04, 2014 at 06:53:53PM +0200, Jan Kara wrote:
> > > > 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: Jan Kara <jack@suse.cz>
> > > > ---
> > >
> > > Looks good to me. Thanks Jan.
> > >
> > > Reviewed-by: Brian Foster <bfoster@redhat.com>
> > Ping Dave? Are you going to pick up this patch?
>
> I did - it's already in Linus' tree for 3.16:
>
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/fs/xfs/xfs_alloc.c?id=30265117ee1e23fa91920f337a3ea91207f700dc
Ah, sorry. I was expecting some email about acceptance. I'll check the git
tree next time.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-16 9:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04 16:53 [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len() Jan Kara
2014-06-04 18:44 ` Brian Foster
2014-06-13 15:02 ` Jan Kara
2014-06-13 23:56 ` Dave Chinner
2014-06-16 9:00 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox