sbull ldd3示例驱动程序卡住了

时间:2014-11-12 08:05:06

标签: linux linux-kernel linux-device-driver kernel-module block-device

我正在编写一个块设备驱动程序,并从这里开始使用sbull示例: http://lwn.net/images/pdf/LDD3/ldd3_pdf.tar.bz2 我在内核版本为3.5.0-23的机器上成功加载了sbull驱动程序。 当我运行此代码时:

int main(){
int fd;

if ((fd = open("/dev/sbulla",O_RDWR)) < 0)
{
    perror("open: ");
    exit(1);
}

lseek(fd,4096,SEEK_SET);
write(fd,"yonityoyin",10);

lseek(fd,4096*2,SEEK_SET);
write(fd,"yonityoyin",10);

close(fd);

}

会话陷入困境。 如果我在机器上打开另一个会话并打印dmesg,我会在一段时间后得到这个:

[56437.815570] INFO: task a.out:4640 blocked for more than 120 seconds.
[56437.822742] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[56437.831563] a.out           D ffffffff8180cbe0     0  4640   4639 0x00000000
[56437.831571]  ffff880852715c08 0000000000000082 0000000000000000 0000000000000001
[56437.831580]  ffff880852715fd8 ffff880852715fd8 ffff880852715fd8 00000000000139c0
[56437.831588]  ffff8808547c0000 ffff880851bc2e00 ffff880852715be8 ffff88085fd74258
[56437.831595] Call Trace:
[56437.831623]  [<ffffffff81127220>] ? __lock_page+0x70/0x70
[56437.831638]  [<ffffffff8169d8b9>] schedule+0x29/0x70
[56437.831643]  [<ffffffff8169d98f>] io_schedule+0x8f/0xd0
[56437.831652]  [<ffffffff8112722e>] sleep_on_page+0xe/0x20
[56437.831657]  [<ffffffff8169c25f>] __wait_on_bit+0x5f/0x90
[56437.831663]  [<ffffffff81127c1b>] ? find_get_pages_tag+0xcb/0x170
[56437.831674]  [<ffffffff81127388>] wait_on_page_bit+0x78/0x80
[56437.831682]  [<ffffffff81078490>] ? autoremove_wake_function+0x40/0x40
[56437.831691]  [<ffffffff8112749c>] filemap_fdatawait_range+0x10c/0x1a0
[56437.831701]  [<ffffffff81133000>] ? do_writepages+0x20/0x40
[56437.831706]  [<ffffffff8112755b>] filemap_fdatawait+0x2b/0x30
[56437.831711]  [<ffffffff811298e4>] filemap_write_and_wait+0x44/0x60
[56437.831718]  [<ffffffff811c0091>] __sync_blockdev+0x21/0x40
[56437.831722]  [<ffffffff811c00c3>] sync_blockdev+0x13/0x20
[56437.831726]  [<ffffffff811c0139>] __blkdev_put+0x69/0x1c0
[56437.831736]  [<ffffffff811c02eb>] blkdev_put+0x5b/0x160
[56437.831740]  [<ffffffff811c0415>] blkdev_close+0x25/0x30
[56437.831750]  [<ffffffff81188afe>] __fput+0xbe/0x240
[56437.831756]  [<ffffffff81188ca5>] fput+0x25/0x30
[56437.831761]  [<ffffffff81185976>] filp_close+0x66/0x90
[56437.831766]  [<ffffffff81185a3e>] sys_close+0x9e/0x110
[56437.831775]  [<ffffffff816a7029>] system_call_fastpath+0x16/0x1b

驱动程序有什么问题? 为了清楚起见,我在原始的sbull驱动程序中遇到了这个问题。

1 个答案:

答案 0 :(得分:0)

请参阅较新的示例代码。

https://github.com/martinezjavier/ldd3