linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <koverstreet@google.com>
To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
	dm-devel@redhat.com
Cc: axboe@kernel.dk, Kent Overstreet <koverstreet@google.com>,
	tj@kernel.org, neilb@suse.de
Subject: [PATCH v2 20/26] block: Add bio_for_each_segment_all()
Date: Mon, 10 Sep 2012 17:22:31 -0700	[thread overview]
Message-ID: <1347322957-25260-21-git-send-email-koverstreet@google.com> (raw)
In-Reply-To: <1347322957-25260-1-git-send-email-koverstreet@google.com>

This is part of the immutable bvec prep work; bio_for_each_segment() is
going to have a different implementation so these need to be split
apart.

This change is also to better document the intent of code that's using
it - bio_for_each_segment_all() is only legal to use for code that owns
the bio.

Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
---
 drivers/md/raid1.c  |  2 +-
 fs/bio.c            | 12 ++++++------
 fs/exofs/ore.c      |  2 +-
 fs/exofs/ore_raid.c |  2 +-
 include/linux/bio.h | 16 +++++++++-------
 mm/bounce.c         |  2 +-
 6 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 6cd1fb2..ade95ac 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1283,7 +1283,7 @@ read_again:
 			 * know the original bi_idx, so we just free
 			 * them all
 			 */
-			__bio_for_each_segment(bvec, mbio, j, 0)
+			bio_for_each_segment_all(bvec, mbio, j)
 				bvec->bv_page = r1_bio->behind_bvecs[j].bv_page;
 			if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
 				atomic_inc(&r1_bio->behind_remaining);
diff --git a/fs/bio.c b/fs/bio.c
index 7fb9f4e..efdc437 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -959,7 +959,7 @@ static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs,
 	int iov_idx = 0;
 	unsigned int iov_off = 0;
 
