All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Overstreet <kmo@daterainc.com>
To: axboe@kernel.dk
Cc: neilb@suse.de, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, dm-devel@redhat.com,
	linux-raid@vger.kernel.org, Kent Overstreet <kmo@daterainc.com>,
	Alasdair Kergon <agk@redhat.com>
Subject: [PATCH 16/22] dm: Refactor for new bio cloning/splitting
Date: Wed,  7 Aug 2013 14:54:25 -0700	[thread overview]
Message-ID: <1375912471-5106-17-git-send-email-kmo@daterainc.com> (raw)
In-Reply-To: <1375912471-5106-1-git-send-email-kmo@daterainc.com>

We need to convert the dm code to the new bvec_iter primitives which
respect bi_bvec_done; they also allow us to drastically simplify dm's
bio splitting code.

Also kill bio_sector_offset(), dm was the only user and it doesn't make
much sense anymore.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
---
 drivers/md/dm.c     | 170 ++++++----------------------------------------------
 fs/bio.c            |  38 ------------
 include/linux/bio.h |   1 -
 3 files changed, 18 insertions(+), 191 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 5544af7..696269d 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1050,7 +1050,6 @@ struct clone_info {
 	struct dm_io *io;
 	sector_t sector;
 	sector_t sector_count;
-	unsigned short idx;
 };
 
 static void bio_setup_sector(struct bio *bio, sector_t sector, sector_t len)
@@ -1059,68 +1058,24 @@ static void bio_setup_sector(struct bio *bio, sector_t sector, sector_t len)
 	bio->bi_iter.bi_size = to_bytes(len);
 }
 
-static void bio_setup_bv(struct bio *bio, unsigned short idx, unsigned short bv_count)
-{
-	bio->bi_iter.bi_idx = idx;
-	bio->bi_vcnt = idx + bv_count;
-	bio->bi_flags &= ~(1 << BIO_SEG_VALID);
-}
-
-static void clone_bio_integrity(struct bio *bio, struct bio *clone,
-				unsigned short idx, unsigned len, unsigned offset,
-				unsigned trim)
-{
-	if (!bio_integrity(bio))
-		return;
-
-	bio_integrity_clone(clone, bio, GFP_NOIO);
-
-	if (trim)
-		bio_integrity_trim(clone, bio_sector_offset(bio, idx, offset), len);
-}
-
-/*
- * Creates a little bio that just does part of a bvec.
- */
-static void clone_split_bio(struct dm_target_io *tio, struct bio *bio,
-			    sector_t sector, unsigned short idx,
-			    unsigned offset, unsigned len)
-{
-	struct bio *clone = &tio->clone;
-	struct bio_vec *bv = bio->bi_io_vec + idx;
-
-	*clone->bi_io_vec = *bv;
-
-	bio_setup_sector(clone, sector, len);
-
-	clone->bi_bdev = bio->bi_bdev;
-	clone->bi_rw = bio->bi_rw;
-	clone->bi_vcnt = 1;
-	clone->bi_io_vec->bv_offset = offset;
-	clone->bi_io_vec->bv_len = clone->bi_iter.bi_size;
-	clone->bi_flags |= 1 << BIO_CLONED;
-
-	clone_bio_integrity(bio, clone, idx, len, offset, 1);
-}
-
 /*
  * Creates a bio that consists of range of complete bvecs.
  */
 static void clone_bio(struct dm_target_io *tio, struct bio *bio,
-		      sector_t sector, unsigned short idx,
-		      unsigned short bv_count, unsigned len)
+		      sector_t sector, unsigned len)
 {
 	struct bio *clone = &tio->clone;
-	unsigned trim = 0;
 
 	__bio_clone(clone, bio);
-	bio_setup_sector(clone, sector, len);
-	bio_setup_bv(clone, idx, bv_count);
 
-	if (idx != bio->bi_iter.bi_idx ||
-	    clone->bi_iter.bi_size < bio->bi_iter.bi_size)
-		trim = 1;
-	clone_bio_integrity(bio, clone, idx, len, 0, trim);
+	if (bio_integrity(bio))
+		bio_integrity_clone(clone, bio, GFP_NOIO);
+
+	bio_advance(clone, (sector - clone->bi_iter.bi_sector) << 9);
+	bio->bi_iter.bi_size = len << 9;
+
+	if (bio_integrity(bio))
+		bio_integrity_trim(clone, 0, len);
 }
 
 static struct dm_target_io *alloc_tio(struct clone_info *ci,
@@ -1182,10 +1137,7 @@ static int __send_empty_flush(struct clone_info *ci)
 }
 
 static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
