From patchwork Fri Feb 26 15:40:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8438791 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 44EE79F314 for ; Fri, 26 Feb 2016 15:42:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57586203B6 for ; Fri, 26 Feb 2016 15:42:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 61D2F20392 for ; Fri, 26 Feb 2016 15:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754635AbcBZPlY (ORCPT ); Fri, 26 Feb 2016 10:41:24 -0500 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34222 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754142AbcBZPlX (ORCPT ); Fri, 26 Feb 2016 10:41:23 -0500 Received: by mail-pa0-f65.google.com with SMTP id yy13so4642313pab.1; Fri, 26 Feb 2016 07:41:22 -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=9aLkzvzFpASVspSP6JOd0R94sKwWLCAaHo0q2+mu4RE=; b=QjRZdbiekXWsqXrQwflWD/MHW2a+PkkGurshVpzRnbhzWNmnjyoe6F9io1TPoVzRkz Vw1796hNEZHLjDnC24fQQTLFkqoyldnSrEqptAiDz2OZwGB/Fn/wkOfO7nxfNtdvWslU zHH4dgqj21fzNKM5tmVUND2MJ2or8C1WCyEts09l2aByLJycv+oYmRJmdpNdQUPMjCXX YlYdoAeuXY5uapskOtJZyLtpORfsVG0/8e0ItJLrZOa/4kBzBqUZc0HiTJAUJU4Ganem JTmk7Esi3e696AAQm2yXIuB8YebaS0FFIbpVKBsbYxThg8KfF+7x8vsY2ZOXumCPQ2Nx yaug== X-Gm-Message-State: AD7BkJLa3F3e+S97HSF/5xyjGEI9Tc7yoOpTug7qb6Q0nJCkdRlQAjC0GMG9lWb8/DiDXg== X-Received: by 10.66.254.168 with SMTP id aj8mr2974368pad.18.1456501282268; Fri, 26 Feb 2016 07:41:22 -0800 (PST) Received: from localhost ([45.35.47.131]) by smtp.gmail.com with ESMTPSA id d8sm20299451pas.14.2016.02.26.07.41.20 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 26 Feb 2016 07:41:21 -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 v2 1/4] block: bio: introduce helpers to get the 1st and last bvec Date: Fri, 26 Feb 2016 23:40:50 +0800 Message-Id: <1456501253-7269-2-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456501253-7269-1-git-send-email-ming.lei@canonical.com> References: <1456501253-7269-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=ham 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 Reviewed-by: Sagi Grimberg Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei --- include/linux/bio.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 5349e68..cb68888 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -310,6 +310,43 @@ 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); +} + +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 */