diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-10 20:04:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-10 20:04:23 -0400 |
commit | ce40be7a820bb393ac4ac69865f018d2f4038cf0 (patch) | |
tree | b1fe5a93346eb06f22b1c303d63ec5456d7212ab /drivers/md/dm.c | |
parent | ba0a5a36f60e4c1152af3a2ae2813251974405bf (diff) | |
parent | 02f3939e1a9357b7c370a4a69717cf9c02452737 (diff) |
Merge branch 'for-3.7/core' of git://git.kernel.dk/linux-block
Pull block IO update from Jens Axboe:
"Core block IO bits for 3.7. Not a huge round this time, it contains:
- First series from Kent cleaning up and generalizing bio allocation
and freeing.
- WRITE_SAME support from Martin.
- Mikulas patches to prevent O_DIRECT crashes when someone changes
the block size of a device.
- Make bio_split() work on data-less bio's (like trim/discards).
- A few other minor fixups."
Fixed up silent semantic mis-merge as per Mikulas Patocka and Andrew
Morton. It is due to the VM no longer using a prio-tree (see commit
6b2dbba8b6ac: "mm: replace vma prio_tree with an interval tree").
So make set_blocksize() use mapping_mapped() instead of open-coding the
internal VM knowledge that has changed.
* 'for-3.7/core' of git://git.kernel.dk/linux-block: (26 commits)
block: makes bio_split support bio without data
scatterlist: refactor the sg_nents
scatterlist: add sg_nents
fs: fix include/percpu-rwsem.h export error
percpu-rw-semaphore: fix documentation typos
fs/block_dev.c:1644:5: sparse: symbol 'blkdev_mmap' was not declared
blockdev: turn a rw semaphore into a percpu rw semaphore
Fix a crash when block device is read and block size is changed at the same time
block: fix request_queue->flags initialization
block: lift the initial queue bypass mode on blk_register_queue() instead of blk_init_allocated_queue()
block: ioctl to zero block ranges
block: Make blkdev_issue_zeroout use WRITE SAME
block: Implement support for WRITE SAME
block: Consolidate command flag and queue limit checks for merges
block: Clean up special command handling logic
block/blk-tag.c: Remove useless kfree
block: remove the duplicated setting for congestion_threshold
block: reject invalid queue attribute values
block: Add bio_clone_bioset(), bio_clone_kmalloc()
block: Consolidate bio_alloc_bioset(), bio_kmalloc()
...
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r-- | drivers/md/dm.c | 74 |
1 files changed, 22 insertions, 52 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 67ffa391edcf..66ceaff6455c 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -86,12 +86,17 @@ struct dm_rq_target_io { | |||
86 | }; | 86 | }; |
87 | 87 | ||
88 | /* | 88 | /* |
89 | * For request-based dm. | 89 | * For request-based dm - the bio clones we allocate are embedded in these |
90 | * One of these is allocated per bio. | 90 | * structs. |
91 | * | ||
92 | * We allocate these with bio_alloc_bioset, using the front_pad parameter when | ||
93 | * the bioset is created - this means the bio has to come at the end of the | ||
94 | * struct. | ||
91 | */ | 95 | */ |
92 | struct dm_rq_clone_bio_info { | 96 | struct dm_rq_clone_bio_info { |
93 | struct bio *orig; | 97 | struct bio *orig; |
94 | struct dm_rq_target_io *tio; | 98 | struct dm_rq_target_io *tio; |
99 | struct bio clone; | ||
95 | }; | 100 | }; |
96 | 101 | ||
97 | union map_info *dm_get_mapinfo(struct bio *bio) | 102 | union map_info *dm_get_mapinfo(struct bio *bio) |
@@ -211,6 +216,11 @@ struct dm_md_mempools { | |||
211 | static struct kmem_cache *_io_cache; | 216 | static struct kmem_cache *_io_cache; |
212 | static struct kmem_cache *_tio_cache; | 217 | static struct kmem_cache *_tio_cache; |
213 | static struct kmem_cache *_rq_tio_cache; | 218 | static struct kmem_cache *_rq_tio_cache; |
219 | |||
220 | /* | ||
221 | * Unused now, and needs to be deleted. But since io_pool is overloaded and it's | ||
222 | * still used for _io_cache, I'm leaving this for a later cleanup | ||
223 | */ | ||
214 | static struct kmem_cache *_rq_bio_info_cache; | 224 | static struct kmem_cache *_rq_bio_info_cache; |
215 | 225 | ||
216 | static int __init local_init(void) | 226 | static int __init local_init(void) |
@@ -467,16 +477,6 @@ static void free_rq_tio(struct dm_rq_target_io *tio) | |||
467 | mempool_free(tio, tio->md->tio_pool); | 477 | mempool_free(tio, tio->md->tio_pool); |
468 | } | 478 | } |
469 | 479 | ||
470 | static struct dm_rq_clone_bio_info *alloc_bio_info(struct mapped_device *md) | ||
471 | { | ||
472 | return mempool_alloc(md->io_pool, GFP_ATOMIC); | ||
473 | } | ||
474 | |||
475 | static void free_bio_info(struct dm_rq_clone_bio_info *info) | ||
476 | { | ||
477 | mempool_free(info, info->tio->md->io_pool); | ||
478 | } | ||
479 | |||
480 | static int md_in_flight(struct mapped_device *md) | 480 | static int md_in_flight(struct mapped_device *md) |
481 | { | 481 | { |
482 | return atomic_read(&md->pending[READ]) + | 482 | return atomic_read(&md->pending[READ]) + |
@@ -681,11 +681,6 @@ static void clone_endio(struct bio *bio, int error) | |||
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | /* | ||
685 | * Store md for cleanup instead of tio which is about to get freed. | ||
686 | */ | ||
687 | bio->bi_private = md->bs; | ||
688 | |||
689 | free_tio(md, tio); | 684 | free_tio(md, tio); |
690 | bio_put(bio); | 685 | bio_put(bio); |
691 | dec_pending(io, error); | 686 | dec_pending(io, error); |
@@ -1036,11 +1031,6 @@ static void __map_bio(struct dm_target *ti, struct bio *clone, | |||
1036 | /* error the io and bail out, or requeue it if needed */ | 1031 | /* error the io and bail out, or requeue it if needed */ |
1037 | md = tio->io->md; | 1032 | md = tio->io->md; |
1038 | dec_pending(tio->io, r); | 1033 | dec_pending(tio->io, r); |
1039 | /* | ||
1040 | * Store bio_set for cleanup. | ||
1041 | */ | ||
1042 | clone->bi_end_io = NULL; | ||
1043 | clone->bi_private = md->bs; | ||
1044 | bio_put(clone); | 1034 | bio_put(clone); |
1045 | free_tio(md, tio); | 1035 | free_tio(md, tio); |
1046 | } else if (r) { | 1036 | } else if (r) { |
@@ -1059,13 +1049,6 @@ struct clone_info { | |||
1059 | unsigned short idx; | 1049 | unsigned short idx; |
1060 | }; | 1050 | }; |
1061 | 1051 | ||
1062 | static void dm_bio_destructor(struct bio *bio) | ||
1063 | { | ||
1064 | struct bio_set *bs = bio->bi_private; | ||
1065 | |||
1066 | bio_free(bio, bs); | ||
1067 | } | ||
1068 | |||
1069 | /* | 1052 | /* |
1070 | * Creates a little bio that just does part of a bvec. | 1053 | * Creates a little bio that just does part of a bvec. |
1071 | */ | 1054 | */ |
@@ -1077,7 +1060,6 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector, | |||
1077 | struct bio_vec *bv = bio->bi_io_vec + idx; | 1060 | struct bio_vec *bv = bio->bi_io_vec + idx; |
1078 | 1061 | ||
1079 | clone = bio_alloc_bioset(GFP_NOIO, 1, bs); | 1062 | clone = bio_alloc_bioset(GFP_NOIO, 1, bs); |
1080 | clone->bi_destructor = dm_bio_destructor; | ||
1081 | *clone->bi_io_vec = *bv; | 1063 | *clone->bi_io_vec = *bv; |
1082 | 1064 | ||
1083 | clone->bi_sector = sector; | 1065 | clone->bi_sector = sector; |
@@ -1090,7 +1072,7 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector, | |||
1090 | clone->bi_flags |= 1 << BIO_CLONED; | 1072 | clone->bi_flags |= 1 << BIO_CLONED; |
1091 | 1073 | ||
1092 | if (bio_integrity(bio)) { | 1074 | if (bio_integrity(bio)) { |
1093 | bio_integrity_clone(clone, bio, GFP_NOIO, bs); | 1075 | bio_integrity_clone(clone, bio, GFP_NOIO); |
1094 | bio_integrity_trim(clone, | 1076 | bio_integrity_trim(clone, |
1095 | bio_sector_offset(bio, idx, offset), len); | 1077 | bio_sector_offset(bio, idx, offset), len); |
1096 | } | 1078 | } |
@@ -1109,7 +1091,6 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector, | |||
1109 | 1091 | ||
1110 | clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs); | 1092 | clone = bio_alloc_bioset(GFP_NOIO, bio->bi_max_vecs, bs); |
1111 | __bio_clone(clone, bio); | 1093 | __bio_clone(clone, bio); |
1112 | clone->bi_destructor = dm_bio_destructor; | ||
1113 | clone->bi_sector = sector; | 1094 | clone->bi_sector = sector; |
1114 | clone->bi_idx = idx; | 1095 | clone->bi_idx = idx; |
1115 | clone->bi_vcnt = idx + bv_count; | 1096 | clone->bi_vcnt = idx + bv_count; |
@@ -1117,7 +1098,7 @@ static struct bio *clone_bio(struct bio *bio, sector_t sector, | |||
1117 | clone->bi_flags &= ~(1 << BIO_SEG_VALID); | 1098 | clone->bi_flags &= ~(1 << BIO_SEG_VALID); |
1118 | 1099 | ||
1119 | if (bio_integrity(bio)) { | 1100 | if (bio_integrity(bio)) { |
1120 | bio_integrity_clone(clone, bio, GFP_NOIO, bs); | 1101 | bio_integrity_clone(clone, bio, GFP_NOIO); |
1121 | 1102 | ||
1122 | if (idx != bio->bi_idx || clone->bi_size < bio->bi_size) | 1103 | if (idx != bio->bi_idx || clone->bi_size < bio->bi_size) |
1123 | bio_integrity_trim(clone, | 1104 | bio_integrity_trim(clone, |
@@ -1152,9 +1133,8 @@ static void __issue_target_request(struct clone_info *ci, struct dm_target *ti, | |||
1152 | * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush | 1133 | * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush |
1153 | * and discard, so no need for concern about wasted bvec allocations. | 1134 | * and discard, so no need for concern about wasted bvec allocations. |
1154 | */ | 1135 | */ |
1155 | clone = bio_alloc_bioset(GFP_NOIO, ci->bio->bi_max_vecs, ci->md->bs); | 1136 | clone = bio_clone_bioset(ci->bio, GFP_NOIO, ci->md->bs); |
1156 | __bio_clone(clone, ci->bio); | 1137 | |
1157 | clone->bi_destructor = dm_bio_destructor; | ||
1158 | if (len) { | 1138 | if (len) { |
1159 | clone->bi_sector = ci->sector; | 1139 | clone->bi_sector = ci->sector; |
1160 | clone->bi_size = to_bytes(len); | 1140 | clone->bi_size = to_bytes(len); |
@@ -1484,30 +1464,17 @@ void dm_dispatch_request(struct request *rq) | |||
1484 | } | 1464 | } |
1485 | EXPORT_SYMBOL_GPL(dm_dispatch_request); | 1465 | EXPORT_SYMBOL_GPL(dm_dispatch_request); |
1486 | 1466 | ||
1487 | static void dm_rq_bio_destructor(struct bio *bio) | ||
1488 | { | ||
1489 | struct dm_rq_clone_bio_info *info = bio->bi_private; | ||
1490 | struct mapped_device *md = info->tio->md; | ||
1491 | |||
1492 | free_bio_info(info); | ||
1493 | bio_free(bio, md->bs); | ||
1494 | } | ||
1495 | |||
1496 | static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig, | 1467 | static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig, |
1497 | void *data) | 1468 | void *data) |
1498 | { | 1469 | { |
1499 | struct dm_rq_target_io *tio = data; | 1470 | struct dm_rq_target_io *tio = data; |
1500 | struct mapped_device *md = tio->md; | 1471 | struct dm_rq_clone_bio_info *info = |
1501 | struct dm_rq_clone_bio_info *info = alloc_bio_info(md); | 1472 | container_of(bio, struct dm_rq_clone_bio_info, clone); |
1502 | |||
1503 | if (!info) | ||
1504 | return -ENOMEM; | ||
1505 | 1473 | ||
1506 | info->orig = bio_orig; | 1474 | info->orig = bio_orig; |
1507 | info->tio = tio; | 1475 | info->tio = tio; |
1508 | bio->bi_end_io = end_clone_bio; | 1476 | bio->bi_end_io = end_clone_bio; |
1509 | bio->bi_private = info; | 1477 | bio->bi_private = info; |
1510 | bio->bi_destructor = dm_rq_bio_destructor; | ||
1511 | 1478 | ||
1512 | return 0; | 1479 | return 0; |
1513 | } | 1480 | } |
@@ -2771,7 +2738,10 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity) | |||
2771 | if (!pools->tio_pool) | 2738 | if (!pools->tio_pool) |
2772 | goto free_io_pool_and_out; | 2739 | goto free_io_pool_and_out; |
2773 | 2740 | ||
2774 | pools->bs = bioset_create(pool_size, 0); | 2741 | pools->bs = (type == DM_TYPE_BIO_BASED) ? |
2742 | bioset_create(pool_size, 0) : | ||
2743 | bioset_create(pool_size, | ||
2744 | offsetof(struct dm_rq_clone_bio_info, clone)); | ||
2775 | if (!pools->bs) | 2745 | if (!pools->bs) |
2776 | goto free_tio_pool_and_out; | 2746 | goto free_tio_pool_and_out; |
2777 | 2747 | ||