[PATCH 05/15] block: add a max_user_discard_sectors queue limit
Keith Busch
kbusch at kernel.org
Mon Jan 22 10:27:15 PST 2024
On Mon, Jan 22, 2024 at 06:36:35PM +0100, Christoph Hellwig wrote:
> @@ -174,23 +174,23 @@ 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_not_zero(q->limits.max_hw_discard_sectors,
> + q->limits.max_user_discard_sectors);
Shouldn't writing 0 disable discards?
More information about the Linux-nvme
mailing list