views:

85

answers:

3

I want to maintain a list of block numbers as they are physically written to using the linux kernel source. I plan to modify the kernel source to do this. I just need to find the structure and functions in the kernel source that handle writing to physical partitions and get the block numbers as they write to the physical partition.

Any way of doing this? Any help is appreciated. If I can find where the kernel is actually writing to the partitions and returning the block numbers, that'd work.

A: 

I believe you could do this entirely from userspace, without modifying the kernel, using the blktrace interface.

caf
A: 

Yes, I have seen blktrace, but I want to do this programmatically in a module and then use this list for another task. I want more than to just list out block numbers. I have an app that will utilize this list so I need to maintain the block numbers myself and not with a utility like blktrace. I just need to find where in the kernel calls write for a partition and returns block numbers after writing.

SpdStr
You should edit your question to include this, rather than providing supplemental information to your question in the form of an answer.
Tim Post
Well, you don't have to use the `blktrace` utility itself - you can write your application to use the underlying `ioctl()s` that `blktrace` uses.
caf
A: 

It isn't just one place to check. For instance, if the block device was an iSCSI or AoE target, you would be looking for their respective drivers, then ultimately the same on the other end.

The same would go for normal SCSI, misc flash devices, etc, minus network interaction.

VFS just pulls these all together in a convenient, unified and consistent interface for calls like read() and write() to work while providing buffering. The actual magic, including ordering and write barriers are handled by the block dev drivers themselves.

In the case of using device mapper, the path alters slightly. It goes from vfs -> dm_(target) -> blockdev_driver.

Tim Post