In some scenarios, we want to modify the blk timeout, but the blk timeout is a hard-code constant, the default value is 30s, so this patch changes blk timeout to a variable that can be controlled via sysctl. Signed-off-by: lwk modified: block/blk-mq.c modified: drivers/block/Makefile new file: drivers/block/blk_sysctl.c modified: include/linux/blkdev.h --- block/blk-mq.c | 2 +- drivers/block/Makefile | 1 + drivers/block/blk_sysctl.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 drivers/block/blk_sysctl.c diff --git a/block/blk-mq.c b/block/blk-mq.c index 40490ac88..2a087b6b8 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4537,7 +4537,7 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, goto err_hctxs; INIT_WORK(&q->timeout_work, blk_mq_timeout_work); - blk_queue_rq_timeout(q, set->timeout ? set->timeout : 30 * HZ); + blk_queue_rq_timeout(q, set->timeout ? set->timeout : sysctl_blk_timeout); q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT; diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 1105a2d4f..544e6b6b5 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -12,6 +12,7 @@ ccflags-y += -I$(src) obj-$(CONFIG_BLK_DEV_RUST_NULL) += rnull_mod.o rnull_mod-y := rnull.o +obj-$(CONFIG_SYSCTL) += blk_sysctl.o obj-$(CONFIG_MAC_FLOPPY) += swim3.o obj-$(CONFIG_BLK_DEV_SWIM) += swim_mod.o obj-$(CONFIG_BLK_DEV_FD) += floppy.o diff --git a/drivers/block/blk_sysctl.c b/drivers/block/blk_sysctl.c new file mode 100644 index 000000000..f8f96ad12 --- /dev/null +++ b/drivers/block/blk_sysctl.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * blk_sysctl.c: sysctl interface to block subsystem. + * + * Begun Nov 10, 2025, lwk. + * Added /proc/sys/block directory entry + */ + +#include +#include +#include +#include + + +unsigned int sysctl_blk_timeout = 30; + +static struct ctl_table blk_table_sysctls[] = { + { + .procname = "blk_timeout", + .data = &sysctl_blk_timeout, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec + }, + {} +}; + +static __init int sysctl_blk_init(void) +{ +#ifdef CONFIG_SYSCTL + register_sysctl_init("block", blk_table_sysctls); +#endif + + return 0; +} + +__initcall(sysctl_blk_init); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d37751789..51802d5f7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -42,6 +42,7 @@ struct blk_queue_stats; struct blk_stat_callback; struct blk_crypto_profile; +extern unsigned int sysctl_blk_timeout; extern const struct device_type disk_type; extern const struct device_type part_type; extern const struct class block_class; -- 2.47.3