aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index aeb63a3ac330..b5764a86c8b5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -102,6 +102,8 @@ struct mapped_device {
102 mempool_t *io_pool; 102 mempool_t *io_pool;
103 mempool_t *tio_pool; 103 mempool_t *tio_pool;
104 104
105 struct bio_set *bs;
106
105 /* 107 /*
106 * Event handling. 108 * Event handling.
107 */ 109 */
@@ -122,16 +124,10 @@ struct mapped_device {
122static kmem_cache_t *_io_cache; 124static kmem_cache_t *_io_cache;
123static kmem_cache_t *_tio_cache; 125static kmem_cache_t *_tio_cache;
124 126
125static struct bio_set *dm_set;
126
127static int __init local_init(void) 127static int __init local_init(void)
128{ 128{
129 int r; 129 int r;
130 130
131 dm_set = bioset_create(16, 16, 4);
132 if (!dm_set)
133 return -ENOMEM;
134
135 /* allocate a slab for the dm_ios */ 131 /* allocate a slab for the dm_ios */
136 _io_cache = kmem_cache_create("dm_io", 132 _io_cache = kmem_cache_create("dm_io",
137 sizeof(struct dm_io), 0, 0, NULL, NULL); 133 sizeof(struct dm_io), 0, 0, NULL, NULL);
@@ -165,8 +161,6 @@ static void local_exit(void)
165 kmem_cache_destroy(_tio_cache); 161 kmem_cache_destroy(_tio_cache);
166 kmem_cache_destroy(_io_cache); 162 kmem_cache_destroy(_io_cache);
167 163
168 bioset_free(dm_set);
169
170 if (unregister_blkdev(_major, _name) < 0) 164 if (unregister_blkdev(_major, _name) < 0)
171 DMERR("unregister_blkdev failed"); 165 DMERR("unregister_blkdev failed");
172 166
@@ -475,7 +469,7 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
475{ 469{
476 int r = 0; 470 int r = 0;
477 struct target_io *tio = bio->bi_private; 471 struct target_io *tio = bio->bi_private;
478 struct dm_io *io = tio->io; 472 struct mapped_device *md = tio->io->md;
479 dm_endio_fn endio = tio->ti->type->end_io; 473 dm_endio_fn endio = tio->ti->type->end_io;
480 474
481 if (bio->bi_size) 475 if (bio->bi_size)
@@ -494,9 +488,15 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
494 return 1; 488 return 1;
495 } 489 }
496 490
497 free_tio(io->md, tio); 491 dec_pending(tio->io, error);
498 dec_pending(io, error); 492
493 /*
494 * Store md for cleanup instead of tio which is about to get freed.
495 */
496 bio->bi_private = md->bs;
497
499 bio_put(bio); 498 bio_put(bio);
499 free_tio(md, tio);
500 return r; 500 return r;
501} 501}
502 502
@@ -525,6 +525,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
525{ 525{
526 int r; 526 int r;
527 sector_t sector; 527 sector_t sector;
528 struct mapped_device *md;
528 529
529 /* 530 /*
530 * Sanity checks. 531 * Sanity checks.
@@ -554,10 +555,14 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
554 555
555 else if (r < 0) { 556 else if (r < 0) {
556 /* error the io and bail out */ 557 /* error the io and bail out */
557 struct dm_io *io = tio->io; 558 md = tio->io->md;
558 free_tio(tio->io->md, tio); 559 dec_pending(tio->io, r);
559 dec_pending(io, r); 560 /*
561 * Store bio_set for cleanup.
562 */
563 clone->bi_private = md->bs;
560 bio_put(clone); 564 bio_put(clone);
565 free_tio(md, tio);
561 } 566 }
562} 567}
563 568
@@ -573,7 +578,9 @@ struct clone_info {
573 578
574static void dm_bio_destructor(struct bio *bio) 579static void dm_bio_destructor(struct bio *bio)
575{ 580{
576 bio_free(bio, dm_set); 581 struct bio_set *bs = bio->bi_private;
582
583 bio_free(bio, bs);
577} 584}
578 585
579/* 586/*
@@ -581,12 +588,12 @@ static void dm_bio_destructor(struct bio *bio)
581 */ 588 */
582static struct bio *split_bvec(struct bio *bio, sector_t sector, 589static struct bio *split_bvec(struct bio *bio, sector_t sector,
583 unsigned short idx, unsigned int offset, 590 unsigned short idx, unsigned int offset,
584 unsigned int len) 591 unsigned int len, struct bio_set *bs)
585{ 592{
586 struct bio *clone; 593 struct bio *clone;
587 struct bio_vec *bv = bio->bi_io_vec + idx; 594 struct bio_vec *bv = bio->bi_io_vec + idx;
588 595
589 clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set); 596 clone = bio_alloc_bioset(GFP_NOIO, 1, bs);
590 clone->bi_destructor = dm_bio_destructor; 597 clone->bi_destructor = dm_bio_destructor;
591 *clone->bi_io_vec = *bv; 598 *clone->bi_io_vec = *bv;
592 599
@@ -606,11 +613,13 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
606 */ 613 */
607static struct bio *clone_bio(struct bio *bio, sector_t sector, 614static struct bio *clone_bio(struct bio *bio, sector_t sector,
608 unsigned short idx, unsigned short bv_count, 615 unsigned short idx, unsigned short bv_count,
609 unsigned int len) 616 unsigned int len, struct bio_set *bs)
610{ 617{
611 struct bio *clone; 618 struct bio *clone;
612 619
613 clone = bio_clone(bio, GFP_NOIO); 620 clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs);
621 __bio_clone(clone, bio);
622 clone->bi_destructor = dm_bio_destructor;
614 clone->bi_sector = sector; 623 clone->bi_sector = sector;
615 clone->bi_idx = idx; 624 clone->bi_idx = idx;
616 clone->bi_vcnt = idx + bv_count; 625 clone->bi_vcnt = idx + bv_count;
@@ -641,7 +650,8 @@ static void __clone_and_map(struct clone_info *ci)
641 * the remaining io with a single clone. 650 * the remaining io with a single clone.
642 */ 651 */
643 clone = clone_bio(bio, ci->sector, ci->idx, 652 clone = clone_bio(bio, ci->sector, ci->idx,
644 bio->bi_vcnt - ci->idx, ci->sector_count); 653 bio->bi_vcnt - ci->idx, ci->sector_count,
654 ci->md->bs);
645 __map_bio(ti, clone, tio); 655 __map_bio(ti, clone, tio);
646 ci->sector_count = 0; 656 ci->sector_count = 0;
647 657
@@ -664,7 +674,8 @@ static void __clone_and_map(struct clone_info *ci)
664 len += bv_len; 674 len += bv_len;
665 } 675 }
666 676
667 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len); 677 clone = clone_bio(bio, ci->sector, ci->idx, i - ci->idx, len,
678 ci->md->bs);
668 __map_bio(ti, clone, tio); 679 __map_bio(ti, clone, tio);
669 680
670 ci->sector += len; 681 ci->sector += len;
@@ -693,7 +704,8 @@ static void __clone_and_map(struct clone_info *ci)
693 len = min(remaining, max); 704 len = min(remaining, max);
694 705
695 clone = split_bvec(bio, ci->sector, ci->idx, 706 clone = split_bvec(bio, ci->sector, ci->idx,
696 bv->bv_offset + offset, len); 707 bv->bv_offset + offset, len,
708 ci->md->bs);
697 709
698 __map_bio(ti, clone, tio); 710 __map_bio(ti, clone, tio);
699 711
@@ -961,6 +973,10 @@ static struct mapped_device *alloc_dev(int minor)
961 if (!md->tio_pool) 973 if (!md->tio_pool)
962 goto bad3; 974 goto bad3;
963 975
976 md->bs = bioset_create(16, 16, 4);
977 if (!md->bs)
978 goto bad_no_bioset;
979
964 md->disk = alloc_disk(1); 980 md->disk = alloc_disk(1);
965 if (!md->disk) 981 if (!md->disk)
966 goto bad4; 982 goto bad4;
@@ -988,6 +1004,8 @@ static struct mapped_device *alloc_dev(int minor)
988 return md; 1004 return md;
989 1005
990 bad4: 1006 bad4:
1007 bioset_free(md->bs);
1008 bad_no_bioset:
991 mempool_destroy(md->tio_pool); 1009 mempool_destroy(md->tio_pool);
992 bad3: 1010 bad3:
993 mempool_destroy(md->io_pool); 1011 mempool_destroy(md->io_pool);
@@ -1012,6 +1030,7 @@ static void free_dev(struct mapped_device *md)
1012 } 1030 }
1013 mempool_destroy(md->tio_pool); 1031 mempool_destroy(md->tio_pool);
1014 mempool_destroy(md->io_pool); 1032 mempool_destroy(md->io_pool);
1033 bioset_free(md->bs);
1015 del_gendisk(md->disk); 1034 del_gendisk(md->disk);
1016 free_minor(minor); 1035 free_minor(minor);
1017 1036