diff options
Diffstat (limited to 'block/blk-settings.c')
-rw-r--r-- | block/blk-settings.c | 269 |
1 files changed, 239 insertions, 30 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c index 57af728d94bb..1c4df9bf6813 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c | |||
@@ -134,7 +134,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn) | |||
134 | q->backing_dev_info.state = 0; | 134 | q->backing_dev_info.state = 0; |
135 | q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; | 135 | q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; |
136 | blk_queue_max_sectors(q, SAFE_MAX_SECTORS); | 136 | blk_queue_max_sectors(q, SAFE_MAX_SECTORS); |
137 | blk_queue_hardsect_size(q, 512); | 137 | blk_queue_logical_block_size(q, 512); |
138 | blk_queue_dma_alignment(q, 511); | 138 | blk_queue_dma_alignment(q, 511); |
139 | blk_queue_congestion_threshold(q); | 139 | blk_queue_congestion_threshold(q); |
140 | q->nr_batching = BLK_BATCH_REQ; | 140 | q->nr_batching = BLK_BATCH_REQ; |
@@ -179,16 +179,16 @@ void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask) | |||
179 | */ | 179 | */ |
180 | if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT)) | 180 | if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT)) |
181 | dma = 1; | 181 | dma = 1; |
182 | q->bounce_pfn = max_low_pfn; | 182 | q->limits.bounce_pfn = max_low_pfn; |
183 | #else | 183 | #else |
184 | if (b_pfn < blk_max_low_pfn) | 184 | if (b_pfn < blk_max_low_pfn) |
185 | dma = 1; | 185 | dma = 1; |
186 | q->bounce_pfn = b_pfn; | 186 | q->limits.bounce_pfn = b_pfn; |
187 | #endif | 187 | #endif |
188 | if (dma) { | 188 | if (dma) { |
189 | init_emergency_isa_pool(); | 189 | init_emergency_isa_pool(); |
190 | q->bounce_gfp = GFP_NOIO | GFP_DMA; | 190 | q->bounce_gfp = GFP_NOIO | GFP_DMA; |
191 | q->bounce_pfn = b_pfn; | 191 | q->limits.bounce_pfn = b_pfn; |
192 | } | 192 | } |
193 | } | 193 | } |
194 | EXPORT_SYMBOL(blk_queue_bounce_limit); | 194 | EXPORT_SYMBOL(blk_queue_bounce_limit); |
@@ -211,14 +211,23 @@ void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors) | |||
211 | } | 211 | } |
212 | 212 | ||
213 | if (BLK_DEF_MAX_SECTORS > max_sectors) | 213 | if (BLK_DEF_MAX_SECTORS > max_sectors) |
214 | q->max_hw_sectors = q->max_sectors = max_sectors; | 214 | q->limits.max_hw_sectors = q->limits.max_sectors = max_sectors; |
215 | else { | 215 | else { |
216 | q->max_sectors = BLK_DEF_MAX_SECTORS; | 216 | q->limits.max_sectors = BLK_DEF_MAX_SECTORS; |
217 | q->max_hw_sectors = max_sectors; | 217 | q->limits.max_hw_sectors = max_sectors; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | EXPORT_SYMBOL(blk_queue_max_sectors); | 220 | EXPORT_SYMBOL(blk_queue_max_sectors); |
221 | 221 | ||
222 | void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors) | ||
223 | { | ||
224 | if (BLK_DEF_MAX_SECTORS > max_sectors) | ||
225 | q->limits.max_hw_sectors = BLK_DEF_MAX_SECTORS; | ||
226 | else | ||
227 | q->limits.max_hw_sectors = max_sectors; | ||
228 | } | ||
229 | EXPORT_SYMBOL(blk_queue_max_hw_sectors); | ||
230 | |||
222 | /** | 231 | /** |
223 | * blk_queue_max_phys_segments - set max phys segments for a request for this queue | 232 | * blk_queue_max_phys_segments - set max phys segments for a request for this queue |
224 | * @q: the request queue for the device | 233 | * @q: the request queue for the device |
@@ -238,7 +247,7 @@ void blk_queue_max_phys_segments(struct request_queue *q, | |||
238 | __func__, max_segments); | 247 | __func__, max_segments); |
239 | } | 248 | } |
240 | 249 | ||
241 | q->max_phys_segments = max_segments; | 250 | q->limits.max_phys_segments = max_segments; |
242 | } | 251 | } |
243 | EXPORT_SYMBOL(blk_queue_max_phys_segments); | 252 | EXPORT_SYMBOL(blk_queue_max_phys_segments); |
244 | 253 | ||
@@ -262,7 +271,7 @@ void blk_queue_max_hw_segments(struct request_queue *q, | |||
262 | __func__, max_segments); | 271 | __func__, max_segments); |
263 | } | 272 | } |
264 | 273 | ||
265 | q->max_hw_segments = max_segments; | 274 | q->limits.max_hw_segments = max_segments; |
266 | } | 275 | } |
267 | EXPORT_SYMBOL(blk_queue_max_hw_segments); | 276 | EXPORT_SYMBOL(blk_queue_max_hw_segments); |
268 | 277 | ||
@@ -283,26 +292,110 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size) | |||
283 | __func__, max_size); | 292 | __func__, max_size); |
284 | } | 293 | } |
285 | 294 | ||
286 | q->max_segment_size = max_size; | 295 | q->limits.max_segment_size = max_size; |
287 | } | 296 | } |
288 | EXPORT_SYMBOL(blk_queue_max_segment_size); | 297 | EXPORT_SYMBOL(blk_queue_max_segment_size); |
289 | 298 | ||
290 | /** | 299 | /** |
291 | * blk_queue_hardsect_size - set hardware sector size for the queue | 300 | * blk_queue_logical_block_size - set logical block size for the queue |
292 | * @q: the request queue for the device | 301 | * @q: the request queue for the device |
293 | * @size: the hardware sector size, in bytes | 302 | * @size: the logical block size, in bytes |
294 | * | 303 | * |
295 | * Description: | 304 | * Description: |
296 | * This should typically be set to the lowest possible sector size | 305 | * This should be set to the lowest possible block size that the |
297 | * that the hardware can operate on (possible without reverting to | 306 | * storage device can address. The default of 512 covers most |
298 | * even internal read-modify-write operations). Usually the default | 307 | * hardware. |
299 | * of 512 covers most hardware. | ||
300 | **/ | 308 | **/ |
301 | void blk_queue_hardsect_size(struct request_queue *q, unsigned short size) | 309 | void blk_queue_logical_block_size(struct request_queue *q, unsigned short size) |
310 | { | ||
311 | q->limits.logical_block_size = size; | ||
312 | |||
313 | if (q->limits.physical_block_size < size) | ||
314 | q->limits.physical_block_size = size; | ||
315 | |||
316 | if (q->limits.io_min < q->limits.physical_block_size) | ||
317 | q->limits.io_min = q->limits.physical_block_size; | ||
318 | } | ||
319 | EXPORT_SYMBOL(blk_queue_logical_block_size); | ||
320 | |||
321 | /** | ||
322 | * blk_queue_physical_block_size - set physical block size for the queue | ||
323 | * @q: the request queue for the device | ||
324 | * @size: the physical block size, in bytes | ||
325 | * | ||
326 | * Description: | ||
327 | * This should be set to the lowest possible sector size that the | ||
328 | * hardware can operate on without reverting to read-modify-write | ||
329 | * operations. | ||
330 | */ | ||
331 | void blk_queue_physical_block_size(struct request_queue *q, unsigned short size) | ||
332 | { | ||
333 | q->limits.physical_block_size = size; | ||
334 | |||
335 | if (q->limits.physical_block_size < q->limits.logical_block_size) | ||
336 | q->limits.physical_block_size = q->limits.logical_block_size; | ||
337 | |||
338 | if (q->limits.io_min < q->limits.physical_block_size) | ||
339 | q->limits.io_min = q->limits.physical_block_size; | ||
340 | } | ||
341 | EXPORT_SYMBOL(blk_queue_physical_block_size); | ||
342 | |||
343 | /** | ||
344 | * blk_queue_alignment_offset - set physical block alignment offset | ||
345 | * @q: the request queue for the device | ||
346 | * @alignment: alignment offset in bytes | ||
347 | * | ||
348 | * Description: | ||
349 | * Some devices are naturally misaligned to compensate for things like | ||
350 | * the legacy DOS partition table 63-sector offset. Low-level drivers | ||
351 | * should call this function for devices whose first sector is not | ||
352 | * naturally aligned. | ||
353 | */ | ||
354 | void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset) | ||
302 | { | 355 | { |
303 | q->hardsect_size = size; | 356 | q->limits.alignment_offset = |
357 | offset & (q->limits.physical_block_size - 1); | ||
358 | q->limits.misaligned = 0; | ||
304 | } | 359 | } |
305 | EXPORT_SYMBOL(blk_queue_hardsect_size); | 360 | EXPORT_SYMBOL(blk_queue_alignment_offset); |
361 | |||
362 | /** | ||
363 | * blk_queue_io_min - set minimum request size for the queue | ||
364 | * @q: the request queue for the device | ||
365 | * @io_min: smallest I/O size in bytes | ||
366 | * | ||
367 | * Description: | ||
368 | * Some devices have an internal block size bigger than the reported | ||
369 | * hardware sector size. This function can be used to signal the | ||
370 | * smallest I/O the device can perform without incurring a performance | ||
371 | * penalty. | ||
372 | */ | ||
373 | void blk_queue_io_min(struct request_queue *q, unsigned int min) | ||
374 | { | ||
375 | q->limits.io_min = min; | ||
376 | |||
377 | if (q->limits.io_min < q->limits.logical_block_size) | ||
378 | q->limits.io_min = q->limits.logical_block_size; | ||
379 | |||
380 | if (q->limits.io_min < q->limits.physical_block_size) | ||
381 | q->limits.io_min = q->limits.physical_block_size; | ||
382 | } | ||
383 | EXPORT_SYMBOL(blk_queue_io_min); | ||
384 | |||
385 | /** | ||
386 | * blk_queue_io_opt - set optimal request size for the queue | ||
387 | * @q: the request queue for the device | ||
388 | * @io_opt: optimal request size in bytes | ||
389 | * | ||
390 | * Description: | ||
391 | * Drivers can call this function to set the preferred I/O request | ||
392 | * size for devices that report such a value. | ||
393 | */ | ||
394 | void blk_queue_io_opt(struct request_queue *q, unsigned int opt) | ||
395 | { | ||
396 | q->limits.io_opt = opt; | ||
397 | } | ||
398 | EXPORT_SYMBOL(blk_queue_io_opt); | ||
306 | 399 | ||
307 | /* | 400 | /* |
308 | * Returns the minimum that is _not_ zero, unless both are zero. | 401 | * Returns the minimum that is _not_ zero, unless both are zero. |
@@ -317,14 +410,27 @@ EXPORT_SYMBOL(blk_queue_hardsect_size); | |||
317 | void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) | 410 | void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) |
318 | { | 411 | { |
319 | /* zero is "infinity" */ | 412 | /* zero is "infinity" */ |
320 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); | 413 | t->limits.max_sectors = min_not_zero(queue_max_sectors(t), |
321 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); | 414 | queue_max_sectors(b)); |
322 | t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, b->seg_boundary_mask); | 415 | |
416 | t->limits.max_hw_sectors = min_not_zero(queue_max_hw_sectors(t), | ||
417 | queue_max_hw_sectors(b)); | ||
418 | |||
419 | t->limits.seg_boundary_mask = min_not_zero(queue_segment_boundary(t), | ||
420 | queue_segment_boundary(b)); | ||
421 | |||
422 | t->limits.max_phys_segments = min_not_zero(queue_max_phys_segments(t), | ||
423 | queue_max_phys_segments(b)); | ||
424 | |||
425 | t->limits.max_hw_segments = min_not_zero(queue_max_hw_segments(t), | ||
426 | queue_max_hw_segments(b)); | ||
427 | |||
428 | t->limits.max_segment_size = min_not_zero(queue_max_segment_size(t), | ||
429 | queue_max_segment_size(b)); | ||
430 | |||
431 | t->limits.logical_block_size = max(queue_logical_block_size(t), | ||
432 | queue_logical_block_size(b)); | ||
323 | 433 | ||
324 | t->max_phys_segments = min_not_zero(t->max_phys_segments, b->max_phys_segments); | ||
325 | t->max_hw_segments = min_not_zero(t->max_hw_segments, b->max_hw_segments); | ||
326 | t->max_segment_size = min_not_zero(t->max_segment_size, b->max_segment_size); | ||
327 | t->hardsect_size = max(t->hardsect_size, b->hardsect_size); | ||
328 | if (!t->queue_lock) | 434 | if (!t->queue_lock) |
329 | WARN_ON_ONCE(1); | 435 | WARN_ON_ONCE(1); |
330 | else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) { | 436 | else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) { |
@@ -337,6 +443,109 @@ void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) | |||
337 | EXPORT_SYMBOL(blk_queue_stack_limits); | 443 | EXPORT_SYMBOL(blk_queue_stack_limits); |
338 | 444 | ||
339 | /** | 445 | /** |
446 | * blk_stack_limits - adjust queue_limits for stacked devices | ||
447 | * @t: the stacking driver limits (top) | ||
448 | * @b: the underlying queue limits (bottom) | ||
449 | * @offset: offset to beginning of data within component device | ||
450 | * | ||
451 | * Description: | ||
452 | * Merges two queue_limit structs. Returns 0 if alignment didn't | ||
453 | * change. Returns -1 if adding the bottom device caused | ||
454 | * misalignment. | ||
455 | */ | ||
456 | int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | ||
457 | sector_t offset) | ||
458 | { | ||
459 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); | ||
460 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); | ||
461 | t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn); | ||
462 | |||
463 | t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, | ||
464 | b->seg_boundary_mask); | ||
465 | |||
466 | t->max_phys_segments = min_not_zero(t->max_phys_segments, | ||
467 | b->max_phys_segments); | ||
468 | |||
469 | t->max_hw_segments = min_not_zero(t->max_hw_segments, | ||
470 | b->max_hw_segments); | ||
471 | |||
472 | t->max_segment_size = min_not_zero(t->max_segment_size, | ||
473 | b->max_segment_size); | ||
474 | |||
475 | t->logical_block_size = max(t->logical_block_size, | ||
476 | b->logical_block_size); | ||
477 | |||
478 | t->physical_block_size = max(t->physical_block_size, | ||
479 | b->physical_block_size); | ||
480 | |||
481 | t->io_min = max(t->io_min, b->io_min); | ||
482 | t->no_cluster |= b->no_cluster; | ||
483 | |||
484 | /* Bottom device offset aligned? */ | ||
485 | if (offset && | ||
486 | (offset & (b->physical_block_size - 1)) != b->alignment_offset) { | ||
487 | t->misaligned = 1; | ||
488 | return -1; | ||
489 | } | ||
490 | |||
491 | /* If top has no alignment offset, inherit from bottom */ | ||
492 | if (!t->alignment_offset) | ||
493 | t->alignment_offset = | ||
494 | b->alignment_offset & (b->physical_block_size - 1); | ||
495 | |||
496 | /* Top device aligned on logical block boundary? */ | ||
497 | if (t->alignment_offset & (t->logical_block_size - 1)) { | ||
498 | t->misaligned = 1; | ||
499 | return -1; | ||
500 | } | ||
501 | |||
502 | return 0; | ||
503 | } | ||
504 | EXPORT_SYMBOL(blk_stack_limits); | ||
505 | |||
506 | /** | ||
507 | * disk_stack_limits - adjust queue limits for stacked drivers | ||
508 | * @disk: MD/DM gendisk (top) | ||
509 | * @bdev: the underlying block device (bottom) | ||
510 | * @offset: offset to beginning of data within component device | ||
511 | * | ||
512 | * Description: | ||
513 | * Merges the limits for two queues. Returns 0 if alignment | ||
514 | * didn't change. Returns -1 if adding the bottom device caused | ||
515 | * misalignment. | ||
516 | */ | ||
517 | void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, | ||
518 | sector_t offset) | ||
519 | { | ||
520 | struct request_queue *t = disk->queue; | ||
521 | struct request_queue *b = bdev_get_queue(bdev); | ||
522 | |||
523 | offset += get_start_sect(bdev) << 9; | ||
524 | |||
525 | if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) { | ||
526 | char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE]; | ||
527 | |||
528 | disk_name(disk, 0, top); | ||
529 | bdevname(bdev, bottom); | ||
530 | |||
531 | printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n", | ||
532 | top, bottom); | ||
533 | } | ||
534 | |||
535 | if (!t->queue_lock) | ||
536 | WARN_ON_ONCE(1); | ||
537 | else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) { | ||
538 | unsigned long flags; | ||
539 | |||
540 | spin_lock_irqsave(t->queue_lock, flags); | ||
541 | if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) | ||
542 | queue_flag_clear(QUEUE_FLAG_CLUSTER, t); | ||
543 | spin_unlock_irqrestore(t->queue_lock, flags); | ||
544 | } | ||
545 | } | ||
546 | EXPORT_SYMBOL(disk_stack_limits); | ||
547 | |||
548 | /** | ||
340 | * blk_queue_dma_pad - set pad mask | 549 | * blk_queue_dma_pad - set pad mask |
341 | * @q: the request queue for the device | 550 | * @q: the request queue for the device |
342 | * @mask: pad mask | 551 | * @mask: pad mask |
@@ -396,11 +605,11 @@ int blk_queue_dma_drain(struct request_queue *q, | |||
396 | dma_drain_needed_fn *dma_drain_needed, | 605 | dma_drain_needed_fn *dma_drain_needed, |
397 | void *buf, unsigned int size) | 606 | void *buf, unsigned int size) |
398 | { | 607 | { |
399 | if (q->max_hw_segments < 2 || q->max_phys_segments < 2) | 608 | if (queue_max_hw_segments(q) < 2 || queue_max_phys_segments(q) < 2) |
400 | return -EINVAL; | 609 | return -EINVAL; |
401 | /* make room for appending the drain */ | 610 | /* make room for appending the drain */ |
402 | --q->max_hw_segments; | 611 | blk_queue_max_hw_segments(q, queue_max_hw_segments(q) - 1); |
403 | --q->max_phys_segments; | 612 | blk_queue_max_phys_segments(q, queue_max_phys_segments(q) - 1); |
404 | q->dma_drain_needed = dma_drain_needed; | 613 | q->dma_drain_needed = dma_drain_needed; |
405 | q->dma_drain_buffer = buf; | 614 | q->dma_drain_buffer = buf; |
406 | q->dma_drain_size = size; | 615 | q->dma_drain_size = size; |
@@ -422,7 +631,7 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask) | |||
422 | __func__, mask); | 631 | __func__, mask); |
423 | } | 632 | } |
424 | 633 | ||
425 | q->seg_boundary_mask = mask; | 634 | q->limits.seg_boundary_mask = mask; |
426 | } | 635 | } |
427 | EXPORT_SYMBOL(blk_queue_segment_boundary); | 636 | EXPORT_SYMBOL(blk_queue_segment_boundary); |
428 | 637 | ||