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 /fs | |
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 'fs')
-rw-r--r-- | fs/bio-integrity.c | 44 | ||||
-rw-r--r-- | fs/bio.c | 231 | ||||
-rw-r--r-- | fs/block_dev.c | 68 | ||||
-rw-r--r-- | fs/exofs/ore.c | 5 |
4 files changed, 188 insertions, 160 deletions
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c index e85c04b9f61c..a3f28f331b2b 100644 --- a/fs/bio-integrity.c +++ b/fs/bio-integrity.c | |||
@@ -70,23 +70,25 @@ static inline int use_bip_pool(unsigned int idx) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio | 73 | * bio_integrity_alloc - Allocate integrity payload and attach it to bio |
74 | * @bio: bio to attach integrity metadata to | 74 | * @bio: bio to attach integrity metadata to |
75 | * @gfp_mask: Memory allocation mask | 75 | * @gfp_mask: Memory allocation mask |
76 | * @nr_vecs: Number of integrity metadata scatter-gather elements | 76 | * @nr_vecs: Number of integrity metadata scatter-gather elements |
77 | * @bs: bio_set to allocate from | ||
78 | * | 77 | * |
79 | * Description: This function prepares a bio for attaching integrity | 78 | * Description: This function prepares a bio for attaching integrity |
80 | * metadata. nr_vecs specifies the maximum number of pages containing | 79 | * metadata. nr_vecs specifies the maximum number of pages containing |
81 | * integrity metadata that can be attached. | 80 | * integrity metadata that can be attached. |
82 | */ | 81 | */ |
83 | struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | 82 | struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, |
84 | gfp_t gfp_mask, | 83 | gfp_t gfp_mask, |
85 | unsigned int nr_vecs, | 84 | unsigned int nr_vecs) |
86 | struct bio_set *bs) | ||
87 | { | 85 | { |
88 | struct bio_integrity_payload *bip; | 86 | struct bio_integrity_payload *bip; |
89 | unsigned int idx = vecs_to_idx(nr_vecs); | 87 | unsigned int idx = vecs_to_idx(nr_vecs); |
88 | struct bio_set *bs = bio->bi_pool; | ||
89 | |||
90 | if (!bs) | ||
91 | bs = fs_bio_set; | ||
90 | 92 | ||
91 | BUG_ON(bio == NULL); | 93 | BUG_ON(bio == NULL); |
92 | bip = NULL; | 94 | bip = NULL; |
@@ -114,37 +116,22 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, | |||
114 | 116 | ||
115 | return bip; | 117 | return bip; |
116 | } | 118 | } |
117 | EXPORT_SYMBOL(bio_integrity_alloc_bioset); | ||
118 | |||
119 | /** | ||
120 | * bio_integrity_alloc - Allocate integrity payload and attach it to bio | ||
121 | * @bio: bio to attach integrity metadata to | ||
122 | * @gfp_mask: Memory allocation mask | ||
123 | * @nr_vecs: Number of integrity metadata scatter-gather elements | ||
124 | * | ||
125 | * Description: This function prepares a bio for attaching integrity | ||
126 | * metadata. nr_vecs specifies the maximum number of pages containing | ||
127 | * integrity metadata that can be attached. | ||
128 | */ | ||
129 | struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, | ||
130 | gfp_t gfp_mask, | ||
131 | unsigned int nr_vecs) | ||
132 | { | ||
133 | return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set); | ||
134 | } | ||
135 | EXPORT_SYMBOL(bio_integrity_alloc); | 119 | EXPORT_SYMBOL(bio_integrity_alloc); |
136 | 120 | ||
137 | /** | 121 | /** |
138 | * bio_integrity_free - Free bio integrity payload | 122 | * bio_integrity_free - Free bio integrity payload |
139 | * @bio: bio containing bip to be freed | 123 | * @bio: bio containing bip to be freed |
140 | * @bs: bio_set this bio was allocated from | ||
141 | * | 124 | * |
142 | * Description: Used to free the integrity portion of a bio. Usually | 125 | * Description: Used to free the integrity portion of a bio. Usually |
143 | * called from bio_free(). | 126 | * called from bio_free(). |
144 | */ | 127 | */ |
145 | void bio_integrity_free(struct bio *bio, struct bio_set *bs) | 128 | void bio_integrity_free(struct bio *bio) |
146 | { | 129 | { |
147 | struct bio_integrity_payload *bip = bio->bi_integrity; | 130 | struct bio_integrity_payload *bip = bio->bi_integrity; |
131 | struct bio_set *bs = bio->bi_pool; | ||
132 | |||
133 | if (!bs) | ||
134 | bs = fs_bio_set; | ||
148 | 135 | ||
149 | BUG_ON(bip == NULL); | 136 | BUG_ON(bip == NULL); |
150 | 137 | ||
@@ -730,19 +717,18 @@ EXPORT_SYMBOL(bio_integrity_split); | |||
730 | * @bio: New bio | 717 | * @bio: New bio |
731 | * @bio_src: Original bio | 718 | * @bio_src: Original bio |
732 | * @gfp_mask: Memory allocation mask | 719 | * @gfp_mask: Memory allocation mask |
733 | * @bs: bio_set to allocate bip from | ||
734 | * | 720 | * |
735 | * Description: Called to allocate a bip when cloning a bio | 721 | * Description: Called to allocate a bip when cloning a bio |
736 | */ | 722 | */ |
737 | int bio_integrity_clone(struct bio *bio, struct bio *bio_src, | 723 | int bio_integrity_clone(struct bio *bio, struct bio *bio_src, |
738 | gfp_t gfp_mask, struct bio_set *bs) | 724 | gfp_t gfp_mask) |
739 | { | 725 | { |
740 | struct bio_integrity_payload *bip_src = bio_src->bi_integrity; | 726 | struct bio_integrity_payload *bip_src = bio_src->bi_integrity; |
741 | struct bio_integrity_payload *bip; | 727 | struct bio_integrity_payload *bip; |
742 | 728 | ||
743 | BUG_ON(bip_src == NULL); | 729 | BUG_ON(bip_src == NULL); |
744 | 730 | ||
745 | bip = bio_integrity_alloc_bioset(bio, gfp_mask, bip_src->bip_vcnt, bs); | 731 | bip = bio_integrity_alloc(bio, gfp_mask, bip_src->bip_vcnt); |
746 | 732 | ||
747 | if (bip == NULL) | 733 | if (bip == NULL) |
748 | return -EIO; | 734 | return -EIO; |
@@ -55,6 +55,7 @@ static struct biovec_slab bvec_slabs[BIOVEC_NR_POOLS] __read_mostly = { | |||
55 | * IO code that does not need private memory pools. | 55 | * IO code that does not need private memory pools. |
56 | */ | 56 | */ |
57 | struct bio_set *fs_bio_set; | 57 | struct bio_set *fs_bio_set; |
58 | EXPORT_SYMBOL(fs_bio_set); | ||
58 | 59 | ||
59 | /* | 60 | /* |
60 | * Our slab pool management | 61 | * Our slab pool management |
@@ -233,26 +234,37 @@ fallback: | |||
233 | return bvl; | 234 | return bvl; |
234 | } | 235 | } |
235 | 236 | ||
236 | void bio_free(struct bio *bio, struct bio_set *bs) | 237 | static void __bio_free(struct bio *bio) |
237 | { | 238 | { |
239 | bio_disassociate_task(bio); | ||
240 | |||
241 | if (bio_integrity(bio)) | ||
242 | bio_integrity_free(bio); | ||
243 | } | ||
244 | |||
245 | static void bio_free(struct bio *bio) | ||
246 | { | ||
247 | struct bio_set *bs = bio->bi_pool; | ||
238 | void *p; | 248 | void *p; |
239 | 249 | ||
240 | if (bio_has_allocated_vec(bio)) | 250 | __bio_free(bio); |
241 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
242 | 251 | ||
243 | if (bio_integrity(bio)) | 252 | if (bs) { |
244 | bio_integrity_free(bio, bs); | 253 | if (bio_has_allocated_vec(bio)) |
254 | bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); | ||
245 | 255 | ||
246 | /* | 256 | /* |
247 | * If we have front padding, adjust the bio pointer before freeing | 257 | * If we have front padding, adjust the bio pointer before freeing |
248 | */ | 258 | */ |
249 | p = bio; | 259 | p = bio; |
250 | if (bs->front_pad) | ||
251 | p -= bs->front_pad; | 260 | p -= bs->front_pad; |
252 | 261 | ||
253 | mempool_free(p, bs->bio_pool); | 262 | mempool_free(p, bs->bio_pool); |
263 | } else { | ||
264 | /* Bio was allocated by bio_kmalloc() */ | ||
265 | kfree(bio); | ||
266 | } | ||
254 | } | 267 | } |
255 | EXPORT_SYMBOL(bio_free); | ||
256 | 268 | ||
257 | void bio_init(struct bio *bio) | 269 | void bio_init(struct bio *bio) |
258 | { | 270 | { |
@@ -263,48 +275,85 @@ void bio_init(struct bio *bio) | |||
263 | EXPORT_SYMBOL(bio_init); | 275 | EXPORT_SYMBOL(bio_init); |
264 | 276 | ||
265 | /** | 277 | /** |
278 | * bio_reset - reinitialize a bio | ||
279 | * @bio: bio to reset | ||
280 | * | ||
281 | * Description: | ||
282 | * After calling bio_reset(), @bio will be in the same state as a freshly | ||
283 | * allocated bio returned bio bio_alloc_bioset() - the only fields that are | ||
284 | * preserved are the ones that are initialized by bio_alloc_bioset(). See | ||
285 | * comment in struct bio. | ||
286 | */ | ||
287 | void bio_reset(struct bio *bio) | ||
288 | { | ||
289 | unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS); | ||
290 | |||
291 | __bio_free(bio); | ||
292 | |||
293 | memset(bio, 0, BIO_RESET_BYTES); | ||
294 | bio->bi_flags = flags|(1 << BIO_UPTODATE); | ||
295 | } | ||
296 | EXPORT_SYMBOL(bio_reset); | ||
297 | |||
298 | /** | ||
266 | * bio_alloc_bioset - allocate a bio for I/O | 299 | * bio_alloc_bioset - allocate a bio for I/O |
267 | * @gfp_mask: the GFP_ mask given to the slab allocator | 300 | * @gfp_mask: the GFP_ mask given to the slab allocator |
268 | * @nr_iovecs: number of iovecs to pre-allocate | 301 | * @nr_iovecs: number of iovecs to pre-allocate |
269 | * @bs: the bio_set to allocate from. | 302 | * @bs: the bio_set to allocate from. |
270 | * | 303 | * |
271 | * Description: | 304 | * Description: |
272 | * bio_alloc_bioset will try its own mempool to satisfy the allocation. | 305 | * If @bs is NULL, uses kmalloc() to allocate the bio; else the allocation is |
273 | * If %__GFP_WAIT is set then we will block on the internal pool waiting | 306 | * backed by the @bs's mempool. |
274 | * for a &struct bio to become free. | ||
275 | * | 307 | * |
276 | * Note that the caller must set ->bi_destructor on successful return | 308 | * When @bs is not NULL, if %__GFP_WAIT is set then bio_alloc will always be |
277 | * of a bio, to do the appropriate freeing of the bio once the reference | 309 | * able to allocate a bio. This is due to the mempool guarantees. To make this |
278 | * count drops to zero. | 310 | * work, callers must never allocate more than 1 bio at a time from this pool. |
279 | **/ | 311 | * Callers that need to allocate more than 1 bio must always submit the |
312 | * previously allocated bio for IO before attempting to allocate a new one. | ||
313 | * Failure to do so can cause deadlocks under memory pressure. | ||
314 | * | ||
315 | * RETURNS: | ||
316 | * Pointer to new bio on success, NULL on failure. | ||
317 | */ | ||
280 | struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs) | 318 | struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs) |
281 | { | 319 | { |
320 | unsigned front_pad; | ||
321 | unsigned inline_vecs; | ||
282 | unsigned long idx = BIO_POOL_NONE; | 322 | unsigned long idx = BIO_POOL_NONE; |
283 | struct bio_vec *bvl = NULL; | 323 | struct bio_vec *bvl = NULL; |
284 | struct bio *bio; | 324 | struct bio *bio; |
285 | void *p; | 325 | void *p; |
286 | 326 | ||
287 | p = mempool_alloc(bs->bio_pool, gfp_mask); | 327 | if (!bs) { |
328 | if (nr_iovecs > UIO_MAXIOV) | ||
329 | return NULL; | ||
330 | |||
331 | p = kmalloc(sizeof(struct bio) + | ||
332 | nr_iovecs * sizeof(struct bio_vec), | ||
333 | gfp_mask); | ||
334 | front_pad = 0; | ||
335 | inline_vecs = nr_iovecs; | ||
336 | } else { | ||
337 | p = mempool_alloc(bs->bio_pool, gfp_mask); | ||
338 | front_pad = bs->front_pad; | ||
339 | inline_vecs = BIO_INLINE_VECS; | ||
340 | } | ||
341 | |||
288 | if (unlikely(!p)) | 342 | if (unlikely(!p)) |
289 | return NULL; | 343 | return NULL; |
290 | bio = p + bs->front_pad; | ||
291 | 344 | ||
345 | bio = p + front_pad; | ||
292 | bio_init(bio); | 346 | bio_init(bio); |
293 | 347 | ||
294 | if (unlikely(!nr_iovecs)) | 348 | if (nr_iovecs > inline_vecs) { |
295 | goto out_set; | ||
296 | |||
297 | if (nr_iovecs <= BIO_INLINE_VECS) { | ||
298 | bvl = bio->bi_inline_vecs; | ||
299 | nr_iovecs = BIO_INLINE_VECS; | ||
300 | } else { | ||
301 | bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs); | 349 | bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs); |
302 | if (unlikely(!bvl)) | 350 | if (unlikely(!bvl)) |
303 | goto err_free; | 351 | goto err_free; |
304 | 352 | } else if (nr_iovecs) { | |
305 | nr_iovecs = bvec_nr_vecs(idx); | 353 | bvl = bio->bi_inline_vecs; |
306 | } | 354 | } |
307 | out_set: | 355 | |
356 | bio->bi_pool = bs; | ||
308 | bio->bi_flags |= idx << BIO_POOL_OFFSET; | 357 | bio->bi_flags |= idx << BIO_POOL_OFFSET; |
309 | bio->bi_max_vecs = nr_iovecs; | 358 | bio->bi_max_vecs = nr_iovecs; |
310 | bio->bi_io_vec = bvl; | 359 | bio->bi_io_vec = bvl; |
@@ -316,80 +365,6 @@ err_free: | |||
316 | } | 365 | } |
317 | EXPORT_SYMBOL(bio_alloc_bioset); | 366 | EXPORT_SYMBOL(bio_alloc_bioset); |
318 | 367 | ||
319 | static void bio_fs_destructor(struct bio *bio) | ||
320 | { | ||
321 | bio_free(bio, fs_bio_set); | ||
322 | } | ||
323 | |||
324 | /** | ||
325 | * bio_alloc - allocate a new bio, memory pool backed | ||
326 | * @gfp_mask: allocation mask to use | ||
327 | * @nr_iovecs: number of iovecs | ||
328 | * | ||
329 | * bio_alloc will allocate a bio and associated bio_vec array that can hold | ||
330 | * at least @nr_iovecs entries. Allocations will be done from the | ||
331 | * fs_bio_set. Also see @bio_alloc_bioset and @bio_kmalloc. | ||
332 | * | ||
333 | * If %__GFP_WAIT is set, then bio_alloc will always be able to allocate | ||
334 | * a bio. This is due to the mempool guarantees. To make this work, callers | ||
335 | * must never allocate more than 1 bio at a time from this pool. Callers | ||
336 | * that need to allocate more than 1 bio must always submit the previously | ||
337 | * allocated bio for IO before attempting to allocate a new one. Failure to | ||
338 | * do so can cause livelocks under memory pressure. | ||
339 | * | ||
340 | * RETURNS: | ||
341 | * Pointer to new bio on success, NULL on failure. | ||
342 | */ | ||
343 | struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs) | ||
344 | { | ||
345 | struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set); | ||
346 | |||
347 | if (bio) | ||
348 | bio->bi_destructor = bio_fs_destructor; | ||
349 | |||
350 | return bio; | ||
351 | } | ||
352 | EXPORT_SYMBOL(bio_alloc); | ||
353 | |||
354 | static void bio_kmalloc_destructor(struct bio *bio) | ||
355 | { | ||
356 | if (bio_integrity(bio)) | ||
357 | bio_integrity_free(bio, fs_bio_set); | ||
358 | kfree(bio); | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * bio_kmalloc - allocate a bio for I/O using kmalloc() | ||
363 | * @gfp_mask: the GFP_ mask given to the slab allocator | ||
364 | * @nr_iovecs: number of iovecs to pre-allocate | ||
365 | * | ||
366 | * Description: | ||
367 | * Allocate a new bio with @nr_iovecs bvecs. If @gfp_mask contains | ||
368 | * %__GFP_WAIT, the allocation is guaranteed to succeed. | ||
369 | * | ||
370 | **/ | ||
371 | struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs) | ||
372 | { | ||
373 | struct bio *bio; | ||
374 | |||
375 | if (nr_iovecs > UIO_MAXIOV) | ||
376 | return NULL; | ||
377 | |||
378 | bio = kmalloc(sizeof(struct bio) + nr_iovecs * sizeof(struct bio_vec), | ||
379 | gfp_mask); | ||
380 | if (unlikely(!bio)) | ||
381 | return NULL; | ||
382 | |||
383 | bio_init(bio); | ||
384 | bio->bi_flags |= BIO_POOL_NONE << BIO_POOL_OFFSET; | ||
385 | bio->bi_max_vecs = nr_iovecs; | ||
386 | bio->bi_io_vec = bio->bi_inline_vecs; | ||
387 | bio->bi_destructor = bio_kmalloc_destructor; | ||
388 | |||
389 | return bio; | ||
390 | } | ||
391 | EXPORT_SYMBOL(bio_kmalloc); | ||
392 | |||
393 | void zero_fill_bio(struct bio *bio) | 368 | void zero_fill_bio(struct bio *bio) |
394 | { | 369 | { |
395 | unsigned long flags; | 370 | unsigned long flags; |
@@ -420,11 +395,8 @@ void bio_put(struct bio *bio) | |||
420 | /* | 395 | /* |
421 | * last put frees it | 396 | * last put frees it |
422 | */ | 397 | */ |
423 | if (atomic_dec_and_test(&bio->bi_cnt)) { | 398 | if (atomic_dec_and_test(&bio->bi_cnt)) |
424 | bio_disassociate_task(bio); | 399 | bio_free(bio); |
425 | bio->bi_next = NULL; | ||
426 | bio->bi_destructor(bio); | ||
427 | } | ||
428 | } | 400 | } |
429 | EXPORT_SYMBOL(bio_put); | 401 | EXPORT_SYMBOL(bio_put); |
430 | 402 | ||
@@ -466,26 +438,28 @@ void __bio_clone(struct bio *bio, struct bio *bio_src) | |||
466 | EXPORT_SYMBOL(__bio_clone); | 438 | EXPORT_SYMBOL(__bio_clone); |
467 | 439 | ||
468 | /** | 440 | /** |
469 | * bio_clone - clone a bio | 441 | * bio_clone_bioset - clone a bio |
470 | * @bio: bio to clone | 442 | * @bio: bio to clone |
471 | * @gfp_mask: allocation priority | 443 | * @gfp_mask: allocation priority |
444 | * @bs: bio_set to allocate from | ||
472 | * | 445 | * |
473 | * Like __bio_clone, only also allocates the returned bio | 446 | * Like __bio_clone, only also allocates the returned bio |
474 | */ | 447 | */ |
475 | struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask) | 448 | struct bio *bio_clone_bioset(struct bio *bio, gfp_t gfp_mask, |
449 | struct bio_set *bs) | ||
476 | { | 450 | { |
477 | struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set); | 451 | struct bio *b; |
478 | 452 | ||
453 | b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, bs); | ||
479 | if (!b) | 454 | if (!b) |
480 | return NULL; | 455 | return NULL; |
481 | 456 | ||
482 | b->bi_destructor = bio_fs_destructor; | ||
483 | __bio_clone(b, bio); | 457 | __bio_clone(b, bio); |
484 | 458 | ||
485 | if (bio_integrity(bio)) { | 459 | if (bio_integrity(bio)) { |
486 | int ret; | 460 | int ret; |
487 | 461 | ||
488 | ret = bio_integrity_clone(b, bio, gfp_mask, fs_bio_set); | 462 | ret = bio_integrity_clone(b, bio, gfp_mask); |
489 | 463 | ||
490 | if (ret < 0) { | 464 | if (ret < 0) { |
491 | bio_put(b); | 465 | bio_put(b); |
@@ -495,7 +469,7 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask) | |||
495 | 469 | ||
496 | return b; | 470 | return b; |
497 | } | 471 | } |
498 | EXPORT_SYMBOL(bio_clone); | 472 | EXPORT_SYMBOL(bio_clone_bioset); |
499 | 473 | ||
500 | /** | 474 | /** |
501 | * bio_get_nr_vecs - return approx number of vecs | 475 | * bio_get_nr_vecs - return approx number of vecs |
@@ -1501,7 +1475,7 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors) | |||
1501 | trace_block_split(bdev_get_queue(bi->bi_bdev), bi, | 1475 | trace_block_split(bdev_get_queue(bi->bi_bdev), bi, |
1502 | bi->bi_sector + first_sectors); | 1476 | bi->bi_sector + first_sectors); |
1503 | 1477 | ||
1504 | BUG_ON(bi->bi_vcnt != 1); | 1478 | BUG_ON(bi->bi_vcnt != 1 && bi->bi_vcnt != 0); |
1505 | BUG_ON(bi->bi_idx != 0); | 1479 | BUG_ON(bi->bi_idx != 0); |
1506 | atomic_set(&bp->cnt, 3); | 1480 | atomic_set(&bp->cnt, 3); |
1507 | bp->error = 0; | 1481 | bp->error = 0; |
@@ -1511,17 +1485,22 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors) | |||
1511 | bp->bio2.bi_size -= first_sectors << 9; | 1485 | bp->bio2.bi_size -= first_sectors << 9; |
1512 | bp->bio1.bi_size = first_sectors << 9; | 1486 | bp->bio1.bi_size = first_sectors << 9; |
1513 | 1487 | ||
1514 | bp->bv1 = bi->bi_io_vec[0]; | 1488 | if (bi->bi_vcnt != 0) { |
1515 | bp->bv2 = bi->bi_io_vec[0]; | 1489 | bp->bv1 = bi->bi_io_vec[0]; |
1516 | bp->bv2.bv_offset += first_sectors << 9; | 1490 | bp->bv2 = bi->bi_io_vec[0]; |
1517 | bp->bv2.bv_len -= first_sectors << 9; | 1491 | |
1518 | bp->bv1.bv_len = first_sectors << 9; | 1492 | if (bio_is_rw(bi)) { |
1493 | bp->bv2.bv_offset += first_sectors << 9; | ||
1494 | bp->bv2.bv_len -= first_sectors << 9; | ||
1495 | bp->bv1.bv_len = first_sectors << 9; | ||
1496 | } | ||
1519 | 1497 | ||
1520 | bp->bio1.bi_io_vec = &bp->bv1; | 1498 | bp->bio1.bi_io_vec = &bp->bv1; |
1521 | bp->bio2.bi_io_vec = &bp->bv2; | 1499 | bp->bio2.bi_io_vec = &bp->bv2; |
1522 | 1500 | ||
1523 | bp->bio1.bi_max_vecs = 1; | 1501 | bp->bio1.bi_max_vecs = 1; |
1524 | bp->bio2.bi_max_vecs = 1; | 1502 | bp->bio2.bi_max_vecs = 1; |
1503 | } | ||
1525 | 1504 | ||
1526 | bp->bio1.bi_end_io = bio_pair_end_1; | 1505 | bp->bio1.bi_end_io = bio_pair_end_1; |
1527 | bp->bio2.bi_end_io = bio_pair_end_2; | 1506 | bp->bio2.bi_end_io = bio_pair_end_2; |
diff --git a/fs/block_dev.c b/fs/block_dev.c index 38e721b35d45..b3c1d3dae77d 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -116,6 +116,8 @@ EXPORT_SYMBOL(invalidate_bdev); | |||
116 | 116 | ||
117 | int set_blocksize(struct block_device *bdev, int size) | 117 | int set_blocksize(struct block_device *bdev, int size) |
118 | { | 118 | { |
119 | struct address_space *mapping; | ||
120 | |||
119 | /* Size must be a power of two, and between 512 and PAGE_SIZE */ | 121 | /* Size must be a power of two, and between 512 and PAGE_SIZE */ |
120 | if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) | 122 | if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) |
121 | return -EINVAL; | 123 | return -EINVAL; |
@@ -124,6 +126,19 @@ int set_blocksize(struct block_device *bdev, int size) | |||
124 | if (size < bdev_logical_block_size(bdev)) | 126 | if (size < bdev_logical_block_size(bdev)) |
125 | return -EINVAL; | 127 | return -EINVAL; |
126 | 128 | ||
129 | /* Prevent starting I/O or mapping the device */ | ||
130 | percpu_down_write(&bdev->bd_block_size_semaphore); | ||
131 | |||
132 | /* Check that the block device is not memory mapped */ | ||
133 | mapping = bdev->bd_inode->i_mapping; | ||
134 | mutex_lock(&mapping->i_mmap_mutex); | ||
135 | if (mapping_mapped(mapping)) { | ||
136 | mutex_unlock(&mapping->i_mmap_mutex); | ||
137 | percpu_up_write(&bdev->bd_block_size_semaphore); | ||
138 | return -EBUSY; | ||
139 | } | ||
140 | mutex_unlock(&mapping->i_mmap_mutex); | ||
141 | |||
127 | /* Don't change the size if it is same as current */ | 142 | /* Don't change the size if it is same as current */ |
128 | if (bdev->bd_block_size != size) { | 143 | if (bdev->bd_block_size != size) { |
129 | sync_blockdev(bdev); | 144 | sync_blockdev(bdev); |
@@ -131,6 +146,9 @@ int set_blocksize(struct block_device *bdev, int size) | |||
131 | bdev->bd_inode->i_blkbits = blksize_bits(size); | 146 | bdev->bd_inode->i_blkbits = blksize_bits(size); |
132 | kill_bdev(bdev); | 147 | kill_bdev(bdev); |
133 | } | 148 | } |
149 | |||
150 | percpu_up_write(&bdev->bd_block_size_semaphore); | ||
151 | |||
134 | return 0; | 152 | return 0; |
135 | } | 153 | } |
136 | 154 | ||
@@ -441,6 +459,12 @@ static struct inode *bdev_alloc_inode(struct super_block *sb) | |||
441 | struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL); | 459 | struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL); |
442 | if (!ei) | 460 | if (!ei) |
443 | return NULL; | 461 | return NULL; |
462 | |||
463 | if (unlikely(percpu_init_rwsem(&ei->bdev.bd_block_size_semaphore))) { | ||
464 | kmem_cache_free(bdev_cachep, ei); | ||
465 | return NULL; | ||
466 | } | ||
467 | |||
444 | return &ei->vfs_inode; | 468 | return &ei->vfs_inode; |
445 | } | 469 | } |
446 | 470 | ||
@@ -449,6 +473,8 @@ static void bdev_i_callback(struct rcu_head *head) | |||
449 | struct inode *inode = container_of(head, struct inode, i_rcu); | 473 | struct inode *inode = container_of(head, struct inode, i_rcu); |
450 | struct bdev_inode *bdi = BDEV_I(inode); | 474 | struct bdev_inode *bdi = BDEV_I(inode); |
451 | 475 | ||
476 | percpu_free_rwsem(&bdi->bdev.bd_block_size_semaphore); | ||
477 | |||
452 | kmem_cache_free(bdev_cachep, bdi); | 478 | kmem_cache_free(bdev_cachep, bdi); |
453 | } | 479 | } |
454 | 480 | ||
@@ -1567,6 +1593,22 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) | |||
1567 | return blkdev_ioctl(bdev, mode, cmd, arg); | 1593 | return blkdev_ioctl(bdev, mode, cmd, arg); |
1568 | } | 1594 | } |
1569 | 1595 | ||
1596 | ssize_t blkdev_aio_read(struct kiocb *iocb, const struct iovec *iov, | ||
1597 | unsigned long nr_segs, loff_t pos) | ||
1598 | { | ||
1599 | ssize_t ret; | ||
1600 | struct block_device *bdev = I_BDEV(iocb->ki_filp->f_mapping->host); | ||
1601 | |||
1602 | percpu_down_read(&bdev->bd_block_size_semaphore); | ||
1603 | |||
1604 | ret = generic_file_aio_read(iocb, iov, nr_segs, pos); | ||
1605 | |||
1606 | percpu_up_read(&bdev->bd_block_size_semaphore); | ||
1607 | |||
1608 | return ret; | ||
1609 | } | ||
1610 | EXPORT_SYMBOL_GPL(blkdev_aio_read); | ||
1611 | |||
1570 | /* | 1612 | /* |
1571 | * Write data to the block device. Only intended for the block device itself | 1613 | * Write data to the block device. Only intended for the block device itself |
1572 | * and the raw driver which basically is a fake block device. | 1614 | * and the raw driver which basically is a fake block device. |
@@ -1578,12 +1620,16 @@ ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1578 | unsigned long nr_segs, loff_t pos) | 1620 | unsigned long nr_segs, loff_t pos) |
1579 | { | 1621 | { |
1580 | struct file *file = iocb->ki_filp; | 1622 | struct file *file = iocb->ki_filp; |
1623 | struct block_device *bdev = I_BDEV(file->f_mapping->host); | ||
1581 | struct blk_plug plug; | 1624 | struct blk_plug plug; |
1582 | ssize_t ret; | 1625 | ssize_t ret; |
1583 | 1626 | ||
1584 | BUG_ON(iocb->ki_pos != pos); | 1627 | BUG_ON(iocb->ki_pos != pos); |
1585 | 1628 | ||
1586 | blk_start_plug(&plug); | 1629 | blk_start_plug(&plug); |
1630 | |||
1631 | percpu_down_read(&bdev->bd_block_size_semaphore); | ||
1632 | |||
1587 | ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); | 1633 | ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); |
1588 | if (ret > 0 || ret == -EIOCBQUEUED) { | 1634 | if (ret > 0 || ret == -EIOCBQUEUED) { |
1589 | ssize_t err; | 1635 | ssize_t err; |
@@ -1592,11 +1638,29 @@ ssize_t blkdev_aio_write(struct kiocb *iocb, const struct iovec *iov, | |||
1592 | if (err < 0 && ret > 0) | 1638 | if (err < 0 && ret > 0) |
1593 | ret = err; | 1639 | ret = err; |
1594 | } | 1640 | } |
1641 | |||
1642 | percpu_up_read(&bdev->bd_block_size_semaphore); | ||
1643 | |||
1595 | blk_finish_plug(&plug); | 1644 | blk_finish_plug(&plug); |
1645 | |||
1596 | return ret; | 1646 | return ret; |
1597 | } | 1647 | } |
1598 | EXPORT_SYMBOL_GPL(blkdev_aio_write); | 1648 | EXPORT_SYMBOL_GPL(blkdev_aio_write); |
1599 | 1649 | ||
1650 | static int blkdev_mmap(struct file *file, struct vm_area_struct *vma) | ||
1651 | { | ||
1652 | int ret; | ||
1653 | struct block_device *bdev = I_BDEV(file->f_mapping->host); | ||
1654 | |||
1655 | percpu_down_read(&bdev->bd_block_size_semaphore); | ||
1656 | |||
1657 | ret = generic_file_mmap(file, vma); | ||
1658 | |||
1659 | percpu_up_read(&bdev->bd_block_size_semaphore); | ||
1660 | |||
1661 | return ret; | ||
1662 | } | ||
1663 | |||
1600 | /* | 1664 | /* |
1601 | * Try to release a page associated with block device when the system | 1665 | * Try to release a page associated with block device when the system |
1602 | * is under memory pressure. | 1666 | * is under memory pressure. |
@@ -1627,9 +1691,9 @@ const struct file_operations def_blk_fops = { | |||
1627 | .llseek = block_llseek, | 1691 | .llseek = block_llseek, |
1628 | .read = do_sync_read, | 1692 | .read = do_sync_read, |
1629 | .write = do_sync_write, | 1693 | .write = do_sync_write, |
1630 | .aio_read = generic_file_aio_read, | 1694 | .aio_read = blkdev_aio_read, |
1631 | .aio_write = blkdev_aio_write, | 1695 | .aio_write = blkdev_aio_write, |
1632 | .mmap = generic_file_mmap, | 1696 | .mmap = blkdev_mmap, |
1633 | .fsync = blkdev_fsync, | 1697 | .fsync = blkdev_fsync, |
1634 | .unlocked_ioctl = block_ioctl, | 1698 | .unlocked_ioctl = block_ioctl, |
1635 | #ifdef CONFIG_COMPAT | 1699 | #ifdef CONFIG_COMPAT |
diff --git a/fs/exofs/ore.c b/fs/exofs/ore.c index 1585db1aa365..f936cb50dc0d 100644 --- a/fs/exofs/ore.c +++ b/fs/exofs/ore.c | |||
@@ -814,8 +814,8 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp) | |||
814 | struct bio *bio; | 814 | struct bio *bio; |
815 | 815 | ||
816 | if (per_dev != master_dev) { | 816 | if (per_dev != master_dev) { |
817 | bio = bio_kmalloc(GFP_KERNEL, | 817 | bio = bio_clone_kmalloc(master_dev->bio, |
818 | master_dev->bio->bi_max_vecs); | 818 | GFP_KERNEL); |
819 | if (unlikely(!bio)) { | 819 | if (unlikely(!bio)) { |
820 | ORE_DBGMSG( | 820 | ORE_DBGMSG( |
821 | "Failed to allocate BIO size=%u\n", | 821 | "Failed to allocate BIO size=%u\n", |
@@ -824,7 +824,6 @@ static int _write_mirror(struct ore_io_state *ios, int cur_comp) | |||
824 | goto out; | 824 | goto out; |
825 | } | 825 | } |
826 | 826 | ||
827 | __bio_clone(bio, master_dev->bio); | ||
828 | bio->bi_bdev = NULL; | 827 | bio->bi_bdev = NULL; |
829 | bio->bi_next = NULL; | 828 | bio->bi_next = NULL; |
830 | per_dev->offset = master_dev->offset; | 829 | per_dev->offset = master_dev->offset; |