block/blk-mq-debugfs.c
Source file repositories/reference/linux-study-clean/block/blk-mq-debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-mq-debugfs.c- Extension
.c- Size
- 20931 bytes
- Lines
- 830
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/blkdev.hlinux/build_bug.hlinux/debugfs.hblk.hblk-mq.hblk-mq-debugfs.hblk-mq-sched.hblk-rq-qos.h
Detected Declarations
struct show_busy_paramsfunction Copyrightfunction queue_requeue_list_stopfunction blk_flags_showfunction queue_pm_only_showfunction queue_state_showfunction queue_state_writefunction hctx_state_showfunction hctx_flags_showfunction __blk_mq_debugfs_rq_showfunction blk_mq_debugfs_rq_showfunction hctx_dispatch_stopfunction hctx_show_busy_rqfunction hctx_busy_showfunction hctx_type_showfunction hctx_ctx_map_showfunction blk_mq_debugfs_tags_showfunction hctx_tags_showfunction hctx_tags_bitmap_showfunction hctx_sched_tags_showfunction hctx_sched_tags_bitmap_showfunction hctx_active_showfunction hctx_dispatch_busy_showfunction blk_mq_debugfs_showfunction blk_mq_debugfs_writefunction blk_mq_debugfs_openfunction blk_mq_debugfs_releasefunction debugfs_create_filesfunction blk_mq_debugfs_registerfunction queue_for_each_hw_ctxfunction blk_mq_debugfs_register_ctxfunction blk_mq_debugfs_register_hctxfunction blk_mq_debugfs_unregister_hctxfunction blk_mq_debugfs_register_hctxsfunction blk_mq_debugfs_unregister_hctxsfunction blk_mq_debugfs_register_schedfunction blk_mq_debugfs_unregister_schedfunction blk_mq_debugfs_register_rqosfunction blk_mq_debugfs_register_rq_qosfunction blk_mq_debugfs_register_sched_hctxfunction blk_mq_debugfs_unregister_sched_hctxexport __blk_mq_debugfs_rq_showexport blk_mq_debugfs_rq_show
Annotated Snippet
const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
const enum req_op op = req_op(rq);
const char *op_str = blk_op_str(op);
BUILD_BUG_ON(ARRAY_SIZE(cmd_flag_name) != __REQ_NR_BITS);
BUILD_BUG_ON(ARRAY_SIZE(rqf_name) != __RQF_BITS);
seq_printf(m, "%p {.op=", rq);
if (strcmp(op_str, "UNKNOWN") == 0)
seq_printf(m, "%u", op);
else
seq_printf(m, "%s", op_str);
seq_puts(m, ", .cmd_flags=");
blk_flags_show(m, (__force unsigned int)(rq->cmd_flags & ~REQ_OP_MASK),
cmd_flag_name, ARRAY_SIZE(cmd_flag_name));
seq_puts(m, ", .rq_flags=");
blk_flags_show(m, (__force unsigned int)rq->rq_flags, rqf_name,
ARRAY_SIZE(rqf_name));
seq_printf(m, ", .state=%s", blk_mq_rq_state_name(blk_mq_rq_state(rq)));
seq_printf(m, ", .tag=%d, .internal_tag=%d", rq->tag,
rq->internal_tag);
if (mq_ops->show_rq)
mq_ops->show_rq(m, rq);
seq_puts(m, "}\n");
return 0;
}
EXPORT_SYMBOL_GPL(__blk_mq_debugfs_rq_show);
int blk_mq_debugfs_rq_show(struct seq_file *m, void *v)
{
return __blk_mq_debugfs_rq_show(m, list_entry_rq(v));
}
EXPORT_SYMBOL_GPL(blk_mq_debugfs_rq_show);
#define TO_HCTX(m) ((struct blk_mq_hw_ctx *)m->private)
static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos)
__acquires(&TO_HCTX(m)->lock)
{
struct blk_mq_hw_ctx *hctx = m->private;
spin_lock(&hctx->lock);
return seq_list_start(&hctx->dispatch, *pos);
}
static void *hctx_dispatch_next(struct seq_file *m, void *v, loff_t *pos)
{
struct blk_mq_hw_ctx *hctx = m->private;
return seq_list_next(v, &hctx->dispatch, pos);
}
static void hctx_dispatch_stop(struct seq_file *m, void *v)
__releases(&TO_HCTX(m)->lock)
{
struct blk_mq_hw_ctx *hctx = m->private;
spin_unlock(&hctx->lock);
}
#undef TO_HCTX
static const struct seq_operations hctx_dispatch_seq_ops = {
.start = hctx_dispatch_start,
.next = hctx_dispatch_next,
.stop = hctx_dispatch_stop,
.show = blk_mq_debugfs_rq_show,
};
struct show_busy_params {
struct seq_file *m;
struct blk_mq_hw_ctx *hctx;
};
/*
* Note: the state of a request may change while this function is in progress,
* e.g. due to a concurrent blk_mq_finish_request() call. Returns true to
* keep iterating requests.
*/
static bool hctx_show_busy_rq(struct request *rq, void *data)
{
const struct show_busy_params *params = data;
if (rq->mq_hctx == params->hctx)
__blk_mq_debugfs_rq_show(params->m, rq);
return true;
}
static int hctx_busy_show(void *data, struct seq_file *m)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/blkdev.h`, `linux/build_bug.h`, `linux/debugfs.h`, `blk.h`, `blk-mq.h`, `blk-mq-debugfs.h`, `blk-mq-sched.h`.
- Detected declarations: `struct show_busy_params`, `function Copyright`, `function queue_requeue_list_stop`, `function blk_flags_show`, `function queue_pm_only_show`, `function queue_state_show`, `function queue_state_write`, `function hctx_state_show`, `function hctx_flags_show`, `function __blk_mq_debugfs_rq_show`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.