Blame view
block/blk-timeout.c
3.77 KB
3dcf60bcb block: add SPDX t... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
242f9dcb8 block: unify requ... |
2 3 4 5 6 7 |
/* * Functions related to generic timeout handling of requests. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/blkdev.h> |
581d4e28d block: add fault ... |
8 |
#include <linux/fault-inject.h> |
242f9dcb8 block: unify requ... |
9 10 |
#include "blk.h" |
904158376 block: fix blk_ab... |
11 |
#include "blk-mq.h" |
242f9dcb8 block: unify requ... |
12 |
|
581d4e28d block: add fault ... |
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#ifdef CONFIG_FAIL_IO_TIMEOUT static DECLARE_FAULT_ATTR(fail_io_timeout); static int __init setup_fail_io_timeout(char *str) { return setup_fault_attr(&fail_io_timeout, str); } __setup("fail_io_timeout=", setup_fail_io_timeout); int blk_should_fake_timeout(struct request_queue *q) { if (!test_bit(QUEUE_FLAG_FAIL_IO, &q->queue_flags)) return 0; return should_fail(&fail_io_timeout, 1); } static int __init fail_io_timeout_debugfs(void) { |
dd48c085c fault-injection: ... |
33 34 |
struct dentry *dir = fault_create_debugfs_attr("fail_io_timeout", NULL, &fail_io_timeout); |
8616ebb16 block: replace IS... |
35 |
return PTR_ERR_OR_ZERO(dir); |
581d4e28d block: add fault ... |
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
} late_initcall(fail_io_timeout_debugfs); ssize_t part_timeout_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gendisk *disk = dev_to_disk(dev); int set = test_bit(QUEUE_FLAG_FAIL_IO, &disk->queue->queue_flags); return sprintf(buf, "%d ", set != 0); } ssize_t part_timeout_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct gendisk *disk = dev_to_disk(dev); int val; if (count) { struct request_queue *q = disk->queue; char *p = (char *) buf; val = simple_strtoul(p, &p, 10); |
581d4e28d block: add fault ... |
61 |
if (val) |
8814ce8a0 block: Introduce ... |
62 |
blk_queue_flag_set(QUEUE_FLAG_FAIL_IO, q); |
581d4e28d block: add fault ... |
63 |
else |
8814ce8a0 block: Introduce ... |
64 |
blk_queue_flag_clear(QUEUE_FLAG_FAIL_IO, q); |
581d4e28d block: add fault ... |
65 66 67 68 69 70 |
} return count; } #endif /* CONFIG_FAIL_IO_TIMEOUT */ |
242f9dcb8 block: unify requ... |
71 72 73 74 75 76 77 |
/** * blk_abort_request -- Request request recovery for the specified command * @req: pointer to the request of interest * * This function requests that the block layer start recovery for the * request by deleting the timer and calling the q's timeout function. * LLDDs who implement their own error recovery MAY ignore the timeout |
39795d653 block: don't hold... |
78 |
* event if they generated blk_abort_request. |
242f9dcb8 block: unify requ... |
79 80 81 |
*/ void blk_abort_request(struct request *req) { |
4316b79e4 block: kill legac... |
82 83 84 85 86 |
/* * All we need to ensure is that timeout scan takes place * immediately and that scan sees the new timeout value. * No need for fancy synchronizations. */ |
079076b34 block: remove dea... |
87 |
WRITE_ONCE(req->deadline, jiffies); |
4316b79e4 block: kill legac... |
88 |
kblockd_schedule_work(&req->q->timeout_work); |
242f9dcb8 block: unify requ... |
89 90 |
} EXPORT_SYMBOL_GPL(blk_abort_request); |
0d2602ca3 blk-mq: improve s... |
91 92 93 94 95 96 97 98 99 100 |
unsigned long blk_rq_timeout(unsigned long timeout) { unsigned long maxt; maxt = round_jiffies_up(jiffies + BLK_MAX_TIMEOUT); if (time_after(timeout, maxt)) timeout = maxt; return timeout; } |
c4a634f43 block: fold __blk... |
101 102 103 104 105 106 107 108 109 |
/** * blk_add_timer - Start timeout timer for a single request * @req: request that is about to start running. * * Notes: * Each request has its own timer, and as it is added to the queue, we * set up the timer. When the request completes, we cancel the timer. */ void blk_add_timer(struct request *req) |
242f9dcb8 block: unify requ... |
110 111 112 |
{ struct request_queue *q = req->q; unsigned long expiry; |
2eef33e43 block: clean up m... |
113 114 115 116 117 |
/* * Some LLDs, like scsi, peek at the timeout to prevent a * command from being retried forever. */ if (!req->timeout) |
242f9dcb8 block: unify requ... |
118 |
req->timeout = q->rq_timeout; |
2eef33e43 block: clean up m... |
119 |
|
f5e350f02 blk-mq: Fix timeo... |
120 |
req->rq_flags &= ~RQF_TIMED_OUT; |
079076b34 block: remove dea... |
121 122 123 |
expiry = jiffies + req->timeout; WRITE_ONCE(req->deadline, expiry); |
3b627a3f9 block: clarify bl... |
124 125 |
/* |
242f9dcb8 block: unify requ... |
126 |
* If the timer isn't already pending or this timeout is earlier |
7838c15b8 Block: use round_... |
127 |
* than an existing one, modify the timer. Round up to next nearest |
242f9dcb8 block: unify requ... |
128 129 |
* second. */ |
079076b34 block: remove dea... |
130 |
expiry = blk_rq_timeout(round_jiffies_up(expiry)); |
242f9dcb8 block: unify requ... |
131 132 |
if (!timer_pending(&q->timeout) || |
f793aa537 block: relax when... |
133 134 135 136 137 138 139 140 141 142 |
time_before(expiry, q->timeout.expires)) { unsigned long diff = q->timeout.expires - expiry; /* * Due to added timer slack to group timers, the timer * will often be a little in front of what we asked for. * So apply some tolerance here too, otherwise we keep * modifying the timer because expires for value X * will be X + something. */ |
c7bca4183 block: ensure tha... |
143 |
if (!timer_pending(&q->timeout) || (diff >= HZ / 2)) |
f793aa537 block: relax when... |
144 145 |
mod_timer(&q->timeout, expiry); } |
320ae51fe blk-mq: new multi... |
146 147 |
} |