I have a question regarding following code from LDD v3
while ((req = elv_next_request(q)) != NULL) { struct sbull_dev *dev = req->rq_disk->private_data; if (! blk_fs_request(req)) { printk (KERN_NOTICE "Skip non-fs request\n"); end_request(req, 0); continue; } sbull_transfer(dev, req->sector, req->current_nr_sectors, req->buffer, rq_data_dir(req)); end_request(req, 1); }
If the function sbull_transfer may sleep, can I defer it using work queue? Can I dequeue the request before processing as shown in following code.
struct dev_data { struct sbull_dev *dev; struct request *req; };
void deffered_routine(void *data) { struct dev_data *dev_data = data; struct request *req = dev_data->req; struct sbull_dev *dev = dev_data->dev; sbull_transfer(dev, req->sector, req->current_nr_sectors, req->buffer, rq_data_dir(req));
if (!end_that_request_first(req, uptodate, req->hard_cur_sectors)) { add_disk_randomness(req->rq_disk); //blkdev_dequeue_request(req); end_that_request_last(req); } return; }
/* request function snip */ while ((req = elv_next_request(q)) != NULL) { struct work_struct work; struct dev_data device_data; struct sbull_dev *dev = req->rq_disk->private_data; if (! blk_fs_request(req)) { printk (KERN_NOTICE "Skip non-fs request\n"); end_request(req, 0); continue; }
device_data->dev = dev; device_data->req = req; INIT_WORK(&work, deffered_routine, &device_data); schedule_work(&work); blkdev_dequeue_request(req); }
Regards
Mohanlal
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/