xfs
[Top] [All Lists]

Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()

To: Jan Kara <jack@xxxxxxx>
Subject: Re: [PATCH v2] xfs: Fix rounding in xfs_alloc_fix_len()
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Wed, 4 Jun 2014 14:44:40 -0400
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1401900833-25485-1-git-send-email-jack@xxxxxxx>
References: <1401900833-25485-1-git-send-email-jack@xxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
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@xxxxxxx>
> ---

Looks good to me. Thanks Jan.

Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx>

>  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@xxxxxxxxxxx
> http://oss.sgi.com/mailman/listinfo/xfs

<Prev in Thread] Current Thread [Next in Thread>