[dm-devel] [PATCH v3 05/26] md: Convert md_trim_bio() to use bio_advance()

NeilBrown neilb at suse.de
Wed Sep 26 00:38:27 UTC 2012


On Mon, 24 Sep 2012 15:34:45 -0700 Kent Overstreet <koverstreet at google.com>
wrote:

> Signed-off-by: Kent Overstreet <koverstreet at google.com>
> CC: Jens Axboe <axboe at kernel.dk>
> CC: NeilBrown <neilb at suse.de>
> ---
>  drivers/md/md.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 7a2b079..51ce48c 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -190,25 +190,16 @@ void md_trim_bio(struct bio *bio, int offset, int size)
>  	struct bio_vec *bvec;
>  	int sofar = 0;
>  
> -	size <<= 9;
>  	if (offset == 0 && size == bio->bi_size)
>  		return;

Safer to leave the "size <<= 9" where it is, otherwise that condition will
always fail.

Otherwise,
 Acked-by: NeilBrown <neilb at suse.de>

NeilBrown


>  
> -	bio->bi_sector += offset;
> -	bio->bi_size = size;
> -	offset <<= 9;
>  	clear_bit(BIO_SEG_VALID, &bio->bi_flags);
>  
> -	while (bio->bi_idx < bio->bi_vcnt &&
> -	       bio->bi_io_vec[bio->bi_idx].bv_len <= offset) {
> -		/* remove this whole bio_vec */
> -		offset -= bio->bi_io_vec[bio->bi_idx].bv_len;
> -		bio->bi_idx++;
> -	}
> -	if (bio->bi_idx < bio->bi_vcnt) {
> -		bio->bi_io_vec[bio->bi_idx].bv_offset += offset;
> -		bio->bi_io_vec[bio->bi_idx].bv_len -= offset;
> -	}
> +	bio_advance(bio, offset << 9);
> +
> +	size <<= 9;
> +	bio->bi_size = size;
> +
>  	/* avoid any complications with bi_idx being non-zero*/
>  	if (bio->bi_idx) {
>  		memmove(bio->bi_io_vec, bio->bi_io_vec+bio->bi_idx,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/dm-devel/attachments/20120926/6b6e8067/attachment.sig>


More information about the dm-devel mailing list