make_request函数中的一个bug

 110repeat:
111/* we don't allow the write-requests to fill up the queue completely:
112 * we want some room for reads: they take precedence. The last third
113 * of the requests are only for reads.
114
*/
115 if (rw == READ)
116 req = request+NR_REQUEST;
117 else
118 req = request+((NR_REQUEST*2)/3);
119/* find an empty request */
120 while (--req >= request)
121 if (req->dev<0)
122 break;
123/* if none found, sleep on new requests: check for rw_ahead */
124 if (req < request) {
125 if (rw_ahead) {
126 unlock_buffer(bh);
sti();
127 return;
128 }
129 sleep_on(&wait_for_request);
130 goto repeat;
131 }

该段代码取自kernel/blk_drv/ll_rw_blk.c

代码进入代码跟离开代码的时候应该本别加上cli/sti用来禁止中断。具体原因请参看另外一篇博客。(http://www.cnblogs.com/gitclubs/archive/2012/02/23/2365300.html)

因为这段代码操作的数据request数组以及wait_for_request变量,很有可能在某个中断中被修改,因此此处应该改为如下代码:

 109        cli();
110repeat:
111/* we don't allow the write-requests to fill up the queue completely:
112 * we want some room for reads: they take precedence. The last third
113 * of the requests are only for reads.
114
*/
115 if (rw == READ)
116 req = request+NR_REQUEST;
117 else
118 req = request+((NR_REQUEST*2)/3);
119/* find an empty request */
120 while (--req >= request)
121 if (req->dev<0)
122 break;
123/* if none found, sleep on new requests: check for rw_ahead */
124 if (req < request) {
125 if (rw_ahead) {
126 unlock_buffer(bh);
127 return;
128 }
129 sleep_on(&wait_for_request);
130 goto repeat;
131 }
132 sti();



 

posted on 2012-02-23 22:01  杰特实验室  阅读(461)  评论(0编辑  收藏  举报

导航