aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin K. Petersen <martin.petersen@oracle.com>2010-01-11 03:21:48 -0500
committerJens Axboe <jens.axboe@oracle.com>2010-01-11 08:29:19 -0500
commitdd3d145d49c5816b79acc6761ebbd842bc50b0ee (patch)
tree107bdb2f46c6aa6bc482909d7ebdbb1da40b7b4f
parentfe0b393f2c0a0d23a9bc9ed7dc51a1ee511098bd (diff)
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: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--block/genhd.c2
-rw-r--r--include/linux/blkdev.h7
2 files changed, 6 insertions, 3 deletions
diff --git a/block/genhd.c b/block/genhd.c
index b11a4ad7d571..d13ba76a169c 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -867,7 +867,7 @@ static ssize_t disk_discard_alignment_show(struct device *dev,
867{ 867{
868 struct gendisk *disk = dev_to_disk(dev); 868 struct gendisk *disk = dev_to_disk(dev);
869 869
870 return sprintf(buf, "%u\n", queue_discard_alignment(disk->queue)); 870 return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue));
871} 871}
872 872
873static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); 873static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9b98173a8184..a41bcc8e140f 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1148,8 +1148,11 @@ static inline int queue_discard_alignment(struct request_queue *q)
1148static inline int queue_sector_discard_alignment(struct request_queue *q, 1148static inline int queue_sector_discard_alignment(struct request_queue *q,
1149 sector_t sector) 1149 sector_t sector)
1150{ 1150{
1151 return ((sector << 9) - q->limits.discard_alignment) 1151 struct queue_limits *lim = &q->limits;
1152 & (q->limits.discard_granularity - 1); 1152 unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);
1153
1154 return (lim->discard_granularity + lim->discard_alignment - alignment)
1155 & (lim->discard_granularity - 1);
1153} 1156}
1154 1157
1155static inline unsigned int queue_discard_zeroes_data(struct request_queue *q) 1158static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)