From patchwork Wed Jun 27 12:45:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10491395 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 4F18D60325 for ; Wed, 27 Jun 2018 12:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3ED9A28D83 for ; Wed, 27 Jun 2018 12:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32DA728D85; Wed, 27 Jun 2018 12:48:12 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 951D828D80 for ; Wed, 27 Jun 2018 12:48:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A82EC6B027D; Wed, 27 Jun 2018 08:48:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A334E6B027E; Wed, 27 Jun 2018 08:48:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 922076B027F; Wed, 27 Jun 2018 08:48:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 63C0B6B027D for ; Wed, 27 Jun 2018 08:48:10 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id d7-v6so1835912qth.21 for ; Wed, 27 Jun 2018 05:48:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=CdM5RprJDQqB2vgWG8tVlsvcqNdmR7LkPGyMXg0cNHo=; b=YBVhFCrolHbzHHlGpNl75t1c8/qbd+aULRcvO/LcoxdLdW5kzwNaNEpR8JO9hBs2Rl 5jZgRpoTumHjGGj6mES+MtP3KquWdGi94V8spguBR788xuuGORNANZk/KFj/zmyS0NP5 Dankfbg3sg6Bd9JBBGV5VT/2cbT6l+58IthX5oJc4wKt+Rgj4Gxq/rA7y0D+9DBzOUAf +KSQ2CHdirXrAD51c6m2X17+ct9EZ3fMQ9rEVAD/lhiwraUNMOXKCQd8UqWWeIlBggUA pPxK+WPjnxAA1437vUIeGKHk2aHa9pIPUHgGTB1NXF6gayhWyZqiBgZ2vrY+HZxrPfmK G4ng== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E0FHvGw1sngbbdp6s/GTmivDqIUDoTydbvwrs8v2FceXXeRcQMk 1EoLXQ//1VfOL6MXNVTrsXHWFzlS8dNPra38eSsWKDN+QWZ5pjCcAUNBzPkN3BVCkzPZyyOZiyo QLbk5K6aIxM/F3/IR3q4nsHmqO0a02lmJXyTsL9E8DPSuHdhQBHiIvmCC/Z6v1pVRPw== X-Received: by 2002:a0c:b665:: with SMTP id q37-v6mr5230456qvf.43.1530103690199; Wed, 27 Jun 2018 05:48:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcSTjVXXz+Qe5cIXiSLWm/9Affg0gJxe1BSJyk1dgeBDko+JO4lQ8su2JGP80BmREear4F1 X-Received: by 2002:a0c:b665:: with SMTP id q37-v6mr5230425qvf.43.1530103689543; Wed, 27 Jun 2018 05:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103689; cv=none; d=google.com; s=arc-20160816; b=M9NOfEPz6L5yzTLLqQT69KkkxLa1B6sEckvBIb6YYa7VKFFEYb+RhEgxt0QuqYkmMq M27c0WAw0ia3JFtd9hsDNcNzC7bF4q9mCEDSG/iezpqW0msF30ATtziEdgU6rPrqCOuN VY39dUr83ewPxr5E8Md2hbIVxrrmneQKFUEotLKWPLfNVYXQk6OGCcmf7yX0eh2joiml vIt57pvW9DZwA3/Rv+YtHzGh5QkEwVAFHn5Jq+Xg0Tut2/jY968195kVLkT/L97Xru1c eWC9PSoYMsOGa+X/B2briZaFBAJG9fiJGMzI5VTZ0JLJcHtiKB2z7QS+LznzC4J0dfFh U1Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=CdM5RprJDQqB2vgWG8tVlsvcqNdmR7LkPGyMXg0cNHo=; b=hQMIoFuHW4g2kETR0atOoGiZHe+IRqNbWXDe66L8n09/qm5c/03r3Qm/nOglpHKRYq mC0BMMJHGnfiw44ZTNtqYT3h3BllES2qq7lslZHuhUAKZSbuCdN52WeY4AIgW16TSU18 9G2MBCJgKAUFV/61rzBkpaGI+6s5EsnzQOcWLZ3BXq6Ky7r4SdVjvZYiDtHHorY0T5qo It2pBHGXB/CWKxfIyq7bXzs3USXC0wZq6WezKS+JeCYU/BhLd6Hd9iLlXe48bfEqRfO8 7WiMqNK59jqDNfC4GIP8WHI9w5L2i85ewKHZi007j1ekl1ZtSYa3X7LrP3htRIiLSdOd iORQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id t15-v6si767121qth.145.2018.06.27.05.48.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 05:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 245B670206; Wed, 27 Jun 2018 12:48:09 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id E121D1C5B9; Wed, 27 Jun 2018 12:48:00 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , 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 , Randy Dunlap , Ming Lei Subject: [PATCH V7 11/24] block: introduce bio_for_each_bvec() Date: Wed, 27 Jun 2018 20:45:35 +0800 Message-Id: <20180627124548.3456-12-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 27 Jun 2018 12:48:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 27 Jun 2018 12:48:09 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This helper is used for iterating over multipage bvec for bio splitting/merge, Signed-off-by: Ming Lei --- include/linux/bio.h | 34 +++++++++++++++++++++++++++++++--- include/linux/bvec.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 21d07858ddef..551444bd9795 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -80,6 +80,9 @@ #define bio_data_dir(bio) \ (op_is_write(bio_op(bio)) ? WRITE : READ) +#define bio_iter_mp_iovec(bio, iter) \ + mp_bvec_iter_bvec((bio)->bi_io_vec, (iter)) + /* * Check whether this bio carries any data or not. A NULL bio is allowed. */ @@ -165,8 +168,8 @@ static inline bool bio_full(struct bio *bio) #define bio_for_each_segment_all(bvl, bio, i) \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) -static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, - unsigned bytes) +static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes, bool mp) { iter->bi_sector += bytes >> 9; @@ -174,11 +177,26 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, iter->bi_size -= bytes; iter->bi_done += bytes; } else { - bvec_iter_advance(bio->bi_io_vec, iter, bytes); + if (!mp) + bvec_iter_advance(bio->bi_io_vec, iter, bytes); + else + mp_bvec_iter_advance(bio->bi_io_vec, iter, bytes); /* TODO: It is reasonable to complete bio with error here. */ } } +static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes) +{ + __bio_advance_iter(bio, iter, bytes, false); +} + +static inline void bio_advance_mp_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes) +{ + __bio_advance_iter(bio, iter, bytes, true); +} + static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, unsigned int bytes) { @@ -202,6 +220,16 @@ 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_bvec(bvl, bio, iter, start) \ + for (iter = (start); \ + (iter).bi_size && \ + ((bvl = bio_iter_mp_iovec((bio), (iter))), 1); \ + bio_advance_mp_iter((bio), &(iter), (bvl).bv_len)) + +/* returns one real segment(multipage bvec) each time */ +#define bio_for_each_bvec(bvl, bio, iter) \ + __bio_for_each_bvec(bvl, bio, iter, (bio)->bi_iter) + #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) static inline unsigned bio_segments(struct bio *bio) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 03a12fbb90d8..417d44cf1e82 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -126,8 +126,16 @@ struct bvec_iter { .bv_offset = bvec_iter_offset((bvec), (iter)), \ }) -static inline bool bvec_iter_advance(const struct bio_vec *bv, - struct bvec_iter *iter, unsigned bytes) +#define mp_bvec_iter_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = mp_bvec_iter_page((bvec), (iter)), \ + .bv_len = mp_bvec_iter_len((bvec), (iter)), \ + .bv_offset = mp_bvec_iter_offset((bvec), (iter)), \ +}) + +static inline bool __bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes, bool mp) { if (WARN_ONCE(bytes > iter->bi_size, "Attempted to advance past end of bvec iter\n")) { @@ -136,8 +144,14 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, } while (bytes) { - unsigned iter_len = bvec_iter_len(bv, *iter); - unsigned len = min(bytes, iter_len); + unsigned len; + + if (mp) + len = mp_bvec_iter_len(bv, *iter); + else + len = bvec_iter_len(bv, *iter); + + len = min(bytes, len); bytes -= len; iter->bi_size -= len; @@ -176,6 +190,20 @@ static inline bool bvec_iter_rewind(const struct bio_vec *bv, return true; } +static inline bool bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes) +{ + return __bvec_iter_advance(bv, iter, bytes, false); +} + +static inline bool mp_bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes) +{ + return __bvec_iter_advance(bv, iter, bytes, true); +} + #define for_each_bvec(bvl, bio_vec, iter, start) \ for (iter = (start); \ (iter).bi_size && \