diff options
Diffstat (limited to 'block/blk-settings.c')
-rw-r--r-- | block/blk-settings.c | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c index 66d4aa8799b7..dd1f1e0e196f 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/blkdev.h> | 8 | #include <linux/blkdev.h> |
9 | #include <linux/bootmem.h> /* for max_pfn/max_low_pfn */ | 9 | #include <linux/bootmem.h> /* for max_pfn/max_low_pfn */ |
10 | #include <linux/gcd.h> | 10 | #include <linux/gcd.h> |
11 | #include <linux/jiffies.h> | ||
11 | 12 | ||
12 | #include "blk.h" | 13 | #include "blk.h" |
13 | 14 | ||
@@ -96,7 +97,11 @@ void blk_set_default_limits(struct queue_limits *lim) | |||
96 | lim->max_segment_size = MAX_SEGMENT_SIZE; | 97 | lim->max_segment_size = MAX_SEGMENT_SIZE; |
97 | lim->max_sectors = BLK_DEF_MAX_SECTORS; | 98 | lim->max_sectors = BLK_DEF_MAX_SECTORS; |
98 | lim->max_hw_sectors = INT_MAX; | 99 | lim->max_hw_sectors = INT_MAX; |
99 | lim->max_discard_sectors = SAFE_MAX_SECTORS; | 100 | lim->max_discard_sectors = 0; |
101 | lim->discard_granularity = 0; | ||
102 | lim->discard_alignment = 0; | ||
103 | lim->discard_misaligned = 0; | ||
104 | lim->discard_zeroes_data = -1; | ||
100 | lim->logical_block_size = lim->physical_block_size = lim->io_min = 512; | 105 | lim->logical_block_size = lim->physical_block_size = lim->io_min = 512; |
101 | lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT); | 106 | lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT); |
102 | lim->alignment_offset = 0; | 107 | lim->alignment_offset = 0; |
@@ -141,7 +146,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn) | |||
141 | q->nr_batching = BLK_BATCH_REQ; | 146 | q->nr_batching = BLK_BATCH_REQ; |
142 | 147 | ||
143 | q->unplug_thresh = 4; /* hmm */ | 148 | q->unplug_thresh = 4; /* hmm */ |
144 | q->unplug_delay = (3 * HZ) / 1000; /* 3 milliseconds */ | 149 | q->unplug_delay = msecs_to_jiffies(3); /* 3 milliseconds */ |
145 | if (q->unplug_delay == 0) | 150 | if (q->unplug_delay == 0) |
146 | q->unplug_delay = 1; | 151 | q->unplug_delay = 1; |
147 | 152 | ||
@@ -488,6 +493,16 @@ void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) | |||
488 | } | 493 | } |
489 | EXPORT_SYMBOL(blk_queue_stack_limits); | 494 | EXPORT_SYMBOL(blk_queue_stack_limits); |
490 | 495 | ||
496 | static unsigned int lcm(unsigned int a, unsigned int b) | ||
497 | { | ||
498 | if (a && b) | ||
499 | return (a * b) / gcd(a, b); | ||
500 | else if (b) | ||
501 | return b; | ||
502 | |||
503 | return a; | ||
504 | } | ||
505 | |||
491 | /** | 506 | /** |
492 | * blk_stack_limits - adjust queue_limits for stacked devices | 507 | * blk_stack_limits - adjust queue_limits for stacked devices |
493 | * @t: the stacking driver limits (top) | 508 | * @t: the stacking driver limits (top) |
@@ -502,6 +517,10 @@ EXPORT_SYMBOL(blk_queue_stack_limits); | |||
502 | int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | 517 | int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
503 | sector_t offset) | 518 | sector_t offset) |
504 | { | 519 | { |
520 | int ret; | ||
521 | |||
522 | ret = 0; | ||
523 | |||
505 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); | 524 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); |
506 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); | 525 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); |
507 | t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn); | 526 | t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn); |
@@ -526,12 +545,19 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
526 | 545 | ||
527 | t->io_min = max(t->io_min, b->io_min); | 546 | t->io_min = max(t->io_min, b->io_min); |
528 | t->no_cluster |= b->no_cluster; | 547 | t->no_cluster |= b->no_cluster; |
548 | t->discard_zeroes_data &= b->discard_zeroes_data; | ||
529 | 549 | ||
530 | /* Bottom device offset aligned? */ | 550 | /* Bottom device offset aligned? */ |
531 | if (offset && | 551 | if (offset && |
532 | (offset & (b->physical_block_size - 1)) != b->alignment_offset) { | 552 | (offset & (b->physical_block_size - 1)) != b->alignment_offset) { |
533 | t->misaligned = 1; | 553 | t->misaligned = 1; |
534 | return -1; | 554 | ret = -1; |
555 | } | ||
556 | |||
557 | if (offset && | ||
558 | (offset & (b->discard_granularity - 1)) != b->discard_alignment) { | ||
559 | t->discard_misaligned = 1; | ||
560 | ret = -1; | ||
535 | } | 561 | } |
536 | 562 | ||
537 | /* If top has no alignment offset, inherit from bottom */ | 563 | /* If top has no alignment offset, inherit from bottom */ |
@@ -539,23 +565,26 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
539 | t->alignment_offset = | 565 | t->alignment_offset = |
540 | b->alignment_offset & (b->physical_block_size - 1); | 566 | b->alignment_offset & (b->physical_block_size - 1); |
541 | 567 | ||
568 | if (!t->discard_alignment) | ||
569 | t->discard_alignment = | ||
570 | b->discard_alignment & (b->discard_granularity - 1); | ||
571 | |||
542 | /* Top device aligned on logical block boundary? */ | 572 | /* Top device aligned on logical block boundary? */ |
543 | if (t->alignment_offset & (t->logical_block_size - 1)) { | 573 | if (t->alignment_offset & (t->logical_block_size - 1)) { |
544 | t->misaligned = 1; | 574 | t->misaligned = 1; |
545 | return -1; | 575 | ret = -1; |
546 | } | 576 | } |
547 | 577 | ||
548 | /* Find lcm() of optimal I/O size */ | 578 | /* Find lcm() of optimal I/O size and granularity */ |
549 | if (t->io_opt && b->io_opt) | 579 | t->io_opt = lcm(t->io_opt, b->io_opt); |
550 | t->io_opt = (t->io_opt * b->io_opt) / gcd(t->io_opt, b->io_opt); | 580 | t->discard_granularity = lcm(t->discard_granularity, |
551 | else if (b->io_opt) | 581 | b->discard_granularity); |
552 | t->io_opt = b->io_opt; | ||
553 | 582 | ||
554 | /* Verify that optimal I/O size is a multiple of io_min */ | 583 | /* Verify that optimal I/O size is a multiple of io_min */ |
555 | if (t->io_min && t->io_opt % t->io_min) | 584 | if (t->io_min && t->io_opt % t->io_min) |
556 | return -1; | 585 | ret = -1; |
557 | 586 | ||
558 | return 0; | 587 | return ret; |
559 | } | 588 | } |
560 | EXPORT_SYMBOL(blk_stack_limits); | 589 | EXPORT_SYMBOL(blk_stack_limits); |
561 | 590 | ||