block/blk-mq-sysfs.c
Source file repositories/reference/linux-study-clean/block/blk-mq-sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-mq-sysfs.c- Extension
.c- Size
- 6564 bytes
- Lines
- 299
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source 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.
- 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/module.hlinux/backing-dev.hlinux/bio.hlinux/blkdev.hlinux/mm.hlinux/init.hlinux/slab.hlinux/workqueue.hlinux/smp.hblk.hblk-mq.h
Detected Declarations
struct blk_mq_hw_ctx_sysfs_entryfunction blk_mq_sysfs_releasefunction blk_mq_ctx_sysfs_releasefunction blk_mq_hw_sysfs_releasefunction blk_mq_hw_sysfs_showfunction blk_mq_hw_sysfs_nr_tags_showfunction blk_mq_hw_sysfs_nr_reserved_tags_showfunction blk_mq_hw_sysfs_cpus_showfunction for_each_cpufunction blk_mq_unregister_hctxfunction blk_mq_register_hctxfunction hctx_for_each_ctxfunction blk_mq_hctx_kobj_initfunction blk_mq_sysfs_deinitfunction for_each_possible_cpufunction blk_mq_sysfs_initfunction for_each_possible_cpufunction blk_mq_sysfs_registerfunction blk_mq_sysfs_unregisterfunction blk_mq_sysfs_unregister_hctxsfunction blk_mq_sysfs_register_hctxsfunction queue_for_each_hw_ctx
Annotated Snippet
struct blk_mq_hw_ctx_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct blk_mq_hw_ctx *, char *);
};
static ssize_t blk_mq_hw_sysfs_show(struct kobject *kobj,
struct attribute *attr, char *page)
{
struct blk_mq_hw_ctx_sysfs_entry *entry;
struct blk_mq_hw_ctx *hctx;
struct request_queue *q;
ssize_t res;
entry = container_of_const(attr, struct blk_mq_hw_ctx_sysfs_entry, attr);
hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj);
q = hctx->queue;
if (!entry->show)
return -EIO;
mutex_lock(&q->elevator_lock);
res = entry->show(hctx, page);
mutex_unlock(&q->elevator_lock);
return res;
}
static ssize_t blk_mq_hw_sysfs_nr_tags_show(struct blk_mq_hw_ctx *hctx,
char *page)
{
return sprintf(page, "%u\n", hctx->tags->nr_tags);
}
static ssize_t blk_mq_hw_sysfs_nr_reserved_tags_show(struct blk_mq_hw_ctx *hctx,
char *page)
{
return sprintf(page, "%u\n", hctx->tags->nr_reserved_tags);
}
static ssize_t blk_mq_hw_sysfs_cpus_show(struct blk_mq_hw_ctx *hctx, char *page)
{
const size_t size = PAGE_SIZE - 1;
unsigned int i, first = 1;
int ret = 0, pos = 0;
for_each_cpu(i, hctx->cpumask) {
if (first)
ret = snprintf(pos + page, size - pos, "%u", i);
else
ret = snprintf(pos + page, size - pos, ", %u", i);
if (ret >= size - pos)
break;
first = 0;
pos += ret;
}
ret = snprintf(pos + page, size + 1 - pos, "\n");
return pos + ret;
}
static const struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_tags = {
.attr = {.name = "nr_tags", .mode = 0444 },
.show = blk_mq_hw_sysfs_nr_tags_show,
};
static const struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_nr_reserved_tags = {
.attr = {.name = "nr_reserved_tags", .mode = 0444 },
.show = blk_mq_hw_sysfs_nr_reserved_tags_show,
};
static const struct blk_mq_hw_ctx_sysfs_entry blk_mq_hw_sysfs_cpus = {
.attr = {.name = "cpu_list", .mode = 0444 },
.show = blk_mq_hw_sysfs_cpus_show,
};
static const struct attribute *const default_hw_ctx_attrs[] = {
&blk_mq_hw_sysfs_nr_tags.attr,
&blk_mq_hw_sysfs_nr_reserved_tags.attr,
&blk_mq_hw_sysfs_cpus.attr,
NULL,
};
ATTRIBUTE_GROUPS(default_hw_ctx);
static const struct sysfs_ops blk_mq_hw_sysfs_ops = {
.show = blk_mq_hw_sysfs_show,
};
static const struct kobj_type blk_mq_ktype = {
.release = blk_mq_sysfs_release,
};
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/backing-dev.h`, `linux/bio.h`, `linux/blkdev.h`, `linux/mm.h`, `linux/init.h`, `linux/slab.h`.
- Detected declarations: `struct blk_mq_hw_ctx_sysfs_entry`, `function blk_mq_sysfs_release`, `function blk_mq_ctx_sysfs_release`, `function blk_mq_hw_sysfs_release`, `function blk_mq_hw_sysfs_show`, `function blk_mq_hw_sysfs_nr_tags_show`, `function blk_mq_hw_sysfs_nr_reserved_tags_show`, `function blk_mq_hw_sysfs_cpus_show`, `function for_each_cpu`, `function blk_mq_unregister_hctx`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source implementation candidate.
- 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.