From patchwork Fri May 25 03:46:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426225 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 7BB176025B for ; Fri, 25 May 2018 03:55:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D6EC294E4 for ; Fri, 25 May 2018 03:55:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6207A295A6; Fri, 25 May 2018 03:55:50 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 14E6C294E4 for ; Fri, 25 May 2018 03:55:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935638AbeEYDuG (ORCPT ); Thu, 24 May 2018 23:50:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935619AbeEYDuE (ORCPT ); Thu, 24 May 2018 23:50:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44A2F401EF03; Fri, 25 May 2018 03:50:04 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C405202345C; Fri, 25 May 2018 03:49:56 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , Huang Ying , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Ming Lei Subject: [RESEND PATCH V5 17/33] block: bio: introduce bio_for_each_page_all2 and bio_for_each_segment_all Date: Fri, 25 May 2018 11:46:05 +0800 Message-Id: <20180525034621.31147-18-ming.lei@redhat.com> In-Reply-To: <20180525034621.31147-1-ming.lei@redhat.com> References: <20180525034621.31147-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 25 May 2018 03:50:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 25 May 2018 03:50:04 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' 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 patch introduces bio_for_each_page_all2(), which is for replacing bio_for_each_page_all() in case that the returned bvec has to be single page bvec. Given the interface type has to be changed for passing one local iterator variable of 'bvec_iter_all', and doing all changes in one single patch isn't realistic, so use the name of bio_for_each_page_all2() temporarily for conversion, and once all bio_for_each_page_all() is converted, the original name of bio_for_each_page_all() will be recovered finally. This patch introduce bio_for_each_segment_all too, which is used for updating bvec table directly, and users should be carful about this helper since it returns real multipage segment now. Signed-off-by: Ming Lei --- include/linux/bio.h | 18 ++++++++++++++++++ include/linux/bvec.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 61a04c131641..75baad77d9a8 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -225,6 +225,24 @@ static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, #define bio_for_each_segment(bvl, bio, iter) \ __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter) +#define bio_for_each_segment_all(bvl, bio, i) \ + bio_for_each_page_all((bvl), (bio), (i)) + +/* + * This helper returns singlepage bvec to caller, and the sp bvec is + * generated in-flight from multipage bvec stored in bvec table. So we + * can _not_ change the bvec stored in bio->bi_io_vec[] via this helper. + * + * If bvec need to be updated in the table, please use + * bio_for_each_segment_all() and make sure it is correctly used since + * bvec may points to one multipage bvec. + */ +#define bio_for_each_page_all2(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_elements(struct bio *bio, bool seg) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 217afcd83a15..2deee87b823e 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -84,6 +84,12 @@ struct bvec_iter { current bvec */ }; +/* this iter is only for implementing bio_for_each_page_all2() */ +struct bvec_iter_all { + struct bvec_iter iter; + struct bio_vec bv; /* in-flight singlepage bvec */ +}; + /* * various member access, note that bio_data should of course not be used * on highmem page vectors