Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2998869imm; Thu, 24 May 2018 20:51:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqTcZpxavDj68gLW8F7qcz9FED+aVD/ZQRdLZaehZAOtGmUvtzODRtap6wIw8Hk80r3i4yY X-Received: by 2002:a63:798d:: with SMTP id u135-v6mr586332pgc.401.1527220276063; Thu, 24 May 2018 20:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220275; cv=none; d=google.com; s=arc-20160816; b=uZLj7Ix1iho+LG1TbHNStuomh+lj5MasIpY1+N4k9paYVdDQxdtsppnWT2vm9V5r8v G7HeMicvdw752vrN9bjLzv832HaGgO0R5pOyhxEdRoqnicJdlwdJ9VZBktaKwHxNkqex 99SjxmH0kSsN7gKgQ0PvQmCaLz5srlo3DlLmwEz7YNYRpQ0NVre0wUSUCw8v0ESsu0c0 H4Y2j8rtRqW7LWphJqpzgH9uBD34I/pR7LXlOl3H3WTonKkioy0l/n1faHQZjT/zKbqU qTqGiaRYtW9Sr9oyL21tsohXgr3Crvnw/gEH1JHlqdBeVMvyVkqrgRYKYa+dTAkJ5gjV Vz/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=lO8usbshcANMX9YtYPoIOLTZmPPvraKC7YlTKszn3Lc=; b=TanyRpBOVNHc9Gq2fefFHaCPHUv6VV7mOD/9Nwsp8EGt0wdUC9i1ZBuJ6Q79UZQa72 VXprwO2CrIPib75Ht4axS6mjWoG4+FueXNFsZEyPFz7kyj8mkZju1AaOF65oSCS9Z8uM cD1lOLe2KejEVRUMJiZhoO9V47TH85usVFiw1/tb9pnncTpU2xwl5QFyM28pay54XLQv vN5/P/S+oDs2BcxoQHwdyAH/ST6/aCwPJpLkrwsgSPvWzSz+1dvSNb7oiKzfoO4pFAeU 927T9kwhOXBQ1OB3KOH0hUpwV4lgLsth88Rg1++ofk9zno47bzZCEXD5/MttAsfIQQHA EfVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e37-v6si23150766plb.400.2018.05.24.20.51.01; Thu, 24 May 2018 20:51:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935668AbeEYDuH (ORCPT + 99 others); Thu, 24 May 2018 23:50:07 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.9.5