gpmn 发表于 2005-9-6 20:57:34

0.11的make_request

大家好!
我读0.11kernel/blk_drv/ll_rw_blk.c的时候有点疑问:
这里查找的时候没有关中,如果这个时候被中断,在别的任务里面做了修改,肯定会对本任务的查找有影响啊。比如,找到一个空slot,结果中断,另一任务中也找到该slot并且修改该slot,等调度回来的时候不就崩了吗?

static void make_request(int major,int rw, struct buffer_head * bh)
{
        struct request * req;
        int rw_ahead;

/* WRITEA/READA is special case - it is not really needed, so if the */
/* buffer is locked, we just forget about it, else it's a normal read */
        if (rw_ahead = (rw == READA || rw == WRITEA)) {
                if (bh->b_lock)
                        return;
                if (rw == READA)
                        rw = READ;
                else
                        rw = WRITE;
        }
        if (rw!=READ && rw!=WRITE)
                panic("Bad block dev command, must be R/W/RA/WA");
        lock_buffer(bh);
        if ((rw == WRITE && !bh->b_dirt) || (rw == READ && bh->b_uptodate)) {
                unlock_buffer(bh);
                return;
        }
repeat:
/* we don't allow the write-requests to fill up the queue completely:
* we want some room for reads: they take precedence. The last third
* of the requests are only for reads.
*/
        if (rw == READ)
                req = request+NR_REQUEST;
        else
                req = request+((NR_REQUEST*2)/3);
/* find an empty request */
        while (--req >= request)
                if (req->dev<0)
                        break;
/* if none found, sleep on new requests: check for rw_ahead */
        if (req < request) {
                if (rw_ahead) {
                        unlock_buffer(bh);
                        return;
                }
                sleep_on(&wait_for_request);
                goto repeat;
        }
/* fill up the request-info, and add it to the queue */
        req->dev = bh->b_dev;
        req->cmd = rw;
        req->errors=0;
        req->sector = bh->b_blocknr<<1;
        req->nr_sectors = 2;
        req->buffer = bh->b_data;
        req->waiting = NULL;
        req->bh = bh;
        req->next = NULL;
        add_request(major+blk_dev,req);
}

macana 发表于 2005-9-22 21:13:11

Re: 0.11的make_request

0.11的内核代码应该不会被抢占吧

大家好!
我读0.11kernel/blk_drv/ll_rw_blk.c的时候有点疑问:
这里查找的时候没有关中,如果这个时候被中断,在别的任务里面做了修改,肯定会对本任务的查找有影响啊。比如,找到一个空slot,结果中断,另一任务中也找到该slot并且修改该slot,等调度回来的时候不就崩了吗?
页: [1]
查看完整版本: 0.11的make_request