History

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.

Mike Snitzer committed 6 years ago

Commit 07d098e1 parent 22ada802 files · +13 −9Browse files

Showing the changes to include/linux/blkdev.h (1 of 2 files). Show all

Unified · Split

include/linux/blkdev.h+9−3
@@ -1063,11 +1063,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, · 1062 unmodified lines
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,