Linux Kernel - Where in the kernel are blocks of data physically written to specific disk partitions?
I'm modifying the Linux kernel and am trying to find where in the kernel source blocks of data are physically written to disk partitions such as ubd0. Where does this occur in kernel source? The actual phys开发者_Python百科ical write call? I cannot find this. Thanks!
Edit: The end goal is a list of block numbers that have been written to a few different partitions. As data is physically written to the list, the block numbers written are returned and maintained.
This depends on the particular driver and device type. For a SCSI device, SCSI commands go to the device driver. They are generated at the SCSI layer, and sent to the device by the device's driver, then to the device.
There is a great deal of abstraction from the sys_write system call until the data is pushed to a device, and the device driver itself may not even know that it is doing a write.
For your edit, have a look at blktrace: http://linux.die.net/man/8/blktrace
Ok, another answer; you'll like this one better. This occurs in generic_make_request. The comments are quite descriptive: http://lxr.linux.no/#linux+v2.6.32/block/blk-core.c#L1380
The bio struct in that function, seen here: http://lxr.linux.no/#linux+v2.6.32/include/linux/bio.h#L58
shows the bio_vec, which is the list of stuff going to the device.
q->make_request_fn(q, bio); is the actual function pointer call into the device itself.
http://lxr.linux.no/#linux+v2.6.32/include/linux/types.h#L126
Shows how the indices are used to write to the partition. You should note that this is not just used for writes.
If you really want to invent this particular wheel from scratch, I would tap in to the request queue functions. For example, to record the request as it enters the queue, you could put code into submit_bio()
.
I'm not sure of the best place to hook on the queue exit. Perhaps elv_next_request()
on older kernels or blk_start_request()
on newer ones.
It's in the device drivers and is usually done via combination of DMA transfers and interrupts signaling I/O completion. These are different for each specific hardware device. Take a look here for how complicated this gets with a simple floppy.
Edit:
Look into IO scheduler code.
精彩评论