From: Luke Wang Secure erase should use max_secure_erase_sectors instead of being limited by max_discard_sectors. Separate the handling of REQ_OP_SECURE_ERASE from REQ_OP_DISCARD to allow each operation to use its own size limit. Signed-off-by: Luke Wang --- block/blk-merge.c | 9 +++++++-- block/blk.h | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index d3115d7469df..0885e4b982ed 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -169,8 +169,13 @@ struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim, granularity = max(lim->discard_granularity >> 9, 1U); - max_discard_sectors = - min(lim->max_discard_sectors, bio_allowed_max_sectors(lim)); + if (bio_op(bio) == REQ_OP_SECURE_ERASE) + max_discard_sectors = min(lim->max_secure_erase_sectors, + bio_allowed_max_sectors(lim)); + else + max_discard_sectors = min(lim->max_discard_sectors, + bio_allowed_max_sectors(lim)); + max_discard_sectors -= max_discard_sectors % granularity; if (unlikely(!max_discard_sectors)) return bio; diff --git a/block/blk.h b/block/blk.h index e4c433f62dfc..4cd5a91346d8 100644 --- a/block/blk.h +++ b/block/blk.h @@ -208,10 +208,14 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq) struct request_queue *q = rq->q; enum req_op op = req_op(rq); - if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) + if (unlikely(op == REQ_OP_DISCARD)) return min(q->limits.max_discard_sectors, UINT_MAX >> SECTOR_SHIFT); + if (unlikely(op == REQ_OP_SECURE_ERASE)) + return min(q->limits.max_secure_erase_sectors, + UINT_MAX >> SECTOR_SHIFT); + if (unlikely(op == REQ_OP_WRITE_ZEROES)) return q->limits.max_write_zeroes_sectors; -- 2.34.1