]> www.infradead.org Git - nvme.git/commitdiff
block: get rid of request queue ->sysfs_dir_lock
authorNilay Shroff <nilay@linux.ibm.com>
Tue, 28 Jan 2025 14:34:13 +0000 (20:04 +0530)
committerJens Axboe <axboe@kernel.dk>
Wed, 29 Jan 2025 14:16:47 +0000 (07:16 -0700)
The request queue uses ->sysfs_dir_lock for protecting the addition/
deletion of kobject entries under sysfs while we register/unregister
blk-mq. However kobject addition/deletion is already protected with
kernfs/sysfs internal synchronization primitives. So use of q->sysfs_
dir_lock seems redundant.

Moreover, q->sysfs_dir_lock is also used at few other callsites along
with q->sysfs_lock for protecting the addition/deletion of kojects.
One such example is when we register with sysfs a set of independent
access ranges for a disk. Here as well we could get rid off q->sysfs_
dir_lock and only use q->sysfs_lock.

The only variable which q->sysfs_dir_lock appears to protect is q->
mq_sysfs_init_done which is set/unset while registering/unregistering
blk-mq with sysfs. But use of q->mq_sysfs_init_done could be easily
replaced using queue registered bit QUEUE_FLAG_REGISTERED.

So with this patch we remove q->sysfs_dir_lock from each callsite
and replace q->mq_sysfs_init_done using QUEUE_FLAG_REGISTERED.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20250128143436.874357-2-nilay@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
block/blk-ia-ranges.c
block/blk-mq-sysfs.c
block/blk-sysfs.c
include/linux/blkdev.h

index 32fb28a6372cdf62dc5b842a97e89fe164049889..d6c4fa3943b5cf88b9aa0c17e7fca08268d0d735 100644 (file)
@@ -430,7 +430,6 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
        refcount_set(&q->refs, 1);
        mutex_init(&q->debugfs_mutex);
        mutex_init(&q->sysfs_lock);
-       mutex_init(&q->sysfs_dir_lock);
        mutex_init(&q->limits_lock);
        mutex_init(&q->rq_qos_mutex);
        spin_lock_init(&q->queue_lock);
index c9eb4241e048390c814b4e9ceba5ae035de07a60..d479f5481b66a14c15effbdaf0fd3a7c42f3b7c0 100644 (file)
@@ -111,7 +111,6 @@ int disk_register_independent_access_ranges(struct gendisk *disk)
        struct request_queue *q = disk->queue;
        int i, ret;
 
-       lockdep_assert_held(&q->sysfs_dir_lock);
        lockdep_assert_held(&q->sysfs_lock);
 
        if (!iars)
@@ -155,7 +154,6 @@ void disk_unregister_independent_access_ranges(struct gendisk *disk)
        struct blk_independent_access_ranges *iars = disk->ia_ranges;
        int i;
 
-       lockdep_assert_held(&q->sysfs_dir_lock);
        lockdep_assert_held(&q->sysfs_lock);
 
        if (!iars)
@@ -289,7 +287,6 @@ void disk_set_independent_access_ranges(struct gendisk *disk,
 {
        struct request_queue *q = disk->queue;
 
-       mutex_lock(&q->sysfs_dir_lock);
        mutex_lock(&q->sysfs_lock);
        if (iars && !disk_check_ia_ranges(disk, iars)) {
                kfree(iars);
@@ -313,6 +310,5 @@ void disk_set_independent_access_ranges(struct gendisk *disk,
                disk_register_independent_access_ranges(disk);
 unlock:
        mutex_unlock(&q->sysfs_lock);
-       mutex_unlock(&q->sysfs_dir_lock);
 }
 EXPORT_SYMBOL_GPL(disk_set_independent_access_ranges);
index 156e9bb07abf1a4801f35f7197674b723155a5d8..6113328abd7084ee8c93f2e08cd7ea9e6a28e331 100644 (file)
@@ -223,8 +223,6 @@ int blk_mq_sysfs_register(struct gendisk *disk)
        unsigned long i, j;
        int ret;
 
-       lockdep_assert_held(&q->sysfs_dir_lock);
-
        ret = kobject_add(q->mq_kobj, &disk_to_dev(disk)->kobj, "mq");
        if (ret < 0)
                goto out;
@@ -237,7 +235,6 @@ int blk_mq_sysfs_register(struct gendisk *disk)
                        goto unreg;
        }
 
-       q->mq_sysfs_init_done = true;
 
 out:
        return ret;
@@ -259,15 +256,12 @@ void blk_mq_sysfs_unregister(struct gendisk *disk)
        struct blk_mq_hw_ctx *hctx;
        unsigned long i;
 
-       lockdep_assert_held(&q->sysfs_dir_lock);
 
        queue_for_each_hw_ctx(q, hctx, i)
                blk_mq_unregister_hctx(hctx);
 
        kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
        kobject_del(q->mq_kobj);
-
-       q->mq_sysfs_init_done = false;
 }
 
 void blk_mq_sysfs_unregister_hctxs(struct request_queue *q)
@@ -275,15 +269,11 @@ void blk_mq_sysfs_unregister_hctxs(struct request_queue *q)
        struct blk_mq_hw_ctx *hctx;
        unsigned long i;
 
-       mutex_lock(&q->sysfs_dir_lock);
-       if (!q->mq_sysfs_init_done)
-               goto unlock;
+       if (!blk_queue_registered(q))
+               return;
 
        queue_for_each_hw_ctx(q, hctx, i)
                blk_mq_unregister_hctx(hctx);
-
-unlock:
-       mutex_unlock(&q->sysfs_dir_lock);
 }
 
 int blk_mq_sysfs_register_hctxs(struct request_queue *q)
