LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   traverse all the disks or get hd_struct by device name in kernel module (https://www.linuxquestions.org/questions/linux-kernel-70/traverse-all-the-disks-or-get-hd_struct-by-device-name-in-kernel-module-4175505421/)

xianyu1337 05-19-2014 03:13 AM

traverse all the disks or get hd_struct by device name in kernel module
 
hi.

I'm writing a kernel module(on linux 2.6.32), to get the disk_stats of all the disks(not partition) in use. In other words, I'm getting the data just like what /sys/block/sda/stat shows, but in kernel module.

(NOTE: By 'not partition', I mean we just handle sda and ignore sda1/sda2/etc, for example.)

Is there anything like for_each_netdev or for_each_possible_cpu for block device? Beacuse there may be multiple disks and I need a way to traverse them. Or at the latest, how can I get the related data structure with the block device's name(like sda)?

I know we can get a disk's disk_stats from the disk's hd_struct, but how could I get this hd_struct?

I have read linux2.6.32/block/genhd.c, and I know the content of file /sys/block/sda/stat is generated by diskstats_show. But how does the second argument come?

Please help me. thanks.


All times are GMT -5. The time now is 01:11 AM.