Block device Operation Method

Source: Internet
Author: User

When performing I/O operations on the system (kernel) and the hard disk, the interaction between the three objects must be considered. They are systems, controllers, and drives (such as hard drives or floppy drives ). The system can directly send commands to the Controller or wait for the Controller to send an interrupt request. After receiving the command, the controller controls the operation on the drive, reads and writes data, or performs other operations. Therefore, we can regard the interrupt signal sent by the Controller as the synchronous operation signal between the three.
First, the system specifies the C function that should be called during the interrupt process caused by the completion of command execution by the Controller, and then sends the read, write, reset or other operation commands to the block device controller.
When the Controller completes the specified command, it sends an interrupt request signal, causing the system to execute the interrupt processing process for Block devices, and call the specified C function to read and write or execute other commands.
For disk write operations, the system needs to wait for the Controller to give a response that allows writing data to the Controller after a write command is issued (using the active hd_out, that is, you need to query the data request service mark drq location waiting for the Controller Status Register. Once drq is set, the system can send data of one slice to the Controller buffer. The hd_out () function is also used.
When the Controller writes all the data to the drive (or an error occurs), an interrupt request signal is generated to execute the pre-defined C function (write_intr () during the interrupt processing ()). This function will query whether there is data to be written. If yes, the system transfers data from one slice to the Controller buffer, and waits for the interruption caused by the Controller writing data to the drive again. If all the data has been written to the drive at this time, the C function will execute the processing after the disk is written: wake up the processes waiting for the data related to this request item, wake up the processes waiting for the request item, release the current request item, delete this request item from the linked list, and release the locked buffer. Finally, call the operation function of the request item to execute the next read/write disk request item (if any ).
For a disk reading operation, the system sends a command to the Controller, including the start position of the sector to be read and written, the number of sectors, and other information, waiting for the Controller to generate an interrupt signal. When the Controller transmits the specified sector of data from the drive to its own buffer according to the READ command requirements, the request will be interrupted. This will execute the C function (read_intr () preset for the read disk operation ()). This function first places the data of one sector in the Controller buffer zone into the system buffer zone, adjusts the current write position in the system buffer zone, and then decreases the number of read sectors. If there is still data to be read (the decreasing result value is not 0), continue waiting for the Controller to send the next interruption signal. If all required sectors have been read to the system buffer at this time, end the processing like the write disk operation above.
For a virtual disk device, because its read/write operations do not involve synchronization with external devices, there is no such interruption process. The read and write operations of the current request item on the virtual device are fully implemented in do_rd_request.
After a read/write or other command is sent to the hard disk or floppy disk controller, the sending command function does not wait for the execution of the command, but immediately returns the program that calls it, and finally return to other programs that call the block device read/write function ll_rw_block () to wait for the completion of block device Io.

Reprinted from: http://bluefish.blog.51cto.com/214870/40790

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.