STRUCT BLK_MQ_OPS(9)
okay bestie, so you're looking at struct blk_mq_ops(9) from the Kernel API Manual? This is the callback squad that block drivers use to implement their behaviour. Let's get into it π
β¨
πΈ NAME πΈ
struct blk_mq_ops β the callback functions that implement block driver behaviour. It's giving "driver behaviour: the musical" π
β¨ SYNOPSIS β¨
struct blk_mq_ops {
blk_status_t (*queue_rq)(struct blk_mq_hw_ctx *, const struct
blk_mq_queue_data *);
void (*commit_rqs)(struct blk_mq_hw_ctx *);
void (*queue_rqs)(struct rq_list *rqlist);
int (*get_budget)(struct request_queue *);
void (*put_budget)(struct request_queue *, int);
void (*set_rq_budget_token)(struct request *, int);
int (*get_rq_budget_token)(struct request *);
enum blk_eh_timer_return (*timeout)(struct request *);
int (*poll)(struct blk_mq_hw_ctx *, struct io_comp_batch *);
void (*complete)(struct request *);
int (*init_hctx)(struct blk_mq_hw_ctx *, void *, unsigned int);
void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
int (*init_request)(struct blk_mq_tag_set *set, struct request *,
unsigned int, int);
void (*exit_request)(struct blk_mq_tag_set *set, struct request *,
unsigned int);
void (*cleanup_rq)(struct request *);
bool (*busy)(struct request_queue *);
void (*map_queues)(struct blk_mq_tag_set *set);
#ifdef CONFIG_BLK_DEBUG_FS;
void (*show_rq)(struct seq_file *m, struct request *rq);
#endif;
};
π MEMBERS (the callback crew) π
Here's the squad, one by one:
queue_rqβ queue a new request from block IO. This is literally the main entrance for new requests, the VIP lounge πͺcommit_rqsβ if a driver usesbd->lastto judge when to submit requests to hardware, it must define this function. In case of errors that make us stop issuing further requests, this hook serves the purpose of kicking the hardware (which the last request otherwise would have done). So like, it's the emergency backup kick π₯queue_rqsβ queue a list of new requests. Driver is guaranteed that each request belongs to the same queue. If the driver doesn't empty therqlistcompletely, then the rest will be queued individually by the block layer upon return. Batch 'em if you want, but leftovers get handled by the block layer π§Ήget_budgetβ reserve budget before queue request. Once.queue_rqis run, it is driver's responsibility to release the reserved budget. Also we have to handle failure case of.get_budgetfor avoiding I/O deadlock. So don't forget to release, and don't ignore failures, or you'll deadlock I/O πput_budgetβ release the reserved budget. That's it, that's the tweet π¦set_rq_budget_tokenβ store rq's budget token. Keep that token safe πget_rq_budget_tokenβ retrieve rq's budget token. Gimme that token back πtimeoutβ called on request timeout. When things take too long, this gets the call β°pollβ called to poll for completion of a specific tag. Like checking if your order's ready yet πcompleteβ mark the request as complete. Done and dusted βinit_hctxβ called when the block layer side of a hardware queue has been set up, allowing the driver to allocate/init matching structures. Set up your side of the hardware queue ποΈexit_hctxβ ditto for exit/teardown. Tear it down π§¨init_requestβ called for every command allocated by the block layer to allow the driver to set up driver specific data. Tag greater than or equal toqueue_depthis for setting up flush request. So set up your driver data, and note the flush request case πΎexit_requestβ ditto for exit/teardown. Clean up after yourself π§½cleanup_rqβ called before freeing one request which isn't completed yet, and usually for freeing the driver private data. Cleanup on aisle request π§Όbusyβ if set, returns whether or not this queue currently is busy. Like a "do not disturb" sign for the queue π«map_queuesβ this allows drivers specify their own queue mapping by overriding the setup-time function that builds themq_map. Custom mapping, your rules πΊοΈshow_rqβ used by the debugfs implementation to show driver-specific information about a request. Only present ifCONFIG_BLK_DEBUG_FSis defined, btw. For when you need to peek under the hood π
π SEE ALSO π
Go check out these other icons:
- Kernel file
./include/linux/blk-mq.h enum blk_eh_timer_return(9)struct blk_mq_hw_ctx(9)struct blk_mq_queue_map(9)enum hctx_type(9)struct blk_mq_tag_set(9)struct blk_mq_queue_data(9)blk_mq_rq_state(9)blk_mq_add_to_batch(9)blk_mq_rq_from_pdu(9)blk_mq_rq_to_pdu(9)blk_rq_nr_bvec(9)blk_rq_passthrough_stats(9)
Source: ./include/linux β October 2026. Stay slaying, bestie! π«Άπ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms