]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - block/blk-mq-debugfs.c
blk-stat: convert to callback-based statistics reporting
[mirror_ubuntu-artful-kernel.git] / block / blk-mq-debugfs.c
1 /*
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>
22 #include "blk.h"
23 #include "blk-mq.h"
24 #include "blk-mq-tag.h"
25
26 struct blk_mq_debugfs_attr {
27 const char *name;
28 umode_t mode;
29 const struct file_operations *fops;
30 };
31
32 static int blk_mq_debugfs_seq_open(struct inode *inode, struct file *file,
33 const struct seq_operations *ops)
34 {
35 struct seq_file *m;
36 int ret;
37
38 ret = seq_open(file, ops);
39 if (!ret) {
40 m = file->private_data;
41 m->private = inode->i_private;
42 }
43 return ret;
44 }
45
46 static void print_stat(struct seq_file *m, struct blk_rq_stat *stat)
47 {
48 if (stat->nr_samples) {
49 seq_printf(m, "samples=%d, mean=%lld, min=%llu, max=%llu",
50 stat->nr_samples, stat->mean, stat->min, stat->max);
51 } else {
52 seq_puts(m, "samples=0");
53 }
54 }
55
56 static int queue_poll_stat_show(struct seq_file *m, void *v)
57 {
58 struct request_queue *q = m->private;
59
60 seq_puts(m, "read: ");
61 print_stat(m, &q->poll_stat[READ]);
62 seq_puts(m, "\n");
63
64 seq_puts(m, "write: ");
65 print_stat(m, &q->poll_stat[WRITE]);
66 seq_puts(m, "\n");
67 return 0;
68 }
69
70 static int queue_poll_stat_open(struct inode *inode, struct file *file)
71 {
72 return single_open(file, queue_poll_stat_show, inode->i_private);
73 }
74
75 static const struct file_operations queue_poll_stat_fops = {
76 .open = queue_poll_stat_open,
77 .read = seq_read,
78 .llseek = seq_lseek,
79 .release = single_release,
80 };
81
82 static int hctx_state_show(struct seq_file *m, void *v)
83 {
84 struct blk_mq_hw_ctx *hctx = m->private;
85
86 seq_printf(m, "0x%lx\n", hctx->state);
87 return 0;
88 }
89
90 static int hctx_state_open(struct inode *inode, struct file *file)
91 {
92 return single_open(file, hctx_state_show, inode->i_private);
93 }
94
95 static const struct file_operations hctx_state_fops = {
96 .open = hctx_state_open,
97 .read = seq_read,
98 .llseek = seq_lseek,
99 .release = single_release,
100 };
101
102 static int hctx_flags_show(struct seq_file *m, void *v)
103 {
104 struct blk_mq_hw_ctx *hctx = m->private;
105
106 seq_printf(m, "0x%lx\n", hctx->flags);
107 return 0;
108 }
109
110 static int hctx_flags_open(struct inode *inode, struct file *file)
111 {
112 return single_open(file, hctx_flags_show, inode->i_private);
113 }
114
115 static const struct file_operations hctx_flags_fops = {
116 .open = hctx_flags_open,
117 .read = seq_read,
118 .llseek = seq_lseek,
119 .release = single_release,
120 };
121
122 static int blk_mq_debugfs_rq_show(struct seq_file *m, void *v)
123 {
124 struct request *rq = list_entry_rq(v);
125
126 seq_printf(m, "%p {.cmd_flags=0x%x, .rq_flags=0x%x, .tag=%d, .internal_tag=%d}\n",
127 rq, rq->cmd_flags, (__force unsigned int)rq->rq_flags,
128 rq->tag, rq->internal_tag);
129 return 0;
130 }
131
132 static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos)
133 __acquires(&hctx->lock)
134 {
135 struct blk_mq_hw_ctx *hctx = m->private;
136
137 spin_lock(&hctx->lock);
138 return seq_list_start(&hctx->dispatch, *pos);
139 }
140
141 static void *hctx_dispatch_next(struct seq_file *m, void *v, loff_t *pos)
142 {
143 struct blk_mq_hw_ctx *hctx = m->private;
144
145 return seq_list_next(v, &hctx->dispatch, pos);
146 }
147
148 static void hctx_dispatch_stop(struct seq_file *m, void *v)
149 __releases(&hctx->lock)
150 {
151 struct blk_mq_hw_ctx *hctx = m->private;
152
153 spin_unlock(&hctx->lock);
154 }
155
156 static const struct seq_operations hctx_dispatch_seq_ops = {
157 .start = hctx_dispatch_start,
158 .next = hctx_dispatch_next,
159 .stop = hctx_dispatch_stop,
160 .show = blk_mq_debugfs_rq_show,
161 };
162
163 static int hctx_dispatch_open(struct inode *inode, struct file *file)
164 {
165 return blk_mq_debugfs_seq_open(inode, file, &hctx_dispatch_seq_ops);
166 }
167
168 static const struct file_operations hctx_dispatch_fops = {
169 .open = hctx_dispatch_open,
170 .read = seq_read,
171 .llseek = seq_lseek,
172 .release = seq_release,
173 };
174
175 static int hctx_ctx_map_show(struct seq_file *m, void *v)
176 {
177 struct blk_mq_hw_ctx *hctx = m->private;
178
179 sbitmap_bitmap_show(&hctx->ctx_map, m);
180 return 0;
181 }
182
183 static int hctx_ctx_map_open(struct inode *inode, struct file *file)
184 {
185 return single_open(file, hctx_ctx_map_show, inode->i_private);
186 }
187
188 static const struct file_operations hctx_ctx_map_fops = {
189 .open = hctx_ctx_map_open,
190 .read = seq_read,
191 .llseek = seq_lseek,
192 .release = single_release,
193 };
194
195 static void blk_mq_debugfs_tags_show(struct seq_file *m,
196 struct blk_mq_tags *tags)
197 {
198 seq_printf(m, "nr_tags=%u\n", tags->nr_tags);
199 seq_printf(m, "nr_reserved_tags=%u\n", tags->nr_reserved_tags);
200 seq_printf(m, "active_queues=%d\n",
201 atomic_read(&tags->active_queues));
202
203 seq_puts(m, "\nbitmap_tags:\n");
204 sbitmap_queue_show(&tags->bitmap_tags, m);
205
206 if (tags->nr_reserved_tags) {
207 seq_puts(m, "\nbreserved_tags:\n");
208 sbitmap_queue_show(&tags->breserved_tags, m);
209 }
210 }
211
212 static int hctx_tags_show(struct seq_file *m, void *v)
213 {
214 struct blk_mq_hw_ctx *hctx = m->private;
215 struct request_queue *q = hctx->queue;
216 int res;
217
218 res = mutex_lock_interruptible(&q->sysfs_lock);
219 if (res)
220 goto out;
221 if (hctx->tags)
222 blk_mq_debugfs_tags_show(m, hctx->tags);
223 mutex_unlock(&q->sysfs_lock);
224
225 out:
226 return res;
227 }
228
229 static int hctx_tags_open(struct inode *inode, struct file *file)
230 {
231 return single_open(file, hctx_tags_show, inode->i_private);
232 }
233
234 static const struct file_operations hctx_tags_fops = {
235 .open = hctx_tags_open,
236 .read = seq_read,
237 .llseek = seq_lseek,
238 .release = single_release,
239 };
240
241 static int hctx_tags_bitmap_show(struct seq_file *m, void *v)
242 {
243 struct blk_mq_hw_ctx *hctx = m->private;
244 struct request_queue *q = hctx->queue;
245 int res;
246
247 res = mutex_lock_interruptible(&q->sysfs_lock);
248 if (res)
249 goto out;
250 if (hctx->tags)
251 sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m);
252 mutex_unlock(&q->sysfs_lock);
253
254 out:
255 return res;
256 }
257
258 static int hctx_tags_bitmap_open(struct inode *inode, struct file *file)
259 {
260 return single_open(file, hctx_tags_bitmap_show, inode->i_private);
261 }
262
263 static const struct file_operations hctx_tags_bitmap_fops = {
264 .open = hctx_tags_bitmap_open,
265 .read = seq_read,
266 .llseek = seq_lseek,
267 .release = single_release,
268 };
269
270 static int hctx_sched_tags_show(struct seq_file *m, void *v)
271 {
272 struct blk_mq_hw_ctx *hctx = m->private;
273 struct request_queue *q = hctx->queue;
274 int res;
275
276 res = mutex_lock_interruptible(&q->sysfs_lock);
277 if (res)
278 goto out;
279 if (hctx->sched_tags)
280 blk_mq_debugfs_tags_show(m, hctx->sched_tags);
281 mutex_unlock(&q->sysfs_lock);
282
283 out:
284 return res;
285 }
286
287 static int hctx_sched_tags_open(struct inode *inode, struct file *file)
288 {
289 return single_open(file, hctx_sched_tags_show, inode->i_private);
290 }
291
292 static const struct file_operations hctx_sched_tags_fops = {
293 .open = hctx_sched_tags_open,
294 .read = seq_read,
295 .llseek = seq_lseek,
296 .release = single_release,
297 };
298
299 static int hctx_sched_tags_bitmap_show(struct seq_file *m, void *v)
300 {
301 struct blk_mq_hw_ctx *hctx = m->private;
302 struct request_queue *q = hctx->queue;
303 int res;
304
305 res = mutex_lock_interruptible(&q->sysfs_lock);
306 if (res)
307 goto out;
308 if (hctx->sched_tags)
309 sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m);
310 mutex_unlock(&q->sysfs_lock);
311
312 out:
313 return res;
314 }
315
316 static int hctx_sched_tags_bitmap_open(struct inode *inode, struct file *file)
317 {
318 return single_open(file, hctx_sched_tags_bitmap_show, inode->i_private);
319 }
320
321 static const struct file_operations hctx_sched_tags_bitmap_fops = {
322 .open = hctx_sched_tags_bitmap_open,
323 .read = seq_read,
324 .llseek = seq_lseek,
325 .release = single_release,
326 };
327
328 static int hctx_io_poll_show(struct seq_file *m, void *v)
329 {
330 struct blk_mq_hw_ctx *hctx = m->private;
331
332 seq_printf(m, "considered=%lu\n", hctx->poll_considered);
333 seq_printf(m, "invoked=%lu\n", hctx->poll_invoked);
334 seq_printf(m, "success=%lu\n", hctx->poll_success);
335 return 0;
336 }
337
338 static int hctx_io_poll_open(struct inode *inode, struct file *file)
339 {
340 return single_open(file, hctx_io_poll_show, inode->i_private);
341 }
342
343 static ssize_t hctx_io_poll_write(struct file *file, const char __user *buf,
344 size_t count, loff_t *ppos)
345 {
346 struct seq_file *m = file->private_data;
347 struct blk_mq_hw_ctx *hctx = m->private;
348
349 hctx->poll_considered = hctx->poll_invoked = hctx->poll_success = 0;
350 return count;
351 }
352
353 static const struct file_operations hctx_io_poll_fops = {
354 .open = hctx_io_poll_open,
355 .read = seq_read,
356 .write = hctx_io_poll_write,
357 .llseek = seq_lseek,
358 .release = single_release,
359 };
360
361 static int hctx_dispatched_show(struct seq_file *m, void *v)
362 {
363 struct blk_mq_hw_ctx *hctx = m->private;
364 int i;
365
366 seq_printf(m, "%8u\t%lu\n", 0U, hctx->dispatched[0]);
367
368 for (i = 1; i < BLK_MQ_MAX_DISPATCH_ORDER - 1; i++) {
369 unsigned int d = 1U << (i - 1);
370
371 seq_printf(m, "%8u\t%lu\n", d, hctx->dispatched[i]);
372 }
373
374 seq_printf(m, "%8u+\t%lu\n", 1U << (i - 1), hctx->dispatched[i]);
375 return 0;
376 }
377
378 static int hctx_dispatched_open(struct inode *inode, struct file *file)
379 {
380 return single_open(file, hctx_dispatched_show, inode->i_private);
381 }
382
383 static ssize_t hctx_dispatched_write(struct file *file, const char __user *buf,
384 size_t count, loff_t *ppos)
385 {
386 struct seq_file *m = file->private_data;
387 struct blk_mq_hw_ctx *hctx = m->private;
388 int i;
389
390 for (i = 0; i < BLK_MQ_MAX_DISPATCH_ORDER; i++)
391 hctx->dispatched[i] = 0;
392 return count;
393 }
394
395 static const struct file_operations hctx_dispatched_fops = {
396 .open = hctx_dispatched_open,
397 .read = seq_read,
398 .write = hctx_dispatched_write,
399 .llseek = seq_lseek,
400 .release = single_release,
401 };
402
403 static int hctx_queued_show(struct seq_file *m, void *v)
404 {
405 struct blk_mq_hw_ctx *hctx = m->private;
406
407 seq_printf(m, "%lu\n", hctx->queued);
408 return 0;
409 }
410
411 static int hctx_queued_open(struct inode *inode, struct file *file)
412 {
413 return single_open(file, hctx_queued_show, inode->i_private);
414 }
415
416 static ssize_t hctx_queued_write(struct file *file, const char __user *buf,
417 size_t count, loff_t *ppos)
418 {
419 struct seq_file *m = file->private_data;
420 struct blk_mq_hw_ctx *hctx = m->private;
421
422 hctx->queued = 0;
423 return count;
424 }
425
426 static const struct file_operations hctx_queued_fops = {
427 .open = hctx_queued_open,
428 .read = seq_read,
429 .write = hctx_queued_write,
430 .llseek = seq_lseek,
431 .release = single_release,
432 };
433
434 static int hctx_run_show(struct seq_file *m, void *v)
435 {
436 struct blk_mq_hw_ctx *hctx = m->private;
437
438 seq_printf(m, "%lu\n", hctx->run);
439 return 0;
440 }
441
442 static int hctx_run_open(struct inode *inode, struct file *file)
443 {
444 return single_open(file, hctx_run_show, inode->i_private);
445 }
446
447 static ssize_t hctx_run_write(struct file *file, const char __user *buf,
448 size_t count, loff_t *ppos)
449 {
450 struct seq_file *m = file->private_data;
451 struct blk_mq_hw_ctx *hctx = m->private;
452
453 hctx->run = 0;
454 return count;
455 }
456
457 static const struct file_operations hctx_run_fops = {
458 .open = hctx_run_open,
459 .read = seq_read,
460 .write = hctx_run_write,
461 .llseek = seq_lseek,
462 .release = single_release,
463 };
464
465 static int hctx_active_show(struct seq_file *m, void *v)
466 {
467 struct blk_mq_hw_ctx *hctx = m->private;
468
469 seq_printf(m, "%d\n", atomic_read(&hctx->nr_active));
470 return 0;
471 }
472
473 static int hctx_active_open(struct inode *inode, struct file *file)
474 {
475 return single_open(file, hctx_active_show, inode->i_private);
476 }
477
478 static const struct file_operations hctx_active_fops = {
479 .open = hctx_active_open,
480 .read = seq_read,
481 .llseek = seq_lseek,
482 .release = single_release,
483 };
484
485 static void *ctx_rq_list_start(struct seq_file *m, loff_t *pos)
486 __acquires(&ctx->lock)
487 {
488 struct blk_mq_ctx *ctx = m->private;
489
490 spin_lock(&ctx->lock);
491 return seq_list_start(&ctx->rq_list, *pos);
492 }
493
494 static void *ctx_rq_list_next(struct seq_file *m, void *v, loff_t *pos)
495 {
496 struct blk_mq_ctx *ctx = m->private;
497
498 return seq_list_next(v, &ctx->rq_list, pos);
499 }
500
501 static void ctx_rq_list_stop(struct seq_file *m, void *v)
502 __releases(&ctx->lock)
503 {
504 struct blk_mq_ctx *ctx = m->private;
505
506 spin_unlock(&ctx->lock);
507 }
508
509 static const struct seq_operations ctx_rq_list_seq_ops = {
510 .start = ctx_rq_list_start,
511 .next = ctx_rq_list_next,
512 .stop = ctx_rq_list_stop,
513 .show = blk_mq_debugfs_rq_show,
514 };
515
516 static int ctx_rq_list_open(struct inode *inode, struct file *file)
517 {
518 return blk_mq_debugfs_seq_open(inode, file, &ctx_rq_list_seq_ops);
519 }
520
521 static const struct file_operations ctx_rq_list_fops = {
522 .open = ctx_rq_list_open,
523 .read = seq_read,
524 .llseek = seq_lseek,
525 .release = seq_release,
526 };
527
528 static int ctx_dispatched_show(struct seq_file *m, void *v)
529 {
530 struct blk_mq_ctx *ctx = m->private;
531
532 seq_printf(m, "%lu %lu\n", ctx->rq_dispatched[1], ctx->rq_dispatched[0]);
533 return 0;
534 }
535
536 static int ctx_dispatched_open(struct inode *inode, struct file *file)
537 {
538 return single_open(file, ctx_dispatched_show, inode->i_private);
539 }
540
541 static ssize_t ctx_dispatched_write(struct file *file, const char __user *buf,
542 size_t count, loff_t *ppos)
543 {
544 struct seq_file *m = file->private_data;
545 struct blk_mq_ctx *ctx = m->private;
546
547 ctx->rq_dispatched[0] = ctx->rq_dispatched[1] = 0;
548 return count;
549 }
550
551 static const struct file_operations ctx_dispatched_fops = {
552 .open = ctx_dispatched_open,
553 .read = seq_read,
554 .write = ctx_dispatched_write,
555 .llseek = seq_lseek,
556 .release = single_release,
557 };
558
559 static int ctx_merged_show(struct seq_file *m, void *v)
560 {
561 struct blk_mq_ctx *ctx = m->private;
562
563 seq_printf(m, "%lu\n", ctx->rq_merged);
564 return 0;
565 }
566
567 static int ctx_merged_open(struct inode *inode, struct file *file)
568 {
569 return single_open(file, ctx_merged_show, inode->i_private);
570 }
571
572 static ssize_t ctx_merged_write(struct file *file, const char __user *buf,
573 size_t count, loff_t *ppos)
574 {
575 struct seq_file *m = file->private_data;
576 struct blk_mq_ctx *ctx = m->private;
577
578 ctx->rq_merged = 0;
579 return count;
580 }
581
582 static const struct file_operations ctx_merged_fops = {
583 .open = ctx_merged_open,
584 .read = seq_read,
585 .write = ctx_merged_write,
586 .llseek = seq_lseek,
587 .release = single_release,
588 };
589
590 static int ctx_completed_show(struct seq_file *m, void *v)
591 {
592 struct blk_mq_ctx *ctx = m->private;
593
594 seq_printf(m, "%lu %lu\n", ctx->rq_completed[1], ctx->rq_completed[0]);
595 return 0;
596 }
597
598 static int ctx_completed_open(struct inode *inode, struct file *file)
599 {
600 return single_open(file, ctx_completed_show, inode->i_private);
601 }
602
603 static ssize_t ctx_completed_write(struct file *file, const char __user *buf,
604 size_t count, loff_t *ppos)
605 {
606 struct seq_file *m = file->private_data;
607 struct blk_mq_ctx *ctx = m->private;
608
609 ctx->rq_completed[0] = ctx->rq_completed[1] = 0;
610 return count;
611 }
612
613 static const struct file_operations ctx_completed_fops = {
614 .open = ctx_completed_open,
615 .read = seq_read,
616 .write = ctx_completed_write,
617 .llseek = seq_lseek,
618 .release = single_release,
619 };
620
621 static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = {
622 {"poll_stat", 0400, &queue_poll_stat_fops},
623 {},
624 };
625
626 static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
627 {"state", 0400, &hctx_state_fops},
628 {"flags", 0400, &hctx_flags_fops},
629 {"dispatch", 0400, &hctx_dispatch_fops},
630 {"ctx_map", 0400, &hctx_ctx_map_fops},
631 {"tags", 0400, &hctx_tags_fops},
632 {"tags_bitmap", 0400, &hctx_tags_bitmap_fops},
633 {"sched_tags", 0400, &hctx_sched_tags_fops},
634 {"sched_tags_bitmap", 0400, &hctx_sched_tags_bitmap_fops},
635 {"io_poll", 0600, &hctx_io_poll_fops},
636 {"dispatched", 0600, &hctx_dispatched_fops},
637 {"queued", 0600, &hctx_queued_fops},
638 {"run", 0600, &hctx_run_fops},
639 {"active", 0400, &hctx_active_fops},
640 {},
641 };
642
643 static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = {
644 {"rq_list", 0400, &ctx_rq_list_fops},
645 {"dispatched", 0600, &ctx_dispatched_fops},
646 {"merged", 0600, &ctx_merged_fops},
647 {"completed", 0600, &ctx_completed_fops},
648 {},
649 };
650
651 int blk_mq_debugfs_register(struct request_queue *q, const char *name)
652 {
653 if (!blk_debugfs_root)
654 return -ENOENT;
655
656 q->debugfs_dir = debugfs_create_dir(name, blk_debugfs_root);
657 if (!q->debugfs_dir)
658 goto err;
659
660 if (blk_mq_debugfs_register_hctxs(q))
661 goto err;
662
663 return 0;
664
665 err:
666 blk_mq_debugfs_unregister(q);
667 return -ENOMEM;
668 }
669
670 void blk_mq_debugfs_unregister(struct request_queue *q)
671 {
672 debugfs_remove_recursive(q->debugfs_dir);
673 q->mq_debugfs_dir = NULL;
674 q->debugfs_dir = NULL;
675 }
676
677 static bool debugfs_create_files(struct dentry *parent, void *data,
678 const struct blk_mq_debugfs_attr *attr)
679 {
680 for (; attr->name; attr++) {
681 if (!debugfs_create_file(attr->name, attr->mode, parent,
682 data, attr->fops))
683 return false;
684 }
685 return true;
686 }
687
688 static int blk_mq_debugfs_register_ctx(struct request_queue *q,
689 struct blk_mq_ctx *ctx,
690 struct dentry *hctx_dir)
691 {
692 struct dentry *ctx_dir;
693 char name[20];
694
695 snprintf(name, sizeof(name), "cpu%u", ctx->cpu);
696 ctx_dir = debugfs_create_dir(name, hctx_dir);
697 if (!ctx_dir)
698 return -ENOMEM;
699
700 if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs))
701 return -ENOMEM;
702
703 return 0;
704 }
705
706 static int blk_mq_debugfs_register_hctx(struct request_queue *q,
707 struct blk_mq_hw_ctx *hctx)
708 {
709 struct blk_mq_ctx *ctx;
710 struct dentry *hctx_dir;
711 char name[20];
712 int i;
713
714 snprintf(name, sizeof(name), "%u", hctx->queue_num);
715 hctx_dir = debugfs_create_dir(name, q->mq_debugfs_dir);
716 if (!hctx_dir)
717 return -ENOMEM;
718
719 if (!debugfs_create_files(hctx_dir, hctx, blk_mq_debugfs_hctx_attrs))
720 return -ENOMEM;
721
722 hctx_for_each_ctx(hctx, ctx, i) {
723 if (blk_mq_debugfs_register_ctx(q, ctx, hctx_dir))
724 return -ENOMEM;
725 }
726
727 return 0;
728 }
729
730 int blk_mq_debugfs_register_hctxs(struct request_queue *q)
731 {
732 struct blk_mq_hw_ctx *hctx;
733 int i;
734
735 if (!q->debugfs_dir)
736 return -ENOENT;
737
738 q->mq_debugfs_dir = debugfs_create_dir("mq", q->debugfs_dir);
739 if (!q->mq_debugfs_dir)
740 goto err;
741
742 if (!debugfs_create_files(q->mq_debugfs_dir, q, blk_mq_debugfs_queue_attrs))
743 goto err;
744
745 queue_for_each_hw_ctx(q, hctx, i) {
746 if (blk_mq_debugfs_register_hctx(q, hctx))
747 goto err;
748 }
749
750 return 0;
751
752 err:
753 blk_mq_debugfs_unregister_hctxs(q);
754 return -ENOMEM;
755 }
756
757 void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
758 {
759 debugfs_remove_recursive(q->mq_debugfs_dir);
760 q->mq_debugfs_dir = NULL;
761 }