public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Alan D. Brunelle" <Alan.Brunelle@hp.com>
To: "Alan D. Brunelle" <Alan.Brunelle@hp.com>
Cc: Daniel Phillips <phillips@phunq.net>, linux-kernel@vger.kernel.org
Subject: Re: [RFC] Stacking bio support - patch 1/4 for 2.6.23.17 (stable)
Date: Fri, 14 Mar 2008 10:04:16 -0400	[thread overview]
Message-ID: <47DA85E0.2080501@hp.com> (raw)
In-Reply-To: <47DA84B7.1000409@hp.com>

[-- Attachment #1: Type: text/plain, Size: 1 bytes --]



[-- Attachment #2: 0001-BIO-single-alloc.patch --]
[-- Type: text/x-patch, Size: 4512 bytes --]

>From 7a91a074d4442d37ec43830c58ac94d39d17bd3d Mon Sep 17 00:00:00 2001
From: Alan D. Brunelle <alan.brunelle@hp.com>
Date: Fri, 14 Mar 2008 07:52:09 -0400
Subject: [PATCH] BIO single alloc


---
 drivers/md/dm.c |   76 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 58 insertions(+), 18 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index fac09d5..02173df 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -491,11 +491,9 @@ static void dec_pending(struct dm_io *io, int error)
 	}
 }
 
-static int clone_endio(struct bio *bio, unsigned int done, int error)
+static int dm_endio(struct bio *bio, unsigned int done, int error, struct dm_target_io *tio)
 {
 	int r = 0;
-	struct dm_target_io *tio = bio->bi_private;
-	struct mapped_device *md = tio->io->md;
 	dm_endio_fn endio = tio->ti->type->end_io;
 
 	if (bio->bi_size)
@@ -522,17 +520,28 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
 	}
 
 	dec_pending(tio->io, error);
+	return r;
+}
 
+static int clone_endio(struct bio *bio, unsigned int done, int error)
+{
+	struct dm_target_io *tio = bio->bi_private;
+	struct mapped_device *md = tio->io->md;
+	int r = dm_endio(bio, done, error, tio);
 	/*
 	 * Store md for cleanup instead of tio which is about to get freed.
 	 */
 	bio->bi_private = md->bs;
-
 	bio_put(bio);
 	free_tio(md, tio);
 	return r;
 }
 
+static int dm_endio_pop(struct bio *bio, unsigned int done, int error)
+{
+	return dm_endio(bio, done, error, bio_pop(bio));
+}
+
 static sector_t max_io_len(struct mapped_device *md,
 			   sector_t sector, struct dm_target *ti)
 {
@@ -553,8 +562,7 @@ static sector_t max_io_len(struct mapped_device *md,
 	return len;
 }
 
-static void __map_bio(struct dm_target *ti, struct bio *clone,
-		      struct dm_target_io *tio)
+static void __map_bio(struct dm_target *ti, struct bio *clone, struct dm_target_io *tio)
 {
 	int r;
 	sector_t sector;
@@ -600,6 +608,37 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
 	}
 }
 
