Search code examples
clinuxlinux-kernellinux-device-driverscsi

How to find the scsi_host_template functions for a block device?


I was looking into the IO path of the Linux kernel, and towards the bottom in the function scsi_dispatch_cmd(), the driver code is invoked

rtn = host->hostt->queuecommand(host, cmd);

So, for my block device like /dev/sda/, is there a way to find out which hostt or scsi_host_template it is using. I want to check which function queuecommand is pointing to..


Solution

  • Just as a sketch of reflection on this subject.
    In my machine for USB drive I can see this:

    $ ls -l /dev/sdg
    brw-rw---- 1 root disk 8, 96 Apr 27 01:21 /dev/sdg
    $ ll /sys/dev/block/8\:96/device/drive
    lrwxrwxrwx 1 root root 0 Apr 27 01:32 /sys/dev/block/8:96/device/driver -> ../../../../../../../../../bus/scsi/drivers/sd
    

    So normally such block devices are handled through the regular Linux scsi disk driver. Which is related with e.g. usb handling:

    $ lsmod | grep sd
    sd_mod                 49152  13
    scsi_mod              225280  5 sd_mod,usb_storage,libata,uas,sg
    

    In this particular case we can see the relation between queuecommand and mentioned drive:

    $ grep queuecommand /proc/kallsyms
    ffffffffc052be60 t uas_queuecommand [uas]
    ffffffffc0582ad0 t queuecommand [usb_storage]
    

    Now, being in Linux source dir:

    $ grep -rnI '\.queuecommand =' | grep usb
    drivers/usb/storage/uas.c:846:  .queuecommand = uas_queuecommand,
    drivers/usb/storage/scsiglue.c:609: .queuecommand =         queuecommand,
    

    Hope this will help you.