Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


❑ unplug_fnis used to unplug a block device. A plugged device does not execute requests but
collects them and sends them when it is unplugged. Used skillfully, this method enhances block
layer performance. The remaining three functions are slightly more specialized.

❑ merge_bvec_fndetermines if it is allowed to augment an existing request with more data.
Since request queues usually have fixed size limits for their requests, the kernel can use these
to answer the question. However, more specialized drivers — especially compound devices
— may have varying limits so that they need to provide this function. The kernel provides the
auxiliary routineblk_queue_merge_bvecto setmerge_bvec_fnfor a queue.

❑ prepare_flush_fnis called to prepare flushing the queue, that is, before all pending requests
are executed in one go. Devices can perform necessary cleanups in this method.

The auxiliary functionblk_queue_orderedis available to equip a request queue with a specific
method.

❑ Completing requests, that is, ending all I/O, canbe a time-consuming process for large requests.
During the development of 2.6.16, the possibility to complete requests asynchronously using
SoftIRQs (see Chapter 14 for more details on this mechanism) was added. Asynchronous com-
pletion of a request can be demanded by callingblk_complete_request,andsoftirq_done_fn
is in this case used as a callback to notify the driver that the completion is finished.

The kernel provides the standard functionblk_init_queue_nodeto generate a standard request queue.
The only management function that must be provided by the driver itself in this case isrequest_fn.
Any other management issues are handled by standard functions. Drivers that implement request man-
agement this way are required to callblk_init_queue_nodeand attach the resultingrequest_queue
instance to theirgendiskbeforeadd_diskis called to activate the disk.

Request queues can be plugged when the system is overloaded. New requests then remain unprocessed
until the queue is unplugged (this is calledqueue plugging). Theunplug_elements are used to imple-
ment a timer mechanism that automatically unplugs a queue after a certain period of time.unplug_fnis
responsible for actual unplugging.

queue_flagsis used to control the internal state of the queue with the help of flags.

The last part of therequest_liststructure contains information that describes the managed block device
in more detail and reflects the hardware-specific device settings. This information is always in the form
of numeric values; the meaning of the individual elements is given in Table 6-2.

nr_requestsindicates the maximum number of requests that may be associated with a queue; we come
back to this topic in Chapter 17.

6.5.3 Adding Disks and Partitions to the System


After having introduced numerous data structures that build up the block layer, everything is set to
examine in more detail how generic hard disks are added to the system. As mentioned above,add_diskis
provided for this purpose. A discussion of the implementation follows an examination of how partitions
are added to the kernel’s data structures usingadd_partition.
Free download pdf