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.
Showing the changes to include/linux/blkdev.h (1 of 2 files). Show all
Unified · Split
| @@ -1063,11 +1063,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, · 1062 unmodified lines | ||
| 1063 | 1063 | static inline unsigned int blk_max_size_offset(struct request_queue *q, |
| 1064 | 1064 | sector_t offset) |
| 1065 | 1065 | { |
| 1066 | − if (!q->limits.chunk_sectors) | |
| 1066 | + unsigned int chunk_sectors = q->limits.chunk_sectors; | |
| 1067 | + | |
| 1068 | + if (!chunk_sectors) | |
| 1067 | 1069 | return q->limits.max_sectors; |
| 1068 | 1070 | |
| 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); | |
| 1071 | 1077 | } |
| 1072 | 1078 | |
| 1073 | 1079 | static inline unsigned int blk_rq_get_max_sectors(struct request *rq, |