From: Milan Broz <mbroz@redhat.com>

Tidy dm_io and target_io allocation functions.

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 drivers/md/dm.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

Index: current-quilt/drivers/md/dm.c
===================================================================
--- current-quilt.orig/drivers/md/dm.c	2007-07-25 21:04:53.000000000 +0100
+++ current-quilt/drivers/md/dm.c	2007-07-25 21:04:54.000000000 +0100
@@ -327,9 +327,15 @@ out:
 	return r;
 }
 
-static struct dm_io *alloc_io(struct mapped_device *md)
+static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
 {
-	return mempool_alloc(md->io_pool, GFP_NOIO);
+	struct dm_io *io = mempool_alloc(md->io_pool, GFP_NOIO);
+
+	io->md = md;
+	io->bio = bio;
+	io->error = 0;
+
+	return io;
 }
 
 static void free_io(struct mapped_device *md, struct dm_io *io)
@@ -337,9 +343,16 @@ static void free_io(struct mapped_device
 	mempool_free(io, md->io_pool);
 }
 
-static struct dm_target_io *alloc_tio(struct mapped_device *md)
+static struct dm_target_io *alloc_tio(struct mapped_device *md, struct dm_io *io,
+				   struct dm_table *map)
 {
-	return mempool_alloc(md->tio_pool, GFP_NOIO);
+	struct dm_target_io *tio = mempool_alloc(md->tio_pool, GFP_NOIO);
+
+	tio->io = io;
+	tio->ti = dm_table_find_target(map, io->bio->bi_sector);
+	memset(&tio->info, 0, sizeof(tio->info));
+
+	return tio;
 }
 
 static void free_tio(struct mapped_device *md, struct dm_target_io *tio)
@@ -767,17 +780,10 @@ static int __split_bio(struct mapped_dev
 	if (unlikely(!map))
 		return -EIO;
 
-	io = alloc_io(md);
-	io->error = 0;
-	atomic_set(&io->io_count, 1);
-	io->bio = bio;
-	io->md = md;
-
-	tio = alloc_tio(md);
-	tio->io = io;
-	tio->ti = dm_table_find_target(map, bio->bi_sector);
-	memset(&tio->info, 0, sizeof(tio->info));
+	io = alloc_io(md, bio);
+	tio = alloc_tio(md, io, map);
 
+	atomic_set(&io->io_count, 1);
 	start_io_acct(io);
 	__clone_and_map(bio, io, tio);