-	__bio_for_each_segment(bvec, bio, i, 0) {
+	bio_for_each_segment_all(bvec, bio, i) {
 		char *bv_addr = page_address(bvec->bv_page);
 		unsigned int bv_len = iovecs[i].bv_len;
 
@@ -1141,7 +1141,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
 	return bio;
 cleanup:
 	if (!map_data)
-		bio_for_each_segment(bvec, bio, i)
+		bio_for_each_segment_all(bvec, bio, i)
 			__free_page(bvec->bv_page);
 
 	bio_put(bio);
@@ -1355,7 +1355,7 @@ static void __bio_unmap_user(struct bio *bio)
 	/*
 	 * make sure we dirty pages we wrote to
 	 */
-	__bio_for_each_segment(bvec, bio, i, 0) {
+	bio_for_each_segment_all(bvec, bio, i) {
 		if (bio_data_dir(bio) == READ)
 			set_page_dirty_lock(bvec->bv_page);
 
@@ -1461,7 +1461,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
 	int i;
 	char *p = bmd->sgvecs[0].iov_base;
 
-	__bio_for_each_segment(bvec, bio, i, 0) {
+	bio_for_each_segment_all(bvec, bio, i) {
 		char *addr = page_address(bvec->bv_page);
 		int len = bmd->iovecs[i].bv_len;
 
@@ -1501,7 +1501,7 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
 	if (!reading) {
 		void *p = data;
 
-		bio_for_each_segment(bvec, bio, i) {
+		bio_for_each_segment_all(bvec, bio, i) {
 			char *addr = page_address(bvec->bv_page);
 
 			memcpy(addr, p, bvec->bv_len);
@@ -1780,7 +1780,7 @@ sector_t bio_sector_offset(struct bio *bio, unsigned short index,
 	if (index >= bio->bi_idx)
 		index = bio->bi_vcnt - 1;
 
-	__bio_for_each_segment(bv, bio, i, 0) {
+	bio_for_each_segment_all(bv, bio, i) {
 		if (i == index) {
 			if (offset > bv->bv_offset)
 				sectors += (offset - bv->bv_offset) / sector_sz;
diff --git a/fs/exofs/ore.c b/fs/exofs/ore.c
index f936cb5..b744228 100644
--- a/fs/exofs/ore.c
+++ b/fs/exofs/ore.c
@@ -401,7 +401,7 @@ static void _clear_bio(struct bio *bio)
 	struct bio_vec *bv;
 	unsigned i;
 
-	__bio_for_each_segment(bv, bio, i, 0) {
+	bio_for_each_segment_all(bv, bio, i) {
 		unsigned this_count = bv->bv_len;
 
 		if (likely(PAGE_SIZE == this_count))
diff --git a/fs/exofs/ore_raid.c b/fs/exofs/ore_raid.c
index 5f376d1..4dec928 100644
--- a/fs/exofs/ore_raid.c
+++ b/fs/exofs/ore_raid.c
@@ -432,7 +432,7 @@ static void _mark_read4write_pages_uptodate(struct ore_io_state *ios, int ret)
 		if (!bio)
 			continue;
 
-		__bio_for_each_segment(bv, bio, i, 0) {
+		bio_for_each_segment_all(bv, bio, i) {
 			struct page *page = bv->bv_page;
 
 			SetPageUptodate(page);
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 92015ce..b433ff8 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -137,16 +137,18 @@ static inline int bio_has_allocated_vec(struct bio *bio)
 #define bio_io_error(bio) bio_endio((bio), -EIO)
 
 /*
- * drivers should not use the __ version unless they _really_ want to
- * run through the entire bio and not just pending pieces
+ * drivers should _never_ use the all version - the bio may have been split
+ * before it got to the driver and the driver won't own all of it
  */
-#define __bio_for_each_segment(bvl, bio, i, start_idx)			\
-	for (bvl = bio_iovec_idx((bio), (start_idx)), i = (start_idx);	\
-	     i < (bio)->bi_vcnt;					\
-	     bvl++, i++)
+#define bio_for_each_segment_all(bvl, bio, i)				\
+	for (i = 0;							\
+	     bvl = bio_iovec_idx((bio), (i)), i < (bio)->bi_vcnt;	\
+	     i++)
 
 #define bio_for_each_segment(bvl, bio, i)				\
-	__bio_for_each_segment(bvl, bio, i, (bio)->bi_idx)
+	for (i = (bio)->bi_idx;						\
+	     bvl = bio_iovec_idx((bio), (i)), i < (bio)->bi_vcnt;	\
+	     i++)
 
 /*
  * get a reference to a bio, so it won't disappear. the intended use is
diff --git a/mm/bounce.c b/mm/bounce.c
index 3068300..89324e2 100644
--- a/mm/bounce.c
+++ b/mm/bounce.c
@@ -134,7 +134,7 @@ static void bounce_end_io(struct bio *bio, mempool_t *pool, int err)
 	/*
 	 * free up bounce indirect pages used
 	 */
-	__bio_for_each_segment(bvec, bio, i, 0) {
+	bio_for_each_segment_all(bvec, bio, i) {
 		org_vec = bio_orig->bi_io_vec + i;
 		if (bvec->bv_page == org_vec->bv_page)
 			continue;
-- 
1.7.12

  parent reply	other threads:[~2012-09-11  0:22 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11  0:22 [PATCH v2 00/26] Prep work for immutable bio vecs Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 01/26] block: Convert integrity to bvec_alloc_bs(), and a bugfix Kent Overstreet
     [not found]   ` <1347322957-25260-2-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 20:36     ` [dm-devel] " Vivek Goyal
2012-09-11 20:48       ` Kent Overstreet
2012-09-11 22:07       ` Kent Overstreet
     [not found]         ` <20120911220750.GM19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:39           ` Martin K. Petersen
     [not found]             ` <yq1wqzzrpy1.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:08               ` Kent Overstreet
2012-09-20 21:53     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 02/26] block: Add bio_advance() Kent Overstreet
     [not found]   ` <1347322957-25260-3-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 21:58     ` Tejun Heo
2012-09-20 23:13       ` Kent Overstreet
     [not found]         ` <20120920231308.GB5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:25           ` Tejun Heo
     [not found]             ` <20120920232506.GI7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:38               ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 03/26] block: Refactor blk_update_request() Kent Overstreet
     [not found]   ` <1347322957-25260-4-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:20     ` Tejun Heo
2012-09-20 23:36       ` Kent Overstreet
     [not found]         ` <20120920233632.GC5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:41           ` Tejun Heo
     [not found]             ` <20120920234133.GM7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:50               ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 04/26] md: Convert md_trim_bio() to use bio_advance() Kent Overstreet
     [not found]   ` <1347322957-25260-5-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:27     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 05/26] block: Add bio_end() Kent Overstreet
     [not found]   ` <1347322957-25260-6-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-17  9:17     ` Steven Whitehouse
2012-09-20 23:32     ` Tejun Heo
     [not found]       ` <20120920233225.GK7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:44         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 06/26] block: Use bio_sectors() more consistently Kent Overstreet
     [not found]   ` <1347322957-25260-7-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:36     ` Tejun Heo
     [not found]       ` <20120920233618.GL7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:47         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 07/26] block: Don't use bi_idx in bio_split() or require it to be 0 Kent Overstreet
     [not found]   ` <1347322957-25260-8-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:45     ` Tejun Heo
     [not found]       ` <20120920234544.GN7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:00         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 09/26] block: Remove some unnecessary bi_vcnt usage Kent Overstreet
     [not found]   ` <1347322957-25260-10-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:51     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 10/26] block: Add submit_bio_wait(), remove from md Kent Overstreet
     [not found]   ` <1347322957-25260-11-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:56     ` Tejun Heo
     [not found]       ` <20120920235643.GQ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:06         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 11/26] raid10: Use bio_reset() Kent Overstreet
2012-09-20 23:59   ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 13/26] raid5: use bio_reset() Kent Overstreet
     [not found]   ` <1347322957-25260-14-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  5:03     ` NeilBrown
     [not found]       ` <20120911150326.79f066c0-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-09-11 19:26         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 14/26] raid1: Refactor narrow_write_error() to not use bi_idx Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 15/26] block: Add bio_copy_data() Kent Overstreet
     [not found]   ` <1347322957-25260-16-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:06     ` Tejun Heo
2012-09-21  0:09       ` Kent Overstreet
     [not found]         ` <20120921000945.GK5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:15           ` Tejun Heo
2012-09-21  0:09       ` Tejun Heo
     [not found]         ` <20120921000947.GT7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:13           ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 16/26] pktcdvd: use bio_copy_data() Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 17/26] pktcdvd: Use bio_reset() in disabled code to kill bi_idx usage Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 18/26] raid1: use bio_copy_data() Kent Overstreet
2012-09-11  0:22 ` Kent Overstreet [this message]
     [not found]   ` <1347322957-25260-21-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:35     ` [PATCH v2 20/26] block: Add bio_for_each_segment_all() Tejun Heo
2012-09-11  0:22 ` [PATCH v2 22/26] block: Add bio_alloc_pages() Kent Overstreet
     [not found]   ` <1347322957-25260-23-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:47     ` Tejun Heo
     [not found]       ` <20120921004711.GZ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  4:50         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 24/26] block: Add an explicit bio flag for bios that own their bvec Kent Overstreet
     [not found] ` <1347322957-25260-1-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  0:22   ` [PATCH v2 08/26] block: Remove bi_idx references Kent Overstreet
     [not found]     ` <1347322957-25260-9-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:49       ` Tejun Heo
2012-09-21  0:04         ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 12/26] raid1: use bio_reset() Kent Overstreet
     [not found]     ` <1347322957-25260-13-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  4:59       ` NeilBrown
2012-09-11 18:28         ` Kent Overstreet
     [not found]           ` <20120911182825.GG19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 21:17             ` NeilBrown
2012-09-11  0:22   ` [PATCH v2 19/26] bounce: Refactor __blk_queue_bounce to not use bi_io_vec Kent Overstreet
     [not found]     ` <1347322957-25260-20-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:25       ` Tejun Heo
2012-09-21  0:29         ` Kent Overstreet
2012-09-21  0:27       ` Tejun Heo
2012-09-21  0:34         ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 21/26] block: Convert some code to bio_for_each_segment_all() Kent Overstreet
     [not found]     ` <1347322957-25260-22-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:38       ` Tejun Heo
     [not found]         ` <20120921003832.GY7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:50           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 23/26] raid1: use bio_alloc_pages() Kent Overstreet
     [not found]     ` <1347322957-25260-24-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:48       ` Tejun Heo
     [not found]         ` <20120921004827.GA7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  4:51           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 25/26] bio-integrity: Add explicit field for owner of bip_buf Kent Overstreet
     [not found]     ` <1347322957-25260-26-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:41       ` Martin K. Petersen
     [not found]         ` <yq1sjanrpu7.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:09           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 26/26] block: Add BIO_SUBMITTED flag, kill BIO_CLONED Kent Overstreet
2012-09-11  5:22   ` [PATCH v2 00/26] Prep work for immutable bio vecs NeilBrown
2012-09-20 23:22 ` Tejun Heo
2012-10-15 20:08 [PATCH v4 00/24] " Kent Overstreet
2012-10-15 20:09 ` [PATCH v2 20/26] block: Add bio_for_each_segment_all() Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347322957-25260-21-git-send-email-koverstreet@google.com \
    --to=koverstreet@google.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).