Skip to content

Commit 4eb44d1

Browse files
Li Lingfengaxboe
authored andcommitted
block: remove init_mutex and open-code blk_iolatency_try_init
Commit a13696b ("blk-iolatency: Make initialization lazy") adds a mutex named "init_mutex" in blk_iolatency_try_init for the race condition of initializing RQ_QOS_LATENCY. Now a new lock has been add to struct request_queue by commit a13bd91 ("block/rq_qos: protect rq_qos apis with a new lock"). And it has been held in blkg_conf_open_bdev before calling blk_iolatency_init. So it's not necessary to keep init_mutex in blk_iolatency_try_init, just remove it. Since init_mutex has been removed, blk_iolatency_try_init can be open-coded back to iolatency_set_limit() like ioc_qos_write(). Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com> Reviewed-by: Michal Koutný <mkoutny@suse.com> Link: https://lore.kernel.org/r/20230810035111.2236335-1-lilingfeng@huaweicloud.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c8659bb commit 4eb44d1

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

block/blk-iolatency.c

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -824,29 +824,6 @@ static void iolatency_clear_scaling(struct blkcg_gq *blkg)
824824
}
825825
}
826826

827-
static int blk_iolatency_try_init(struct blkg_conf_ctx *ctx)
828-
{
829-
static DEFINE_MUTEX(init_mutex);
830-
int ret;
831-
832-
ret = blkg_conf_open_bdev(ctx);
833-
if (ret)
834-
return ret;
835-
836-
/*
837-
* blk_iolatency_init() may fail after rq_qos_add() succeeds which can
838-
* confuse iolat_rq_qos() test. Make the test and init atomic.
839-
*/
840-
mutex_lock(&init_mutex);
841-
842-
if (!iolat_rq_qos(ctx->bdev->bd_queue))
843-
ret = blk_iolatency_init(ctx->bdev->bd_disk);
844-
845-
mutex_unlock(&init_mutex);
846-
847-
return ret;
848-
}
849-
850827
static ssize_t iolatency_set_limit(struct kernfs_open_file *of, char *buf,
851828
size_t nbytes, loff_t off)
852829
{
@@ -861,7 +838,17 @@ static ssize_t iolatency_set_limit(struct kernfs_open_file *of, char *buf,
861838

862839
blkg_conf_init(&ctx, buf);
863840

864-
ret = blk_iolatency_try_init(&ctx);
841+
ret = blkg_conf_open_bdev(&ctx);
842+
if (ret)
843+
goto out;
844+
845+
/*
846+
* blk_iolatency_init() may fail after rq_qos_add() succeeds which can
847+
* confuse iolat_rq_qos() test. Make the test and init atomic.
848+
*/
849+
lockdep_assert_held(ctx.bdev->bd_queue->rq_qos_mutex);
850+
if (!iolat_rq_qos(ctx.bdev->bd_queue))
851+
ret = blk_iolatency_init(ctx.bdev->bd_disk);
865852
if (ret)
866853
goto out;
867854

0 commit comments

Comments
 (0)