views:

123

answers:

3

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 physical 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.

+1  A: 

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.

WhirlWind
Thanks WhirlWind. I'm going to dive into this and take a look at the links. This will be a good starting point. I'll let you know how it goes. Thanks again!
SpdStr
@SpdStr Good luck. Kernel fiddling is fun.
WhirlWind
A: 

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.

Nikolai N Fetissov
I think I'm phrasing the question wrong. 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. I have heard of blktrace but need this done programmatically as I need to handle the list myself and do work with it.
SpdStr
Example: as data is written to disk, the block numbers would be returned and maintained in memory by my code.
SpdStr
you should update your question, or ask for what you really want in the first place.
WhirlWind
A: 

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.

Eric Seppanen