diff options
author | Shaohua Li <shli@kernel.org> | 2012-12-13 22:15:36 -0500 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2012-12-14 14:46:04 -0500 |
commit | 8dd2cb7e880d2f77fba53b523c99133ad5054cfd (patch) | |
tree | ea51e89f8c8bf9ca8e888d68ecf6732a52e8e99d /include/linux/blkdev.h | |
parent | 75274551c81796b636c5acb0c2597dec7ec2e6c4 (diff) |
block: discard granularity might not be power of 2
In MD raid case, discard granularity might not be power of 2, for example, a
4-disk raid5 has 3*chunk_size discard granularity. Correct the calculation for
such cases.
Reported-by: Neil Brown <neilb@suse.de>
Signed-off-by: Shaohua Li <shli@fusionio.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blkdev.h')
-rw-r--r-- | include/linux/blkdev.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c9d233e727f2..acb4f7bbbd32 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h | |||
@@ -1188,13 +1188,14 @@ static inline int queue_discard_alignment(struct request_queue *q) | |||
1188 | 1188 | ||
1189 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) | 1189 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
1190 | { | 1190 | { |
1191 | unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1); | 1191 | sector_t alignment = sector << 9; |
1192 | alignment = sector_div(alignment, lim->discard_granularity); | ||
1192 | 1193 | ||
1193 | if (!lim->max_discard_sectors) | 1194 | if (!lim->max_discard_sectors) |
1194 | return 0; | 1195 | return 0; |
1195 | 1196 | ||
1196 | return (lim->discard_granularity + lim->discard_alignment - alignment) | 1197 | alignment = lim->discard_granularity + lim->discard_alignment - alignment; |
1197 | & (lim->discard_granularity - 1); | 1198 | return sector_div(alignment, lim->discard_granularity); |
1198 | } | 1199 | } |
1199 | 1200 | ||
1200 | static inline int bdev_discard_alignment(struct block_device *bdev) | 1201 | static inline int bdev_discard_alignment(struct block_device *bdev) |