From patchwork Fri Jan 11 11:01:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10757693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97B146C5 for ; Fri, 11 Jan 2019 11:03:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89EEB29B7F for ; Fri, 11 Jan 2019 11:03:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E30529C0E; Fri, 11 Jan 2019 11:03:27 +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=unavailable 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 1626929B7F for ; Fri, 11 Jan 2019 11:03:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3274C8E0008; Fri, 11 Jan 2019 06:03:26 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2D5D68E0001; Fri, 11 Jan 2019 06:03:26 -0500 (EST) 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 1C68C8E0008; Fri, 11 Jan 2019 06:03:26 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id E33D18E0001 for ; Fri, 11 Jan 2019 06:03:25 -0500 (EST) Received: by mail-qt1-f197.google.com with SMTP id 42so15970234qtr.7 for ; Fri, 11 Jan 2019 03:03:25 -0800 (PST) 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=rGjI+V/4rg/dWoUNu9x64XeJFFqTvq16W4s9QZuA0vA=; b=Af+6lD9xyI0cpyU0VKH0MKeOZNVu5Yh/2HP/f2EW8vHQ1IKetHA0YTPKdbJqi3jn/k NxpHjiDiwy0DWepxipu+pR+AGssrrODOqj3v85uI7jVLycwiWspTrhwpPI9OCb1f1C// hlzR4Stpn1Wlv2zEs7AB+e84t+8PsbTEh2V/GUjuiKpeuH32zy9cCiLh5ZZxHR5qSivi Z5meCK93KIbLk9P86e07Y7a0xsuxM4sD2g7eiS1WNCUyMDHJtz3UjtA2xg74kpCr9iY0 Tei0liLGNa4nGU0u0T5BKc8WZur1aarWOUitEtkMlQYGDGu+oNcdrC7bxyO7yQkOpfA/ OPOw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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: AJcUukeWiCHHF4NkWtjs5FiYHBuUaKveK+Z/Am5C1BMwH+tLAqiGP7za S1uwdDV/Yf4I6FDRQqHSSy6lvrNP+2SVcqHgUSAmeUL3VSYhHBfTvpuVUMKfy0+gGkbbhoAA1vR a7d+vYBCF4p6FqmosImbONxMR7CFbBsKJ3qCPzY+GTzroC0sWWhyF1avQmmI/5Xfj9g== X-Received: by 2002:ac8:e0b:: with SMTP id a11mr13580511qti.140.1547204605711; Fri, 11 Jan 2019 03:03:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN4aky3WcCouA3OMm1r1tSsnQUiVuJKn0QRu1B1uZDpfAxA/gyYcNVE8gNQn9qM/Jsd9Flw8 X-Received: by 2002:ac8:e0b:: with SMTP id a11mr13580494qti.140.1547204605213; Fri, 11 Jan 2019 03:03:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547204605; cv=none; d=google.com; s=arc-20160816; b=ggHUbhirYkwEXlmjRPNv3xK9DtbQjFwrNcLG4ljnNxKo4ksEJ56qEvhhIhi3t49qZZ L/hath9yu9J8pO3B3crF/6sclmk4XvbacDdMZ452Bcy8KL6kYmLdHar9xbSar3jvlJAl UViPpWDgASFBx/OsJERKTn+ZnLWcbHmlTqHSPMyJ3PV0gF5O1RZpXOZSsZjhxczH1EDd vJy5WKn5rhFbjE9S3q+jdfnERl2ckpk8tVcDRjNnWOSLlMQkFY+7y2tHqItRxivVIhZM qu3DaOunmBiKA9hLzHUWRt/VC7Tkwe5KL5cYYNocT/w8B1wscTlddmLfkFWs++iS8Hk2 Wobg== 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; bh=rGjI+V/4rg/dWoUNu9x64XeJFFqTvq16W4s9QZuA0vA=; b=YL13dAg1njf/fTRLu/e56UYeQrK3UTW5pn7iOGuRwYf/Kg1ebSRpmfd11tvaIjbDyZ HoqHAbSFsI3YCyszv9aO+kFxIub+jmkbqJx5fn0TnQ6FqIX4tkVAdtHmd37m77IjH6OP usH2TI5wELPytP0fuYwudeXAl0w5zG5hTMfWNYnLK1P8aBH2HjlIaP7Bc4UZdCB5t9vs hzG3iG4oAH90vnhCqnOvf6MsiiDGM0MWvpM89JOTAQVUvnbL/lEa/4TYdBEs/pA92ZQ2 f5CmC9eEa/RB9+UXlEIYMIXmmmzR/TJluV4nSSCm7M7cpip+danoZ3ktL2XGw9CC74KI XSqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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 (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id r72si1385583qkl.162.2019.01.11.03.03.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jan 2019 03:03:25 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 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-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DCC8432D0; Fri, 11 Jan 2019 11:03:24 +0000 (UTC) Received: from localhost (ovpn-8-28.pek2.redhat.com [10.72.8.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id A73E1600C4; Fri, 11 Jan 2019 11:03:11 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V13 06/19] block: introduce bio_for_each_bvec() and rq_for_each_bvec() Date: Fri, 11 Jan 2019 19:01:14 +0800 Message-Id: <20190111110127.21664-7-ming.lei@redhat.com> In-Reply-To: <20190111110127.21664-1-ming.lei@redhat.com> References: <20190111110127.21664-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 11 Jan 2019 11:03:24 +0000 (UTC) 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 bio_for_each_bvec() is used for iterating over multi-page bvec for bio split & merge code. rq_for_each_bvec() can be used for drivers which may handle the multi-page bvec directly, so far loop is one perfect use case. Reviewed-by: Christoph Hellwig Reviewed-by: Omar Sandoval Signed-off-by: Ming Lei --- include/linux/bio.h | 10 ++++++++++ include/linux/blkdev.h | 4 ++++ include/linux/bvec.h | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 16a65361535f..06888d45beb4 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -156,6 +156,16 @@ static inline void bio_advance_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 = bvec_iter_bvec((bio)->bi_io_vec, (iter))), 1); \ + bio_advance_iter((bio), &(iter), (bvl).bv_len)) + +/* iterate over multi-page bvec */ +#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/blkdev.h b/include/linux/blkdev.h index 338604dff7d0..7f4ca073e2f3 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -797,6 +797,10 @@ struct req_iterator { __rq_for_each_bio(_iter.bio, _rq) \ bio_for_each_segment(bvl, _iter.bio, _iter.iter) +#define rq_for_each_bvec(bvl, _rq, _iter) \ + __rq_for_each_bio(_iter.bio, _rq) \ + bio_for_each_bvec(bvl, _iter.bio, _iter.iter) + #define rq_iter_last(bvec, _iter) \ (_iter.bio->bi_next == NULL && \ bio_iter_last(bvec, _iter.iter)) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index babc6316c117..d441486db605 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -65,6 +65,13 @@ struct bvec_iter { #define bvec_iter_page_idx(bvec, iter) \ (bvec_iter_offset((bvec), (iter)) / PAGE_SIZE) +#define bvec_iter_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = bvec_iter_page((bvec), (iter)), \ + .bv_len = bvec_iter_len((bvec), (iter)), \ + .bv_offset = bvec_iter_offset((bvec), (iter)), \ +}) + /* For building single-page bvec(segment) in flight */ #define segment_iter_offset(bvec, iter) \ (bvec_iter_offset((bvec), (iter)) % PAGE_SIZE)