Function Request_fn
As mentioned earlier, when a block device driver uses Blk_run_queue to allocate and initialize Request_queue, the function also needs to drive the specified custom policy function request_fn and the desired spin lock queue_lock. When driving to realize your own request_fn, you need to understand the following features
When the generic block c
random data of a fixed size. Efficient block device drivers are highly performance-critical and are not just read-write operations in user applications. Modern operating systems work with virtual memory, transferring unwanted data to other storage media, such as disks, where the block driver is a conduit between core
strictly required in terms of performance, not only in the read and write operations of user applications. The modern operating system uses virtual memory to transfer unwanted data to other storage media such as disks. The block driver is a pipeline between the core memory and other storage media, therefore, they can be considered as part of the virtual memory subsystem. A data
the bio, and finally sends the bio request to the specified fast device through Submit_bio.4, if the user state calls a write function, the kernel executes the Blkdev_file_write function, if not the direct IO operation, then executes the buffered write operation procedure, calls directly generic_file_buffered_ Write function. The Buffered write method writes dat
= bh->b_size; The size of the storage sector Bio->bi_io_vec[0].bv_offset = Bh_offset (BH); The offset in bytes in the storage sector bio->bi_vcnt = 1; Count value bio->bi_idx = 0; Index value bio->bi_size = bh->b_size; The size of the storage sector bio->bi_end_io = End_bio_bh_io_sync; Set I/o callback function bio->bi_private = BH; Point to which b
pointer to a function.If the above remark is confusing to the reader, then please move on to a bench and let's Begin the story.Access to a common block layer, such as a request to read a piece of data on a block device, usually prepares a bio and then calls the Generic_make_request () function.The caller is fortunate
disk is initialized (Hd_init ()), the operation function of the request item has been specified for the hard disk do_hd_request, and all the hard drive reads and writes will eventually call this function. When the high-level execution block device reads and writes the low-level Ll_rw_block function obtains the main device number, then
(! End_that_request_first (req, 1, sectors_xferred)) {Blkdev_dequeue_request (req);End_that_request_last (req);}}}req = elv_next_request (q) Gets the first outstanding request in the queue, two calls withoutThe same result is obtained when running End_that_request_last or end_request, because it does not deleteThe request in the queue. The next request will be received only if the request is closed. Sbull_xfer_request is hereis the actual data transf
boundary problem, the page boundary.
Since the Kmap () function We use can only map one physical page at a time, when the data that needs to be accessed spans the page boundaries in the block device's memory block,
We need to identify the situation and make the appropriate processing, that is, multiple calls to the Kmap () and Kunmap () functions to access e
I. Summary
Figure 1 is a hierarchical implementation of block device operations. When a process calls read to read a file, the kernel executes the following process: first, it reads the file block that has been cached through the VFS layer, this cache is read by a buffer_head structure. If the file
, sectors_xferred)) {Blkdev_dequeue_request (req);End_that_request_last (req);}}}req = elv_next_request (q) Gets the first outstanding request in the queue, two calls withoutThe same result is obtained when executing end_that_request_last or end_request, because it does not deleteThe request in the queue. Only the end of the request will get the next request. Sbull_xfer_request is hereis the actual transfer data.An actual
;From the code fragment, we can see all theprobe entries is malloc and initialized by default value.2. Device number RegistrationAny block device driver can callblk_register_region () to register the device number and region. Actuallyblk_register_region Packages Kobj_map () with Bdev_map as Kobj_map parameter.650) this
Ll_re_block () function: This function applies to all kernel Block devices for read/write requests. This function first creates a request item and inserts it into the request queue of the specified block device. The actual read/write operation is to use the request item Function request_fn () -For hard disk, It is do_hd_request (). after the function creates a re
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
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.