sd_prep_fn

rohan puri rohan.puri15 at gmail.com
Thu Nov 10 10:53:19 EST 2011


On Thu, Nov 10, 2011 at 6:26 PM, sumeet gandhare
<sumeetgandhare at gmail.com>wrote:

>
>
> On Thu, Nov 10, 2011 at 6:13 PM, rohan puri <rohan.puri15 at gmail.com>wrote:
>
>>
>>
>> On Thu, Nov 10, 2011 at 4:50 PM, sumeet gandhare <
>> sumeetgandhare at gmail.com> wrote:
>>
>>> Hi All,
>>>   I am trying to understand the scsi upper layer and middle layer code
>>> and found the function sd_prep_fn which seems to convert a request to a
>>> scsi command. I want to know when this function sd_prep_fn gets invoked.
>>>
>>> It seems sd_probe_async invokes
>>>
>>>    blk_queue_prep_rq <http://lxr.linux.no/linux+*/+code=blk_queue_prep_rq>(sdp <http://lxr.linux.no/linux+*/+code=sdp>->request_queue <http://lxr.linux.no/linux+*/+code=request_queue>, sd_prep_fn <http://lxr.linux.no/linux+*/+code=sd_prep_fn>);
>>>
>>>
>>>
>>> Further following code is invoking the prep_rq_fn
>>>
>>> which is the blk_peek_request
>>>
>>> http://lxr.linux.no/#linux+v3.1/block/blk-core.c#L1879 <http://lxr.linux.no/#linux+v3.1/block/blk-core.c%23L1879>
>>>
>>>
>>>
>>> and blk_peek_request is getting invoked from
>>>
>>> scsi_request_fn
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1493 <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1493>
>>>
>>>
>>>
>>> scsi_request_fn is registered with the block layer as a request function at the following code
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1688 <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1688>
>>>
>>>
>>>
>>> And scsi_alloc_queue is invoked from scsi_alloc_sdev
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L238 <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L238>
>>>
>>>
>>>
>>> scsi_alloc_sdev is invoked as a part of scsi lun discovery from lots of places
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1004 <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1004>
>>>
>>> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c#L1306 <http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_scan.c%23L1306>
>>>
>>>
>>>
>>> The confusion I have is that the sd.c upper layer driver has not registered for a request function using blk_init_queue
>>>
>>> Any help would be appreciated.
>>>
>>> Thanks
>>> Sumeet
>>>
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>> Hello Sumeet,
>>
>> sd_prep_fn function is set to the request queue's prep_rq_fn member as
>> you have mentioned.
>>
>> Now this function gets called in
>>
>> ret = q->prep_rq_fn(q, rq); in function blk_peek_request() which is
>> called from scsi_request_fn() in file scsi_lib.c
>>
>> Regards,
>> Rohan Puri
>>
>
> Hi Rohan,
>  Thanks for your response and help.
>  It seems there is scsi_prep_fn too. I thought the blk_peek_request()
> invokes scsi_prep_fn and not sd_prep_fn.
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1248<http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1248>
>
> scsi_prep_fn is registered here
>
> http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c#L1684<http://lxr.linux.no/#linux+v3.1/drivers/scsi/scsi_lib.c%23L1684>
>
>
> Please could you confirm.
>
> Thanks
> Sumeet
>

Whenever a new scsi device is attached sd_probe is called sd_async_probe()
is the async part of sd_probe() So when this is called the prep_fn is set
to sd_prep_fn and hence this will be called.

sd_prep_fn is for scsi disk, similarly there is a function sr_prep_fn which
gets called for scsi cd-rom.

Regards,
Rohan Puri
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111110/7aa8945f/attachment.html 


More information about the Kernelnewbies mailing list