为什么bdev_get_queue返回NULL?

时间:2017-12-22 15:11:00

标签: linux-kernel block-device

我为块设备开发了一个“过滤器”(Linux,Ubuntu 16), 在过滤器驱动程序的初始化过程中,我尝试使用后端的队列指针(存在设备), bdev_get_queue 宏的主体显示很酷的注释“this永远不是NULL“,但我为 struct block_device bd_disk 字段留下了NULL。

我需要另外检查一下吗?

static int __init dua_init(void)
{
    int status;
    struct request_queue *backend_queue = NULL;
    struct super_block *sb = NULL;

    printk(KERN_NOTICE __MODULE__ ": Initialize the driver ...\n");

    if ( IS_ERR(backend_bdev = lookup_bdev(dudrv_bckend, FMODE_READ)) )
        {
        status = PTR_ERR(backend_bdev);
        printk(KERN_ERR __MODULE__ ": lookup_bdev(%s) -> %d\n", dudrv_bckend, status);
        return  status;
        }

    $DELAY(1);

    if ( sb = freeze_bdev(backend_bdev) )
        $TRACE(": freeze I/O on block device %s ...", dudrv_bckend);

    $DELAY(1);

    $TRACE(" %p ", backend_bdev->bd_disk);

    $DELAY(1);

    backend_queue = bdev_get_queue(backend_bdev);

    $TRACE(" -- ");

    $DELAY(1);

    if ( backend_make_request_fn != backend_queue->make_request_fn )
        {
        backend_make_request_fn = backend_queue->make_request_fn;
        backend_queue->make_request_fn = dua_make_request_fn;

        $TRACE(": Change for %s request_fn = %p -> %p, ", dudrv_bckend, backend_make_request_fn, backend_queue->make_request_fn);
        }
    else    {
        printk(KERN_NOTICE __MODULE__ ": I/O request process has been set.\n");
        }

    $TRACE(" -- ");

    /* unlock filesystem */
    $DELAY(1);
    if ( sb )
        if (status = thaw_bdev(backend_bdev, sb))
            printk(KERN_NOTICE __MODULE__ ": thaw_bdev() -> %d\n", status);

    printk(KERN_NOTICE __MODULE__ ": End the driver initialization.\n");

    return 0;
}

Update1:​​队列的指针有什么区别,应该由 bdev_get_queue struct block_device返回。 bd_queue

1 个答案:

答案 0 :(得分:0)

lookup_bdev()不创建完整的Block I / O上下文。