Skip to content

Commit 07d098e

Browse files
snitmaxboe
authored andcommitted
block: allow 'chunk_sectors' to be non-power-of-2
It is possible, albeit more unlikely, for a block device to have a non power-of-2 for chunk_sectors (e.g. 10+2 RAID6 with 128K chunk_sectors, which results in a full-stripe size of 1280K. This causes the RAID6's io_opt to be advertised as 1280K, and a stacked device _could_ then be made to use a blocksize, aka chunk_sectors, that matches non power-of-2 io_opt of underlying RAID6 -- resulting in stacked device's chunk_sectors being a non power-of-2). Update blk_queue_chunk_sectors() and blk_max_size_offset() to accommodate drivers that need a non power-of-2 chunk_sectors. Reviewed-by: Ming Lei <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 22ada80 commit 07d098e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

block/blk-settings.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,13 @@ EXPORT_SYMBOL(blk_queue_max_hw_sectors);
172172
*
173173
* Description:
174174
* If a driver doesn't want IOs to cross a given chunk size, it can set
175-
* this limit and prevent merging across chunks. Note that the chunk size
176-
* must currently be a power-of-2 in sectors. Also note that the block
177-
* layer must accept a page worth of data at any offset. So if the
178-
* crossing of chunks is a hard limitation in the driver, it must still be
179-
* prepared to split single page bios.
175+
* this limit and prevent merging across chunks. Note that the block layer
176+
* must accept a page worth of data at any offset. So if the crossing of
177+
* chunks is a hard limitation in the driver, it must still be prepared
178+
* to split single page bios.
180179
**/
181180
void blk_queue_chunk_sectors(struct request_queue *q, unsigned int chunk_sectors)
182181
{
183-
BUG_ON(!is_power_of_2(chunk_sectors));
184182
q->limits.chunk_sectors = chunk_sectors;
185183
}
186184
EXPORT_SYMBOL(blk_queue_chunk_sectors);

include/linux/blkdev.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
10631063
static inline unsigned int blk_max_size_offset(struct request_queue *q,
10641064
sector_t offset)
10651065
{
1066-
if (!q->limits.chunk_sectors)
1066+
unsigned int chunk_sectors = q->limits.chunk_sectors;
1067+
1068+
if (!chunk_sectors)
10671069
return q->limits.max_sectors;
10681070

1069-
return min(q->limits.max_sectors, (unsigned int)(q->limits.chunk_sectors -
1070-
(offset & (q->limits.chunk_sectors - 1))));
1071+
if (likely(is_power_of_2(chunk_sectors)))
1072+
chunk_sectors -= offset & (chunk_sectors - 1);
1073+
else
1074+
chunk_sectors -= sector_div(offset, chunk_sectors);
1075+
1076+
return min(q->limits.max_sectors, chunk_sectors);
10711077
}
10721078

10731079
static inline unsigned int blk_rq_get_max_sectors(struct request *rq,

0 commit comments

Comments
 (0)