LKM: Last block written to device

孤人 提交于 2019-12-22 18:11:09

问题


I am trying to find a way, inside a module, to keep track of the last block written to a block device. The specific device I need is the one mounted at root (I know the /dev/ name ahead of time if that helps.)

My original idea was to wrap the submit_bio function, since it has a logging function already if you "echo 1 > /proc/sys/vm/block_dump". Unfortunately it seems I'd need to modify the source code to make that function a pointer. I'd like to keep this all inside the module if at all possible.

After that, I looked into finding the file system type, and wrapping the default file operations (these are already function pointers, after all). Those are declared as a const, though, so same issue.

This is kind of an odd thing to be trying to do, I understand. Need to do it none-the-less. Does anyone have any ideas that might get me going?


回答1:


The Linux kernel provides several different tracing toolkits; the blktrace tools were designed specifically for block devices. The blkparse(1) tool will parse the output of the blktrace(8) utility. (At least Ubuntu has these packaged in the blktrace package; I expect other distributions to be similar.) The bklparse(1) tool can give you the sector information.

Documentation/trace/events.txt describes another tracing mechanism -- one that could allow you to follow the block:block_bio_complete event, which includes the sector information. This won't require installing the bkltrace toolkit but I'll (sheepishly) admit that I don't know where to read the trace log.



来源:https://stackoverflow.com/questions/10037944/lkm-last-block-written-to-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!