All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <aelder@sgi.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: Boris Ranto <branto@redhat.com>, xfs-oss <xfs@oss.sgi.com>
Subject: Re: [PATCH] mkfs.xfs: don't increase agblocks past maximum
Date: Tue, 20 Sep 2011 15:00:28 -0500	[thread overview]
Message-ID: <1316548828.2912.48.camel@doink> (raw)
In-Reply-To: <4E77B7E2.6020805@redhat.com>

On Mon, 2011-09-19 at 16:45 -0500, Eric Sandeen wrote:
> RH QA discovered this bug:
> 
> Steps to Reproduce:
> 1. Create 4 TB - 1 B partition
> dd if=/dev/zero of=x.img bs=1 count=0 seek=4398046511103
> 2. Create xfs fs with 512 B block size on the partition
> mkfs.xfs -b size=512 xfs.img
> 
> Actual results:
> Agsize is computed incorrectly resulting in fs creation fail:
> agsize (2147483648b) too big, maximum is 2147483647 blocks
> 
> This is due to the "rounding up" at the very end of the calculations;
> there may be other places to alleviate the problem, but it seems
> most obvious to simply skip the rounding up if it would create too
> many blocks in the AG.  Worst case, we lose 1 block per AG.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---

The fix is the right way about it.

This may seem petty, but I think this would be better:

	blocks = dblocks >> shift
	if (blocks & xfs_mask32lo(shift)) {
		if (blocks < XFS_AG_MAX_BLOCKS(blocklog))
			blocks++;
	}

It emphasizes more why we'd be doing the increment,
plus I'd rather see a "real" increment rather than
adding a Boolean value.

Either way:
Reviewed-by: Alex Elder <aelder@sgi.com>

> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 5b3b9a7..856a261 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -658,7 +659,9 @@ calc_default_ag_geometry(
>  	 * last bit of the filesystem. The same principle applies
>  	 * to the AG count, so we don't lose the last AG!
>  	 */
> -	blocks = (dblocks >> shift) + ((dblocks & xfs_mask32lo(shift)) != 0);
> +	blocks = (dblocks >> shift);
> +	if (blocks < XFS_AG_MAX_BLOCKS(blocklog))
> +		blocks += ((dblocks & xfs_mask32lo(shift)) != 0);
>  
>  done:
>  	*agsize = blocks;
> 
> _______________________________________________
> 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

  reply	other threads:[~2011-09-20 20:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19 21:45 [PATCH] mkfs.xfs: don't increase agblocks past maximum Eric Sandeen
2011-09-20 20:00 ` Alex Elder [this message]
2011-09-20 20:03   ` Eric Sandeen
2011-09-20 20:04     ` Alex Elder
2011-09-20 20:30 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316548828.2912.48.camel@doink \
    --to=aelder@sgi.com \
    --cc=branto@redhat.com \
    --cc=sandeen@redhat.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.