linux内核之块设备二---真正派发请求request

本文探讨了Linux内核中块设备请求的派发机制,包括触发请求的四个关键时机:重试请求失败、添加unplug标记的bio、达到unplug阈值和unplug定时器超时。讲解了相关函数`__generic_unplug_device`和`generic_unplug_device`的作用,并指出在初始化请求队列时,默认使用scsi_request_fn作为请求下发接口。
摘要由CSDN通过智能技术生成
  • 触发请求request派发的时机:
    1. 重新申请一个请求失败时
    2. 将一个带有unplug标记的bio添加到请求队列时
    3. 将请求添加调度器的调度队列,达到了unplug阈值时
    4. unplug定时时间到,周期性

  • 前三个调用__generic_unplug_device,最后一个调用generic_unplug_device

  • 互斥机制:加锁,请求队列的锁

  • 在初始化请求队列时,默认的块设备的请求下发接口设置为scsi_request_fn

/*真正派发请求request*/
void generic_unplug_device(struct request_queue *q)
{
    if (blk_queue_plugged(q)) {
        spin_lock_irq(q->queue_lock);
        __generic_unplug_device(q);
        spin_unlock_irq(q->queue_lock);
    }
}

/*
 * remove the plug and let it rip..
 */
void __generic_unplug_device(struct request_queue *q)
{
    if (unlikely(blk_queue_stopped(q)))
        return;
    if (!blk_remove_plug(q) && !blk_queue_nonrot(q))
        return;

    q->request_fn(q);
}

/*
 * remove the queue from the plugged list, if present. called with
 * queue lock held and interrupts disabled.
 */
int blk_remove_plug(struct request_queue *q)
{
    WARN_ON(!irqs_disabled());

    if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q))
        return 0;

    del_timer(&q->unplug_timer);
    return 1;
}


/*
 * Function:    scsi_request_fn()
 *
 * Purpose:     Main strategy routine for SCSI.
 *
 * Arguments:   q       - Pointer to actual queue.
 *
 * Returns:     Nothing
 *
 * Lock status: IO request lock assumed to be held when called.
 */
static void scsi_request_fn(struct request_queue *q)
{
    struct scsi_device *sdev = q->queuedata;
    struct Scsi_Host *shost;
    struct scsi_cmnd *cmd;
    struct request *req;

    if(!get_device(&sdev->sdev_gendev))
        /* We must be tearing the block queue down already */
        return;

    /*
     * To start with, we keep looping until the queue is empty, or until
     * the host is no longer able to accept any more requests.
     */
    shost = sdev->host;
    whi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值