From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752187AbcBOHC3 (ORCPT ); Mon, 15 Feb 2016 02:02:29 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35882 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbcBOHCH (ORCPT ); Mon, 15 Feb 2016 02:02:07 -0500 From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Ming Lei , stable@vger.kernel.org Subject: [PATCH 1/4] block: bio: introduce helpers to get the 1st and last bvec Date: Mon, 15 Feb 2016 15:01:24 +0800 Message-Id: <1455519687-23873-2-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455519687-23873-1-git-send-email-ming.lei@canonical.com> References: <1455519687-23873-1-git-send-email-ming.lei@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org After bio splitting is introduced, the splitted bio can be fast-cloned, which is correct because biovecs has become immutable since v3.13. Unfortunately bio_will_gap() isn't ready for this kind of change, because it figures out the last bvec via 'bi_io_vec[prev->bi_vcnt - 1]'. This patch introduces two helpers for getting the first and last bvec of one bio. Cc: stable@vger.kernel.org # v4.3+ Reported-by: Sagi Grimberg Cc: Christoph Hellwig Signed-off-by: Ming Lei --- include/linux/bio.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 5349e68..56d2db8 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -265,6 +265,26 @@ static inline unsigned bio_segments(struct bio *bio) return segs; } +static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv) +{ + *bv = bio_iovec(bio); +} + +/* + * bio_get_last_bvec() is introduced to get the last bvec of one + * bio for bio_will_gap(). + * + * TODO: make it more efficient. + */ +static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv) +{ + struct bvec_iter iter; + + bio_for_each_segment(*bv, bio, iter) + if (bv->bv_len == iter.bi_size) + break; +} + /* * get a reference to a bio, so it won't disappear. the intended use is * something like: -- 1.9.1