From: Tom Yan <tom.ty89@xxxxxxxxx> Since discard_max_bytes has been adjustable by user, one might would like to apply granularity in its value that the SSD has but is not able to report (e.g. SATA SSD). By making sure the maximum bi_size is a multiple of the discard_max_bytes set, user can then expect identical behaviour of the `--step` option of `blkdiscard` from discard_max_bytes. Signed-off-by: Tom Yan <tom.ty89@xxxxxxxxx> diff --git a/block/blk-lib.c b/block/blk-lib.c index 9ebf653..3430508 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -43,7 +43,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, DECLARE_COMPLETION_ONSTACK(wait); struct request_queue *q = bdev_get_queue(bdev); int type = REQ_WRITE | REQ_DISCARD; - unsigned int granularity; + unsigned int max_discard_sectors, granularity; int alignment; struct bio_batch bb; struct bio *bio; @@ -82,7 +82,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, } /* Make sure bi_size doesn't overflow */ - req_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9); + max_discard_sectors = UINT_MAX >> 9; + + /* Make sure bi_size aligns to discard_max_bytes */ + max_discard_sectors -= max_discard_sectors % q->limits.max_discard_sectors; + + req_sects = min_t(sector_t, nr_sects, max_discard_sectors); /* * If splitting a request, and the next starting sector would be -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html