Handling Requests: A Simple Introduction
The most important function in a block driver is the request function, which performs the low-level operations related to reading and writing data. This section discusses the basic design of the request procedure.
The Request Queue
When the kernel schedules a data transfer, it queues the request in a list, ordered in such a way that it maximizes system performance. The queue of requests is then passed to the driver’s request function, which has the following prototype:
void request_fn(request_queue_t *queue);
The request function should perform the following tasks for each request in the queue:
Check the validity of the request. This test is performed by the macro
INIT_REQUEST, defined inblk.h; the test consists of looking for problems that could indicate a bug in the system’s request queue handling.Perform the actual data transfer. The
CURRENTvariable (a macro, actually) can be used to retrieve the details of the current request.CURRENTis a pointer tostruct request, whose fields are described in the next section.Clean up the request just processed. This operation is performed by end_request, a static function whose code resides in
blk.h. end_request handles the management of the request queue and wakes up processes waiting on the I/O operation. It also manages theCURRENTvariable, ensuring that it points to the next unsatisfied request. The driver passes the function a single argument, which is 1 in case of success and ...