当前位置: 技术问答>linux和unix
linux内核读文件出现的错误。。。。。。。。。。。。。。。。。。。
来源: 互联网 发布时间:2016-12-25
本文导语: 代码如下: int read_file(void) { char buf_read[1024]={0}; struct file *fp; mm_segment_t fs; loff_t pos; printk("hello entern"); fp = filp_open("/mnt/btr-test/file2", O_RDWR , 0644); if (IS_ERR(fp)) { p...
代码如下:
该函数在vfs下层的文件系统中被调用,然后问题是当文件被成功打开后,vfs_read操作时便没响应了,从/var/log/message中看到的信息是:
Aug 24 16:02:53 ipshot kernel: INFO: task btrfsctl:5714 blocked for more than 120 seconds.
Aug 24 16:02:53 ipshot kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
Aug 24 16:02:53 ipshot kernel: btrfsctl D ffff88001500daf0 0 5714 3585 0x00000080
Aug 24 16:02:53 ipshot kernel: ffff88001387b328 0000000000000082 ffff88001387b298 0000000000000000
Aug 24 16:02:53 ipshot kernel: 0000000000014c80 ffff88001500d560 ffff88001500daf0 ffff88001387bfd8
Aug 24 16:02:53 ipshot kernel: ffff88001500daf8 0000000000014c80 ffff88001387a010 0000000000014c80
Aug 24 16:02:53 ipshot kernel: Call Trace:
Aug 24 16:02:53 ipshot kernel: [] btrfs_tree_lock+0x111/0x120 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_wake_function+0x0/0x20 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_search_slot+0x836/0x8a0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_lookup_file_extent+0x3d/0x40 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_get_extent+0x147/0x9d0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_lookup_ordered_extent+0x33/0x1e0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] __extent_read_full_page+0x190/0x670 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? __mem_cgroup_commit_charge+0x5c/0xb0
Aug 24 16:02:53 ipshot kernel: [] ? mem_cgroup_charge_common+0x6d/0x90
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_get_extent+0x0/0x9d0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] extent_read_full_page+0x2e/0x50 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_readpage+0x23/0x30 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] generic_file_aio_read+0x1f1/0x6e0
Aug 24 16:02:53 ipshot kernel: [] do_sync_read+0xda/0x120
Aug 24 16:02:53 ipshot kernel: [] ? release_console_sem+0x1c1/0x200
Aug 24 16:02:53 ipshot kernel: [] ? security_file_permission+0x8b/0x90
Aug 24 16:02:53 ipshot kernel: [] vfs_read+0xc5/0x190
难道说不能在文件系统内部调用上层VFS的接口?
int read_file(void)
{
char buf_read[1024]={0};
struct file *fp;
mm_segment_t fs;
loff_t pos;
printk("hello entern");
fp = filp_open("/mnt/btr-test/file2", O_RDWR , 0644);
if (IS_ERR(fp)) {
printk("open flie faildn");
return -1;
}
printk("open successn");
fs = get_fs();
set_fs(KERNEL_DS);
pos = 0;
vfs_read(fp, buf_read, sizeof(buf_read), &pos);
printk("read: %sn", buf_read);
filp_close(fp, NULL);
set_fs(fs);
return 0;
}
该函数在vfs下层的文件系统中被调用,然后问题是当文件被成功打开后,vfs_read操作时便没响应了,从/var/log/message中看到的信息是:
Aug 24 16:02:53 ipshot kernel: INFO: task btrfsctl:5714 blocked for more than 120 seconds.
Aug 24 16:02:53 ipshot kernel: "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
Aug 24 16:02:53 ipshot kernel: btrfsctl D ffff88001500daf0 0 5714 3585 0x00000080
Aug 24 16:02:53 ipshot kernel: ffff88001387b328 0000000000000082 ffff88001387b298 0000000000000000
Aug 24 16:02:53 ipshot kernel: 0000000000014c80 ffff88001500d560 ffff88001500daf0 ffff88001387bfd8
Aug 24 16:02:53 ipshot kernel: ffff88001500daf8 0000000000014c80 ffff88001387a010 0000000000014c80
Aug 24 16:02:53 ipshot kernel: Call Trace:
Aug 24 16:02:53 ipshot kernel: [] btrfs_tree_lock+0x111/0x120 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_wake_function+0x0/0x20 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_search_slot+0x836/0x8a0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_lookup_file_extent+0x3d/0x40 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_get_extent+0x147/0x9d0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_lookup_ordered_extent+0x33/0x1e0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] __extent_read_full_page+0x190/0x670 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] ? __mem_cgroup_commit_charge+0x5c/0xb0
Aug 24 16:02:53 ipshot kernel: [] ? mem_cgroup_charge_common+0x6d/0x90
Aug 24 16:02:53 ipshot kernel: [] ? btrfs_get_extent+0x0/0x9d0 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] extent_read_full_page+0x2e/0x50 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] btrfs_readpage+0x23/0x30 [btrfs]
Aug 24 16:02:53 ipshot kernel: [] generic_file_aio_read+0x1f1/0x6e0
Aug 24 16:02:53 ipshot kernel: [] do_sync_read+0xda/0x120
Aug 24 16:02:53 ipshot kernel: [] ? release_console_sem+0x1c1/0x200
Aug 24 16:02:53 ipshot kernel: [] ? security_file_permission+0x8b/0x90
Aug 24 16:02:53 ipshot kernel: [] vfs_read+0xc5/0x190
难道说不能在文件系统内部调用上层VFS的接口?
|
试试用.
fp->f_op->read
fp->f_op->read