<div dir="ltr"><div><div><div><div>My doubt is :-<br></div>When we know block device driver , request structure, request queue operation .. as per LDD.<br></div>How and where the request structure we are getting in scsi layer fits/relates to thi sblock layer request structure....<br>

<br></div>is the sequence ..block device layer request function -&gt; calls scsi layer request function ?<br><br><br></div><br><div><div><br><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Tue, Nov 5, 2013 at 6:34 PM, nidhi mittal hada <span dir="ltr">&lt;<a href="mailto:nidhimittal19@gmail.com" target="_blank">nidhimittal19@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div><div><u><b>Setting of sd_prep_fn()</b></u><br>sd_probe is called<b><i> whenever a</i></b> <b><i>new scsi device is attached to the system.  </i></b><br><br>sd_probe  calls -&gt;  sd_probe_async-&gt;<br>


        inside sd_probe_async, request prep fn is set to <b>sd_prep_fn</b><br>&gt;&gt;&gt;&gt;like this  blk_queue_prep_rq(sdp-&gt;request_queue, sd_prep_fn);<br><br><br><u><b>Calling of sd_prep_fn</b></u><br></div><div>

?????<br>
<br></div><div>Is this request queue sdp-&gt;request_queue, different from the request 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></div><div><br></div>Thanks<br></div>Nidhi<br></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On Tue, Nov 5, 2013 at 6:13 PM, nidhi mittal hada <span dir="ltr">&lt;<a href="mailto:nidhimittal19@gmail.com" target="_blank">nidhimittal19@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">scsi_alloc_sdev(must be called once for each scsi device) --&gt;calls<br>scsi_alloc_queue (that sets up sdev-&gt;request_queue <br>


                                    sets up scsi_request_fn and <br>
                                    sets up req prep function as scsi_prep_fn)<br><br><font size="1">1738 struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)<br>1739 {<br>1740         struct request_queue *q;<br>



1742         q = __scsi_alloc_queue(sdev-&gt;host, 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>



1743         if (!q)<br>1744                 return NULL;<br>1746         blk_queue_prep_rq(q, 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>



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></font>And after this call sdev_request_queue is allocated................<br>



 <br>Now, scsi_request_fn should be called while processing each request in this sdev-&gt;request_queue...<br>Please correct me if i m wrong.<br>Now, inside scsi_request_fn, we get next queueable request by calling <br>blk_peek_request - to fetch request from request queue ..<br>



<br>blk_peek_request -&gt; calls __elv_next_request to fetch next request-<br>and calls prep_rq_fn(q, rq);<br><br><br><span style="color:rgb(116,27,71)"><b><font>which is scsi_prep_fn not the sd_prep_fn isnt it ??</font></b></span><br>



<br><br></div><div class="gmail_extra">Then where is sd_prep_fn is used for ??<br><br></div><div class="gmail_extra">Thanks<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div class="gmail_extra">


Nidhi<br><br><br></div></font></span><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Nov 5, 2013 at 5:39 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:1px solid rgb(204,204,204);padding-left:1ex">



Hi Nidhi,<br>
<br>
About the function call trace you can use ftrace to find out, another<br>
useful tool is scsi_logging_level to set more verbose logging output for<br>
scsi core.<br>
<br>
Regards<br>
Jack<br>
<div>On 11/05/2013 12:48 PM, nidhi mittal hada wrote:<br>
&gt;<br>
&gt; Hi All<br>
&gt;<br>
&gt; i have got a requirement where I need to encrypt/decrypt data that goes<br>
&gt; from scsi layer to a particular block device.<br>
&gt; As per my understanding till now on scsi subsystem in linux, i think i<br>
&gt; need to<br>
&gt; use crypto api and call appropriate encrypt/decrypt function from sd<br>
&gt; driver for block device.<br>
&gt;<br>
&gt; I need to locate that specific function where this change needs to be<br>
&gt; made ...<br>
&gt; I know basic block device driver writing in linux .. But not able to fit<br>
&gt; scsi in this picture.<br>
&gt;<br>
&gt; I have few basic doubts.. kindly help in resolving ...<br>
&gt;<br>
&gt; 1) Now, as example block device driver sbull, as given LDD, works on<br>
&gt; request queue, fetches req from this queue, using function req =<br>
&gt; elv_next_request(q)),<br>
&gt; in request function.<br>
&gt; what is corresponding function in sd layer ?<br>
&gt; That is the function where i have req-&gt;buffer in hand with me..<br>
&gt;<br>
&gt;<br>
&gt; 2) For a write operation from initiator to disk<br>
&gt; is the hierarchy like this<br>
</div>&gt; *sd_prep_fn*<br>
<div>&gt; generic block device request structure -&gt; converted into scsi specific<br>
&gt; request structure<br>
&gt; OR<br>
&gt; what is scsi_prep_fn for??<br>
&gt;<br>
&gt; 3)How is Scpnt pointer that is req-&gt; special is used in sd_prep_func..<br>
&gt; is processed? i mean which layer picks Scpnt up and processes ??<br>
&gt;<br>
&gt; 4)Any document any URL any kind of instruction will be extremely helpful.<br>
&gt;<br>
</div>&gt; 5)Whenever a *new scsi device is attached *sd_probe is called<br>
<div>&gt; sd_async_probe() is the async part of sd_probe() So when this is called<br>
&gt; the prep_fn is set to sd_prep_fn and hence this will be called.<br>
&gt;<br>
</div>&gt; *But i thought sd_prep_fn should be called for each and every request<br>
&gt; .....??*<br>
<div>&gt; Kindly help me to clear the confusion ..<br>
&gt;<br>
&gt;<br>
&gt; Thanks<br>
&gt; Nidhi<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div>&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
&gt;<br>
<br>
</blockquote></div><br><br clear="all"><br><br>
</div></div></div></div>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>Thanks &amp; Regards <br>Nidhi Mittal Hada<br><br><a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br>

<br>

</font></span></div>
</blockquote></div><br><br clear="all"><br>-- <br>Thanks &amp; Regards <br>Nidhi Mittal Hada<br><br><a href="http://nidhi-searchingmyself.blogspot.com/" target="_blank">http://nidhi-searchingmyself.blogspot.com/</a><br><br>


</div>