From patchwork Fri Feb 19 03:20:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8355831 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D67FDC0553 for ; Fri, 19 Feb 2016 03:20:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0FEE20416 for ; Fri, 19 Feb 2016 03:20:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32627203F7 for ; Fri, 19 Feb 2016 03:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422656AbcBSDUj (ORCPT ); Thu, 18 Feb 2016 22:20:39 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:34612 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422649AbcBSDUh (ORCPT ); Thu, 18 Feb 2016 22:20:37 -0500 Received: by mail-pf0-f172.google.com with SMTP id x65so43054644pfb.1; Thu, 18 Feb 2016 19:20:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pPFo/azRR6RKgu9RVkXQwwnEFxAjf339TMIYc8rTEEU=; b=QU34xQNGJZE6djx+byt36YVKymcW5mckQLJIkpONXcQ3aDezGKVWU1Q8K3Y/HJmN/n fVhEQLmiAnZcS5OAf8YAsfuHam5HOnNfhT6rgR5juEvMkqz5HgGsZUo+g8TswGGEozVi zUlhld2rkYqklKnQMB3cT2nb1/9qnkrF3G5y84aYu7+DaXxeLa0KrDN8InSi23RXSBOQ fB0MjZx0n8z9q9OlNYuE/8aVBNmriIVBQvY8GTzz52SnU4Xa8BeyUc8Vanagbv0D8lrM aYL41z1udJ3HQZPunRjekzH9yCLp2bEJ2p0Jz9U1DR3PnO5KTpLN89/By0ViH5o7QoGt iygg== X-Gm-Message-State: AG10YOTFmFVmOqwRHgnmdGN/tphz2REzLCKK04Ld3JG4Gjb10D4R7Umuf6GzcE/OSgO8kA== X-Received: by 10.98.31.221 with SMTP id l90mr15174340pfj.92.1455852037037; Thu, 18 Feb 2016 19:20:37 -0800 (PST) Received: from localhost ([116.251.208.106]) by smtp.gmail.com with ESMTPSA id tn5sm13467059pac.32.2016.02.18.19.20.35 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 18 Feb 2016 19:20:36 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Kent Overstreet , Keith Busch , Elliott Robert , Ming Lei , stable@vger.kernel.org Subject: [PATCH v1 1/4] block: bio: introduce helpers to get the 1st and last bvec Date: Fri, 19 Feb 2016 11:20:19 +0800 Message-Id: <1455852022-14188-2-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455852022-14188-1-git-send-email-ming.lei@canonical.com> References: <1455852022-14188-1-git-send-email-ming.lei@canonical.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The bio passed to bio_will_gap() may be fast cloned from upper layer(dm, md, bcache, fs, ...), or from bio splitting in block core. Unfortunately bio_will_gap() just figures out the last bvec via 'bi_io_vec[prev->bi_vcnt - 1]' directly, and this way is obviously wrong. This patch introduces two helpers for getting the first and last bvec of one bio for fixing the issue. Cc: stable@vger.kernel.org Reported-by: Sagi Grimberg Cc: Christoph Hellwig Signed-off-by: Ming Lei Reviewed-by: Sagi Grimberg Reviewed-by: Christoph Hellwig --- include/linux/bio.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 5349e68..3ce2e45 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -310,6 +310,47 @@ static inline void bio_clear_flag(struct bio *bio, unsigned int bit) bio->bi_flags &= ~(1U << bit); } +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(). + */ +static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv) +{ + struct bvec_iter iter = bio->bi_iter; + int idx; + + if (!bio_flagged(bio, BIO_CLONED)) { + *bv = bio->bi_io_vec[bio->bi_vcnt - 1]; + return; + } + + if (unlikely(!bio_multiple_segments(bio))) { + *bv = bio_iovec(bio); + return; + } + + bio_advance_iter(bio, &iter, iter.bi_size); + + if (!iter.bi_bvec_done) + idx = iter.bi_idx - 1; + else /* in the middle of bvec */ + idx = iter.bi_idx; + + *bv = bio->bi_io_vec[idx]; + + /* + * iter.bi_bvec_done records actual length of the last bvec + * if this bio ends in the middle of one io vector + */ + if (iter.bi_bvec_done) + bv->bv_len = iter.bi_bvec_done; +} + enum bip_flags { BIP_BLOCK_INTEGRITY = 1 << 0, /* block layer owns integrity data */ BIP_MAPPED_INTEGRITY = 1 << 1, /* ref tag has been remapped */