aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-10 20:04:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-10 20:04:23 -0400
commitce40be7a820bb393ac4ac69865f018d2f4038cf0 (patch)
treeb1fe5a93346eb06f22b1c303d63ec5456d7212ab /drivers/md
parentba0a5a36f60e4c1152af3a2ae2813251974405bf (diff)
parent02f3939e1a9357b7c370a4a69717cf9c02452737 (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')
-rw-r--r--drivers/md/dm-crypt.c16
-rw-r--r--drivers/md/dm-io.c11
-rw-r--r--drivers/md/dm.c74
-rw-r--r--drivers/md/md.c44
-rw-r--r--drivers/md/raid0.c1
5 files changed, 27 insertions, 119 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 664743d6a6cd..bbf459bca61d 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -798,14 +798,6 @@ static int crypt_convert(struct crypt_config *cc,
798 return 0; 798 return 0;
799} 799}
800 800
801static void dm_crypt_bio_destructor(struct bio *bio)
802{
803 struct dm_crypt_io *io = bio->bi_private;
804 struct crypt_config *cc = io->cc;
805
806 bio_free(bio, cc->bs);
807}
808
809/* 801/*
810 * Generate a new unfragmented bio with the given size 802 * Generate a new unfragmented bio with the given size
811 * This should never violate the device limitations 803 * This should never violate the device limitations
@@ -974,7 +966,6 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone)
974 clone->bi_end_io = crypt_endio; 966 clone->bi_end_io = crypt_endio;
975 clone->bi_bdev = cc->dev->bdev; 967 clone->bi_bdev = cc->dev->bdev;
976 clone->bi_rw = io->base_bio->bi_rw; 968 clone->bi_rw = io->base_bio->bi_rw;
977 clone->bi_destructor = dm_crypt_bio_destructor;
978} 969}
979 970
980static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp) 971static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
@@ -988,19 +979,14 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
988 * copy the required bvecs because we need the original 979 * copy the required bvecs because we need the original
989 * one in order to decrypt the whole bio data *afterwards*. 980 * one in order to decrypt the whole bio data *afterwards*.
990 */ 981 */
991 clone = bio_alloc_bioset(gfp, bio_segments(base_bio), cc->bs); 982 clone = bio_clone_bioset(base_bio, gfp, cc->bs);
992 if (!clone) 983 if (!clone)
993 return 1; 984 return 1;
994 985
995 crypt_inc_pending(io); 986 crypt_inc_pending(io);
996 987
997 clone_init(io, clone); 988 clone_init(io, clone);
998 clone->bi_idx = 0;
999 clone->bi_vcnt = bio_segments(base_bio);
1000 clone->bi_size = base_bio->bi_size;
1001 clone->bi_sector = cc->start + io->sector; 989 clone->bi_sector = cc->start + io->sector;
1002 memcpy(clone->bi_io_vec, bio_iovec(base_bio),
1003 sizeof(struct bio_vec) * clone->bi_vcnt);
1004 990
1005 generic_make_request(clone); 991 generic_make_request(clone);
1006 return 0; 992 return 0;
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index ea5dd289fe2a..1c46f97d6664 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -249,16 +249,6 @@ static void vm_dp_init(struct dpages *dp, void *data)
249 dp->context_ptr = data; 249 dp->context_ptr = data;
250} 250}
251 251
252static void dm_bio_destructor(struct bio *bio)
253{
254 unsigned region;
255 struct io *io;
256
257 retrieve_io_and_region_from_bio(bio, &io, &region);
258
259 bio_free(bio, io->client->bios);
260}
261
262/* 252/*
263 * Functions for getting the pages from kernel memory. 253 * Functions for getting the pages from kernel memory.
264 */ 254 */
@@ -317,7 +307,6 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
317 bio->bi_sector = where->sector + (where->count - remaining); 307 bio->bi_sector = where->sector + (where->count - remaining);
318 bio->bi_bdev = where->bdev; 308 bio->bi_bdev = where->bdev;
319 bio->bi_end_io = endio; 309 bio->bi_end_io = endio;
320 bio->bi_destructor = dm_bio_destructor;
321 store_io_and_region_in_bio(bio, io, region); 310 store_io_and_region_in_bio(bio, io, region);
322 311
323 if (rw & REQ_DISCARD) { 312 if (rw & REQ_DISCARD) {
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 */
92struct dm_rq_clone_bio_info { 96struct 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
97union map_info *dm_get_mapinfo(struct bio *bio) 102union map_info *dm_get_mapinfo(struct bio *bio)
@@ -211,6 +216,11 @@ struct dm_md_mempools {
211static struct kmem_cache *_io_cache; 216static struct kmem_cache *_io_cache;
212static struct kmem_cache *_tio_cache; 217static struct kmem_cache *_tio_cache;
213static struct kmem_cache *_rq_tio_cache; 218static 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 */
214static struct kmem_cache *_rq_bio_info_cache; 224static struct kmem_cache *_rq_bio_info_cache;
215 225
216static int __init local_init(void) 226static 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
470static 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
475static void free_bio_info(struct dm_rq_clone_bio_info *info)
476{
477 mempool_free(info, info->tio->md->io_pool);
478}
479
480static int md_in_flight(struct mapped_device *md) 480static 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
1062static 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}
1485EXPORT_SYMBOL_GPL(dm_dispatch_request); 1465EXPORT_SYMBOL_GPL(dm_dispatch_request);
1486 1466
1487static 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
1496static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig, 1467static 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
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 308e87b417e0..95c88012a3b9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -155,32 +155,17 @@ static int start_readonly;
155 * like bio_clone, but with a local bio set 155 * like bio_clone, but with a local bio set
156 */ 156 */
157 157
158static void mddev_bio_destructor(struct bio *bio)
159{
160 struct mddev *mddev, **mddevp;
161
162 mddevp = (void*)bio;
163 mddev = mddevp[-1];
164
165 bio_free(bio, mddev->bio_set);
166}
167
168struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, 158struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs,
169 struct mddev *mddev) 159 struct mddev *mddev)
170{ 160{
171 struct bio *b; 161 struct bio *b;
172 struct mddev **mddevp;
173 162
174 if (!mddev || !mddev->bio_set) 163 if (!mddev || !mddev->bio_set)
175 return bio_alloc(gfp_mask, nr_iovecs); 164 return bio_alloc(gfp_mask, nr_iovecs);
176 165
177 b = bio_alloc_bioset(gfp_mask, nr_iovecs, 166 b = bio_alloc_bioset(gfp_mask, nr_iovecs, mddev->bio_set);
178 mddev->bio_set);
179 if (!b) 167 if (!b)
180 return NULL; 168 return NULL;
181 mddevp = (void*)b;
182 mddevp[-1] = mddev;
183 b->bi_destructor = mddev_bio_destructor;
184 return b; 169 return b;
185} 170}
186EXPORT_SYMBOL_GPL(bio_alloc_mddev); 171EXPORT_SYMBOL_GPL(bio_alloc_mddev);
@@ -188,32 +173,10 @@ EXPORT_SYMBOL_GPL(bio_alloc_mddev);
188struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask, 173struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask,
189 struct mddev *mddev) 174 struct mddev *mddev)
190{ 175{
191 struct bio *b;
192 struct mddev **mddevp;
193
194 if (!mddev || !mddev->bio_set) 176 if (!mddev || !mddev->bio_set)
195 return bio_clone(bio, gfp_mask); 177 return bio_clone(bio, gfp_mask);
196 178
197 b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, 179 return bio_clone_bioset(bio, gfp_mask, mddev->bio_set);
198 mddev->bio_set);
199 if (!b)
200 return NULL;
201 mddevp = (void*)b;
202 mddevp[-1] = mddev;
203 b->bi_destructor = mddev_bio_destructor;
204 __bio_clone(b, bio);
205 if (bio_integrity(bio)) {
206 int ret;
207
208 ret = bio_integrity_clone(b, bio, gfp_mask, mddev->bio_set);
209
210 if (ret < 0) {
211 bio_put(b);
212 return NULL;
213 }
214 }
215
216 return b;
217} 180}
218EXPORT_SYMBOL_GPL(bio_clone_mddev); 181EXPORT_SYMBOL_GPL(bio_clone_mddev);
219 182
@@ -5006,8 +4969,7 @@ int md_run(struct mddev *mddev)
5006 } 4969 }
5007 4970
5008 if (mddev->bio_set == NULL) 4971 if (mddev->bio_set == NULL)
5009 mddev->bio_set = bioset_create(BIO_POOL_SIZE, 4972 mddev->bio_set = bioset_create(BIO_POOL_SIZE, 0);
5010 sizeof(struct mddev *));
5011 4973
5012 spin_lock(&pers_lock); 4974 spin_lock(&pers_lock);
5013 pers = find_pers(mddev->level, mddev->clevel); 4975 pers = find_pers(mddev->level, mddev->clevel);
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index de63a1fc3737..a9e4fa95dfaa 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -422,6 +422,7 @@ static int raid0_run(struct mddev *mddev)
422 if (md_check_no_bitmap(mddev)) 422 if (md_check_no_bitmap(mddev))
423 return -EINVAL; 423 return -EINVAL;
424 blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors); 424 blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
425 blk_queue_max_write_same_sectors(mddev->queue, mddev->chunk_sectors);
425 426
426 /* if private is not null, we are here after takeover */ 427 /* if private is not null, we are here after takeover */
427 if (mddev->private == NULL) { 428 if (mddev->private == NULL) {