From: Milan Broz Add sector and remaining counter into dm_crypt_io instead of using local variables. [AGK FIXME: Does io->remaining in process_write() need extra lock here?] Signed-off-by: Herbert Xu Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 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:55.000000000 +0100 +++ linux-2.6.23/drivers/md/dm-crypt.c 2007-10-10 17:20:56.000000000 +0100 @@ -53,6 +53,8 @@ struct dm_crypt_io { atomic_t pending; int error; + unsigned remaining; + sector_t sector; }; struct crypt_config; @@ -614,19 +616,20 @@ static void process_write(struct dm_cryp struct crypt_config *cc = io->target->private; struct bio *base_bio = io->base_bio; struct bio *clone; - unsigned remaining = base_bio->bi_size; - sector_t sector = base_bio->bi_sector - io->target->begin; + + 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, sector, 1); + 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. */ - while (remaining) { - clone = crypt_alloc_buffer(io, remaining); + while (io->remaining) { + clone = crypt_alloc_buffer(io, io->remaining); if (unlikely(!clone)) { crypt_dec_pending(io, -ENOMEM); return; @@ -645,13 +648,13 @@ static void process_write(struct dm_cryp /* crypt_convert should have filled the clone bio */ BUG_ON(io->ctx.idx_out < clone->bi_vcnt); - clone->bi_sector = cc->start + sector; - remaining -= clone->bi_size; - sector += bio_sectors(clone); + clone->bi_sector = cc->start + io->sector; + io->remaining -= clone->bi_size; + io->sector += bio_sectors(clone); /* Grab another reference to the io struct * before we kick off the request */ - if (remaining) + if (io->remaining) atomic_inc(&io->pending); generic_make_request(clone); @@ -660,7 +663,7 @@ static void process_write(struct dm_cryp * may be gone already. */ /* out of memory -> run queues */ - if (remaining) + if (io->remaining) congestion_wait(WRITE, HZ/100); } }