2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
3 * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
4 * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
6 * This file is released under the GPL.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/bio.h>
14 #include <linux/blkdev.h>
15 #include <linux/mempool.h>
16 #include <linux/slab.h>
17 #include <linux/crypto.h>
18 #include <linux/workqueue.h>
19 #include <asm/atomic.h>
20 #include <linux/scatterlist.h>
25 #define DM_MSG_PREFIX "crypt"
26 #define MESG_STR(x) x, sizeof(x)
29 * per bio private data
32 struct dm_target *target;
34 struct bio *first_clone;
35 struct work_struct work;
41 * context holding the current state of a multi-part conversion
43 struct convert_context {
46 unsigned int offset_in;
47 unsigned int offset_out;
56 struct crypt_iv_operations {
57 int (*ctr)(struct crypt_config *cc, struct dm_target *ti,
59 void (*dtr)(struct crypt_config *cc);
60 const char *(*status)(struct crypt_config *cc);
61 int (*generator)(struct crypt_config *cc, u8 *iv, sector_t sector);
65 * Crypt: maps a linear range of a block device
66 * and encrypts / decrypts at the same time.
68 enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID };
74 * pool for per bio private data and
75 * for encryption buffer pages
83 struct crypt_iv_operations *iv_gen_ops;
85 struct crypto_cipher *iv_gen_private;
89 char cipher[CRYPTO_MAX_ALG_NAME];
90 char chainmode[CRYPTO_MAX_ALG_NAME];
91 struct crypto_blkcipher *tfm;
93 unsigned int key_size;
98 #define MIN_POOL_PAGES 32
99 #define MIN_BIO_PAGES 8
101 static kmem_cache_t *_crypt_io_pool;
104 * Different IV generation algorithms:
106 * plain: the initial vector is the 32-bit little-endian version of the sector
107 * number, padded with zeros if neccessary.
109 * essiv: "encrypted sector|salt initial vector", the sector number is
110 * encrypted with the bulk cipher using a salt as key. The salt
111 * should be derived from the bulk cipher's key via hashing.
113 * plumb: unimplemented, see:
114 * http://article.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/454
117 static int crypt_iv_plain_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
119 memset(iv, 0, cc->iv_size);
120 *(u32 *)iv = cpu_to_le32(sector & 0xffffffff);
125 static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
128 struct crypto_cipher *essiv_tfm;
129 struct crypto_hash *hash_tfm;
130 struct hash_desc desc;
131 struct scatterlist sg;
132 unsigned int saltsize;
137 ti->error = "Digest algorithm missing for ESSIV mode";
141 /* Hash the cipher key with the given hash algorithm */
142 hash_tfm = crypto_alloc_hash(opts, 0, CRYPTO_ALG_ASYNC);
143 if (IS_ERR(hash_tfm)) {
144 ti->error = "Error initializing ESSIV hash";
145 return PTR_ERR(hash_tfm);
148 saltsize = crypto_hash_digestsize(hash_tfm);
149 salt = kmalloc(saltsize, GFP_KERNEL);
151 ti->error = "Error kmallocing salt storage in ESSIV";
152 crypto_free_hash(hash_tfm);
156 sg_set_buf(&sg, cc->key, cc->key_size);
158 desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
159 err = crypto_hash_digest(&desc, &sg, cc->key_size, salt);
160 crypto_free_hash(hash_tfm);
163 ti->error = "Error calculating hash in ESSIV";
167 /* Setup the essiv_tfm with the given salt */
168 essiv_tfm = crypto_alloc_cipher(cc->cipher, 0, CRYPTO_ALG_ASYNC);
169 if (IS_ERR(essiv_tfm)) {
170 ti->error = "Error allocating crypto tfm for ESSIV";
172 return PTR_ERR(essiv_tfm);
174 if (crypto_cipher_blocksize(essiv_tfm) !=
175 crypto_blkcipher_ivsize(cc->tfm)) {
176 ti->error = "Block size of ESSIV cipher does "
177 "not match IV size of block cipher";
178 crypto_free_cipher(essiv_tfm);
182 err = crypto_cipher_setkey(essiv_tfm, salt, saltsize);
184 ti->error = "Failed to set key for ESSIV cipher";
185 crypto_free_cipher(essiv_tfm);
191 cc->iv_gen_private = essiv_tfm;
195 static void crypt_iv_essiv_dtr(struct crypt_config *cc)
197 crypto_free_cipher(cc->iv_gen_private);
198 cc->iv_gen_private = NULL;
201 static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
203 memset(iv, 0, cc->iv_size);
204 *(u64 *)iv = cpu_to_le64(sector);
205 crypto_cipher_encrypt_one(cc->iv_gen_private, iv, iv);
209 static struct crypt_iv_operations crypt_iv_plain_ops = {
210 .generator = crypt_iv_plain_gen
213 static struct crypt_iv_operations crypt_iv_essiv_ops = {
214 .ctr = crypt_iv_essiv_ctr,
215 .dtr = crypt_iv_essiv_dtr,
216 .generator = crypt_iv_essiv_gen
221 crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out,
222 struct scatterlist *in, unsigned int length,
223 int write, sector_t sector)
226 struct blkcipher_desc desc = {
229 .flags = CRYPTO_TFM_REQ_MAY_SLEEP,
233 if (cc->iv_gen_ops) {
234 r = cc->iv_gen_ops->generator(cc, iv, sector);
239 r = crypto_blkcipher_encrypt_iv(&desc, out, in, length);
241 r = crypto_blkcipher_decrypt_iv(&desc, out, in, length);
244 r = crypto_blkcipher_encrypt(&desc, out, in, length);
246 r = crypto_blkcipher_decrypt(&desc, out, in, length);
253 crypt_convert_init(struct crypt_config *cc, struct convert_context *ctx,
254 struct bio *bio_out, struct bio *bio_in,
255 sector_t sector, int write)
257 ctx->bio_in = bio_in;
258 ctx->bio_out = bio_out;
261 ctx->idx_in = bio_in ? bio_in->bi_idx : 0;
262 ctx->idx_out = bio_out ? bio_out->bi_idx : 0;
263 ctx->sector = sector + cc->iv_offset;
268 * Encrypt / decrypt data from one bio to another one (can be the same one)
270 static int crypt_convert(struct crypt_config *cc,
271 struct convert_context *ctx)
275 while(ctx->idx_in < ctx->bio_in->bi_vcnt &&
276 ctx->idx_out < ctx->bio_out->bi_vcnt) {
277 struct bio_vec *bv_in = bio_iovec_idx(ctx->bio_in, ctx->idx_in);
278 struct bio_vec *bv_out = bio_iovec_idx(ctx->bio_out, ctx->idx_out);
279 struct scatterlist sg_in = {
280 .page = bv_in->bv_page,
281 .offset = bv_in->bv_offset + ctx->offset_in,
282 .length = 1 << SECTOR_SHIFT
284 struct scatterlist sg_out = {
285 .page = bv_out->bv_page,
286 .offset = bv_out->bv_offset + ctx->offset_out,
287 .length = 1 << SECTOR_SHIFT
290 ctx->offset_in += sg_in.length;
291 if (ctx->offset_in >= bv_in->bv_len) {
296 ctx->offset_out += sg_out.length;
297 if (ctx->offset_out >= bv_out->bv_len) {
302 r = crypt_convert_scatterlist(cc, &sg_out, &sg_in, sg_in.length,
303 ctx->write, ctx->sector);
314 * Generate a new unfragmented bio with the given size
315 * This should never violate the device limitations
316 * May return a smaller bio when running out of pages
319 crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
320 struct bio *base_bio, unsigned int *bio_vec_idx)
323 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
324 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
328 * Use __GFP_NOMEMALLOC to tell the VM to act less aggressively and
329 * to fail earlier. This is not necessary but increases throughput.
330 * FIXME: Is this really intelligent?
333 clone = bio_clone(base_bio, GFP_NOIO|__GFP_NOMEMALLOC);
335 clone = bio_alloc(GFP_NOIO|__GFP_NOMEMALLOC, nr_iovecs);
339 /* if the last bio was not complete, continue where that one ended */
340 clone->bi_idx = *bio_vec_idx;
341 clone->bi_vcnt = *bio_vec_idx;
343 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
345 /* clone->bi_idx pages have already been allocated */
346 size -= clone->bi_idx * PAGE_SIZE;
348 for (i = clone->bi_idx; i < nr_iovecs; i++) {
349 struct bio_vec *bv = bio_iovec_idx(clone, i);
351 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask);
356 * if additional pages cannot be allocated without waiting,
357 * return a partially allocated bio, the caller will then try
358 * to allocate additional bios while submitting this partial bio
360 if ((i - clone->bi_idx) == (MIN_BIO_PAGES - 1))
361 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT;
364 if (size > PAGE_SIZE)
365 bv->bv_len = PAGE_SIZE;
369 clone->bi_size += bv->bv_len;
374 if (!clone->bi_size) {
380 * Remember the last bio_vec allocated to be able
381 * to correctly continue after the splitting.
383 *bio_vec_idx = clone->bi_vcnt;
388 static void crypt_free_buffer_pages(struct crypt_config *cc,
389 struct bio *clone, unsigned int bytes)
391 unsigned int i, start, end;
395 * This is ugly, but Jens Axboe thinks that using bi_idx in the
396 * endio function is too dangerous at the moment, so I calculate the
397 * correct position using bi_vcnt and bi_size.
398 * The bv_offset and bv_len fields might already be modified but we
399 * know that we always allocated whole pages.
400 * A fix to the bi_idx issue in the kernel is in the works, so
401 * we will hopefully be able to revert to the cleaner solution soon.
403 i = clone->bi_vcnt - 1;
404 bv = bio_iovec_idx(clone, i);
405 end = (i << PAGE_SHIFT) + (bv->bv_offset + bv->bv_len) - clone->bi_size;
408 start >>= PAGE_SHIFT;
410 end = clone->bi_vcnt;
414 for (i = start; i < end; i++) {
415 bv = bio_iovec_idx(clone, i);
416 BUG_ON(!bv->bv_page);
417 mempool_free(bv->bv_page, cc->page_pool);
423 * One of the bios was finished. Check for completion of
424 * the whole request and correctly clean up the buffer.
426 static void dec_pending(struct crypt_io *io, int error)
428 struct crypt_config *cc = (struct crypt_config *) io->target->private;
433 if (!atomic_dec_and_test(&io->pending))
437 bio_put(io->first_clone);
439 bio_endio(io->base_bio, io->base_bio->bi_size, io->error);
441 mempool_free(io, cc->io_pool);
447 * Needed because it would be very unwise to do decryption in an
448 * interrupt context, so bios returning from read requests get
451 static struct workqueue_struct *_kcryptd_workqueue;
452 static void kcryptd_do_work(void *data);
454 static void kcryptd_queue_io(struct crypt_io *io)
456 INIT_WORK(&io->work, kcryptd_do_work, io);
457 queue_work(_kcryptd_workqueue, &io->work);
460 static int crypt_endio(struct bio *clone, unsigned int done, int error)
462 struct crypt_io *io = clone->bi_private;
463 struct crypt_config *cc = io->target->private;
464 unsigned read_io = bio_data_dir(clone) == READ;
467 * free the processed pages, even if
468 * it's only a partially completed write
471 crypt_free_buffer_pages(cc, clone, done);
473 if (unlikely(clone->bi_size))
477 * successful reads are decrypted by the worker thread
482 if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) {
488 kcryptd_queue_io(io);
493 dec_pending(io, error);
497 static void clone_init(struct crypt_io *io, struct bio *clone)
499 struct crypt_config *cc = io->target->private;
501 clone->bi_private = io;
502 clone->bi_end_io = crypt_endio;
503 clone->bi_bdev = cc->dev->bdev;
504 clone->bi_rw = io->base_bio->bi_rw;
507 static struct bio *clone_read(struct crypt_io *io,
510 struct crypt_config *cc = io->target->private;
511 struct bio *base_bio = io->base_bio;
515 * The block layer might modify the bvec array, so always
516 * copy the required bvecs because we need the original
517 * one in order to decrypt the whole bio data *afterwards*.
519 clone = bio_alloc(GFP_NOIO, bio_segments(base_bio));
520 if (unlikely(!clone))
523 clone_init(io, clone);
525 clone->bi_vcnt = bio_segments(base_bio);
526 clone->bi_size = base_bio->bi_size;
527 memcpy(clone->bi_io_vec, bio_iovec(base_bio),
528 sizeof(struct bio_vec) * clone->bi_vcnt);
529 clone->bi_sector = cc->start + sector;
534 static struct bio *clone_write(struct crypt_io *io,
537 struct convert_context *ctx)
539 struct crypt_config *cc = io->target->private;
540 struct bio *base_bio = io->base_bio;
543 clone = crypt_alloc_buffer(cc, base_bio->bi_size,
544 io->first_clone, bvec_idx);
548 ctx->bio_out = clone;
550 if (unlikely(crypt_convert(cc, ctx) < 0)) {
551 crypt_free_buffer_pages(cc, clone,
557 clone_init(io, clone);
558 clone->bi_sector = cc->start + sector;
563 static void process_read_endio(struct crypt_io *io)
565 struct crypt_config *cc = io->target->private;
566 struct convert_context ctx;
568 crypt_convert_init(cc, &ctx, io->base_bio, io->base_bio,
569 io->base_bio->bi_sector - io->target->begin, 0);
571 dec_pending(io, crypt_convert(cc, &ctx));
574 static void kcryptd_do_work(void *data)
576 struct crypt_io *io = data;
578 process_read_endio(io);
582 * Decode key from its hex representation
584 static int crypt_decode_key(u8 *key, char *hex, unsigned int size)
592 for (i = 0; i < size; i++) {
596 key[i] = (u8)simple_strtoul(buffer, &endp, 16);
598 if (endp != &buffer[2])
609 * Encode key into its hex representation
611 static void crypt_encode_key(char *hex, u8 *key, unsigned int size)
615 for (i = 0; i < size; i++) {
616 sprintf(hex, "%02x", *key);
622 static int crypt_set_key(struct crypt_config *cc, char *key)
624 unsigned key_size = strlen(key) >> 1;
626 if (cc->key_size && cc->key_size != key_size)
629 cc->key_size = key_size; /* initial settings */
631 if ((!key_size && strcmp(key, "-")) ||
632 (key_size && crypt_decode_key(cc->key, key, key_size) < 0))
635 set_bit(DM_CRYPT_KEY_VALID, &cc->flags);
640 static int crypt_wipe_key(struct crypt_config *cc)
642 clear_bit(DM_CRYPT_KEY_VALID, &cc->flags);
643 memset(&cc->key, 0, cc->key_size * sizeof(u8));
648 * Construct an encryption mapping:
649 * <cipher> <key> <iv_offset> <dev_path> <start>
651 static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
653 struct crypt_config *cc;
654 struct crypto_blkcipher *tfm;
660 unsigned int key_size;
661 unsigned long long tmpll;
664 ti->error = "Not enough arguments";
669 cipher = strsep(&tmp, "-");
670 chainmode = strsep(&tmp, "-");
671 ivopts = strsep(&tmp, "-");
672 ivmode = strsep(&ivopts, ":");
675 DMWARN("Unexpected additional cipher options");
677 key_size = strlen(argv[1]) >> 1;
679 cc = kzalloc(sizeof(*cc) + key_size * sizeof(u8), GFP_KERNEL);
682 "Cannot allocate transparent encryption context";
686 if (crypt_set_key(cc, argv[1])) {
687 ti->error = "Error decoding key";
691 /* Compatiblity mode for old dm-crypt cipher strings */
692 if (!chainmode || (strcmp(chainmode, "plain") == 0 && !ivmode)) {
697 if (strcmp(chainmode, "ecb") && !ivmode) {
698 ti->error = "This chaining mode requires an IV mechanism";
702 if (snprintf(cc->cipher, CRYPTO_MAX_ALG_NAME, "%s(%s)", chainmode,
703 cipher) >= CRYPTO_MAX_ALG_NAME) {
704 ti->error = "Chain mode + cipher name is too long";
708 tfm = crypto_alloc_blkcipher(cc->cipher, 0, CRYPTO_ALG_ASYNC);
710 ti->error = "Error allocating crypto tfm";
714 strcpy(cc->cipher, cipher);
715 strcpy(cc->chainmode, chainmode);
719 * Choose ivmode. Valid modes: "plain", "essiv:<esshash>".
720 * See comments at iv code
724 cc->iv_gen_ops = NULL;
725 else if (strcmp(ivmode, "plain") == 0)
726 cc->iv_gen_ops = &crypt_iv_plain_ops;
727 else if (strcmp(ivmode, "essiv") == 0)
728 cc->iv_gen_ops = &crypt_iv_essiv_ops;
730 ti->error = "Invalid IV mode";
734 if (cc->iv_gen_ops && cc->iv_gen_ops->ctr &&
735 cc->iv_gen_ops->ctr(cc, ti, ivopts) < 0)
738 cc->iv_size = crypto_blkcipher_ivsize(tfm);
740 /* at least a 64 bit sector number should fit in our buffer */
741 cc->iv_size = max(cc->iv_size,
742 (unsigned int)(sizeof(u64) / sizeof(u8)));
744 if (cc->iv_gen_ops) {
745 DMWARN("Selected cipher does not support IVs");
746 if (cc->iv_gen_ops->dtr)
747 cc->iv_gen_ops->dtr(cc);
748 cc->iv_gen_ops = NULL;
752 cc->io_pool = mempool_create_slab_pool(MIN_IOS, _crypt_io_pool);
754 ti->error = "Cannot allocate crypt io mempool";
758 cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
759 if (!cc->page_pool) {
760 ti->error = "Cannot allocate page mempool";
764 if (crypto_blkcipher_setkey(tfm, cc->key, key_size) < 0) {
765 ti->error = "Error setting key";
769 if (sscanf(argv[2], "%llu", &tmpll) != 1) {
770 ti->error = "Invalid iv_offset sector";
773 cc->iv_offset = tmpll;
775 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
776 ti->error = "Invalid device sector";
781 if (dm_get_device(ti, argv[3], cc->start, ti->len,
782 dm_table_get_mode(ti->table), &cc->dev)) {
783 ti->error = "Device lookup failed";
787 if (ivmode && cc->iv_gen_ops) {
790 cc->iv_mode = kmalloc(strlen(ivmode) + 1, GFP_KERNEL);
792 ti->error = "Error kmallocing iv_mode string";
795 strcpy(cc->iv_mode, ivmode);
803 mempool_destroy(cc->page_pool);
805 mempool_destroy(cc->io_pool);
807 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
808 cc->iv_gen_ops->dtr(cc);
810 crypto_free_blkcipher(tfm);
812 /* Must zero key material before freeing */
813 memset(cc, 0, sizeof(*cc) + cc->key_size * sizeof(u8));
818 static void crypt_dtr(struct dm_target *ti)
820 struct crypt_config *cc = (struct crypt_config *) ti->private;
822 mempool_destroy(cc->page_pool);
823 mempool_destroy(cc->io_pool);
826 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
827 cc->iv_gen_ops->dtr(cc);
828 crypto_free_blkcipher(cc->tfm);
829 dm_put_device(ti, cc->dev);
831 /* Must zero key material before freeing */
832 memset(cc, 0, sizeof(*cc) + cc->key_size * sizeof(u8));
836 static int crypt_map(struct dm_target *ti, struct bio *bio,
837 union map_info *map_context)
839 struct crypt_config *cc = ti->private;
841 struct convert_context ctx;
843 unsigned int remaining = bio->bi_size;
844 sector_t sector = bio->bi_sector - ti->begin;
845 unsigned int bvec_idx = 0;
847 io = mempool_alloc(cc->io_pool, GFP_NOIO);
850 io->first_clone = NULL;
852 atomic_set(&io->pending, 1); /* hold a reference */
854 if (bio_data_dir(bio) == WRITE)
855 crypt_convert_init(cc, &ctx, NULL, bio, sector, 1);
858 * The allocated buffers can be smaller than the whole bio,
859 * so repeat the whole process until all the data can be handled.
862 if (bio_data_dir(bio) == WRITE)
863 clone = clone_write(io, sector, &bvec_idx, &ctx);
865 clone = clone_read(io, sector);
869 if (!io->first_clone) {
871 * hold a reference to the first clone, because it
872 * holds the bio_vec array and that can't be freed
873 * before all other clones are released
876 io->first_clone = clone;
878 atomic_inc(&io->pending);
880 remaining -= clone->bi_size;
881 sector += bio_sectors(clone);
883 generic_make_request(clone);
885 /* out of memory -> run queues */
887 blk_congestion_wait(bio_data_dir(clone), HZ/100);
890 /* drop reference, clones could have returned before we reach this */
895 if (io->first_clone) {
896 dec_pending(io, -ENOMEM);
900 /* if no bio has been dispatched yet, we can directly return the error */
901 mempool_free(io, cc->io_pool);
905 static int crypt_status(struct dm_target *ti, status_type_t type,
906 char *result, unsigned int maxlen)
908 struct crypt_config *cc = (struct crypt_config *) ti->private;
910 const char *chainmode = NULL;
914 case STATUSTYPE_INFO:
918 case STATUSTYPE_TABLE:
919 cipher = crypto_blkcipher_name(cc->tfm);
921 chainmode = cc->chainmode;
924 DMEMIT("%s-%s-%s ", cipher, chainmode, cc->iv_mode);
926 DMEMIT("%s-%s ", cipher, chainmode);
928 if (cc->key_size > 0) {
929 if ((maxlen - sz) < ((cc->key_size << 1) + 1))
932 crypt_encode_key(result + sz, cc->key, cc->key_size);
933 sz += cc->key_size << 1;
940 DMEMIT(" %llu %s %llu", (unsigned long long)cc->iv_offset,
941 cc->dev->name, (unsigned long long)cc->start);
947 static void crypt_postsuspend(struct dm_target *ti)
949 struct crypt_config *cc = ti->private;
951 set_bit(DM_CRYPT_SUSPENDED, &cc->flags);
954 static int crypt_preresume(struct dm_target *ti)
956 struct crypt_config *cc = ti->private;
958 if (!test_bit(DM_CRYPT_KEY_VALID, &cc->flags)) {
959 DMERR("aborting resume - crypt key is not set.");
966 static void crypt_resume(struct dm_target *ti)
968 struct crypt_config *cc = ti->private;
970 clear_bit(DM_CRYPT_SUSPENDED, &cc->flags);
977 static int crypt_message(struct dm_target *ti, unsigned argc, char **argv)
979 struct crypt_config *cc = ti->private;
984 if (!strnicmp(argv[0], MESG_STR("key"))) {
985 if (!test_bit(DM_CRYPT_SUSPENDED, &cc->flags)) {
986 DMWARN("not suspended during key manipulation.");
989 if (argc == 3 && !strnicmp(argv[1], MESG_STR("set")))
990 return crypt_set_key(cc, argv[2]);
991 if (argc == 2 && !strnicmp(argv[1], MESG_STR("wipe")))
992 return crypt_wipe_key(cc);
996 DMWARN("unrecognised message received.");
1000 static struct target_type crypt_target = {
1002 .version= {1, 2, 0},
1003 .module = THIS_MODULE,
1007 .status = crypt_status,
1008 .postsuspend = crypt_postsuspend,
1009 .preresume = crypt_preresume,
1010 .resume = crypt_resume,
1011 .message = crypt_message,
1014 static int __init dm_crypt_init(void)
1018 _crypt_io_pool = kmem_cache_create("dm-crypt_io",
1019 sizeof(struct crypt_io),
1021 if (!_crypt_io_pool)
1024 _kcryptd_workqueue = create_workqueue("kcryptd");
1025 if (!_kcryptd_workqueue) {
1027 DMERR("couldn't create kcryptd");
1031 r = dm_register_target(&crypt_target);
1033 DMERR("register failed %d", r);
1040 destroy_workqueue(_kcryptd_workqueue);
1042 kmem_cache_destroy(_crypt_io_pool);
1046 static void __exit dm_crypt_exit(void)
1048 int r = dm_unregister_target(&crypt_target);
1051 DMERR("unregister failed %d", r);
1053 destroy_workqueue(_kcryptd_workqueue);
1054 kmem_cache_destroy(_crypt_io_pool);
1057 module_init(dm_crypt_init);
1058 module_exit(dm_crypt_exit);
1060 MODULE_AUTHOR("Christophe Saout <christophe@saout.de>");
1061 MODULE_DESCRIPTION(DM_NAME " target for transparent encryption / decryption");
1062 MODULE_LICENSE("GPL");