From patchwork Sat Oct 29 08:08:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9403315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B951260587 for ; Sat, 29 Oct 2016 08:21:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4A3528C7A for ; Sat, 29 Oct 2016 08:21:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 996E229F83; Sat, 29 Oct 2016 08:21:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42D7A28C7A for ; Sat, 29 Oct 2016 08:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966405AbcJ2IVe (ORCPT ); Sat, 29 Oct 2016 04:21:34 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35364 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934345AbcJ2IP3 (ORCPT ); Sat, 29 Oct 2016 04:15:29 -0400 Received: by mail-pf0-f194.google.com with SMTP id s8so3383991pfj.2; Sat, 29 Oct 2016 01:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J5xkqZ0gtTniAJO2Zcz+orHr9Xjjbtl+qJMHSkQ7xvA=; b=t4D5EKjYnUnP0mxdW4p/aTEc6voLnOz4sNjBtYHwOSfYP+FtZD1/yTvNSW5Ob+Zw20 15utmLCbdC9I/Yv0k9ItEQ2t+AKZUpJgNCcWhqKFje9cVsP2h0hint11pPz4c8oCML4m cgBe7IuOz/30LqF381i9sZoxu+/rzIBfXROTPs/yjoTzKBTGMUhoi/z7NQaQgQ3FQwDE cQ85xQqisyms9Ne0t0F8jwS+v5ArOYvn9c3W2uWA6HX8zAmHQV1u923JyMZ/EIYbp7FP btqSDsroPRKsAxUW+inpIe/tFmYrTkjehlwFSKcs1wgMWq5C2/0syPZuz7j+SDOIc3GL Csbw== 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=J5xkqZ0gtTniAJO2Zcz+orHr9Xjjbtl+qJMHSkQ7xvA=; b=G5Y0KHpfFhAGQ0WrdijufHefp9fvUBEQNDbe4mDchPyw9vy6THkcfxgOtBhD4gWavH uHGNEbZMxy0c54iTvb15du39O/R0zmhEb/CEycGdJ70m/UV6++JY+VGSde6KR7gcAQv9 fKuMUbCTZjSBJkAeCaEi2ogC21uaVL/YgfNYS2j8erxO1dOBxen1Yq9ZK5j9mSHzWV3G Dyym6/Su4fnayCJZDxHj2NCjsQ3MgV64Gin2LdYUy7dzGJK9aGlINmmDCR7dzVSD+/pQ hXG1VubapSOKY+k7LBCaUmwQd7hjGh3PGSS9tBJye9+ZXq/iC6QxWDL6mYMG6aUaoURO 0Hiw== X-Gm-Message-State: ABUngvd3vlE81Y0A/zojKpy159GR0IMHhd/ltMJ49afDHoEAlwkcYKsZNEpGhENJdepUmQ== X-Received: by 10.99.116.76 with SMTP id e12mr26585531pgn.20.1477728928767; Sat, 29 Oct 2016 01:15:28 -0700 (PDT) Received: from localhost ([45.34.23.101]) by smtp.gmail.com with ESMTPSA id xg4sm23552274pac.39.2016.10.29.01.15.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 01:15:28 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , "Kirill A . Shutemov" , Ming Lei , Mike Christie , Hannes Reinecke , Keith Busch , Mike Snitzer , Johannes Thumshirn , Bart Van Assche Subject: [PATCH 45/60] block: bio: introduce bio_for_each_segment_all_rd() and its write pair Date: Sat, 29 Oct 2016 16:08:44 +0800 Message-Id: <1477728600-12938-46-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> References: <1477728600-12938-1-git-send-email-tom.leiming@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patches introduce bio_for_each_segment_all_rd() and bio_for_each_segment_all_wt(). bio_for_each_segment_all_rd() is for replacing bio_for_each_segment_all() in case the bvec from bio->bi_io_vec is accessed as readonly. bio_for_each_segment_all_wt() is for replacing bio_for_each_segment_all() in case the bvec from bio->bi_io_vec need to be updated. Signed-off-by: Ming Lei --- include/linux/bio.h | 15 +++++++++++++++ include/linux/blk_types.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index ec1c0f2aaa19..f8a025ffaa9c 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -215,6 +215,21 @@ static inline void bio_advance_iter_mp(struct bio *bio, struct bvec_iter *iter, #define bio_for_each_segment_mp(bvl, bio, iter) \ __bio_for_each_segment_mp(bvl, bio, iter, (bio)->bi_iter) +/* the bio has to be singlepage bvecs based */ +#define bio_for_each_segment_all_wt(bvl, bio, i) \ + bio_for_each_segment_all((bvl), (bio), (i)) + +/* + * This helper returns singlepage bvec to caller for readonly + * purpose, and the caller can _not_ change the bvec stored in + * bio->bi_io_vec[] via this helper. + */ +#define bio_for_each_segment_all_rd(bvl, bio, i, bi) \ + for ((bi).iter = BVEC_ITER_ALL_INIT, i = 0, bvl = &(bi).bv; \ + (bi).iter.bi_idx < (bio)->bi_vcnt && \ + (((bi).bv = bio_iter_iovec((bio), (bi).iter)), 1); \ + bio_advance_iter((bio), &(bi).iter, (bi).bv.bv_len), i++) + #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) static inline unsigned __bio_segments(struct bio *bio, bool mp) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index cd395ecec99d..b4a202e98016 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -108,6 +108,12 @@ struct bio { #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs) +/* this iter is only for implementing bio_for_each_segment_rd() */ +struct bvec_iter_all { + struct bvec_iter iter; + struct bio_vec bv; /* in-flight singlepage bvec */ +}; + /* * bio flags */