From: Milan Broz dm-crypt: Use crypto ablkcipher interface Prepare completion for async crypto request. Signed-off-by: Herbert Xu Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 12 ++++++++++++ 1 files changed, 12 insertions(+) Index: linux-2.6.24-rc5/drivers/md/dm-crypt.c =================================================================== --- linux-2.6.24-rc5.orig/drivers/md/dm-crypt.c 2007-12-12 15:44:06.000000000 +0000 +++ linux-2.6.24-rc5/drivers/md/dm-crypt.c 2007-12-12 15:44:07.000000000 +0000 @@ -6,6 +6,7 @@ * This file is released under the GPL. */ +#include #include #include #include @@ -31,6 +32,7 @@ * context holding the current state of a multi-part conversion */ struct convert_context { + struct completion restart; struct bio *bio_in; struct bio *bio_out; unsigned int offset_in; @@ -38,6 +40,7 @@ struct convert_context { unsigned int idx_in; unsigned int idx_out; sector_t sector; + atomic_t pending; }; /* @@ -359,6 +362,8 @@ static void crypt_convert_init(struct cr ctx->idx_in = bio_in ? bio_in->bi_idx : 0; ctx->idx_out = bio_out ? bio_out->bi_idx : 0; ctx->sector = sector + cc->iv_offset; + init_completion(&ctx->restart); + atomic_set(&ctx->pending, 2); } static int crypt_convert_block(struct crypt_config *cc, @@ -418,6 +423,13 @@ static int crypt_convert(struct crypt_co ctx->sector++; } + /* + * If there is pending crypto operation run async + * code. Otherwise process return code synchronously. + */ + if (atomic_sub_return(2, &ctx->pending)) + return -EINPROGRESS; + return r; }