<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&#39;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 ---&gt; 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">&lt;<a href="mailto:xjtuwjp@gmail.com" target="_blank">xjtuwjp@gmail.com</a>&gt;</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">&gt; My doubt is :-<br>
&gt; When we know block device driver , request structure, request queue<br>
&gt; operation .. as per LDD.<br>
&gt; How and where the request structure we are getting in scsi layer<br>
&gt; fits/relates to thi sblock layer request structure....<br>
&gt;<br>
&gt; is the sequence ..block device layer request function -&gt; calls scsi<br>
&gt; layer request function ?<br>
&gt;<br>
&gt;<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">&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Nov 5, 2013 at 6:34 PM, nidhi mittal hada<br>
</div>&gt; &lt;<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a> &lt;mailto:<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;     _*Setting of sd_prep_fn()*_<br>
&gt;     sd_probe is called*/whenever a/* */new scsi device is attached to<br>
&gt;     the system.  /*<br>
&gt;<br>
&gt;     sd_probe  calls -&gt;  sd_probe_async-&gt;<br>
&gt;             inside sd_probe_async, request prep fn is set to *sd_prep_fn*<br>
<div class="im">&gt;     &gt;&gt;&gt;&gt;like this  blk_queue_prep_rq(sdp-&gt;request_queue, sd_prep_fn);<br>
&gt;<br>
&gt;<br>
</div>&gt;     _*Calling of sd_prep_fn*_<br>
<div class="im">&gt;     ?????<br>
&gt;<br>
&gt;     Is this request queue sdp-&gt;request_queue, different from the request<br>
&gt;     queue,<br>
&gt;     for which scsi_prep_fn is used??<br>
&gt;<br>
&gt;     Are they on different layers ?<br>
&gt;<br>
&gt;     Is there some relation between them ?<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;     Thanks<br>
&gt;     Nidhi<br>
&gt;<br>
&gt;<br>
&gt;     On Tue, Nov 5, 2013 at 6:13 PM, nidhi mittal hada<br>
</div><div><div class="h5">&gt;     &lt;<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a> &lt;mailto:<a href="mailto:nidhimittal19@gmail.com">nidhimittal19@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;         scsi_alloc_sdev(must be called once for each scsi device) --&gt;calls<br>
&gt;         scsi_alloc_queue (that sets up sdev-&gt;request_queue<br>
&gt;                                             sets up scsi_request_fn and<br>
&gt;                                             sets up req prep function as<br>
&gt;         scsi_prep_fn)<br>
&gt;<br>
&gt;         1738 struct request_queue *scsi_alloc_queue(struct scsi_device<br>
&gt;         *sdev)<br>
&gt;         1739 {<br>
&gt;         1740         struct request_queue *q;<br>
&gt;         1742         q = __scsi_alloc_queue(sdev-&gt;host,<br>
&gt;         scsi_request_fn);&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;         1743         if (!q)<br>
&gt;         1744                 return NULL;<br>
&gt;         1746         blk_queue_prep_rq(q,<br>
&gt;         scsi_prep_fn);&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;         1747         blk_queue_softirq_done(q, scsi_softirq_done);<br>
&gt;         1748         blk_queue_rq_timed_out(q, scsi_times_out);<br>
&gt;         1749         blk_queue_lld_busy(q, scsi_lld_busy);<br>
&gt;         1750         return q;<br>
&gt;         1751 }<br>
&gt;         And after this call sdev_request_queue is allocated................<br>
&gt;<br>
&gt;         Now, scsi_request_fn should be called while processing each<br>
&gt;         request in this sdev-&gt;request_queue...<br>
&gt;         Please correct me if i m wrong.<br>
&gt;         Now, inside scsi_request_fn, we get next queueable request by<br>
&gt;         calling<br>
&gt;         blk_peek_request - to fetch request from request queue ..<br>
&gt;<br>
&gt;         blk_peek_request -&gt; calls __elv_next_request to fetch next request-<br>
&gt;         and calls prep_rq_fn(q, rq);<br>
&gt;<br>
&gt;<br>
</div></div>&gt;         *which is scsi_prep_fn not the sd_prep_fn isnt it ??*<br>
<div class="im">&gt;<br>
&gt;<br>
&gt;         Then where is sd_prep_fn is used for ??<br>
&gt;<br>
&gt;         Thanks<br>
&gt;         Nidhi<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         On Tue, Nov 5, 2013 at 5:39 PM, Jack Wang &lt;<a href="mailto:xjtuwjp@gmail.com">xjtuwjp@gmail.com</a><br>
</div><div><div class="h5">&gt;         &lt;mailto:<a href="mailto:xjtuwjp@gmail.com">xjtuwjp@gmail.com</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;             Hi Nidhi,<br>
&gt;<br>
&gt;             About the function call trace you can use ftrace to find<br>
&gt;             out, another<br>
&gt;             useful tool is scsi_logging_level to set more verbose<br>
&gt;             logging output for<br>
&gt;             scsi core.<br>
&gt;<br>
&gt;             Regards<br>
&gt;             Jack<br>
&gt;             On 11/05/2013 12:48 PM, nidhi mittal hada wrote:<br>
&gt;             &gt;<br>
&gt;             &gt; Hi All<br>
&gt;             &gt;<br>
&gt;             &gt; i have got a requirement where I need to encrypt/decrypt<br>
&gt;             data that goes<br>
&gt;             &gt; from scsi layer to a particular block device.<br>
&gt;             &gt; As per my understanding till now on scsi subsystem in<br>
&gt;             linux, i think i<br>
&gt;             &gt; need to<br>
&gt;             &gt; use crypto api and call appropriate encrypt/decrypt<br>
&gt;             function from sd<br>
&gt;             &gt; driver for block device.<br>
&gt;             &gt;<br>
&gt;             &gt; I need to locate that specific function where this change<br>
&gt;             needs to be<br>
&gt;             &gt; made ...<br>
&gt;             &gt; I know basic block device driver writing in linux .. But<br>
&gt;             not able to fit<br>
&gt;             &gt; scsi in this picture.<br>
&gt;             &gt;<br>
&gt;             &gt; I have few basic doubts.. kindly help in resolving ...<br>
&gt;             &gt;<br>
&gt;             &gt; 1) Now, as example block device driver sbull, as given<br>
&gt;             LDD, works on<br>
&gt;             &gt; request queue, fetches req from this queue, using function<br>
&gt;             req =<br>
&gt;             &gt; elv_next_request(q)),<br>
&gt;             &gt; in request function.<br>
&gt;             &gt; what is corresponding function in sd layer ?<br>
&gt;             &gt; That is the function where i have req-&gt;buffer in hand with<br>
&gt;             me..<br>
&gt;             &gt;<br>
&gt;             &gt;<br>
&gt;             &gt; 2) For a write operation from initiator to disk<br>
&gt;             &gt; is the hierarchy like this<br>
&gt;             &gt; *sd_prep_fn*<br>
&gt;             &gt; generic block device request structure -&gt; converted into<br>
&gt;             scsi specific<br>
&gt;             &gt; request structure<br>
&gt;             &gt; OR<br>
&gt;             &gt; what is scsi_prep_fn for??<br>
&gt;             &gt;<br>
&gt;             &gt; 3)How is Scpnt pointer that is req-&gt; special is used in<br>
&gt;             sd_prep_func..<br>
&gt;             &gt; is processed? i mean which layer picks Scpnt up and<br>
&gt;             processes ??<br>
&gt;             &gt;<br>
&gt;             &gt; 4)Any document any URL any kind of instruction will be<br>
&gt;             extremely helpful.<br>
&gt;             &gt;<br>
&gt;             &gt; 5)Whenever a *new scsi device is attached *sd_probe is called<br>
&gt;             &gt; sd_async_probe() is the async part of sd_probe() So when<br>
&gt;             this is called<br>
&gt;             &gt; the prep_fn is set to sd_prep_fn and hence this will be<br>
&gt;             called.<br>
&gt;             &gt;<br>
&gt;             &gt; *But i thought sd_prep_fn should be called for each and<br>
&gt;             every request<br>
&gt;             &gt; .....??*<br>
&gt;             &gt; Kindly help me to clear the confusion ..<br>
&gt;             &gt;<br>
&gt;             &gt;<br>
&gt;             &gt; Thanks<br>
&gt;             &gt; Nidhi<br>
&gt;             &gt;<br>
&gt;             &gt;<br>
&gt;             &gt;<br>
&gt;             &gt;<br>
&gt;             &gt; _______________________________________________<br>
&gt;             &gt; Kernelnewbies mailing list<br>
&gt;             &gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
</div></div>&gt;             &lt;mailto:<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a>&gt;<br>
<div class=""><div class="h5">&gt;             &gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
&gt;             &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;     --<br>
&gt;     Thanks &amp; Regards<br>
&gt;     Nidhi Mittal Hada<br>
&gt;<br>
&gt;     <a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Thanks &amp; Regards<br>
&gt; Nidhi Mittal Hada<br>
&gt;<br>
&gt; <a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br>
&gt;<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>