blob: 8ec738f872e505066110e0b4b2a85cb5864ff09f [file] [log] [blame]
Omar Sandoval07e4fea2017-01-25 08:06:40 -08001/*
2 * Copyright (C) 2017 Facebook
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#include <linux/kernel.h>
18#include <linux/blkdev.h>
19#include <linux/debugfs.h>
20
21#include <linux/blk-mq.h>
Omar Sandoval18fbda92017-01-31 14:53:20 -080022#include "blk.h"
Omar Sandoval07e4fea2017-01-25 08:06:40 -080023#include "blk-mq.h"
Omar Sandovald173a252017-05-04 00:31:30 -070024#include "blk-mq-debugfs.h"
Omar Sandovald96b37c2017-01-25 08:06:46 -080025#include "blk-mq-tag.h"
Omar Sandoval07e4fea2017-01-25 08:06:40 -080026
Bart Van Assche91d68902017-04-10 16:13:15 -060027static int blk_flags_show(struct seq_file *m, const unsigned long flags,
28 const char *const *flag_name, int flag_name_count)
29{
30 bool sep = false;
31 int i;
32
33 for (i = 0; i < sizeof(flags) * BITS_PER_BYTE; i++) {
34 if (!(flags & BIT(i)))
35 continue;
36 if (sep)
Omar Sandovalbec03d62017-05-04 00:31:23 -070037 seq_puts(m, "|");
Bart Van Assche91d68902017-04-10 16:13:15 -060038 sep = true;
39 if (i < flag_name_count && flag_name[i])
40 seq_puts(m, flag_name[i]);
41 else
42 seq_printf(m, "%d", i);
43 }
Bart Van Assche91d68902017-04-10 16:13:15 -060044 return 0;
45}
46
Omar Sandoval1a435112017-05-04 00:31:24 -070047#define QUEUE_FLAG_NAME(name) [QUEUE_FLAG_##name] = #name
Bart Van Assche91d68902017-04-10 16:13:15 -060048static const char *const blk_queue_flag_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -070049 QUEUE_FLAG_NAME(QUEUED),
50 QUEUE_FLAG_NAME(STOPPED),
51 QUEUE_FLAG_NAME(SYNCFULL),
52 QUEUE_FLAG_NAME(ASYNCFULL),
53 QUEUE_FLAG_NAME(DYING),
54 QUEUE_FLAG_NAME(BYPASS),
55 QUEUE_FLAG_NAME(BIDI),
56 QUEUE_FLAG_NAME(NOMERGES),
57 QUEUE_FLAG_NAME(SAME_COMP),
58 QUEUE_FLAG_NAME(FAIL_IO),
59 QUEUE_FLAG_NAME(STACKABLE),
60 QUEUE_FLAG_NAME(NONROT),
61 QUEUE_FLAG_NAME(IO_STAT),
62 QUEUE_FLAG_NAME(DISCARD),
63 QUEUE_FLAG_NAME(NOXMERGES),
64 QUEUE_FLAG_NAME(ADD_RANDOM),
65 QUEUE_FLAG_NAME(SECERASE),
66 QUEUE_FLAG_NAME(SAME_FORCE),
67 QUEUE_FLAG_NAME(DEAD),
68 QUEUE_FLAG_NAME(INIT_DONE),
69 QUEUE_FLAG_NAME(NO_SG_MERGE),
70 QUEUE_FLAG_NAME(POLL),
71 QUEUE_FLAG_NAME(WC),
72 QUEUE_FLAG_NAME(FUA),
73 QUEUE_FLAG_NAME(FLUSH_NQ),
74 QUEUE_FLAG_NAME(DAX),
75 QUEUE_FLAG_NAME(STATS),
76 QUEUE_FLAG_NAME(POLL_STATS),
77 QUEUE_FLAG_NAME(REGISTERED),
Bart Van Assche91d68902017-04-10 16:13:15 -060078};
Omar Sandoval1a435112017-05-04 00:31:24 -070079#undef QUEUE_FLAG_NAME
Bart Van Assche91d68902017-04-10 16:13:15 -060080
Omar Sandovalf57de232017-05-04 00:31:28 -070081static int queue_state_show(void *data, struct seq_file *m)
Bart Van Assche91d68902017-04-10 16:13:15 -060082{
Omar Sandovalf57de232017-05-04 00:31:28 -070083 struct request_queue *q = data;
Bart Van Assche91d68902017-04-10 16:13:15 -060084
85 blk_flags_show(m, q->queue_flags, blk_queue_flag_name,
86 ARRAY_SIZE(blk_queue_flag_name));
Bart Van Asschefd07dc82017-04-26 13:47:54 -070087 seq_puts(m, "\n");
Bart Van Assche91d68902017-04-10 16:13:15 -060088 return 0;
89}
90
Omar Sandovalf57de232017-05-04 00:31:28 -070091static ssize_t queue_state_write(void *data, const char __user *buf,
92 size_t count, loff_t *ppos)
Bart Van Assche91d68902017-04-10 16:13:15 -060093{
Omar Sandovalf57de232017-05-04 00:31:28 -070094 struct request_queue *q = data;
Omar Sandoval71b90512017-05-04 00:31:26 -070095 char opbuf[16] = { }, *op;
Bart Van Assche91d68902017-04-10 16:13:15 -060096
Bart Van Assche18d4d7d2017-05-04 00:31:29 -070097 /*
98 * The "state" attribute is removed after blk_cleanup_queue() has called
99 * blk_mq_free_queue(). Return if QUEUE_FLAG_DEAD has been set to avoid
100 * triggering a use-after-free.
101 */
102 if (blk_queue_dead(q))
103 return -ENOENT;
104
Omar Sandoval71b90512017-05-04 00:31:26 -0700105 if (count >= sizeof(opbuf)) {
Omar Sandovalc7e41452017-05-04 00:31:25 -0700106 pr_err("%s: operation too long\n", __func__);
107 goto inval;
108 }
109
Omar Sandoval71b90512017-05-04 00:31:26 -0700110 if (copy_from_user(opbuf, buf, count))
Bart Van Assche91d68902017-04-10 16:13:15 -0600111 return -EFAULT;
Omar Sandoval71b90512017-05-04 00:31:26 -0700112 op = strstrip(opbuf);
Bart Van Assche91d68902017-04-10 16:13:15 -0600113 if (strcmp(op, "run") == 0) {
114 blk_mq_run_hw_queues(q, true);
115 } else if (strcmp(op, "start") == 0) {
116 blk_mq_start_stopped_hw_queues(q, true);
117 } else {
Omar Sandovalc7e41452017-05-04 00:31:25 -0700118 pr_err("%s: unsupported operation '%s'\n", __func__, op);
119inval:
120 pr_err("%s: use either 'run' or 'start'\n", __func__);
Bart Van Assche91d68902017-04-10 16:13:15 -0600121 return -EINVAL;
122 }
Omar Sandovalc7e41452017-05-04 00:31:25 -0700123 return count;
Bart Van Assche91d68902017-04-10 16:13:15 -0600124}
125
Omar Sandoval34dbad52017-03-21 08:56:08 -0700126static void print_stat(struct seq_file *m, struct blk_rq_stat *stat)
127{
128 if (stat->nr_samples) {
129 seq_printf(m, "samples=%d, mean=%lld, min=%llu, max=%llu",
130 stat->nr_samples, stat->mean, stat->min, stat->max);
131 } else {
132 seq_puts(m, "samples=0");
133 }
134}
135
Omar Sandovalf57de232017-05-04 00:31:28 -0700136static int queue_poll_stat_show(void *data, struct seq_file *m)
Omar Sandoval34dbad52017-03-21 08:56:08 -0700137{
Omar Sandovalf57de232017-05-04 00:31:28 -0700138 struct request_queue *q = data;
Stephen Bates02063192017-04-20 16:59:11 -0600139 int bucket;
Omar Sandoval34dbad52017-03-21 08:56:08 -0700140
Stephen Bates02063192017-04-20 16:59:11 -0600141 for (bucket = 0; bucket < BLK_MQ_POLL_STATS_BKTS/2; bucket++) {
142 seq_printf(m, "read (%d Bytes): ", 1 << (9+bucket));
143 print_stat(m, &q->poll_stat[2*bucket]);
144 seq_puts(m, "\n");
Omar Sandoval34dbad52017-03-21 08:56:08 -0700145
Stephen Bates02063192017-04-20 16:59:11 -0600146 seq_printf(m, "write (%d Bytes): ", 1 << (9+bucket));
147 print_stat(m, &q->poll_stat[2*bucket+1]);
148 seq_puts(m, "\n");
149 }
Omar Sandoval34dbad52017-03-21 08:56:08 -0700150 return 0;
151}
152
Omar Sandoval1a435112017-05-04 00:31:24 -0700153#define HCTX_STATE_NAME(name) [BLK_MQ_S_##name] = #name
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700154static const char *const hctx_state_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700155 HCTX_STATE_NAME(STOPPED),
156 HCTX_STATE_NAME(TAG_ACTIVE),
157 HCTX_STATE_NAME(SCHED_RESTART),
158 HCTX_STATE_NAME(TAG_WAITING),
159 HCTX_STATE_NAME(START_ON_RUN),
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700160};
Omar Sandoval1a435112017-05-04 00:31:24 -0700161#undef HCTX_STATE_NAME
162
Omar Sandovalf57de232017-05-04 00:31:28 -0700163static int hctx_state_show(void *data, struct seq_file *m)
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800164{
Omar Sandovalf57de232017-05-04 00:31:28 -0700165 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800166
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700167 blk_flags_show(m, hctx->state, hctx_state_name,
168 ARRAY_SIZE(hctx_state_name));
Bart Van Asschefd07dc82017-04-26 13:47:54 -0700169 seq_puts(m, "\n");
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800170 return 0;
171}
172
Omar Sandoval1a435112017-05-04 00:31:24 -0700173#define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700174static const char *const alloc_policy_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700175 BLK_TAG_ALLOC_NAME(FIFO),
176 BLK_TAG_ALLOC_NAME(RR),
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700177};
Omar Sandoval1a435112017-05-04 00:31:24 -0700178#undef BLK_TAG_ALLOC_NAME
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700179
Omar Sandoval1a435112017-05-04 00:31:24 -0700180#define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700181static const char *const hctx_flag_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700182 HCTX_FLAG_NAME(SHOULD_MERGE),
183 HCTX_FLAG_NAME(TAG_SHARED),
184 HCTX_FLAG_NAME(SG_MERGE),
185 HCTX_FLAG_NAME(BLOCKING),
186 HCTX_FLAG_NAME(NO_SCHED),
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700187};
Omar Sandoval1a435112017-05-04 00:31:24 -0700188#undef HCTX_FLAG_NAME
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700189
Omar Sandovalf57de232017-05-04 00:31:28 -0700190static int hctx_flags_show(void *data, struct seq_file *m)
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800191{
Omar Sandovalf57de232017-05-04 00:31:28 -0700192 struct blk_mq_hw_ctx *hctx = data;
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700193 const int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx->flags);
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800194
Bart Van Asschef5c0b0912017-03-30 11:21:27 -0700195 seq_puts(m, "alloc_policy=");
196 if (alloc_policy < ARRAY_SIZE(alloc_policy_name) &&
197 alloc_policy_name[alloc_policy])
198 seq_puts(m, alloc_policy_name[alloc_policy]);
199 else
200 seq_printf(m, "%d", alloc_policy);
201 seq_puts(m, " ");
202 blk_flags_show(m,
203 hctx->flags ^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy),
204 hctx_flag_name, ARRAY_SIZE(hctx_flag_name));
Bart Van Asschefd07dc82017-04-26 13:47:54 -0700205 seq_puts(m, "\n");
Omar Sandoval9abb2ad2017-01-25 08:06:41 -0800206 return 0;
207}
208
Omar Sandoval1a435112017-05-04 00:31:24 -0700209#define REQ_OP_NAME(name) [REQ_OP_##name] = #name
Bart Van Assche8658dca2017-04-26 13:47:55 -0700210static const char *const op_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700211 REQ_OP_NAME(READ),
212 REQ_OP_NAME(WRITE),
213 REQ_OP_NAME(FLUSH),
214 REQ_OP_NAME(DISCARD),
215 REQ_OP_NAME(ZONE_REPORT),
216 REQ_OP_NAME(SECURE_ERASE),
217 REQ_OP_NAME(ZONE_RESET),
218 REQ_OP_NAME(WRITE_SAME),
219 REQ_OP_NAME(WRITE_ZEROES),
220 REQ_OP_NAME(SCSI_IN),
221 REQ_OP_NAME(SCSI_OUT),
222 REQ_OP_NAME(DRV_IN),
223 REQ_OP_NAME(DRV_OUT),
Bart Van Assche8658dca2017-04-26 13:47:55 -0700224};
Omar Sandoval1a435112017-05-04 00:31:24 -0700225#undef REQ_OP_NAME
Bart Van Assche8658dca2017-04-26 13:47:55 -0700226
Omar Sandoval1a435112017-05-04 00:31:24 -0700227#define CMD_FLAG_NAME(name) [__REQ_##name] = #name
Bart Van Assche8658dca2017-04-26 13:47:55 -0700228static const char *const cmd_flag_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700229 CMD_FLAG_NAME(FAILFAST_DEV),
230 CMD_FLAG_NAME(FAILFAST_TRANSPORT),
231 CMD_FLAG_NAME(FAILFAST_DRIVER),
232 CMD_FLAG_NAME(SYNC),
233 CMD_FLAG_NAME(META),
234 CMD_FLAG_NAME(PRIO),
235 CMD_FLAG_NAME(NOMERGE),
236 CMD_FLAG_NAME(IDLE),
237 CMD_FLAG_NAME(INTEGRITY),
238 CMD_FLAG_NAME(FUA),
239 CMD_FLAG_NAME(PREFLUSH),
240 CMD_FLAG_NAME(RAHEAD),
241 CMD_FLAG_NAME(BACKGROUND),
242 CMD_FLAG_NAME(NOUNMAP),
Bart Van Assche8658dca2017-04-26 13:47:55 -0700243};
Omar Sandoval1a435112017-05-04 00:31:24 -0700244#undef CMD_FLAG_NAME
Bart Van Assche8658dca2017-04-26 13:47:55 -0700245
Omar Sandoval1a435112017-05-04 00:31:24 -0700246#define RQF_NAME(name) [ilog2((__force u32)RQF_##name)] = #name
Bart Van Assche8658dca2017-04-26 13:47:55 -0700247static const char *const rqf_name[] = {
Omar Sandoval1a435112017-05-04 00:31:24 -0700248 RQF_NAME(SORTED),
249 RQF_NAME(STARTED),
250 RQF_NAME(QUEUED),
251 RQF_NAME(SOFTBARRIER),
252 RQF_NAME(FLUSH_SEQ),
253 RQF_NAME(MIXED_MERGE),
254 RQF_NAME(MQ_INFLIGHT),
255 RQF_NAME(DONTPREP),
256 RQF_NAME(PREEMPT),
257 RQF_NAME(COPY_USER),
258 RQF_NAME(FAILED),
259 RQF_NAME(QUIET),
260 RQF_NAME(ELVPRIV),
261 RQF_NAME(IO_STAT),
262 RQF_NAME(ALLOCED),
263 RQF_NAME(PM),
264 RQF_NAME(HASHED),
265 RQF_NAME(STATS),
266 RQF_NAME(SPECIAL_PAYLOAD),
Bart Van Assche8658dca2017-04-26 13:47:55 -0700267};
Omar Sandoval1a435112017-05-04 00:31:24 -0700268#undef RQF_NAME
Bart Van Assche8658dca2017-04-26 13:47:55 -0700269
Omar Sandoval16b738f2017-05-04 00:31:33 -0700270int blk_mq_debugfs_rq_show(struct seq_file *m, void *v)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800271{
272 struct request *rq = list_entry_rq(v);
Bart Van Assche2836ee42017-04-26 13:47:56 -0700273 const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
Bart Van Assche8658dca2017-04-26 13:47:55 -0700274 const unsigned int op = rq->cmd_flags & REQ_OP_MASK;
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800275
Bart Van Assche8658dca2017-04-26 13:47:55 -0700276 seq_printf(m, "%p {.op=", rq);
277 if (op < ARRAY_SIZE(op_name) && op_name[op])
278 seq_printf(m, "%s", op_name[op]);
279 else
280 seq_printf(m, "%d", op);
281 seq_puts(m, ", .cmd_flags=");
282 blk_flags_show(m, rq->cmd_flags & ~REQ_OP_MASK, cmd_flag_name,
283 ARRAY_SIZE(cmd_flag_name));
284 seq_puts(m, ", .rq_flags=");
285 blk_flags_show(m, (__force unsigned int)rq->rq_flags, rqf_name,
286 ARRAY_SIZE(rqf_name));
Bart Van Assche2836ee42017-04-26 13:47:56 -0700287 seq_printf(m, ", .tag=%d, .internal_tag=%d", rq->tag,
Bart Van Assche8658dca2017-04-26 13:47:55 -0700288 rq->internal_tag);
Bart Van Assche2836ee42017-04-26 13:47:56 -0700289 if (mq_ops->show_rq)
290 mq_ops->show_rq(m, rq);
291 seq_puts(m, "}\n");
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800292 return 0;
293}
Omar Sandoval16b738f2017-05-04 00:31:33 -0700294EXPORT_SYMBOL_GPL(blk_mq_debugfs_rq_show);
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800295
296static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos)
Bart Van Asschef3bcb0e2017-02-01 10:20:56 -0800297 __acquires(&hctx->lock)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800298{
299 struct blk_mq_hw_ctx *hctx = m->private;
300
301 spin_lock(&hctx->lock);
302 return seq_list_start(&hctx->dispatch, *pos);
303}
304
305static void *hctx_dispatch_next(struct seq_file *m, void *v, loff_t *pos)
306{
307 struct blk_mq_hw_ctx *hctx = m->private;
308
309 return seq_list_next(v, &hctx->dispatch, pos);
310}
311
312static void hctx_dispatch_stop(struct seq_file *m, void *v)
Bart Van Asschef3bcb0e2017-02-01 10:20:56 -0800313 __releases(&hctx->lock)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800314{
315 struct blk_mq_hw_ctx *hctx = m->private;
316
317 spin_unlock(&hctx->lock);
318}
319
320static const struct seq_operations hctx_dispatch_seq_ops = {
321 .start = hctx_dispatch_start,
322 .next = hctx_dispatch_next,
323 .stop = hctx_dispatch_stop,
324 .show = blk_mq_debugfs_rq_show,
325};
326
Omar Sandovalf57de232017-05-04 00:31:28 -0700327static int hctx_ctx_map_show(void *data, struct seq_file *m)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800328{
Omar Sandovalf57de232017-05-04 00:31:28 -0700329 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval0bfa5282017-01-25 08:06:45 -0800330
331 sbitmap_bitmap_show(&hctx->ctx_map, m);
332 return 0;
333}
334
Omar Sandovald96b37c2017-01-25 08:06:46 -0800335static void blk_mq_debugfs_tags_show(struct seq_file *m,
336 struct blk_mq_tags *tags)
337{
338 seq_printf(m, "nr_tags=%u\n", tags->nr_tags);
339 seq_printf(m, "nr_reserved_tags=%u\n", tags->nr_reserved_tags);
340 seq_printf(m, "active_queues=%d\n",
341 atomic_read(&tags->active_queues));
342
343 seq_puts(m, "\nbitmap_tags:\n");
344 sbitmap_queue_show(&tags->bitmap_tags, m);
345
346 if (tags->nr_reserved_tags) {
347 seq_puts(m, "\nbreserved_tags:\n");
348 sbitmap_queue_show(&tags->breserved_tags, m);
349 }
350}
351
Omar Sandovalf57de232017-05-04 00:31:28 -0700352static int hctx_tags_show(void *data, struct seq_file *m)
Omar Sandovald96b37c2017-01-25 08:06:46 -0800353{
Omar Sandovalf57de232017-05-04 00:31:28 -0700354 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800355 struct request_queue *q = hctx->queue;
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800356 int res;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800357
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800358 res = mutex_lock_interruptible(&q->sysfs_lock);
359 if (res)
360 goto out;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800361 if (hctx->tags)
362 blk_mq_debugfs_tags_show(m, hctx->tags);
363 mutex_unlock(&q->sysfs_lock);
364
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800365out:
366 return res;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800367}
368
Omar Sandovalf57de232017-05-04 00:31:28 -0700369static int hctx_tags_bitmap_show(void *data, struct seq_file *m)
Omar Sandovald96b37c2017-01-25 08:06:46 -0800370{
Omar Sandovalf57de232017-05-04 00:31:28 -0700371 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovald7e36212017-01-25 08:06:47 -0800372 struct request_queue *q = hctx->queue;
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800373 int res;
Omar Sandovald7e36212017-01-25 08:06:47 -0800374
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800375 res = mutex_lock_interruptible(&q->sysfs_lock);
376 if (res)
377 goto out;
Omar Sandovald7e36212017-01-25 08:06:47 -0800378 if (hctx->tags)
379 sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m);
380 mutex_unlock(&q->sysfs_lock);
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800381
382out:
383 return res;
Omar Sandovald7e36212017-01-25 08:06:47 -0800384}
385
Omar Sandovalf57de232017-05-04 00:31:28 -0700386static int hctx_sched_tags_show(void *data, struct seq_file *m)
Omar Sandovald7e36212017-01-25 08:06:47 -0800387{
Omar Sandovalf57de232017-05-04 00:31:28 -0700388 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800389 struct request_queue *q = hctx->queue;
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800390 int res;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800391
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800392 res = mutex_lock_interruptible(&q->sysfs_lock);
393 if (res)
394 goto out;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800395 if (hctx->sched_tags)
396 blk_mq_debugfs_tags_show(m, hctx->sched_tags);
397 mutex_unlock(&q->sysfs_lock);
398
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800399out:
400 return res;
Omar Sandovald96b37c2017-01-25 08:06:46 -0800401}
402
Omar Sandovalf57de232017-05-04 00:31:28 -0700403static int hctx_sched_tags_bitmap_show(void *data, struct seq_file *m)
Omar Sandovald96b37c2017-01-25 08:06:46 -0800404{
Omar Sandovalf57de232017-05-04 00:31:28 -0700405 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovald7e36212017-01-25 08:06:47 -0800406 struct request_queue *q = hctx->queue;
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800407 int res;
Omar Sandovald7e36212017-01-25 08:06:47 -0800408
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800409 res = mutex_lock_interruptible(&q->sysfs_lock);
410 if (res)
411 goto out;
Omar Sandovald7e36212017-01-25 08:06:47 -0800412 if (hctx->sched_tags)
413 sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m);
414 mutex_unlock(&q->sysfs_lock);
Bart Van Assche8c0f14e2017-02-01 10:20:58 -0800415
416out:
417 return res;
Omar Sandovald7e36212017-01-25 08:06:47 -0800418}
419
Omar Sandovalf57de232017-05-04 00:31:28 -0700420static int hctx_io_poll_show(void *data, struct seq_file *m)
Omar Sandovald7e36212017-01-25 08:06:47 -0800421{
Omar Sandovalf57de232017-05-04 00:31:28 -0700422 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovalbe215472017-01-25 08:06:48 -0800423
424 seq_printf(m, "considered=%lu\n", hctx->poll_considered);
425 seq_printf(m, "invoked=%lu\n", hctx->poll_invoked);
426 seq_printf(m, "success=%lu\n", hctx->poll_success);
427 return 0;
428}
429
Omar Sandovalf57de232017-05-04 00:31:28 -0700430static ssize_t hctx_io_poll_write(void *data, const char __user *buf,
Omar Sandovalbe215472017-01-25 08:06:48 -0800431 size_t count, loff_t *ppos)
432{
Omar Sandovalf57de232017-05-04 00:31:28 -0700433 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovalbe215472017-01-25 08:06:48 -0800434
435 hctx->poll_considered = hctx->poll_invoked = hctx->poll_success = 0;
436 return count;
437}
438
Omar Sandovalf57de232017-05-04 00:31:28 -0700439static int hctx_dispatched_show(void *data, struct seq_file *m)
Omar Sandovalbe215472017-01-25 08:06:48 -0800440{
Omar Sandovalf57de232017-05-04 00:31:28 -0700441 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovalbe215472017-01-25 08:06:48 -0800442 int i;
443
444 seq_printf(m, "%8u\t%lu\n", 0U, hctx->dispatched[0]);
445
446 for (i = 1; i < BLK_MQ_MAX_DISPATCH_ORDER - 1; i++) {
447 unsigned int d = 1U << (i - 1);
448
449 seq_printf(m, "%8u\t%lu\n", d, hctx->dispatched[i]);
450 }
451
452 seq_printf(m, "%8u+\t%lu\n", 1U << (i - 1), hctx->dispatched[i]);
453 return 0;
454}
455
Omar Sandovalf57de232017-05-04 00:31:28 -0700456static ssize_t hctx_dispatched_write(void *data, const char __user *buf,
Omar Sandovalbe215472017-01-25 08:06:48 -0800457 size_t count, loff_t *ppos)
458{
Omar Sandovalf57de232017-05-04 00:31:28 -0700459 struct blk_mq_hw_ctx *hctx = data;
Omar Sandovalbe215472017-01-25 08:06:48 -0800460 int i;
461
462 for (i = 0; i < BLK_MQ_MAX_DISPATCH_ORDER; i++)
463 hctx->dispatched[i] = 0;
464 return count;
465}
466
Omar Sandovalf57de232017-05-04 00:31:28 -0700467static int hctx_queued_show(void *data, struct seq_file *m)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800468{
Omar Sandovalf57de232017-05-04 00:31:28 -0700469 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800470
471 seq_printf(m, "%lu\n", hctx->queued);
472 return 0;
473}
474
Omar Sandovalf57de232017-05-04 00:31:28 -0700475static ssize_t hctx_queued_write(void *data, const char __user *buf,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800476 size_t count, loff_t *ppos)
477{
Omar Sandovalf57de232017-05-04 00:31:28 -0700478 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800479
480 hctx->queued = 0;
481 return count;
482}
483
Omar Sandovalf57de232017-05-04 00:31:28 -0700484static int hctx_run_show(void *data, struct seq_file *m)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800485{
Omar Sandovalf57de232017-05-04 00:31:28 -0700486 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800487
488 seq_printf(m, "%lu\n", hctx->run);
489 return 0;
490}
491
Omar Sandovalf57de232017-05-04 00:31:28 -0700492static ssize_t hctx_run_write(void *data, const char __user *buf, size_t count,
493 loff_t *ppos)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800494{
Omar Sandovalf57de232017-05-04 00:31:28 -0700495 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800496
497 hctx->run = 0;
498 return count;
499}
500
Omar Sandovalf57de232017-05-04 00:31:28 -0700501static int hctx_active_show(void *data, struct seq_file *m)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800502{
Omar Sandovalf57de232017-05-04 00:31:28 -0700503 struct blk_mq_hw_ctx *hctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800504
505 seq_printf(m, "%d\n", atomic_read(&hctx->nr_active));
506 return 0;
507}
508
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800509static void *ctx_rq_list_start(struct seq_file *m, loff_t *pos)
Bart Van Asschef3bcb0e2017-02-01 10:20:56 -0800510 __acquires(&ctx->lock)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800511{
512 struct blk_mq_ctx *ctx = m->private;
513
514 spin_lock(&ctx->lock);
515 return seq_list_start(&ctx->rq_list, *pos);
516}
517
518static void *ctx_rq_list_next(struct seq_file *m, void *v, loff_t *pos)
519{
520 struct blk_mq_ctx *ctx = m->private;
521
522 return seq_list_next(v, &ctx->rq_list, pos);
523}
524
525static void ctx_rq_list_stop(struct seq_file *m, void *v)
Bart Van Asschef3bcb0e2017-02-01 10:20:56 -0800526 __releases(&ctx->lock)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800527{
528 struct blk_mq_ctx *ctx = m->private;
529
530 spin_unlock(&ctx->lock);
531}
532
533static const struct seq_operations ctx_rq_list_seq_ops = {
534 .start = ctx_rq_list_start,
535 .next = ctx_rq_list_next,
536 .stop = ctx_rq_list_stop,
537 .show = blk_mq_debugfs_rq_show,
538};
Omar Sandovalf57de232017-05-04 00:31:28 -0700539static int ctx_dispatched_show(void *data, struct seq_file *m)
Omar Sandoval950cd7e2017-01-25 08:06:42 -0800540{
Omar Sandovalf57de232017-05-04 00:31:28 -0700541 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800542
543 seq_printf(m, "%lu %lu\n", ctx->rq_dispatched[1], ctx->rq_dispatched[0]);
544 return 0;
545}
546
Omar Sandovalf57de232017-05-04 00:31:28 -0700547static ssize_t ctx_dispatched_write(void *data, const char __user *buf,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800548 size_t count, loff_t *ppos)
549{
Omar Sandovalf57de232017-05-04 00:31:28 -0700550 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800551
552 ctx->rq_dispatched[0] = ctx->rq_dispatched[1] = 0;
553 return count;
554}
555
Omar Sandovalf57de232017-05-04 00:31:28 -0700556static int ctx_merged_show(void *data, struct seq_file *m)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800557{
Omar Sandovalf57de232017-05-04 00:31:28 -0700558 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800559
560 seq_printf(m, "%lu\n", ctx->rq_merged);
561 return 0;
562}
563
Omar Sandovalf57de232017-05-04 00:31:28 -0700564static ssize_t ctx_merged_write(void *data, const char __user *buf,
565 size_t count, loff_t *ppos)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800566{
Omar Sandovalf57de232017-05-04 00:31:28 -0700567 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800568
569 ctx->rq_merged = 0;
570 return count;
571}
572
Omar Sandovalf57de232017-05-04 00:31:28 -0700573static int ctx_completed_show(void *data, struct seq_file *m)
Omar Sandoval4a46f052017-01-25 08:06:49 -0800574{
Omar Sandovalf57de232017-05-04 00:31:28 -0700575 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800576
577 seq_printf(m, "%lu %lu\n", ctx->rq_completed[1], ctx->rq_completed[0]);
578 return 0;
579}
580
Omar Sandovalf57de232017-05-04 00:31:28 -0700581static ssize_t ctx_completed_write(void *data, const char __user *buf,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800582 size_t count, loff_t *ppos)
583{
Omar Sandovalf57de232017-05-04 00:31:28 -0700584 struct blk_mq_ctx *ctx = data;
Omar Sandoval4a46f052017-01-25 08:06:49 -0800585
586 ctx->rq_completed[0] = ctx->rq_completed[1] = 0;
587 return count;
588}
589
Omar Sandovalf57de232017-05-04 00:31:28 -0700590static int blk_mq_debugfs_show(struct seq_file *m, void *v)
591{
592 const struct blk_mq_debugfs_attr *attr = m->private;
593 void *data = d_inode(m->file->f_path.dentry->d_parent)->i_private;
594
595 return attr->show(data, m);
596}
597
598static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
599 size_t count, loff_t *ppos)
600{
601 struct seq_file *m = file->private_data;
602 const struct blk_mq_debugfs_attr *attr = m->private;
603 void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
604
605 if (!attr->write)
606 return -EPERM;
607
608 return attr->write(data, buf, count, ppos);
609}
610
611static int blk_mq_debugfs_open(struct inode *inode, struct file *file)
612{
613 const struct blk_mq_debugfs_attr *attr = inode->i_private;
614 void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
615 struct seq_file *m;
616 int ret;
617
618 if (attr->seq_ops) {
619 ret = seq_open(file, attr->seq_ops);
620 if (!ret) {
621 m = file->private_data;
622 m->private = data;
623 }
624 return ret;
625 }
626
627 if (WARN_ON_ONCE(!attr->show))
628 return -EPERM;
629
630 return single_open(file, blk_mq_debugfs_show, inode->i_private);
631}
632
633static int blk_mq_debugfs_release(struct inode *inode, struct file *file)
634{
635 const struct blk_mq_debugfs_attr *attr = inode->i_private;
636
637 if (attr->show)
638 return single_release(inode, file);
639 else
640 return seq_release(inode, file);
641}
642
643const struct file_operations blk_mq_debugfs_fops = {
644 .open = blk_mq_debugfs_open,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800645 .read = seq_read,
Omar Sandovalf57de232017-05-04 00:31:28 -0700646 .write = blk_mq_debugfs_write,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800647 .llseek = seq_lseek,
Omar Sandovalf57de232017-05-04 00:31:28 -0700648 .release = blk_mq_debugfs_release,
Omar Sandoval4a46f052017-01-25 08:06:49 -0800649};
650
Omar Sandoval34dbad52017-03-21 08:56:08 -0700651static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = {
Omar Sandovalf57de232017-05-04 00:31:28 -0700652 {"poll_stat", 0400, queue_poll_stat_show},
653 {"state", 0600, queue_state_show, queue_state_write},
Omar Sandoval34dbad52017-03-21 08:56:08 -0700654 {},
655};
656
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800657static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
Omar Sandovalf57de232017-05-04 00:31:28 -0700658 {"state", 0400, hctx_state_show},
659 {"flags", 0400, hctx_flags_show},
660 {"dispatch", 0400, .seq_ops = &hctx_dispatch_seq_ops},
661 {"ctx_map", 0400, hctx_ctx_map_show},
662 {"tags", 0400, hctx_tags_show},
663 {"tags_bitmap", 0400, hctx_tags_bitmap_show},
664 {"sched_tags", 0400, hctx_sched_tags_show},
665 {"sched_tags_bitmap", 0400, hctx_sched_tags_bitmap_show},
666 {"io_poll", 0600, hctx_io_poll_show, hctx_io_poll_write},
667 {"dispatched", 0600, hctx_dispatched_show, hctx_dispatched_write},
668 {"queued", 0600, hctx_queued_show, hctx_queued_write},
669 {"run", 0600, hctx_run_show, hctx_run_write},
670 {"active", 0400, hctx_active_show},
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800671 {},
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800672};
673
674static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
Omar Sandovalf57de232017-05-04 00:31:28 -0700675 {"rq_list", 0400, .seq_ops = &ctx_rq_list_seq_ops},
676 {"dispatched", 0600, ctx_dispatched_show, ctx_dispatched_write},
677 {"merged", 0600, ctx_merged_show, ctx_merged_write},
678 {"completed", 0600, ctx_completed_show, ctx_completed_write},
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800679 {},
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800680};
681
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800682static bool debugfs_create_files(struct dentry *parent, void *data,
Omar Sandovalf57de232017-05-04 00:31:28 -0700683 const struct blk_mq_debugfs_attr *attr)
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800684{
Omar Sandovalf57de232017-05-04 00:31:28 -0700685 d_inode(parent)->i_private = data;
686
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800687 for (; attr->name; attr++) {
688 if (!debugfs_create_file(attr->name, attr->mode, parent,
Omar Sandovalf57de232017-05-04 00:31:28 -0700689 (void *)attr, &blk_mq_debugfs_fops))
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800690 return false;
691 }
692 return true;
693}
694
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600695int blk_mq_debugfs_register(struct request_queue *q)
696{
697 struct blk_mq_hw_ctx *hctx;
698 int i;
699
700 if (!blk_debugfs_root)
701 return -ENOENT;
702
703 q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
704 blk_debugfs_root);
705 if (!q->debugfs_dir)
706 return -ENOMEM;
707
708 if (!debugfs_create_files(q->debugfs_dir, q,
709 blk_mq_debugfs_queue_attrs))
710 goto err;
711
712 /*
713 * blk_mq_init_hctx() attempted to do this already, but q->debugfs_dir
714 * didn't exist yet (because we don't know what to name the directory
715 * until the queue is registered to a gendisk).
716 */
717 queue_for_each_hw_ctx(q, hctx, i) {
718 if (!hctx->debugfs_dir && blk_mq_debugfs_register_hctx(q, hctx))
719 goto err;
Omar Sandovald332ce02017-05-04 08:24:40 -0600720 if (q->elevator && !hctx->sched_debugfs_dir &&
721 blk_mq_debugfs_register_sched_hctx(q, hctx))
722 goto err;
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600723 }
724
725 return 0;
726
727err:
728 blk_mq_debugfs_unregister(q);
729 return -ENOMEM;
730}
731
732void blk_mq_debugfs_unregister(struct request_queue *q)
733{
734 debugfs_remove_recursive(q->debugfs_dir);
Omar Sandovald332ce02017-05-04 08:24:40 -0600735 q->sched_debugfs_dir = NULL;
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600736 q->debugfs_dir = NULL;
737}
738
739static int blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
740 struct blk_mq_ctx *ctx)
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800741{
742 struct dentry *ctx_dir;
743 char name[20];
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800744
745 snprintf(name, sizeof(name), "cpu%u", ctx->cpu);
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600746 ctx_dir = debugfs_create_dir(name, hctx->debugfs_dir);
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800747 if (!ctx_dir)
748 return -ENOMEM;
749
Bart Van Assche72f2f8f2017-02-01 10:20:59 -0800750 if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs))
751 return -ENOMEM;
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800752
753 return 0;
754}
755
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600756int blk_mq_debugfs_register_hctx(struct request_queue *q,
757 struct blk_mq_hw_ctx *hctx)
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800758{
759 struct blk_mq_ctx *ctx;
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800760 char name[20];
761 int i;
762
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800763 if (!q->debugfs_dir)
764 return -ENOENT;
765
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600766 snprintf(name, sizeof(name), "hctx%u", hctx->queue_num);
767 hctx->debugfs_dir = debugfs_create_dir(name, q->debugfs_dir);
768 if (!hctx->debugfs_dir)
769 return -ENOMEM;
770
771 if (!debugfs_create_files(hctx->debugfs_dir, hctx,
772 blk_mq_debugfs_hctx_attrs))
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800773 goto err;
774
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600775 hctx_for_each_ctx(hctx, ctx, i) {
776 if (blk_mq_debugfs_register_ctx(hctx, ctx))
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800777 goto err;
778 }
779
780 return 0;
781
782err:
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600783 blk_mq_debugfs_unregister_hctx(hctx);
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800784 return -ENOMEM;
785}
786
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600787void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800788{
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600789 debugfs_remove_recursive(hctx->debugfs_dir);
Omar Sandovald332ce02017-05-04 08:24:40 -0600790 hctx->sched_debugfs_dir = NULL;
Omar Sandoval9c1051a2017-05-04 08:17:21 -0600791 hctx->debugfs_dir = NULL;
792}
793
794int blk_mq_debugfs_register_hctxs(struct request_queue *q)
795{
796 struct blk_mq_hw_ctx *hctx;
797 int i;
798
799 queue_for_each_hw_ctx(q, hctx, i) {
800 if (blk_mq_debugfs_register_hctx(q, hctx))
801 return -ENOMEM;
802 }
803
804 return 0;
805}
806
807void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
808{
809 struct blk_mq_hw_ctx *hctx;
810 int i;
811
812 queue_for_each_hw_ctx(q, hctx, i)
813 blk_mq_debugfs_unregister_hctx(hctx);
Omar Sandoval07e4fea2017-01-25 08:06:40 -0800814}
Omar Sandovald332ce02017-05-04 08:24:40 -0600815
816int blk_mq_debugfs_register_sched(struct request_queue *q)
817{
818 struct elevator_type *e = q->elevator->type;
819
820 if (!q->debugfs_dir)
821 return -ENOENT;
822
823 if (!e->queue_debugfs_attrs)
824 return 0;
825
826 q->sched_debugfs_dir = debugfs_create_dir("sched", q->debugfs_dir);
827 if (!q->sched_debugfs_dir)
828 return -ENOMEM;
829
830 if (!debugfs_create_files(q->sched_debugfs_dir, q,
831 e->queue_debugfs_attrs))
832 goto err;
833
834 return 0;
835
836err:
837 blk_mq_debugfs_unregister_sched(q);
838 return -ENOMEM;
839}
840
841void blk_mq_debugfs_unregister_sched(struct request_queue *q)
842{
843 debugfs_remove_recursive(q->sched_debugfs_dir);
844 q->sched_debugfs_dir = NULL;
845}
846
847int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
848 struct blk_mq_hw_ctx *hctx)
849{
850 struct elevator_type *e = q->elevator->type;
851
852 if (!hctx->debugfs_dir)
853 return -ENOENT;
854
855 if (!e->hctx_debugfs_attrs)
856 return 0;
857
858 hctx->sched_debugfs_dir = debugfs_create_dir("sched",
859 hctx->debugfs_dir);
860 if (!hctx->sched_debugfs_dir)
861 return -ENOMEM;
862
863 if (!debugfs_create_files(hctx->sched_debugfs_dir, hctx,
864 e->hctx_debugfs_attrs))
865 return -ENOMEM;
866
867 return 0;
868}
869
870void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
871{
872 debugfs_remove_recursive(hctx->sched_debugfs_dir);
873 hctx->sched_debugfs_dir = NULL;
874}