<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class="">I am reading the book, Linux Driver Development 3.</div><div class="">In the chapter on block driver of this book, &nbsp;I need some help to rewriting the sbull_request since the kernel’s block API was changed.&nbsp;</div><div class=""><br class=""></div><div class="">The sbull_request code:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(83, 48, 225);" class="">/*</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(83, 48, 225);" class="">&nbsp;* The simple form of the request function.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(83, 48, 225);" class="">&nbsp;*/</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">static</span> <span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">void</span> sbull_request(request_queue_t *q)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: #00e6e5" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">struct</span> request *req;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">while</span> ((req = elv_next_request(q)) != <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">NULL</span>) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">struct</span> sbull_dev *dev = req-&gt;rq_disk-&gt;private_data;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">if</span> (! blk_fs_request(req)) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printk (KERN_NOTICE <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">"Skip non-fs request</span><span style="font-variant-ligatures: no-common-ligatures; color: #d53bd3" class="">\n</span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">"</span>);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end_request(req, <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">0</span>);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">continue</span>;</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; sbull_transfer(dev, req-&gt;sector, req-&gt;current_nr_sectors,</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req-&gt;buffer, rq_data_dir(req));</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; end_request(req, <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">1</span>);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: #00e6e5" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; background-color: #00e6e5" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">I have rewritten the code above into:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal; color: rgb(83, 48, 225);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(83, 48, 225);" class="">/*</div><div style="margin: 0px; line-height: normal; color: rgb(83, 48, 225);" class="">&nbsp;* The simple form of the request function.</div><div style="margin: 0px; line-height: normal; color: rgb(83, 48, 225);" class="">&nbsp;*/</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">void</span> blkplay_request(<span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">struct</span> request_queue *q)</div><div style="margin: 0px; line-height: normal;" class="">{</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">struct</span> request *req;</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">while</span> (!blk_queue_stopped(q) &amp;&amp;&nbsp;</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (req = blk_peek_request(q)) != <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">NULL</span>) {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #34bd26" class="">struct</span> blkplay_dev *dev = req-&gt;rq_disk-&gt;private_data;</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; blk_start_request(req);</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">if</span> (req-&gt;cmd_type != REQ_TYPE_FS) {</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printk (KERN_NOTICE <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">"Skip non-fs request</span><span style="font-variant-ligatures: no-common-ligatures; color: #d53bd3" class="">\n</span><span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">"</span>);</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blk_end_request(req, -<span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">EIO</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">0</span>);</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #ce7924" class="">continue</span>;</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/* I don’t know how to write the statement below */</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; blkplay_transfer(dev, req-&gt;sector, req-&gt;current_nr_sectors,</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req-&gt;buffer, rq_data_dir(req));</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; &nbsp; &nbsp; blk_end_request_cur(req, <span style="font-variant-ligatures: no-common-ligatures; color: #c33720" class="">0</span>);</div><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; line-height: normal;" class="">}</div></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">Is the rewrite proper?</p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;</p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">The compiler can’t compile it because the request struct no longer has&nbsp;</p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">the field of ‘sector’ and ‘current_nr_sectors’. I have read the kernel code</p><div class="">about the request struct, the &nbsp;kernel code said the __data_len and __sector field of</div></div><div class="">request struct is internal so that we shouldn’t access them directly.</div><div class=""><br class=""></div><div class="">How could I rewrite it ? &nbsp;Thanks.</div>
</body></html>