All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Myers <bpm@sgi.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs-oss <xfs@oss.sgi.com>
Subject: Re: [PATCH 2/3] xfs_repair: Document & robustify blkmap_next_off()
Date: Thu, 31 May 2012 16:27:14 -0500	[thread overview]
Message-ID: <20120531212714.GJ4721@sgi.com> (raw)
In-Reply-To: <4FBABD6A.6070800@redhat.com>

On Mon, May 21, 2012 at 05:10:50PM -0500, Eric Sandeen wrote:
> blkmap_next_off() was cryptic (to me), so document what it does.
> Also catch cases when the passed in extent index 't' is beyond
> the number of extents in the blkmap, so that:
> 
>         ext = blkmap->exts + *t;
> 
> doesn't walk off the end of the array into garbage.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/repair/bmap.c b/repair/bmap.c
> index c43ca7f..85d66dc 100644
> --- a/repair/bmap.c
> +++ b/repair/bmap.c
> @@ -206,8 +206,25 @@ blkmap_last_off(
>  	return ext->startoff + ext->blockcount;
>  }
>  
> -/*
> - * Return the next offset in a block map.
> +/**
> + * blkmap_next_off - Return next logical block offset in a block map.
> + * @blkmap:	blockmap to use
> + * @o:		current file logical block number
> + * @t:		current extent index into blockmap (in/out)
> + *
> + * Given a logical block offset in a file, return the next mapped logical offset
> + * The map index "t" tracks the current extent number in the block map, and
> + * is updated automatically if the returned offset resides within the next
> + * mapped extent.
> + *
> + * If the blockmap contains no extents, or no more logical offsets are mapped,
> + * or the extent index exceeds the number of extents in the map,
> + * return NULLDFILOFF.
> + *
> + * If offset o is beyond extent index t, the first offset in the next extent
> + * after extent t will be returned.
> + *
> + * Intended to be called starting with offset 0, index 0, and iterated.
>   */
>  xfs_dfiloff_t
>  blkmap_next_off(
> @@ -223,10 +240,12 @@ blkmap_next_off(
>  		*t = 0;
>  		return blkmap->exts[0].startoff;
>  	}
> +	if (*t >= blkmap->nexts)
> +		return NULLDFILOFF;
>  	ext = blkmap->exts + *t;
>  	if (o < ext->startoff + ext->blockcount - 1)
>  		return o + 1;
> -	if (*t >= blkmap->nexts - 1)
> +	if (*t == blkmap->nexts - 1)
>  		return NULLDFILOFF;
>  	(*t)++;
>  	return ext[1].startoff;

Ok, so you have 50 extents, and when *t == 49 you don't want to go looking at
ext[50].startoff.  Looks good to me.

Reviewed-by: Ben Myers <bpm@sgi.com>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2012-05-31 21:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21 22:07 [PATCH 0/3] xfs_repair fixes for fragmented multiblock v2 dirs Eric Sandeen
2012-05-21 22:10 ` [PATCH 1/3] xfs_repair: Fix fragmented multiblock dir2 handling in blkmap_getn() Eric Sandeen
2012-05-31 20:55   ` Ben Myers
2012-05-21 22:10 ` [PATCH 2/3] xfs_repair: Document & robustify blkmap_next_off() Eric Sandeen
2012-05-31 21:27   ` Ben Myers [this message]
2012-05-21 22:11 ` [PATCH 3/3] xfs_repair: handle fragmented multiblock dir2 in process_leaf_node_dir2() Eric Sandeen
2012-06-01 20:25   ` Ben Myers
2012-05-22  1:26 ` [PATCH 0/3] xfs_repair fixes for fragmented multiblock v2 dirs Eric Sandeen
2012-05-22 13:41 ` [PATCH 2/3 RESEND] " Eric Sandeen
2012-05-22 13:42 ` [PATCH 3/3 RESEND] xfs_repair: handle fragmented multiblock dir2 in process_leaf_node_dir2() Eric Sandeen

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=20120531212714.GJ4721@sgi.com \
    --to=bpm@sgi.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.