-				     sector_t sector, int nr_iovecs,
-				     unsigned short idx, unsigned short bv_count,
-				     unsigned offset, unsigned len,
-				     unsigned split_bvec)
+				     sector_t sector, unsigned len)
 {
 	struct bio *bio = ci->bio;
 	struct dm_target_io *tio;
@@ -1199,11 +1151,8 @@ static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti
 		num_target_bios = ti->num_write_bios(ti, bio);
 
 	for (target_bio_nr = 0; target_bio_nr < num_target_bios; target_bio_nr++) {
-		tio = alloc_tio(ci, ti, nr_iovecs, target_bio_nr);
-		if (split_bvec)
-			clone_split_bio(tio, bio, sector, idx, offset, len);
-		else
-			clone_bio(tio, bio, sector, idx, bv_count, len);
+		tio = alloc_tio(ci, ti, 0, target_bio_nr);
+		clone_bio(tio, bio, sector, len);
 		__map_bio(tio);
 	}
 }
@@ -1275,68 +1224,13 @@ static int __send_write_same(struct clone_info *ci)
 }
 
 /*
- * Find maximum number of sectors / bvecs we can process with a single bio.
- */
-static sector_t __len_within_target(struct clone_info *ci, sector_t max, int *idx)
-{
-	struct bio *bio = ci->bio;
-	sector_t bv_len, total_len = 0;
-
-	for (*idx = ci->idx; max && (*idx < bio->bi_vcnt); (*idx)++) {
-		bv_len = to_sector(bio->bi_io_vec[*idx].bv_len);
-
-		if (bv_len > max)
-			break;
-
-		max -= bv_len;
-		total_len += bv_len;
-	}
-
-	return total_len;
-}
-
-static int __split_bvec_across_targets(struct clone_info *ci,
-				       struct dm_target *ti, sector_t max)
-{
-	struct bio *bio = ci->bio;
-	struct bio_vec *bv = bio->bi_io_vec + ci->idx;
-	sector_t remaining = to_sector(bv->bv_len);
-	unsigned offset = 0;
-	sector_t len;
-
-	do {
-		if (offset) {
-			ti = dm_table_find_target(ci->map, ci->sector);
-			if (!dm_target_is_valid(ti))
-				return -EIO;
-
-			max = max_io_len(ci->sector, ti);
-		}
-
-		len = min(remaining, max);
-
-		__clone_and_map_data_bio(ci, ti, ci->sector, 1, ci->idx, 0,
-					 bv->bv_offset + offset, len, 1);
-
-		ci->sector += len;
-		ci->sector_count -= len;
-		offset += to_bytes(len);
-	} while (remaining -= len);
-
-	ci->idx++;
-
-	return 0;
-}
-
-/*
  * Select the correct strategy for processing a non-flush bio.
  */
 static int __split_and_process_non_flush(struct clone_info *ci)
 {
 	struct bio *bio = ci->bio;
 	struct dm_target *ti;
-	sector_t len, max;
-	int idx;
+	unsigned len;
 
 	if (unlikely(bio->bi_rw & REQ_DISCARD))
 		return __send_discard(ci);
@@ -1347,41 +1241,14 @@ static int __split_and_process_non_flush(struct clone_info *ci)
 	if (!dm_target_is_valid(ti))
 		return -EIO;
 
-	max = max_io_len(ci->sector, ti);
-
-	/*
-	 * Optimise for the simple case where we can do all of
-	 * the remaining io with a single clone.
-	 */
-	if (ci->sector_count <= max) {
-		__clone_and_map_data_bio(ci, ti, ci->sector, bio->bi_max_vecs,
-					 ci->idx, bio->bi_vcnt - ci->idx, 0,
-					 ci->sector_count, 0);
-		ci->sector_count = 0;
-		return 0;
-	}
-
-	/*
-	 * There are some bvecs that don't span targets.
-	 * Do as many of these as possible.
-	 */
-	if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
-		len = __len_within_target(ci, max, &idx);
-
-		__clone_and_map_data_bio(ci, ti, ci->sector, bio->bi_max_vecs,
-					 ci->idx, idx - ci->idx, 0, len, 0);
+	len = min_t(unsigned, max_io_len(ci->sector, ti), bio_sectors(bio));
 
-		ci->sector += len;
-		ci->sector_count -= len;
-		ci->idx = idx;
+	__clone_and_map_data_bio(ci, ti, ci->sector, len);
 
-		return 0;
-	}
+	ci->sector += len;
+	ci->sector_count -= len;
 
