Linux Kernel - Where in the kernel are data blocks physically written to specific disk partitions?

I am modifying the Linux kernel and trying to find where in the kernel source code the data is physically written to disk partitions such as ubd0. Where does this happen in the kernel source? The actual call to the physical record? I can not find it. Thanks!

Edit: The final goal is a list of block numbers that have been recorded in several different sections. When data is physically written to the list, the recorded block numbers are returned and saved.

+6
linux-kernel kernel kernel-module
source share
3 answers

It depends on the specific type of driver and device. For a SCSI device, SCSI commands go to the device driver. They are generated at the SCSI level and sent to the device by the device driver, then to the device.

There is a big abstraction from the sys_write system call until the data has been transferred to the device, and the device driver itself cannot even know what it is writing.

For your editing, look at blktrace: http://linux.die.net/man/8/blktrace

Ok, another answer; You will like it better. This happens in generic_make_request. Comments are sufficiently outlined: http://lxr.linux.no/#linux+v2.6.32/block/blk-core.c#L1380

The biostructure in this function, seen here: http://lxr.linux.no/#linux+v2.6.32/include/linux/bio.h#L58

shows bio_vec, which is a list of things going to the device.

q-> make_request_fn (q, bio); is the actual call to a function pointer in the device itself.

http://lxr.linux.no/#linux+v2.6.32/include/linux/types.h#L126

Shows how indexes are used to write to a section. It should be noted that this is not just used for recording.

+1
source share

It is located in device drivers and is usually performed through a combination of DMA transfers and interrupt I / O transfers. They are different for each specific hardware device. See here how difficult it is to get with a simple floppy disk.

Edit:

Check out the IO scheduler code .

0
source share

If you really want to invent this wheel from scratch, I would click on the query queue functions. For example, to write a request when entering a queue, you can put the code in submit_bio() .

I’m not sure that it’s best to cling to the queue. Maybe elv_next_request() for older kernels or blk_start_request() for newer ones.

0
source share

All Articles