@@ -292,9 +282,8 @@ int blk_mq_sysfs_register_hctxs(struct request_queue *q)
        unsigned long i;
        int ret = 0;
 
-       mutex_lock(&q->sysfs_dir_lock);
-       if (!q->mq_sysfs_init_done)
-               goto unlock;
+       if (!blk_queue_registered(q))
+               goto out;
 
        queue_for_each_hw_ctx(q, hctx, i) {
                ret = blk_mq_register_hctx(hctx);
@@ -302,8 +291,6 @@ int blk_mq_sysfs_register_hctxs(struct request_queue *q)
                        break;
        }
 
-unlock:
-       mutex_unlock(&q->sysfs_dir_lock);
-
+out:
        return ret;
 }
index e09b455874bfd632fff1a60bd3737e1bf9e6a76c..7b970e6765e72a64bd4e2815fb40d54ebae1b857 100644 (file)
@@ -764,7 +764,6 @@ int blk_register_queue(struct gendisk *disk)
        struct request_queue *q = disk->queue;
        int ret;
 
-       mutex_lock(&q->sysfs_dir_lock);
        kobject_init(&disk->queue_kobj, &blk_queue_ktype);
        ret = kobject_add(&disk->queue_kobj, &disk_to_dev(disk)->kobj, "queue");
        if (ret < 0)
@@ -805,7 +804,6 @@ int blk_register_queue(struct gendisk *disk)
        if (q->elevator)
                kobject_uevent(&q->elevator->kobj, KOBJ_ADD);
        mutex_unlock(&q->sysfs_lock);
-       mutex_unlock(&q->sysfs_dir_lock);
 
        /*
         * SCSI probing may synchronously create and destroy a lot of
@@ -830,7 +828,6 @@ out_debugfs_remove:
        mutex_unlock(&q->sysfs_lock);
 out_put_queue_kobj:
        kobject_put(&disk->queue_kobj);
-       mutex_unlock(&q->sysfs_dir_lock);
        return ret;
 }
 
@@ -861,7 +858,6 @@ void blk_unregister_queue(struct gendisk *disk)
        blk_queue_flag_clear(QUEUE_FLAG_REGISTERED, q);
        mutex_unlock(&q->sysfs_lock);
 
-       mutex_lock(&q->sysfs_dir_lock);
        /*
         * Remove the sysfs attributes before unregistering the queue data
         * structures that can be modified through sysfs.
@@ -878,7 +874,6 @@ void blk_unregister_queue(struct gendisk *disk)
        /* Now that we've deleted all child objects, we can delete the queue. */
        kobject_uevent(&disk->queue_kobj, KOBJ_REMOVE);
        kobject_del(&disk->queue_kobj);
-       mutex_unlock(&q->sysfs_dir_lock);
 
        blk_debugfs_remove(disk);
 }
index 76f0a4e7c2e5d7b3ca922e0d0ea9ceb79cba8ee9..248416ecd01c972f271c46a1a51350099c6357e6 100644 (file)
@@ -561,7 +561,6 @@ struct request_queue {
        struct list_head        flush_list;
 
        struct mutex            sysfs_lock;
-       struct mutex            sysfs_dir_lock;
        struct mutex            limits_lock;
 
        /*
@@ -605,8 +604,6 @@ struct request_queue {
         * Serializes all debugfs metadata operations using the above dentries.
         */
        struct mutex            debugfs_mutex;
-
-       bool                    mq_sysfs_init_done;
 };
 
 /* Keep blk_queue_flag_name[] in sync with the definitions below */