Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp873549imj; Fri, 15 Feb 2019 08:12:03 -0800 (PST) X-Google-Smtp-Source: AHgI3IbxzJ79c5OKm+QcQ+Wvpfe3FYXjphy3MWwPK+GmRcTrKYeAsZoXYP4SKjp6mxKUunaidS2l X-Received: by 2002:a62:3990:: with SMTP id u16mr10563356pfj.80.1550247123288; Fri, 15 Feb 2019 08:12:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550247123; cv=none; d=google.com; s=arc-20160816; b=fjHYgq3Ahd2GJn3fdpeXdVB4/1f5L02IYENeMHmvzXAIv6VGnt/q/CcCBT4nla6WlU RmNC1tugJBAXUz4Q788oLo7/TIYGlhT0eCH/LFWTOFV/mi0jxShpG694V8M/L/PwfqCP 0lWHL71Cnx9VH4FuMRkuFhYwivPiznMT7hFHx578lmsGRtK5XFw0p5Lu9GXg+ZGgZxYr QWQaFpW1PUxhOEtq1Y111aSoRxsX+h/tEvwCj7c9ycg+oCPUV53vtiSm00tDcYV3lbrd /7OjcAv6q3Wb82cz3qIn8TjsWwlg8sIHZ5RMawWKBMNPCetw/KQI4J0CK/kg19mdIDoc 7TGg== 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; bh=Fr9EnIrxI+HhD+i6K4i9/AzKSS6rcNfuTuDhUsAQpw4=; b=zzQJsF/qap72uAbiGRkIRTBRALpclhl6ChWmE+nr+4B9mt3dzLdWu2j6H9Q/VCh8qT eSQzVgMYzgoqGaXWgYWiM0wh33P5sYpNgCgFuoPBDndKyrDHfPeZ61AmradqDHPVcLxG di+ZHcgbSGm3VtjA4rsvSUtO5bAxyIfnZ+ElfwPmL3o+XRruvI712wDBRP3adUAJLwZ2 WxUF36Y0gJzsel4Jok8D7VfxavcyvanG6kKkcnxJuzaHn9yz0wd+3qOrsjC8jdyPICEa 83RQ5pzuDv0j8pdicXx/hl5HuINB9SIFH/Rup3TmFTNt20YwSNTM74FCFfOxoYl4zLyc Msjg== 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 m2si854645pfj.111.2019.02.15.08.11.46; Fri, 15 Feb 2019 08:12:03 -0800 (PST) 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 S2436531AbfBOLPL (ORCPT + 99 others); Fri, 15 Feb 2019 06:15:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49656 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726160AbfBOLPK (ORCPT ); Fri, 15 Feb 2019 06:15:10 -0500 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 E52A5C075BDF; Fri, 15 Feb 2019 11:15:08 +0000 (UTC) Received: from localhost (ovpn-8-22.pek2.redhat.com [10.72.8.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8457600C1; Fri, 15 Feb 2019 11:14:53 +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 V15 05/18] block: introduce bio_for_each_bvec() and rq_for_each_bvec() Date: Fri, 15 Feb 2019 19:13:11 +0800 Message-Id: <20190215111324.30129-6-ming.lei@redhat.com> In-Reply-To: <20190215111324.30129-1-ming.lei@redhat.com> References: <20190215111324.30129-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.31]); Fri, 15 Feb 2019 11:15:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index 72b4f7be2106..7ef8a7505c0a 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 = mp_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 3603270cb82d..b6292d469ea4 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -792,6 +792,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)) -- 2.9.5