From: Milan Broz dm-crypt: Use crypto ablkcipher interface Prepare callback function for async crypto operation. Signed-off-by: Herbert Xu Signed-off-by: Milan Broz --- drivers/md/dm-crypt.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+) Index: linux-2.6.24-rc3/drivers/md/dm-crypt.c =================================================================== --- linux-2.6.24-rc3.orig/drivers/md/dm-crypt.c 2007-12-07 02:53:10.000000000 +0000 +++ linux-2.6.24-rc3/drivers/md/dm-crypt.c 2007-12-07 02:53:14.000000000 +0000 @@ -318,6 +318,28 @@ static struct crypt_iv_operations crypt_ .generator = crypt_iv_null_gen }; +static void crypt_async_done(struct crypto_async_request *async_req, int error) +{ + struct convert_context *ctx = async_req->data; + struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx); + struct crypt_config *cc = io->target->private; + + if (error == -EINPROGRESS) { + complete(&ctx->restart); + return; + } + + mempool_free(ablkcipher_request_cast(async_req), cc->req_pool); + + if (!atomic_dec_and_test(&ctx->pending)) + return; + + if (bio_data_dir(io->base_bio) == READ) + crypt_read_io_done(io, error); + else + crypt_write_io_done(io, error); +} + static int crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out, struct scatterlist *in, unsigned int length, @@ -404,6 +426,10 @@ static void crypt_alloc_req(struct crypt { if (!cc->req) cc->req = mempool_alloc(cc->req_pool, GFP_NOIO); + ablkcipher_request_set_tfm(cc->req, cc->tfm); + ablkcipher_request_set_callback(cc->req, CRYPTO_TFM_REQ_MAY_BACKLOG | + CRYPTO_TFM_REQ_MAY_SLEEP, + crypt_async_done, ctx); } /*