From: Milan Broz <[email-masked]>

Process write request in separate function.

Signed-off-by: Herbert Xu <[email-masked]>
Signed-off-by: Milan Broz <[email-masked]>
---
 drivers/md/dm-crypt.c |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

Index: linux-2.6.23/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.23.orig/drivers/md/dm-crypt.c	2007-10-10 17:20:56.000000000 +0100
+++ linux-2.6.23/drivers/md/dm-crypt.c	2007-10-10 17:20:57.000000000 +0100
@@ -611,28 +611,22 @@ static void process_read(struct dm_crypt
 	generic_make_request(clone);
 }
 
-static void process_write(struct dm_crypt_io *io)
+static void crypt_write_loop(struct dm_crypt_io *io)
 {
 	struct crypt_config *cc = io->target->private;
-	struct bio *base_bio = io->base_bio;
 	struct bio *clone;
 
-	io->remaining = base_bio->bi_size;
-	io->sector = base_bio->bi_sector - io->target->begin;
-
-	atomic_inc(&io->pending);
-
-	crypt_convert_init(cc, &io->ctx, NULL, base_bio, io->sector, 1);
-
 	/*
 	 * The allocated buffers can be smaller than the whole bio,
 	 * so repeat the whole process until all the data can be handled.
 	 */
+	atomic_inc(&io->pending);
+
 	while (io->remaining) {
 		clone = crypt_alloc_buffer(io, io->remaining);
 		if (unlikely(!clone)) {
 			crypt_dec_pending(io, -ENOMEM);
-			return;
+			break;
 		}
 
 		io->ctx.bio_out = clone;
@@ -642,7 +636,7 @@ static void process_write(struct dm_cryp
 			crypt_free_buffer_pages(cc, clone, clone->bi_size);
 			bio_put(clone);
 			crypt_dec_pending(io, -EIO);
-			return;
+			break;
 		}
 
 		/* crypt_convert should have filled the clone bio */
@@ -666,6 +660,22 @@ static void process_write(struct dm_cryp
 		if (io->remaining)
 			congestion_wait(WRITE, HZ/100);
 	}
+
+	crypt_dec_pending(io, 0);
+}
+
+static void process_write(struct dm_crypt_io *io)
+{
+	struct crypt_config *cc = io->target->private;
+	struct bio *base_bio = io->base_bio;
+
+	io->remaining = base_bio->bi_size;
+	io->sector = base_bio->bi_sector - io->target->begin;
+
+	atomic_inc(&io->pending);
+
+	crypt_convert_init(cc, &io->ctx, NULL, base_bio, io->sector, 1);
+	crypt_write_loop(io);
 }
 
 static void process_read_endio(struct dm_crypt_io *io)