本例中相关的代码为:
BLK_INIT_QUEUE(BLK_DEFAULT_QUEUE(MAJOR_NR), &mtdblock_request, &mtdblock_lock); blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR)); |
每个设备有一个默认使用的请求队列,必要时,可使用 BLK_DEFAULT_QUEUE(major) 宏得到该默认队列。这个宏在 blk_dev_struct 结构形成的全局数组(该数组名为 blk_dev)中搜索得到对应的默认队列。blk_dev 数组由内核维护,并可通过主设备号索引。blk_dev_struct 接口定义如下:
struct blk_dev_struct { /* * queue_proc has to be atomic */ request_queue_t request_queue; queue_proc *queue; void *data; }; |
request_queue 成员包含了初始化之后的 I/O 请求队列,data 成员可由驱动程序使用,以便保存一些私有数据。
request_queue定义为:
struct request_queue { /* * the queue request freelist, one for reads and one for writes */ struct request_list rq[2];
/* * Together with queue_head for cacheline sharing */ struct list_head queue_head; elevator_t elevator;
request_fn_proc * request_fn; merge_request_fn * back_merge_fn; merge_request_fn * front_merge_fn; merge_requests_fn * merge_requests_fn; make_request_fn * make_request_fn; plug_device_fn * plug_device_fn; /* * The queue owner gets to use this for whatever they like. * ll_rw_blk doesn't touch it. */ void * queuedata;
/* * This is used to remove the plug when tq_disk runs. */ struct tq_struct plug_tq;
/* * Boolean that indicates whether this queue is plugged or not. */ char plugged;
/* * Boolean that indicates whether current_request is active or * not. */ char head_active;
|
|