diff options
Diffstat (limited to 'block/blk-settings.c')
| -rw-r--r-- | block/blk-settings.c | 121 |
1 files changed, 78 insertions, 43 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c index 6ae118d6e193..d52d4adc440b 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c | |||
| @@ -505,21 +505,30 @@ static unsigned int lcm(unsigned int a, unsigned int b) | |||
| 505 | 505 | ||
| 506 | /** | 506 | /** |
| 507 | * blk_stack_limits - adjust queue_limits for stacked devices | 507 | * blk_stack_limits - adjust queue_limits for stacked devices |
| 508 | * @t: the stacking driver limits (top) | 508 | * @t: the stacking driver limits (top device) |
| 509 | * @b: the underlying queue limits (bottom) | 509 | * @b: the underlying queue limits (bottom, component device) |
| 510 | * @offset: offset to beginning of data within component device | 510 | * @offset: offset to beginning of data within component device |
| 511 | * | 511 | * |
| 512 | * Description: | 512 | * Description: |
| 513 | * Merges two queue_limit structs. Returns 0 if alignment didn't | 513 | * This function is used by stacking drivers like MD and DM to ensure |
| 514 | * change. Returns -1 if adding the bottom device caused | 514 | * that all component devices have compatible block sizes and |
| 515 | * misalignment. | 515 | * alignments. The stacking driver must provide a queue_limits |
| 516 | * struct (top) and then iteratively call the stacking function for | ||
| 517 | * all component (bottom) devices. The stacking function will | ||
| 518 | * attempt to combine the values and ensure proper alignment. | ||
| 519 | * | ||
| 520 | * Returns 0 if the top and bottom queue_limits are compatible. The | ||
| 521 | * top device's block sizes and alignment offsets may be adjusted to | ||
| 522 | * ensure alignment with the bottom device. If no compatible sizes | ||
| 523 | * and alignments exist, -1 is returned and the resulting top | ||
| 524 | * queue_limits will have the misaligned flag set to indicate that | ||
| 525 | * the alignment_offset is undefined. | ||
| 516 | */ | 526 | */ |
| 517 | int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | 527 | int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
| 518 | sector_t offset) | 528 | sector_t offset) |
| 519 | { | 529 | { |
| 520 | int ret; | 530 | sector_t alignment; |
| 521 | 531 | unsigned int top, bottom; | |
| 522 | ret = 0; | ||
| 523 | 532 | ||
| 524 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); | 533 | t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); |
| 525 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); | 534 | t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); |
| @@ -537,6 +546,22 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
| 537 | t->max_segment_size = min_not_zero(t->max_segment_size, | 546 | t->max_segment_size = min_not_zero(t->max_segment_size, |
| 538 | b->max_segment_size); | 547 | b->max_segment_size); |
| 539 | 548 | ||
| 549 | alignment = queue_limit_alignment_offset(b, offset); | ||
| 550 | |||
| 551 | /* Bottom device has different alignment. Check that it is | ||
| 552 | * compatible with the current top alignment. | ||
| 553 | */ | ||
| 554 | if (t->alignment_offset != alignment) { | ||
| 555 | |||
| 556 | top = max(t->physical_block_size, t->io_min) | ||
| 557 | + t->alignment_offset; | ||
| 558 | bottom = max(b->physical_block_size, b->io_min) + alignment; | ||
| 559 | |||
| 560 | /* Verify that top and bottom intervals line up */ | ||
| 561 | if (max(top, bottom) & (min(top, bottom) - 1)) | ||
| 562 | t->misaligned = 1; | ||
| 563 | } | ||
| 564 | |||
| 540 | t->logical_block_size = max(t->logical_block_size, | 565 | t->logical_block_size = max(t->logical_block_size, |
| 541 | b->logical_block_size); | 566 | b->logical_block_size); |
| 542 | 567 | ||
| @@ -544,54 +569,64 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
| 544 | b->physical_block_size); | 569 | b->physical_block_size); |
| 545 | 570 | ||
| 546 | t->io_min = max(t->io_min, b->io_min); | 571 | t->io_min = max(t->io_min, b->io_min); |
| 572 | t->io_opt = lcm(t->io_opt, b->io_opt); | ||
| 573 | |||
| 547 | t->no_cluster |= b->no_cluster; | 574 | t->no_cluster |= b->no_cluster; |
| 548 | t->discard_zeroes_data &= b->discard_zeroes_data; | 575 | t->discard_zeroes_data &= b->discard_zeroes_data; |
| 549 | 576 | ||
| 550 | /* Bottom device offset aligned? */ | 577 | /* Physical block size a multiple of the logical block size? */ |
| 551 | if (offset && | 578 | if (t->physical_block_size & (t->logical_block_size - 1)) { |
| 552 | (offset & (b->physical_block_size - 1)) != b->alignment_offset) { | 579 | t->physical_block_size = t->logical_block_size; |
| 553 | t->misaligned = 1; | 580 | t->misaligned = 1; |
| 554 | ret = -1; | ||
| 555 | } | 581 | } |
| 556 | 582 | ||
| 557 | /* | 583 | /* Minimum I/O a multiple of the physical block size? */ |
| 558 | * Temporarily disable discard granularity. It's currently buggy | 584 | if (t->io_min & (t->physical_block_size - 1)) { |
| 559 | * since we default to 0 for discard_granularity, hence this | 585 | t->io_min = t->physical_block_size; |
| 560 | * "failure" will always trigger for non-zero offsets. | 586 | t->misaligned = 1; |
| 561 | */ | ||
| 562 | #if 0 | ||
| 563 | if (offset && | ||
| 564 | (offset & (b->discard_granularity - 1)) != b->discard_alignment) { | ||
| 565 | t->discard_misaligned = 1; | ||
| 566 | ret = -1; | ||
| 567 | } | 587 | } |
| 568 | #endif | ||
| 569 | |||
| 570 | /* If top has no alignment offset, inherit from bottom */ | ||
| 571 | if (!t->alignment_offset) | ||
| 572 | t->alignment_offset = | ||
| 573 | b->alignment_offset & (b->physical_block_size - 1); | ||
| 574 | 588 | ||
| 575 | if (!t->discard_alignment) | 589 | /* Optimal I/O a multiple of the physical block size? */ |
| 576 | t->discard_alignment = | 590 | if (t->io_opt & (t->physical_block_size - 1)) { |
| 577 | b->discard_alignment & (b->discard_granularity - 1); | 591 | t->io_opt = 0; |
| 578 | |||
| 579 | /* Top device aligned on logical block boundary? */ | ||
| 580 | if (t->alignment_offset & (t->logical_block_size - 1)) { | ||
| 581 | t->misaligned = 1; | 592 | t->misaligned = 1; |
| 582 | ret = -1; | ||
| 583 | } | 593 | } |
| 584 | 594 | ||
| 585 | /* Find lcm() of optimal I/O size and granularity */ | 595 | /* Find lowest common alignment_offset */ |
| 586 | t->io_opt = lcm(t->io_opt, b->io_opt); | 596 | t->alignment_offset = lcm(t->alignment_offset, alignment) |
| 587 | t->discard_granularity = lcm(t->discard_granularity, | 597 | & (max(t->physical_block_size, t->io_min) - 1); |
| 588 | b->discard_granularity); | ||
| 589 | 598 | ||
| 590 | /* Verify that optimal I/O size is a multiple of io_min */ | 599 | /* Verify that new alignment_offset is on a logical block boundary */ |
| 591 | if (t->io_min && t->io_opt % t->io_min) | 600 | if (t->alignment_offset & (t->logical_block_size - 1)) |
| 592 | ret = -1; | 601 | t->misaligned = 1; |
| 602 | |||
| 603 | /* Discard alignment and granularity */ | ||
| 604 | if (b->discard_granularity) { | ||
| 605 | unsigned int granularity = b->discard_granularity; | ||
| 606 | offset &= granularity - 1; | ||
| 607 | |||
| 608 | alignment = (granularity + b->discard_alignment - offset) | ||
| 609 | & (granularity - 1); | ||
| 610 | |||
| 611 | if (t->discard_granularity != 0 && | ||
| 612 | t->discard_alignment != alignment) { | ||
| 613 | top = t->discard_granularity + t->discard_alignment; | ||
| 614 | bottom = b->discard_granularity + alignment; | ||
| 615 | |||
| 616 | /* Verify that top and bottom intervals line up */ | ||
| 617 | if (max(top, bottom) & (min(top, bottom) - 1)) | ||
| 618 | t->discard_misaligned = 1; | ||
| 619 | } | ||
| 620 | |||
| 621 | t->max_discard_sectors = min_not_zero(t->max_discard_sectors, | ||
| 622 | b->max_discard_sectors); | ||
| 623 | t->discard_granularity = max(t->discard_granularity, | ||
| 624 | b->discard_granularity); | ||
| 625 | t->discard_alignment = lcm(t->discard_alignment, alignment) & | ||
| 626 | (t->discard_granularity - 1); | ||
| 627 | } | ||
| 593 | 628 | ||
| 594 | return ret; | 629 | return t->misaligned ? -1 : 0; |
| 595 | } | 630 | } |
| 596 | EXPORT_SYMBOL(blk_stack_limits); | 631 | EXPORT_SYMBOL(blk_stack_limits); |
| 597 | 632 | ||
