summaryrefslogtreecommitdiff
path: root/block/blk-sysfs.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2024-02-13 08:34:16 +0100
committerJens Axboe <axboe@kernel.dk>2024-02-13 08:56:59 -0700
commit4f563a64732dabb2677c7d1232a8f714a18b41b3 (patch)
tree5b697ef500875bf3bf7776dba05c14cebbb48590 /block/blk-sysfs.c
parent0327ca9d53bfbb0918867313049bba7046900f73 (diff)
block: add a max_user_discard_sectors queue limit
Add a new max_user_discard_sectors limit that mirrors max_user_sectors and stores the value that the user manually set. This now allows updates of the max_hw_discard_sectors to not worry about the user limit. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240213073425.1621680-7-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-sysfs.c')
-rw-r--r--block/blk-sysfs.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 26607f9825cb..a1ec27f0ba41 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -174,23 +174,22 @@ static ssize_t queue_discard_max_show(struct request_queue *q, char *page)
static ssize_t queue_discard_max_store(struct request_queue *q,
const char *page, size_t count)
{
- unsigned long max_discard;
- ssize_t ret = queue_var_store(&max_discard, page, count);
+ unsigned long max_discard_bytes;
+ ssize_t ret;
+ ret = queue_var_store(&max_discard_bytes, page, count);
if (ret < 0)
return ret;
- if (max_discard & (q->limits.discard_granularity - 1))
+ if (max_discard_bytes & (q->limits.discard_granularity - 1))
return -EINVAL;
- max_discard >>= 9;
- if (max_discard > UINT_MAX)
+ if ((max_discard_bytes >> SECTOR_SHIFT) > UINT_MAX)
return -EINVAL;
- if (max_discard > q->limits.max_hw_discard_sectors)
- max_discard = q->limits.max_hw_discard_sectors;
-
- q->limits.max_discard_sectors = max_discard;
+ q->limits.max_user_discard_sectors = max_discard_bytes >> SECTOR_SHIFT;
+ q->limits.max_discard_sectors = min(q->limits.max_hw_discard_sectors,
+ q->limits.max_user_discard_sectors);
return ret;
}