summaryrefslogtreecommitdiff
path: root/block/elevator.c
diff options
context:
space:
mode:
authorNilay Shroff <nilay@linux.ibm.com>2025-03-04 13:22:31 +0300
committerJens Axboe <axboe@kernel.dk>2025-03-10 16:30:18 +0300
commitb07a889e833555735ce72ca4a6d39f4c2ca725ba (patch)
tree2a7e7fa712a2b4fdc83c5d36bea2505c2cef9b14 /block/elevator.c
parent6e51a1279cd60cb93e3379ff140d8fa6c39ecf20 (diff)
downloadlinux-b07a889e833555735ce72ca4a6d39f4c2ca725ba.tar.xz
block: move q->sysfs_lock and queue-freeze under show/store method
In preparation to further simplify and group sysfs attributes which don't require locking or require some form of locking other than q-> limits_lock, move acquire/release of q->sysfs_lock and queue freeze/ unfreeze under each attributes' respective show/store method. While we are at it, also remove ->load_module() as it's used to load the module before queue is freezed. Now as we moved queue-freeze under ->store(), we could load module directly from the attributes' store method before we actually start freezing the queue. Currently, the ->load_module() is only used by "scheduler" attribute, so we now load the relevant elevator module before we start freezing the queue in elv_iosched_store(). Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Nilay Shroff <nilay@linux.ibm.com> Link: https://lore.kernel.org/r/20250304102551.2533767-3-nilay@linux.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/elevator.c')
-rw-r--r--block/elevator.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/block/elevator.c b/block/elevator.c
index cd2ce4921601..041f1d983bc7 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -723,11 +723,24 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
{
char elevator_name[ELV_NAME_MAX];
int ret;
+ unsigned int memflags;
+ struct request_queue *q = disk->queue;
+ /*
+ * If the attribute needs to load a module, do it before freezing the
+ * queue to ensure that the module file can be read when the request
+ * queue is the one for the device storing the module file.
+ */
+ elv_iosched_load_module(disk, buf, count);
strscpy(elevator_name, buf, sizeof(elevator_name));
- ret = elevator_change(disk->queue, strstrip(elevator_name));
+
+ mutex_lock(&q->sysfs_lock);
+ memflags = blk_mq_freeze_queue(q);
+ ret = elevator_change(q, strstrip(elevator_name));
if (!ret)
- return count;
+ ret = count;
+ blk_mq_unfreeze_queue(q, memflags);
+ mutex_unlock(&q->sysfs_lock);
return ret;
}
@@ -738,6 +751,7 @@ ssize_t elv_iosched_show(struct gendisk *disk, char *name)
struct elevator_type *cur = NULL, *e;
int len = 0;
+ mutex_lock(&q->sysfs_lock);
if (!q->elevator) {
len += sprintf(name+len, "[none] ");
} else {
@@ -755,6 +769,8 @@ ssize_t elv_iosched_show(struct gendisk *disk, char *name)
spin_unlock(&elv_list_lock);
len += sprintf(name+len, "\n");
+ mutex_unlock(&q->sysfs_lock);
+
return len;
}