Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


blkdev_open

bd_acquire

do_open

get_gendisk

disk->fops->open

flag 0_EXCL set? bd_claim

Figure 6-13: Code flow diagram for
blkdev_open.

bd_acquirefirst finds the matchingblock_deviceinstance for the device. The pointer to the instance can
be read directly frominode->i_bdevif the device has already been used. Otherwise, it is created using
thedev_tinformation. Afterwarddo_opencarries out the main portion of the task, described below.
If exclusive access to the block device is requested by setting the flagO_EXCL, then the block device is
claimed withbd_claim. This sets thefileinstance associated with the device file as current holder of the
block device.

Main device?

Partition information invalid?

Insert block_device into data structures

Partition information invalid

Yes

No

Yes

No

do_open

get_gendisk

disk->fops->open

disk->fops->open

rescan_partitions

rescan_partitions

Device opened before?

Partition?

Figure 6-14: Code flow diagram fordo_open.

The first step ofdo_openis to callget_gendisk. This delivers thegendiskinstance that belongs to the
block device. Recall that thegendiskstructure describes the partitions of the block device as discussed in
Section 6.2.5. However, if the block device is opened for the first time, the information is not yet complete.
Nevertheless, the device-specificblock_device_operationsthat are required to work with the device
can already be found in the generic hard disk structure.

The kernel then needs to proceed differently depending on the type and state of the block device, as is
shown in Figure 6-14. Things are simpler if the block device has been opened before, as can be inferred
from the openers countblock_device->bd_openers.
Free download pdf