Skip to content

Commit fe0b393

Browse files
martinkpetersenJens Axboe
authored andcommitted
block: Correct handling of bottom device misaligment
The top device misalignment flag would not be set if the added bottom device was already misaligned as opposed to causing a stacking failure. Also massage the reporting so that an error is only returned if adding the bottom device caused the misalignment. I.e. don't return an error if the top is already flagged as misaligned. Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c115294 commit fe0b393

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

block/blk-settings.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
528528
sector_t offset)
529529
{
530530
sector_t alignment;
531-
unsigned int top, bottom;
531+
unsigned int top, bottom, ret = 0;
532532

533533
t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
534534
t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
@@ -546,6 +546,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
546546
t->max_segment_size = min_not_zero(t->max_segment_size,
547547
b->max_segment_size);
548548

549+
t->misaligned |= b->misaligned;
550+
549551
alignment = queue_limit_alignment_offset(b, offset);
550552

551553
/* Bottom device has different alignment. Check that it is
@@ -558,8 +560,10 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
558560
bottom = max(b->physical_block_size, b->io_min) + alignment;
559561

560562
/* Verify that top and bottom intervals line up */
561-
if (max(top, bottom) & (min(top, bottom) - 1))
563+
if (max(top, bottom) & (min(top, bottom) - 1)) {
562564
t->misaligned = 1;
565+
ret = -1;
566+
}
563567
}
564568

565569
t->logical_block_size = max(t->logical_block_size,
@@ -578,27 +582,32 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
578582
if (t->physical_block_size & (t->logical_block_size - 1)) {
579583
t->physical_block_size = t->logical_block_size;
580584
t->misaligned = 1;
585+
ret = -1;
581586
}
582587

583588
/* Minimum I/O a multiple of the physical block size? */
584589
if (t->io_min & (t->physical_block_size - 1)) {
585590
t->io_min = t->physical_block_size;
586591
t->misaligned = 1;
592+
ret = -1;
587593
}
588594

589595
/* Optimal I/O a multiple of the physical block size? */
590596
if (t->io_opt & (t->physical_block_size - 1)) {
591597
t->io_opt = 0;
592598
t->misaligned = 1;
599+
ret = -1;
593600
}
594601

595602
/* Find lowest common alignment_offset */
596603
t->alignment_offset = lcm(t->alignment_offset, alignment)
597604
& (max(t->physical_block_size, t->io_min) - 1);
598605

599606
/* Verify that new alignment_offset is on a logical block boundary */
600-
if (t->alignment_offset & (t->logical_block_size - 1))
607+
if (t->alignment_offset & (t->logical_block_size - 1)) {
601608
t->misaligned = 1;
609+
ret = -1;
610+
}
602611

603612
/* Discard alignment and granularity */
604613
if (b->discard_granularity) {
@@ -626,7 +635,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
626635
(t->discard_granularity - 1);
627636
}
628637

629-
return t->misaligned ? -1 : 0;
638+
return ret;
630639
}
631640
EXPORT_SYMBOL(blk_stack_limits);
632641

0 commit comments

Comments
 (0)