<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body ><div>I think sd_prep_fn is a generic function for any SCSI device while<br>scsi_prep_fn specifically SCSI Disks or LUN's, so if you have a filesystem<br>created on top of SCSI Disk scsi_prep_fn function will be called. In case<br>you have any other SCSI device then you will have sd_prep_fn will be called.<br><br>The comment on top of sd_probe mentions this:<br><br>/**<br>* sd_probe - called during driver initialization and whenever a<br>* new scsi device is attached to the system. It is called once<br>* for each scsi device (not just disks) present.<br>* @dev: pointer to device object<br><br><br>Similarly argument to scsi_alloc_sdev ( while internally calls<br>scsi_alloc_queue ---> blk_queue_prep_rq(q, scsi_prep_fn) ) accepts lun id<br>which I think is specific to SCSI LUN.<br><br>For understanding linux SCSI Subsystem you can also refer to kernel SCSI<br>documentation and also the below mentioned link:<br><br><a href="http://www.andante.org/scsidoc/SCSI-1.html">http://www.andante.org/scsidoc/SCSI-1.html</a><br><br><br>Regards,<br>Piyush Moghe</div> <br><br><br>-------- Original message --------<br>From: Jack Wang <xjtuwjp@gmail.com> <br>Date: <br>To: nidhi mittal hada <nidhimittal19@gmail.com> <br>Cc: Kernelnewbies <kernelnewbies@nl.linux.org>,"rohan.puri.15" <rohan.puri.15@gmail.com>,sumeetgandhare <sumeetgandhare@gmail.com>,kernelnewbies@kernelnewbies.org <br>Subject: Re: scsi subsystem in linux <br> <br><br>On 11/05/2013 05:19 PM, nidhi mittal hada wrote:<br>> 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>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>http://blog.csdn.net/fudan_abc/article/details/1966510<br><br>http://blog.csdn.net/fudan_abc/article/details/1966538<br>http://blog.csdn.net/fudan_abc/article/details/1967045<br>http://blog.csdn.net/fudan_abc/article/details/1967050<br><br>BTW: Why not use dm-crypt?<br><br>Jack<br>> <br>> <br>> <br>> <br>> <br>> On Tue, Nov 5, 2013 at 6:34 PM, nidhi mittal hada<br>> <nidhimittal19@gmail.com <mailto:nidhimittal19@gmail.com>> 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>> >>>>like this blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);<br>> <br>> <br>> _*Calling of sd_prep_fn*_<br>> ?????<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>> <nidhimittal19@gmail.com <mailto:nidhimittal19@gmail.com>> 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>> *which is scsi_prep_fn not the sd_prep_fn isnt it ??*<br>> <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 <xjtuwjp@gmail.com<br>> <mailto:xjtuwjp@gmail.com>> 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>> > Kernelnewbies@kernelnewbies.org<br>> <mailto:Kernelnewbies@kernelnewbies.org><br>> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br>> ><br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> <br>> -- <br>> Thanks & Regards<br>> Nidhi Mittal Hada<br>> <br>> http://nidhi-searchingmyself.blogspot.com/<br>> <br>> <br>> <br>> <br>> -- <br>> Thanks & Regards<br>> Nidhi Mittal Hada<br>> <br>> http://nidhi-searchingmyself.blogspot.com/<br>> <br><br><br>_______________________________________________<br>Kernelnewbies mailing list<br>Kernelnewbies@kernelnewbies.org<br>http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br></body>