-	/*
-	 * Handle a bvec that must be split between two or more targets.
-	 */
-	return __split_bvec_across_targets(ci, ti, max);
+	return 0;
 }
 
 /*
@@ -1407,7 +1274,6 @@ static void __split_and_process_bio(struct mapped_device *md,
 	ci.io->md = md;
 	spin_lock_init(&ci.io->endio_lock);
 	ci.sector = bio->bi_iter.bi_sector;
-	ci.idx = bio->bi_iter.bi_idx;
 
 	start_io_acct(ci.io);
 
diff --git a/fs/bio.c b/fs/bio.c
index 46cf8a6..bb62198 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1809,44 +1809,6 @@ void bio_trim(struct bio *bio, int offset, int size)
 }
 EXPORT_SYMBOL_GPL(bio_trim);
 
-/**
- *      bio_sector_offset - Find hardware sector offset in bio
- *      @bio:           bio to inspect
- *      @index:         bio_vec index
- *      @offset:        offset in bv_page
- *
- *      Return the number of hardware sectors between beginning of bio
- *      and an end point indicated by a bio_vec index and an offset
- *      within that vector's page.
- */
-sector_t bio_sector_offset(struct bio *bio, unsigned short index,
-			   unsigned int offset)
-{
-	unsigned int sector_sz;
-	struct bio_vec *bv;
-	sector_t sectors;
-	int i;
-
-	sector_sz = queue_logical_block_size(bio->bi_bdev->bd_disk->queue);
-	sectors = 0;
-
-	if (index >= bio->bi_iter.bi_idx)
-		index = bio->bi_vcnt - 1;
-
-	bio_for_each_segment_all(bv, bio, i) {
-		if (i == index) {
-			if (offset > bv->bv_offset)
-				sectors += (offset - bv->bv_offset) / sector_sz;
-			break;
-		}
-
-		sectors += bv->bv_len / sector_sz;
-	}
-
-	return sectors;
-}
-EXPORT_SYMBOL(bio_sector_offset);
-
 /*
  * create memory pools for biovec's in a bio_set.
  * use the global biovec slabs created for general use.
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 486a997..e9a4fce 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -349,7 +349,6 @@ extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
 extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
 			   unsigned int, unsigned int);
 extern int bio_get_nr_vecs(struct block_device *);
-extern sector_t bio_sector_offset(struct bio *, unsigned short, unsigned int);
 extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
 				unsigned long, unsigned int, int, gfp_t);
 struct sg_iovec;
-- 
1.8.4.rc1

  parent reply	other threads:[~2013-08-07 21:54 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-07 21:54 [PATCH 0/22] Immutable biovecs, block layer changes Kent Overstreet
2013-08-07 21:54 ` [PATCH 01/22] block: Use rw_copy_check_uvector() Kent Overstreet
2013-08-07 21:54 ` [PATCH 02/22] block: Consolidate duplicated bio_trim() implementations Kent Overstreet
2013-08-07 21:54 ` [PATCH 03/22] bcache: Kill unaligned bvec hack Kent Overstreet
2013-08-07 21:54 ` [PATCH 04/22] block: Abstract out bvec iterator Kent Overstreet
2013-08-07 21:54   ` Kent Overstreet
2013-08-07 21:54   ` Kent Overstreet
2013-08-07 22:24   ` Geoff Levand
2013-08-08  2:04   ` Ed Cashin
2013-08-08  2:04     ` Ed Cashin
2013-08-08  2:04     ` Ed Cashin
2013-08-09  0:09     ` Kent Overstreet
2013-08-09  0:09       ` Kent Overstreet
2013-08-09  0:59       ` Ed Cashin
2013-08-09  1:05         ` Kent Overstreet
2013-08-09 20:16           ` Ed Cashin
2013-08-13 14:03           ` Ed Cashin
2013-08-13 18:51             ` Kent Overstreet
2013-08-13 19:18               ` Ed L Cashin
2013-08-07 21:54 ` [PATCH 05/22] dm: Use bvec_iter for dm_bio_record() Kent Overstreet
2013-08-07 21:54 ` [PATCH 06/22] block: Convert bio_iovec() to bvec_iter Kent Overstreet
2013-08-07 21:54 ` [PATCH 07/22] block: Convert bio_for_each_segment() " Kent Overstreet
2013-08-07 21:54 ` Kent Overstreet
2013-08-07 21:54   ` [Cluster-devel] " Kent Overstreet
2013-08-07 21:54   ` Kent Overstreet
2013-08-07 21:54   ` Kent Overstreet
2013-08-07 21:54   ` Kent Overstreet
     [not found] ` <1375912471-5106-1-git-send-email-kmo-PEzghdH756F8UrSeD/g0lQ@public.gmane.org>
2013-08-07 21:54   ` [PATCH 08/22] block: Immutable bio vecs Kent Overstreet
2013-08-07 21:54     ` Kent Overstreet
2013-08-07 21:54 ` [PATCH 09/22] block: Convert bio_copy_data() to bvec_iter Kent Overstreet
2013-08-07 21:54 ` [PATCH 10/22] bio-integrity: Convert " Kent Overstreet
2013-08-07 21:54 ` [PATCH 11/22] block: Kill bio_segments()/bi_vcnt usage Kent Overstreet
2013-08-07 21:54 ` [PATCH 12/22] block: Convert drivers to immutable biovecs Kent Overstreet
2013-08-07 21:54 ` [PATCH 13/22] ceph: Convert " Kent Overstreet
2013-08-07 21:54 ` [PATCH 14/22] block: Kill bio_iovec_idx(), __bio_iovec() Kent Overstreet
2013-08-07 21:54 ` [PATCH 15/22] rbd: Refactor bio cloning, don't clone biovecs Kent Overstreet
2013-08-07 21:54 ` Kent Overstreet [this message]
2013-09-28  4:59   ` [PATCH 16/22] dm: Refactor for new bio cloning/splitting Mike Snitzer
2013-10-03  3:17     ` Kent Overstreet
2013-10-03  3:23       ` Mike Snitzer
2013-10-03 21:45         ` Kent Overstreet
2013-10-03 22:50           ` Mike Snitzer
2013-10-04 17:07             ` Mike Snitzer
2013-10-07  0:14               ` Mike Snitzer
2013-10-11  4:13                 ` Kent Overstreet
2013-10-11 21:16                   ` Mike Snitzer
2013-10-11 22:11                     ` Kent Overstreet
2013-08-07 21:54 ` [PATCH 17/22] block: Remove bi_idx hacks Kent Overstreet
2013-08-07 21:54 ` [PATCH 18/22] block: Generic bio chaining Kent Overstreet
2013-08-10  7:38   ` Kent Overstreet
2013-08-10  7:38     ` Kent Overstreet
2013-08-07 21:54 ` [PATCH 19/22] block: Rename bio_split() -> bio_pair_split() Kent Overstreet
2013-08-07 21:54 ` [PATCH 20/22] block: Introduce new bio_split() Kent Overstreet
2013-08-07 21:54 ` [PATCH 21/22] block: Kill bio_pair_split() Kent Overstreet
2013-08-07 21:54 ` [PATCH 22/22] block: Don't save/copy bvec array anymore, share when cloning Kent Overstreet
2013-08-08 15:09 ` [PATCH 0/22] Immutable biovecs, block layer changes Christoph Hellwig
2013-08-08 21:15   ` Kent Overstreet
2013-09-24 11:00     ` Christoph Hellwig
2013-09-24 13:20       ` Mike Snitzer
2013-09-24 14:29         ` Christoph Hellwig
2013-09-24 19:19         ` Kent Overstreet
2013-09-27 18:38           ` Mike Snitzer
2013-09-24 19:16       ` 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=1375912471-5106-17-git-send-email-kmo@daterainc.com \
    --to=kmo@daterainc.com \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.