<div dir="ltr">I think sd_prep_fn is a generic function for any SCSI device while scsi_prep_fn specifically SCSI Disks or LUN's, so if you have a filesystem created on top of SCSI Disk scsi_prep_fn function will be called. In case you have any other SCSI device then you will have sd_prep_fn will be called.<div>
<br></div><div>The comment on top of sd_probe mentions this:</div><div><br></div><div><div>/**</div><div> *<span class="" style="white-space:pre">        </span>sd_probe - called during driver initialization and whenever a</div>
<div> *<span class="" style="white-space:pre">        </span>new scsi device is attached to the system. It is called once</div><div> *<span class="" style="white-space:pre">        </span>for each scsi device (not just disks) present.</div>
<div> *<span class="" style="white-space:pre">        </span>@dev: pointer to device object</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Similarly argument to scsi_alloc_sdev ( while internally calls scsi_alloc_queue ---> blk_queue_prep_rq(q, scsi_prep_fn) ) accepts lun id which I think is specific to SCSI LUN.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">For understanding linux SCSI Subsystem you can also refer to kernel SCSI documentation and also the below mentioned link: </div><div class="gmail_extra"><br></div>
<div class="gmail_extra"><a href="http://www.andante.org/scsidoc/SCSI-1.html">http://www.andante.org/scsidoc/SCSI-1.html</a></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">
Regards,</div><div class="gmail_extra">Piyush Moghe<br><br><div class="gmail_quote">On Wed, Nov 6, 2013 at 3:25 PM, Jack Wang <span dir="ltr"><<a href="mailto:xjtuwjp@gmail.com" target="_blank">xjtuwjp@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 11/05/2013 05:19 PM, nidhi mittal hada wrote:<br>
</div><div class="im">> My doubt is :-<br>
> When we know block device driver , request structure, request queue<br>
> operation .. as per LDD.<br>
> How and where the request structure we are getting in scsi layer<br>
> fits/relates to thi sblock layer request structure....<br>
><br>
> is the sequence ..block device layer request function -> calls scsi<br>
> layer request function ?<br>
><br>
><br>
<br>
<br>
</div>The links below show how block layer request connect to scsi request,<br>
but In Chinese, sorry, but you may find clue in the code section.<br>
<br>
<a href="http://blog.csdn.net/fudan_abc/article/details/1966510" target="_blank">http://blog.csdn.net/fudan_abc/article/details/1966510</a><br>
<br>
<a href="http://blog.csdn.net/fudan_abc/article/details/1966538" target="_blank">http://blog.csdn.net/fudan_abc/article/details/1966538</a><br>
<a href="http://blog.csdn.net/fudan_abc/article/details/1967045" target="_blank">http://blog.csdn.net/fudan_abc/article/details/1967045</a><br>
<a href="http://blog.csdn.net/fudan_abc/article/details/1967050" target="_blank">http://blog.csdn.net/fudan_abc/article/details/1967050</a><br>
<br>
BTW: Why not use dm-crypt?<br>
<br>
Jack<br>
<div class="im">><br>
><br>
><br>
><br>
><br>
> On Tue, Nov 5, 2013 at 6:34 PM, nidhi mittal hada<br>
</div>> <<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a> <mailto:<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a>>> wrote:<br>
><br>
> _*Setting of sd_prep_fn()*_<br>
> sd_probe is called*/whenever a/* */new scsi device is attached to<br>
> the system. /*<br>
><br>
> sd_probe calls -> sd_probe_async-><br>
> inside sd_probe_async, request prep fn is set to *sd_prep_fn*<br>
<div class="im">> >>>>like this blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);<br>
><br>
><br>
</div>> _*Calling of sd_prep_fn*_<br>
<div class="im">> ?????<br>
><br>
> Is this request queue sdp->request_queue, different from the request<br>
> queue,<br>
> for which scsi_prep_fn is used??<br>
><br>
> Are they on different layers ?<br>
><br>
> Is there some relation between them ?<br>
><br>
><br>
><br>
> Thanks<br>
> Nidhi<br>
><br>
><br>
> On Tue, Nov 5, 2013 at 6:13 PM, nidhi mittal hada<br>
</div><div><div class="h5">> <<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a> <mailto:<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a>>> wrote:<br>
><br>
> scsi_alloc_sdev(must be called once for each scsi device) -->calls<br>
> scsi_alloc_queue (that sets up sdev->request_queue<br>
> sets up scsi_request_fn and<br>
> sets up req prep function as<br>
> scsi_prep_fn)<br>
><br>
> 1738 struct request_queue *scsi_alloc_queue(struct scsi_device<br>
> *sdev)<br>
> 1739 {<br>
> 1740 struct request_queue *q;<br>
> 1742 q = __scsi_alloc_queue(sdev->host,<br>
> scsi_request_fn);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><br>
> 1743 if (!q)<br>
> 1744 return NULL;<br>
> 1746 blk_queue_prep_rq(q,<br>
> scsi_prep_fn);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><br>
> 1747 blk_queue_softirq_done(q, scsi_softirq_done);<br>
> 1748 blk_queue_rq_timed_out(q, scsi_times_out);<br>
> 1749 blk_queue_lld_busy(q, scsi_lld_busy);<br>
> 1750 return q;<br>
> 1751 }<br>
> And after this call sdev_request_queue is allocated................<br>
><br>
> Now, scsi_request_fn should be called while processing each<br>
> request in this sdev->request_queue...<br>
> Please correct me if i m wrong.<br>
> Now, inside scsi_request_fn, we get next queueable request by<br>
> calling<br>
> blk_peek_request - to fetch request from request queue ..<br>
><br>
> blk_peek_request -> calls __elv_next_request to fetch next request-<br>
> and calls prep_rq_fn(q, rq);<br>
><br>
><br>
</div></div>> *which is scsi_prep_fn not the sd_prep_fn isnt it ??*<br>
<div class="im">><br>
><br>
> Then where is sd_prep_fn is used for ??<br>
><br>
> Thanks<br>
> Nidhi<br>
><br>
><br>
><br>
><br>
> On Tue, Nov 5, 2013 at 5:39 PM, Jack Wang <<a href="mailto:xjtuwjp@gmail.com">xjtuwjp@gmail.com</a><br>
</div><div><div class="h5">> <mailto:<a href="mailto:xjtuwjp@gmail.com">xjtuwjp@gmail.com</a>>> wrote:<br>
><br>
> Hi Nidhi,<br>
><br>
> About the function call trace you can use ftrace to find<br>
> out, another<br>
> useful tool is scsi_logging_level to set more verbose<br>
> logging output for<br>
> scsi core.<br>
><br>
> Regards<br>
> Jack<br>
> On 11/05/2013 12:48 PM, nidhi mittal hada wrote:<br>
> ><br>
> > Hi All<br>
> ><br>
> > i have got a requirement where I need to encrypt/decrypt<br>
> data that goes<br>
> > from scsi layer to a particular block device.<br>
> > As per my understanding till now on scsi subsystem in<br>
> linux, i think i<br>
> > need to<br>
> > use crypto api and call appropriate encrypt/decrypt<br>
> function from sd<br>
> > driver for block device.<br>
> ><br>
> > I need to locate that specific function where this change<br>
> needs to be<br>
> > made ...<br>
> > I know basic block device driver writing in linux .. But<br>
> not able to fit<br>
> > scsi in this picture.<br>
> ><br>
> > I have few basic doubts.. kindly help in resolving ...<br>
> ><br>
> > 1) Now, as example block device driver sbull, as given<br>
> LDD, works on<br>
> > request queue, fetches req from this queue, using function<br>
> req =<br>
> > elv_next_request(q)),<br>
> > in request function.<br>
> > what is corresponding function in sd layer ?<br>
> > That is the function where i have req->buffer in hand with<br>
> me..<br>
> ><br>
> ><br>
> > 2) For a write operation from initiator to disk<br>
> > is the hierarchy like this<br>
> > *sd_prep_fn*<br>
> > generic block device request structure -> converted into<br>
> scsi specific<br>
> > request structure<br>
> > OR<br>
> > what is scsi_prep_fn for??<br>
> ><br>
> > 3)How is Scpnt pointer that is req-> special is used in<br>
> sd_prep_func..<br>
> > is processed? i mean which layer picks Scpnt up and<br>
> processes ??<br>
> ><br>
> > 4)Any document any URL any kind of instruction will be<br>
> extremely helpful.<br>
> ><br>
> > 5)Whenever a *new scsi device is attached *sd_probe is called<br>
> > sd_async_probe() is the async part of sd_probe() So when<br>
> this is called<br>
> > the prep_fn is set to sd_prep_fn and hence this will be<br>
> called.<br>
> ><br>
> > *But i thought sd_prep_fn should be called for each and<br>
> every request<br>
> > .....??*<br>
> > Kindly help me to clear the confusion ..<br>
> ><br>
> ><br>
> > Thanks<br>
> > Nidhi<br>
> ><br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > Kernelnewbies mailing list<br>
> > <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
</div></div>> <mailto:<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a>><br>
<div class=""><div class="h5">> > <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
> ><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> --<br>
> Thanks & Regards<br>
> Nidhi Mittal Hada<br>
><br>
> <a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br>
><br>
><br>
><br>
><br>
> --<br>
> Thanks & Regards<br>
> Nidhi Mittal Hada<br>
><br>
> <a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br>
><br>
<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></div></blockquote></div><br></div></div></div>