[SRU,linux-aws-xenial,1/2] block: add io timeout to sysfs
diff mbox series

Message ID 20190826184756.21995-2-kamal@canonical.com
State New
Headers show
Series
  • [SRU,linux-aws-xenial,1/2] block: add io timeout to sysfs
Related show

Commit Message

Kamal Mostafa Aug. 26, 2019, 6:47 p.m. UTC
From: Weiping Zhang <zhangweiping@didiglobal.com>

BugLink: https://bugs.launchpad.net/bugs/1841461

Give a interface to adjust io timeout(ms) by device.

Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(backported from commit 65cd1d13b880920054d6c750679baa80b7f9c072)
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 block/blk-sysfs.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Patch
diff mbox series

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index a113dc1e3eb7..5da33f8d1d53 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -348,6 +348,26 @@  static ssize_t queue_poll_store(struct request_queue *q, const char *page,
 	return ret;
 }
 
+static ssize_t queue_io_timeout_show(struct request_queue *q, char *page)
+{
+	return sprintf(page, "%u\n", jiffies_to_msecs(q->rq_timeout));
+}
+
+static ssize_t queue_io_timeout_store(struct request_queue *q, const char *page,
+				  size_t count)
+{
+	unsigned int val;
+	int err;
+
+	err = kstrtou32(page, 10, &val);
+	if (err || val == 0)
+		return -EINVAL;
+
+	blk_queue_rq_timeout(q, msecs_to_jiffies(val));
+
+	return count;
+}
+
 static struct queue_sysfs_entry queue_requests_entry = {
 	.attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
 	.show = queue_requests_show,
@@ -479,6 +499,12 @@  static struct queue_sysfs_entry queue_poll_entry = {
 	.store = queue_poll_store,
 };
 
+static struct queue_sysfs_entry queue_io_timeout_entry = {
+	.attr = {.name = "io_timeout", .mode = 0644 },
+	.show = queue_io_timeout_show,
+	.store = queue_io_timeout_store,
+};
+
 static struct attribute *default_attrs[] = {
 	&queue_requests_entry.attr,
 	&queue_ra_entry.attr,
@@ -504,6 +530,7 @@  static struct attribute *default_attrs[] = {
 	&queue_iostats_entry.attr,
 	&queue_random_entry.attr,
 	&queue_poll_entry.attr,
+	&queue_io_timeout_entry.attr,
 	NULL,
 };