Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1337020

Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec

From Kent Overstreet <kent.overstreet@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec
Date 2016-02-18 05:30 +0100
Message-ID <r3oo1-84-3@gated-at.bofh.it> (permalink)
References <r2lse-64X-5@gated-at.bofh.it> <r2lse-64X-3@gated-at.bofh.it> <r2mHF-6N6-21@gated-at.bofh.it> <r2nX5-7yQ-17@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Feb 15, 2016 at 05:42:12PM +0800, Ming Lei wrote:
> Cc Kent and Keith.
> 
> Follows another version which should be more efficient.
> Kent and Keith, I appreciate much if you may give a review on it.
> 
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 56d2db8..ef45fec 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -278,11 +278,21 @@ static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv)
>   */
>  static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv)
>  {
> -	struct bvec_iter iter;
> +	struct bvec_iter iter = bio->bi_iter;
> +	int idx;
> +
> +	bio_advance_iter(bio, &iter, iter.bi_size);
> +
> +	WARN_ON(!iter.bi_idx && !iter.bi_bvec_done);
> +
> +	if (!iter.bi_bvec_done)
> +		idx = iter.bi_idx - 1;
> +	else	/* in the middle of bvec */
> +		idx = iter.bi_idx;
>  
> -	bio_for_each_segment(*bv, bio, iter)
> -		if (bv->bv_len == iter.bi_size)
> -			break;
> +	*bv = bio->bi_io_vec[idx];
> +	if (iter.bi_bvec_done)
> +		bv->bv_len = iter.bi_bvec_done;
>  }

It can't be done correctly without a loop.

The reason is that if the bio was split in the middle of a segment, bv->bv_len
on the last biovec will be larger than what's actually used by the bio (it's
being shared between the two splits!).

You have to iterate over all the biovecs so that you can see where
bi_iter->bi_size ends.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec Ming Lei <ming.lei@canonical.com> - 2016-02-15 08:10 +0100
  Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last  bvec Sagi Grimberg <sagig@dev.mellanox.co.il> - 2016-02-15 09:30 +0100
    Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and  last bvec Ming Lei <ming.lei@canonical.com> - 2016-02-15 10:50 +0100
      Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last  bvec Sagi Grimberg <sagig@dev.mellanox.co.il> - 2016-02-15 21:10 +0100
        Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec Ming Lei <ming.lei@canonical.com> - 2016-02-16 14:10 +0100
      RE: [PATCH 1/4] block: bio: introduce helpers to get the 1st and  last bvec "Elliott, Robert (Persistent Memory)" <elliott@hpe.com> - 2016-02-17 04:10 +0100
      Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and  last bvec Kent Overstreet <kent.overstreet@gmail.com> - 2016-02-18 05:30 +0100
        Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec Ming Lei <ming.lei@canonical.com> - 2016-02-18 07:20 +0100
          Re: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec Ming Lei <ming.lei@canonical.com> - 2016-02-19 02:50 +0100

csiph-web