block/blk-mq-tag.c
Source file repositories/reference/linux-study-clean/block/blk-mq-tag.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-mq-tag.c- Extension
.c- Size
- 18421 bytes
- Lines
- 656
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/slab.hlinux/mm.hlinux/kmemleak.hlinux/delay.htrace/events/block.hblk.hblk-mq.hblk-mq-sched.h
Detected Declarations
struct bt_iter_datastruct bt_tags_iter_datafunction Copyrightfunction __blk_mq_tag_busyfunction test_bitfunction blk_mq_tag_wakeup_allfunction __blk_mq_tag_idlefunction __blk_mq_get_tagfunction blk_mq_get_tagsfunction blk_mq_get_tagfunction blk_mq_put_tagfunction blk_mq_put_tagsfunction bt_iterfunction bt_for_eachfunction bt_tags_iterfunction bt_tags_for_eachfunction __blk_mq_all_tag_iterfunction blk_mq_all_tag_iterfunction blk_mq_tagset_busy_iterfunction blk_mq_tagset_count_completed_rqsfunction blk_mq_tagset_wait_completed_requestfunction blk_mq_queue_tag_busy_iterfunction queue_for_each_hw_ctxfunction bt_allocfunction blk_mq_free_tags_callbackfunction blk_mq_free_tagsfunction blk_mq_tag_resize_shared_tagsfunction blk_mq_tag_update_sched_shared_tagsfunction blk_mq_unique_tagexport blk_mq_tagset_busy_iterexport blk_mq_tagset_wait_completed_requestexport blk_mq_unique_tag
Annotated Snippet
struct bt_iter_data {
struct blk_mq_hw_ctx *hctx;
struct request_queue *q;
busy_tag_iter_fn *fn;
void *data;
bool reserved;
};
static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags,
unsigned int bitnr)
{
struct request *rq;
rq = tags->rqs[bitnr];
if (!rq || rq->tag != bitnr || !req_ref_inc_not_zero(rq))
rq = NULL;
return rq;
}
static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
{
struct bt_iter_data *iter_data = data;
struct blk_mq_hw_ctx *hctx = iter_data->hctx;
struct request_queue *q = iter_data->q;
struct blk_mq_tag_set *set = q->tag_set;
struct blk_mq_tags *tags;
struct request *rq;
bool ret = true;
if (blk_mq_is_shared_tags(set->flags))
tags = set->shared_tags;
else
tags = hctx->tags;
if (!iter_data->reserved)
bitnr += tags->nr_reserved_tags;
/*
* We can hit rq == NULL here, because the tagging functions
* test and set the bit before assigning ->rqs[].
*/
rq = blk_mq_find_and_get_req(tags, bitnr);
if (!rq)
return true;
if (rq->q == q && (!hctx || rq->mq_hctx == hctx))
ret = iter_data->fn(rq, iter_data->data);
blk_mq_put_rq_ref(rq);
return ret;
}
/**
* bt_for_each - iterate over the requests associated with a hardware queue
* @hctx: Hardware queue to examine.
* @q: Request queue @hctx is associated with (@hctx->queue).
* @bt: sbitmap to examine. This is either the breserved_tags member
* or the bitmap_tags member of struct blk_mq_tags.
* @fn: Pointer to the function that will be called for each request
* associated with @hctx that has been assigned a driver tag.
* @fn will be called as follows: @fn(rq, @data) where rq is a
* pointer to a request. Return %true to continue iterating tags;
* %false to stop.
* @data: Will be passed as second argument to @fn.
* @reserved: Indicates whether @bt is the breserved_tags member or the
* bitmap_tags member of struct blk_mq_tags.
*/
static void bt_for_each(struct blk_mq_hw_ctx *hctx, struct request_queue *q,
struct sbitmap_queue *bt, busy_tag_iter_fn *fn,
void *data, bool reserved)
{
struct bt_iter_data iter_data = {
.hctx = hctx,
.fn = fn,
.data = data,
.reserved = reserved,
.q = q,
};
sbitmap_for_each_set(&bt->sb, bt_iter, &iter_data);
}
struct bt_tags_iter_data {
struct blk_mq_tags *tags;
busy_tag_iter_fn *fn;
void *data;
unsigned int flags;
};
#define BT_TAG_ITER_RESERVED (1 << 0)
#define BT_TAG_ITER_STARTED (1 << 1)
#define BT_TAG_ITER_STATIC_RQS (1 << 2)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/mm.h`, `linux/kmemleak.h`, `linux/delay.h`, `trace/events/block.h`, `blk.h`.
- Detected declarations: `struct bt_iter_data`, `struct bt_tags_iter_data`, `function Copyright`, `function __blk_mq_tag_busy`, `function test_bit`, `function blk_mq_tag_wakeup_all`, `function __blk_mq_tag_idle`, `function __blk_mq_get_tag`, `function blk_mq_get_tags`, `function blk_mq_get_tag`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration 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.