I am writing this block device driver. From the logs I can see that all requests the block has received were served. Here is the code for fetching requests from the queue:
/* Gets the current request from the dispatch queue */
while ((req = blk_fetch_request(q)) != NULL) {
start_sector = blk_rq_pos(req);
sector_cnt = blk_rq_sectors(req);
dir = rq_data_dir(req);
printk("Received a %s request starting at %d and length %d sectors!\n",
(dir == READ ? "READ" : "WRITE"), start_sector, sector_cnt);
kthread_run(request_handler_thread, req, "request_handler");
//ret = rb_transfer(req);
}
And here is the code for ending the requests:
int start_sector;
int sector_cnt;
int dir;
int error = req->errors ? -EIO : 0;
start_sector = blk_rq_pos(req);
sector_cnt = blk_rq_sectors(req);
dir = rq_data_dir(req);
printk("Ending a %s request starting at %d and length %d sectors!\n",
(dir == READ ? "READ" : "WRITE"), start_sector, sector_cnt);
__blk_end_request_cur(req, error);
From the log messages, I can see there is one-to-one match between fetched and ended block requests. However, I can see that the process is hung and cat /proc/diskstats
reports pending requests.