diff options
-rw-r--r-- | drivers/md/dm-crypt.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 862ce9f6faac..cc189a2bc533 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -456,18 +456,14 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone) | |||
456 | * One of the bios was finished. Check for completion of | 456 | * One of the bios was finished. Check for completion of |
457 | * the whole request and correctly clean up the buffer. | 457 | * the whole request and correctly clean up the buffer. |
458 | */ | 458 | */ |
459 | static void crypt_dec_pending(struct dm_crypt_io *io, int error) | 459 | static void crypt_dec_pending(struct dm_crypt_io *io) |
460 | { | 460 | { |
461 | struct crypt_config *cc = (struct crypt_config *) io->target->private; | 461 | struct crypt_config *cc = io->target->private; |
462 | |||
463 | if (error < 0) | ||
464 | io->error = error; | ||
465 | 462 | ||
466 | if (!atomic_dec_and_test(&io->pending)) | 463 | if (!atomic_dec_and_test(&io->pending)) |
467 | return; | 464 | return; |
468 | 465 | ||
469 | bio_endio(io->base_bio, io->error); | 466 | bio_endio(io->base_bio, io->error); |
470 | |||
471 | mempool_free(io, cc->io_pool); | 467 | mempool_free(io, cc->io_pool); |
472 | } | 468 | } |
473 | 469 | ||
@@ -530,7 +526,11 @@ static void crypt_endio(struct bio *clone, int error) | |||
530 | 526 | ||
531 | out: | 527 | out: |
532 | bio_put(clone); | 528 | bio_put(clone); |
533 | crypt_dec_pending(io, error); | 529 | |
530 | if (unlikely(error)) | ||
531 | io->error = error; | ||
532 | |||
533 | crypt_dec_pending(io); | ||
534 | } | 534 | } |
535 | 535 | ||
536 | static void clone_init(struct dm_crypt_io *io, struct bio *clone) | 536 | static void clone_init(struct dm_crypt_io *io, struct bio *clone) |
@@ -560,7 +560,8 @@ static void process_read(struct dm_crypt_io *io) | |||
560 | */ | 560 | */ |
561 | clone = bio_alloc_bioset(GFP_NOIO, bio_segments(base_bio), cc->bs); | 561 | clone = bio_alloc_bioset(GFP_NOIO, bio_segments(base_bio), cc->bs); |
562 | if (unlikely(!clone)) { | 562 | if (unlikely(!clone)) { |
563 | crypt_dec_pending(io, -ENOMEM); | 563 | io->error = -ENOMEM; |
564 | crypt_dec_pending(io); | ||
564 | return; | 565 | return; |
565 | } | 566 | } |
566 | 567 | ||
@@ -594,7 +595,8 @@ static void process_write(struct dm_crypt_io *io) | |||
594 | while (remaining) { | 595 | while (remaining) { |
595 | clone = crypt_alloc_buffer(io, remaining); | 596 | clone = crypt_alloc_buffer(io, remaining); |
596 | if (unlikely(!clone)) { | 597 | if (unlikely(!clone)) { |
597 | crypt_dec_pending(io, -ENOMEM); | 598 | io->error = -ENOMEM; |
599 | crypt_dec_pending(io); | ||
598 | return; | 600 | return; |
599 | } | 601 | } |
600 | 602 | ||
@@ -604,7 +606,8 @@ static void process_write(struct dm_crypt_io *io) | |||
604 | if (unlikely(crypt_convert(cc, &io->ctx) < 0)) { | 606 | if (unlikely(crypt_convert(cc, &io->ctx) < 0)) { |
605 | crypt_free_buffer_pages(cc, clone); | 607 | crypt_free_buffer_pages(cc, clone); |
606 | bio_put(clone); | 608 | bio_put(clone); |
607 | crypt_dec_pending(io, -EIO); | 609 | io->error = -EIO; |
610 | crypt_dec_pending(io); | ||
608 | return; | 611 | return; |
609 | } | 612 | } |
610 | 613 | ||
@@ -631,14 +634,25 @@ static void process_write(struct dm_crypt_io *io) | |||
631 | } | 634 | } |
632 | } | 635 | } |
633 | 636 | ||
637 | static void crypt_read_done(struct dm_crypt_io *io, int error) | ||
638 | { | ||
639 | if (unlikely(error < 0)) | ||
640 | io->error = -EIO; | ||
641 | |||
642 | crypt_dec_pending(io); | ||
643 | } | ||
644 | |||
634 | static void process_read_endio(struct dm_crypt_io *io) | 645 | static void process_read_endio(struct dm_crypt_io *io) |
635 | { | 646 | { |
636 | struct crypt_config *cc = io->target->private; | 647 | struct crypt_config *cc = io->target->private; |
648 | int r = 0; | ||
637 | 649 | ||
638 | crypt_convert_init(cc, &io->ctx, io->base_bio, io->base_bio, | 650 | crypt_convert_init(cc, &io->ctx, io->base_bio, io->base_bio, |
639 | io->base_bio->bi_sector - io->target->begin); | 651 | io->base_bio->bi_sector - io->target->begin); |
640 | 652 | ||
641 | crypt_dec_pending(io, crypt_convert(cc, &io->ctx)); | 653 | r = crypt_convert(cc, &io->ctx); |
654 | |||
655 | crypt_read_done(io, r); | ||
642 | } | 656 | } |
643 | 657 | ||
644 | static void kcryptd_do_work(struct work_struct *work) | 658 | static void kcryptd_do_work(struct work_struct *work) |