Commit dd3d145d authored by Martin K. Petersen's avatar Martin K. Petersen Committed by Jens Axboe

block: Fix discard alignment calculation and printing

Discard alignment reporting for partitions was incorrect.  Update to
match the algorithm used elsewhere.

The alignment can be negative (misaligned).  Fix format string
accordingly.
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent fe0b393f
...@@ -867,7 +867,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev, ...@@ -867,7 +867,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev,
{ {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
return sprintf(buf, "%u\n", queue_discard_alignment(disk->queue)); return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue));
} }
static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
......
...@@ -1148,8 +1148,11 @@ static inline int queue_discard_alignment(struct request_queue *q) ...@@ -1148,8 +1148,11 @@ static inline int queue_discard_alignment(struct request_queue *q)
static inline int queue_sector_discard_alignment(struct request_queue *q, static inline int queue_sector_discard_alignment(struct request_queue *q,
sector_t sector) sector_t sector)
{ {
return ((sector << 9) - q->limits.discard_alignment) struct queue_limits *lim = &q->limits;
& (q->limits.discard_granularity - 1); unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);
return (lim->discard_granularity + lim->discard_alignment - alignment)
& (lim->discard_granularity - 1);
} }
static inline unsigned int queue_discard_zeroes_data(struct request_queue *q) static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment