Check out the new USENIX Web site. next up previous
Next: The Pseudo Device Driver Up: Implementation Details Previous: Implementation Details

Block Drivers in Linux

Whenever the buffer cache cannot satisfy a read request or pending writes must be flushed to disk, the driver will be called to perform the data transfer. Since struct file_operations does not carry any entry point other than read and write, an additional structure, blk_dev_struct is used to deliver data transfer requests. The definition of the structure as found in the Linux 2.2 kernel [5] is as follows.
struct blk_dev_struct {
       request_fn_proc *request_fn;
       ...
       /*queue function*/
       queue_proc  *queue;
       /*request queue*/ 
       struct request *current_request;
       struct request plug;
       ...
};

When the kernel needs to spawn an I/O operation, it calls the blk_dev[dev_major].request_fn, where device_major is the major number of the device. ll_rw_block() is used to request a number of buffers from the block device or to write a number of buffers into the block device. ll_rw_block() queues the request structure into the corresponding device queue. The device queue can be mentioned by the queue function of the device. Since there are only a fixed number of request structures, if ll_rw_block() does not find any free request structures, it blocks till it gets a free request structure.

Plug: A plug request in blk_dev_struct is used to ``plug'' the device. A device is plugged to force the transfer to start only after we have put all the requests on the list. The request function, corresponding to the major number of the block device, is not called until the plug is removed. This allows clustering of adjacent blocks to speed up disk transfers.


next up previous
Next: The Pseudo Device Driver Up: Implementation Details Previous: Implementation Details
Suresh Siddha 2001-09-13