diff options
-rw-r--r-- | drivers/md/dm-crypt.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 986283c5332f..44e1aa30e3f6 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -584,7 +584,6 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int error) | |||
584 | crypt_free_buffer_pages(cc, clone); | 584 | crypt_free_buffer_pages(cc, clone); |
585 | bio_put(clone); | 585 | bio_put(clone); |
586 | io->error = -EIO; | 586 | io->error = -EIO; |
587 | crypt_dec_pending(io); | ||
588 | return; | 587 | return; |
589 | } | 588 | } |
590 | 589 | ||
@@ -593,6 +592,9 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int error) | |||
593 | 592 | ||
594 | clone->bi_sector = cc->start + io->sector; | 593 | clone->bi_sector = cc->start + io->sector; |
595 | io->sector += bio_sectors(clone); | 594 | io->sector += bio_sectors(clone); |
595 | |||
596 | atomic_inc(&io->pending); | ||
597 | generic_make_request(clone); | ||
596 | } | 598 | } |
597 | 599 | ||
598 | static void kcryptd_crypt_write_convert_loop(struct dm_crypt_io *io) | 600 | static void kcryptd_crypt_write_convert_loop(struct dm_crypt_io *io) |
@@ -610,7 +612,6 @@ static void kcryptd_crypt_write_convert_loop(struct dm_crypt_io *io) | |||
610 | clone = crypt_alloc_buffer(io, remaining); | 612 | clone = crypt_alloc_buffer(io, remaining); |
611 | if (unlikely(!clone)) { | 613 | if (unlikely(!clone)) { |
612 | io->error = -ENOMEM; | 614 | io->error = -ENOMEM; |
613 | crypt_dec_pending(io); | ||
614 | return; | 615 | return; |
615 | } | 616 | } |
616 | 617 | ||
@@ -625,16 +626,6 @@ static void kcryptd_crypt_write_convert_loop(struct dm_crypt_io *io) | |||
625 | if (unlikely(r < 0)) | 626 | if (unlikely(r < 0)) |
626 | return; | 627 | return; |
627 | 628 | ||
628 | /* Grab another reference to the io struct | ||
629 | * before we kick off the request */ | ||
630 | if (remaining) | ||
631 | atomic_inc(&io->pending); | ||
632 | |||
633 | generic_make_request(clone); | ||
634 | |||
635 | /* Do not reference clone after this - it | ||
636 | * may be gone already. */ | ||
637 | |||
638 | /* out of memory -> run queues */ | 629 | /* out of memory -> run queues */ |
639 | if (unlikely(remaining)) | 630 | if (unlikely(remaining)) |
640 | congestion_wait(WRITE, HZ/100); | 631 | congestion_wait(WRITE, HZ/100); |
@@ -645,10 +636,15 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io) | |||
645 | { | 636 | { |
646 | struct crypt_config *cc = io->target->private; | 637 | struct crypt_config *cc = io->target->private; |
647 | 638 | ||
639 | /* | ||
640 | * Prevent io from disappearing until this function completes. | ||
641 | */ | ||
648 | atomic_inc(&io->pending); | 642 | atomic_inc(&io->pending); |
649 | 643 | ||
650 | crypt_convert_init(cc, &io->ctx, NULL, io->base_bio, io->sector); | 644 | crypt_convert_init(cc, &io->ctx, NULL, io->base_bio, io->sector); |
651 | kcryptd_crypt_write_convert_loop(io); | 645 | kcryptd_crypt_write_convert_loop(io); |
646 | |||
647 | crypt_dec_pending(io); | ||
652 | } | 648 | } |
653 | 649 | ||
654 | static void kcryptd_crypt_read_done(struct dm_crypt_io *io, int error) | 650 | static void kcryptd_crypt_read_done(struct dm_crypt_io *io, int error) |