block: add an API to atomically update queue limits

Add a new queue_limits_{start,commit}_update pair of functions that
allows taking an atomic snapshot of queue limits, update it, and
commit it if it passes validity checking.  Also use the low-level
validation helper to implement blk_set_default_limits instead of
duplicating the initialization.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20240213073425.1621680-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig
2024-02-13 08:34:14 +01:00
committed by Jens Axboe
parent c490f226a0
commit d690cb8ae1
4 changed files with 217 additions and 37 deletions

View File

@@ -474,6 +474,7 @@ struct request_queue {
struct mutex sysfs_lock;
struct mutex sysfs_dir_lock;
struct mutex limits_lock;
/*
* for reusing dead hctx instance in case of updating
@@ -862,6 +863,28 @@ static inline unsigned int blk_chunk_sectors_left(sector_t offset,
return chunk_sectors - (offset & (chunk_sectors - 1));
}
/**
* queue_limits_start_update - start an atomic update of queue limits
* @q: queue to update
*
* This functions starts an atomic update of the queue limits. It takes a lock
* to prevent other updates and returns a snapshot of the current limits that
* the caller can modify. The caller must call queue_limits_commit_update()
* to finish the update.
*
* Context: process context. The caller must have frozen the queue or ensured
* that there is outstanding I/O by other means.
*/
static inline struct queue_limits
queue_limits_start_update(struct request_queue *q)
__acquires(q->limits_lock)
{
mutex_lock(&q->limits_lock);
return q->limits;
}
int queue_limits_commit_update(struct request_queue *q,
struct queue_limits *lim);
/*
* Access functions for manipulating queue properties
*/