+static void dm_map(struct bio *bio, struct dm_target *ti, struct dm_target_io *tio)
+{
+	int r;
+	sector_t sector;
+
+	/*
+	 * Map the bio.  If r == 0 we don't need to do
+	 * anything, the target has assumed ownership of
+	 * this io.
+	 */
+	atomic_inc(&tio->io->io_count);
+	sector = bio->bi_sector;
+	r = ti->type->map(ti, bio, &tio->info);
+	if (r == DM_MAPIO_REMAPPED) {
+		/* the bio has been remapped so dispatch it */
+
+		blk_add_trace_remap(bdev_get_queue(bio->bi_bdev), bio,
+				    tio->io->bio->bi_bdev->bd_dev,
+				    bio->bi_sector, sector);
+
+		generic_make_request(bio);
+	} else if (r < 0 || r == DM_MAPIO_REQUEUE) {
+		/* error the io and bail out, or requeue it if needed */
+		bio_pop(bio);
+		dec_pending(tio->io, r);
+	} else if (r) {
+		DMWARN("unimplemented target map return value: %d", r);
+		BUG();
+	}
+}
+
 struct clone_info {
 	struct mapped_device *md;
 	struct dm_table *map;
@@ -676,23 +715,18 @@ static int __clone_and_map(struct clone_info *ci)
 
 	max = max_io_len(ci->md, ci->sector, ti);
 
-	/*
-	 * Allocate a target io object.
-	 */
-	tio = alloc_tio(ci->md);
-	tio->io = ci->io;
-	tio->ti = ti;
-	memset(&tio->info, 0, sizeof(tio->info));
-
 	if (ci->sector_count <= max) {
 		/*
 		 * Optimise for the simple case where we can do all of
 		 * the remaining io with a single clone.
 		 */
-		clone = clone_bio(bio, ci->sector, ci->idx,
-				  bio->bi_vcnt - ci->idx, ci->sector_count,
-				  ci->md->bs);
-		__map_bio(ti, clone, tio);
+		tio = bio_push(bio, sizeof(*tio), dm_endio_pop);
+		*tio = (typeof(*tio)){ .io = ci->io, .ti = ti };
+		bio->bi_sector = ci->sector;
+		bio->bi_idx = ci->idx;
+		bio->bi_size = to_bytes(ci->sector_count);
+		bio->bi_flags &= ~(1 << BIO_SEG_VALID);
+		dm_map(bio, ti, tio);
 		ci->sector_count = 0;
 
 	} else if (to_sector(bio->bi_io_vec[ci->idx].bv_len) <= max) {
@@ -704,6 +738,9 @@ static int __clone_and_map(struct clone_info *ci)
 		sector_t remaining = max;
 		sector_t bv_len;
 
+		tio = alloc_tio(ci->md);
+		*tio = (typeof(*tio)){ .io = ci->io, .ti = ti };
+
 		for (i = ci->idx; remaining && (i < bio->bi_vcnt); i++) {
 			bv_len = to_sector(bio->bi_io_vec[i].bv_len);
 
@@ -730,6 +767,9 @@ static int __clone_and_map(struct clone_info *ci)
 		sector_t remaining = to_sector(bv->bv_len);
 		unsigned int offset = 0;
 
+		tio = alloc_tio(ci->md);
+		*tio = (typeof(*tio)){ .io = ci->io, .ti = ti };
+
 		do {
 			if (offset) {
 				ti = dm_table_find_target(ci->map, ci->sector);
-- 
1.5.2.5


  reply	other threads:[~2008-03-14 14:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 10:52 [RFC] Stacking bio support Daniel Phillips
2008-03-11 11:33 ` Ph. Marek
2008-03-11 12:07   ` Daniel Phillips
2008-03-11 12:38     ` Boaz Harrosh
2008-04-10 13:04       ` Daniel Phillips
2008-04-10 13:34         ` Boaz Harrosh
2008-03-14 13:59 ` Alan D. Brunelle
2008-03-14 14:04   ` Alan D. Brunelle [this message]
2008-03-14 19:41     ` [RFC] Stacking bio support - patch 1/4 for 2.6.23.17 (stable) Daniel Phillips
2008-03-14 14:04   ` [RFC] Stacking bio support Alan D. Brunelle
2008-03-14 14:06     ` Alan D. Brunelle
2008-03-14 14:05   ` [RFC] Stacking bio support - patch 3/4 for 2.6.23.17 (stable) Alan D. Brunelle
2008-03-14 14:05   ` [RFC] Stacking bio support - patch 4/4 " Alan D. Brunelle
2008-03-16 21:38   ` [RFC] Stacking bio support Daniel Phillips

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=47DA85E0.2080501@hp.com \
    --to=alan.brunelle@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@phunq.net \
    /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