Skip to content

Commit fe66286

Browse files
shroffniaxboe
authored andcommitted
block: get rid of request queue ->sysfs_dir_lock
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>
1 parent 5aa21b0 commit fe66286

File tree

5 files changed

+5
-31
lines changed

5 files changed

+5
-31
lines changed

block/blk-core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
430430
refcount_set(&q->refs, 1);
431431
mutex_init(&q->debugfs_mutex);
432432
mutex_init(&q->sysfs_lock);
433-
mutex_init(&q->sysfs_dir_lock);
434433
mutex_init(&q->limits_lock);
435434
mutex_init(&q->rq_qos_mutex);
436435
spin_lock_init(&q->queue_lock);

block/blk-ia-ranges.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ int disk_register_independent_access_ranges(struct gendisk *disk)
111111
struct request_queue *q = disk->queue;
112112
int i, ret;
113113

114-
lockdep_assert_held(&q->sysfs_dir_lock);
115114
lockdep_assert_held(&q->sysfs_lock);
116115

117116
if (!iars)
@@ -155,7 +154,6 @@ void disk_unregister_independent_access_ranges(struct gendisk *disk)
155154
struct blk_independent_access_ranges *iars = disk->ia_ranges;
156155
int i;
157156

158-
lockdep_assert_held(&q->sysfs_dir_lock);
159157
lockdep_assert_held(&q->sysfs_lock);
160158

161159
if (!iars)
@@ -289,7 +287,6 @@ void disk_set_independent_access_ranges(struct gendisk *disk,
289287
{
290288
struct request_queue *q = disk->queue;
291289

292-
mutex_lock(&q->sysfs_dir_lock);
293290
mutex_lock(&q->sysfs_lock);
294291
if (iars && !disk_check_ia_ranges(disk, iars)) {
295292
kfree(iars);
@@ -313,6 +310,5 @@ void disk_set_independent_access_ranges(struct gendisk *disk,
313310
disk_register_independent_access_ranges(disk);
314311
unlock:
315312
mutex_unlock(&q->sysfs_lock);
316-
mutex_unlock(&q->sysfs_dir_lock);
317313
}
318314
EXPORT_SYMBOL_GPL(disk_set_independent_access_ranges);

block/blk-mq-sysfs.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ int blk_mq_sysfs_register(struct gendisk *disk)
223223
unsigned long i, j;
224224
int ret;
225225

226-
lockdep_assert_held(&q->sysfs_dir_lock);
227-
228226
ret = kobject_add(q->mq_kobj, &disk_to_dev(disk)->kobj, "mq");
229227
if (ret < 0)
230228
goto out;
@@ -237,7 +235,6 @@ int blk_mq_sysfs_register(struct gendisk *disk)
237235
goto unreg;
238236
}
239237

240-
q->mq_sysfs_init_done = true;
241238

242239
out:
243240
return ret;
@@ -259,31 +256,24 @@ void blk_mq_sysfs_unregister(struct gendisk *disk)
259256
struct blk_mq_hw_ctx *hctx;
260257
unsigned long i;
261258

262-
lockdep_assert_held(&q->sysfs_dir_lock);
263259

264260
queue_for_each_hw_ctx(q, hctx, i)
265261
blk_mq_unregister_hctx(hctx);
266262

267263
kobject_uevent(q->mq_kobj, KOBJ_REMOVE);
268264
kobject_del(q->mq_kobj);
269-
270-
q->mq_sysfs_init_done = false;
271265
}
272266

273267
void blk_mq_sysfs_unregister_hctxs(struct request_queue *q)
274268
{
275269
struct blk_mq_hw_ctx *hctx;
276270
unsigned long i;
277271

278-
mutex_lock(&q->sysfs_dir_lock);
279-
if (!q->mq_sysfs_init_done)
280-
goto unlock;
272+
if (!blk_queue_registered(q))
273+
return;
281274

282275
queue_for_each_hw_ctx(q, hctx, i)
283276
blk_mq_unregister_hctx(hctx);
284-
285-
unlock:
286-
mutex_unlock(&q->sysfs_dir_lock);
287277
}
288278

289279
int blk_mq_sysfs_register_hctxs(struct request_queue *q)
@@ -292,18 +282,15 @@ int blk_mq_sysfs_register_hctxs(struct request_queue *q)
292282
unsigned long i;
293283
int ret = 0;
294284

295-
mutex_lock(&q->sysfs_dir_lock);
296-
if (!q->mq_sysfs_init_done)
297-
goto unlock;
285+
if (!blk_queue_registered(q))
286+
goto out;
298287

299288
queue_for_each_hw_ctx(q, hctx, i) {
300289
ret = blk_mq_register_hctx(hctx);
301290
if (ret)
302291
break;
303292
}
304293

305-
unlock:
306-
mutex_unlock(&q->sysfs_dir_lock);
307-
294+
out:
308295
return ret;
309296
}

block/blk-sysfs.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ int blk_register_queue(struct gendisk *disk)
764764
struct request_queue *q = disk->queue;
765765
int ret;
766766

767-
mutex_lock(&q->sysfs_dir_lock);
768767
kobject_init(&disk->queue_kobj, &blk_queue_ktype);
769768
ret = kobject_add(&disk->queue_kobj, &disk_to_dev(disk)->kobj, "queue");
770769
if (ret < 0)
@@ -805,7 +804,6 @@ int blk_register_queue(struct gendisk *disk)
805804
if (q->elevator)
806805
kobject_uevent(&q->elevator->kobj, KOBJ_ADD);
807806
mutex_unlock(&q->sysfs_lock);
808-
mutex_unlock(&q->sysfs_dir_lock);
809807

810808
/*
811809
* SCSI probing may synchronously create and destroy a lot of
@@ -830,7 +828,6 @@ int blk_register_queue(struct gendisk *disk)
830828
mutex_unlock(&q->sysfs_lock);
831829
out_put_queue_kobj:
832830
kobject_put(&disk->queue_kobj);
833-
mutex_unlock(&q->sysfs_dir_lock);
834831
return ret;
835832
}
836833

@@ -861,7 +858,6 @@ void blk_unregister_queue(struct gendisk *disk)
861858
blk_queue_flag_clear(QUEUE_FLAG_REGISTERED, q);
862859
mutex_unlock(&q->sysfs_lock);
863860

864-
mutex_lock(&q->sysfs_dir_lock);
865861
/*
866862
* Remove the sysfs attributes before unregistering the queue data
867863
* structures that can be modified through sysfs.
@@ -878,7 +874,6 @@ void blk_unregister_queue(struct gendisk *disk)
878874
/* Now that we've deleted all child objects, we can delete the queue. */
879875
kobject_uevent(&disk->queue_kobj, KOBJ_REMOVE);
880876
kobject_del(&disk->queue_kobj);
881-
mutex_unlock(&q->sysfs_dir_lock);
882877

883878
blk_debugfs_remove(disk);
884879
}

include/linux/blkdev.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ struct request_queue {
561561
struct list_head flush_list;
562562

563563
struct mutex sysfs_lock;
564-
struct mutex sysfs_dir_lock;
565564
struct mutex limits_lock;
566565

567566
/*
@@ -605,8 +604,6 @@ struct request_queue {
605604
* Serializes all debugfs metadata operations using the above dentries.
606605
*/
607606
struct mutex debugfs_mutex;
608-
609-
bool mq_sysfs_init_done;
610607
};
611608

612609
/* Keep blk_queue_flag_name[] in sync with the definitions below */

0 commit comments

Comments
 (0)