一次憨批的文件系统调试之旅
这是我以前做文件系统过滤驱动遇到的,文件老是被截断为0,因此使用qemu,下inode 结构i_size 硬件数据断点,然后bt栈回溯
1 // 2 // 硬件数据断点回溯 3 // 4 5 #0 truncate_setsize (inode=0xffff88807b290e10, newsize=0) at mm/truncate.c:828 6 #1 0xffffffff812fe22b in simple_setattr (dentry=<optimized out>, iattr=0xffffc900001f7b60) 7 at fs/libfs.c:433 8 #2 0xffffffff812f18cb in notify_change (dentry=0xffff88807b277900, attr=0xffffc900001f7b60, 9 delegated_inode=<optimized out>) at fs/attr.c:334 10 #3 0xffffffffc0002f3f in wrapfs_setattr (dentry=<optimized out>, ia=0xffffc900001f7c40) 11 at /home/maojun//dddd/wrapfs-latest-e9c6d88/inode.c:419 12 #4 0xffffffff812f18cb in notify_change (dentry=0xffff88807b29ae40, attr=0xffffc900001f7c40, 13 delegated_inode=<optimized out>) at fs/attr.c:334 14 #5 0xffffffff812c9963 in do_truncate (dentry=0xffff88807b290e10, length=<optimized out>, 15 time_attrs=<optimized out>, filp=<optimized out>) at fs/open.c:67 16 #6 0xffffffff812e0f29 in handle_truncate (filp=<optimized out>) at fs/namei.c:3007 17 #7 do_last (op=<optimized out>, file=<optimized out>, nd=<optimized out>) at fs/namei.c:3425 18 #8 path_openat (nd=0xffffc900001f7d90, op=<optimized out>, flags=<optimized out>) at fs/namei.c:3535 19 #9 0xffffffff812e2b0b in do_filp_open (dfd=<optimized out>, pathname=<optimized out>, 20 op=0xffffc900001f7ed4) at fs/namei.c:3566 21 #10 0xffffffff812cc12a in do_sys_open (dfd=-100, filename=<optimized out>, flags=33345, mode=438) 22 at fs/open.c:1090 23 #11 0xffffffff812cc2d0 in __do_sys_openat (mode=<optimized out>, flags=<optimized out>, 24 filename=<optimized out>, dfd=<optimized out>) at fs/open.c:1118 25 #12 __se_sys_openat (mode=<optimized out>, flags=<optimized out>, filename=<optimized out>, 26 dfd=<optimized out>) at fs/open.c:1112 27 #13 __x64_sys_openat (regs=<optimized out>) at fs/open.c:1112 28 --Type <RET> for more, q to quit, c to continue without paging-- 29 #14 0xffffffff8100442a in do_syscall_64 (nr=<optimized out>, regs=0xe <fixed_percpu_data+14>) 30 at arch/x86/entry/common.c:296 31 #15 0xffffffff81c0008c in entry_SYSCALL_64 () at arch/x86/entry/entry_64.S:175 32 33 // 34 // 普通断点回溯 35 // 36 #0 isolation_open (inode=0xffff88807b2ed7c8, file=0xffff88807c2d4700) 37 at /home/maojun//dddd/wrapfs-latest-e9c6d88/isolation.c:219 38 #1 0xffffffffc0002a4b in wrapfs_open (inode=0xffff88807b2ed7c8, file=0xffff88807c2d4700) 39 at /home/maojun//dddd/wrapfs-latest-e9c6d88/file.c:264 40 #2 0xffffffff812ca4a8 in do_dentry_open (f=0xffff88807c2d4700, inode=0xffff88807b2ed7c8, 41 open=0xffffffffc00028f0 <wrapfs_open>) at fs/open.c:801 42 #3 0xffffffff812cbd7f in vfs_open (path=<optimized out>, file=<optimized out>) at fs/open.c:907 43 #4 0xffffffff812e024b in do_last (op=<optimized out>, file=<optimized out>, nd=<optimized out>) 44 at fs/namei.c:3419 45 #5 path_openat (nd=0xffffc900001f7d90, op=0xffffc900001f7ed4, flags=<optimized out>) at fs/namei.c:3535 46 #6 0xffffffff812e2b0b in do_filp_open (dfd=<optimized out>, pathname=<optimized out>, 47 op=0xffffc900001f7ed4) at fs/namei.c:3566 48 #7 0xffffffff812cc12a in do_sys_open (dfd=-100, filename=<optimized out>, flags=32768, mode=0) 49 at fs/open.c:1090 50 #8 0xffffffff812cc2d0 in __do_sys_openat (mode=<optimized out>, flags=<optimized out>, 51 filename=<optimized out>, dfd=<optimized out>) at fs/open.c:1118 52 #9 __se_sys_openat (mode=<optimized out>, flags=<optimized out>, filename=<optimized out>, 53 dfd=<optimized out>) at fs/open.c:1112 54 #10 __x64_sys_openat (regs=<optimized out>) at fs/open.c:1112 55 #11 0xffffffff8100442a in do_syscall_64 (nr=<optimized out>, regs=0xffff88807c2d4700) 56 at arch/x86/entry/common.c:296 57 #12 0xffffffff81c0008c in entry_SYSCALL_64 () at arch/x86/entry/entry_64.S:175 58 Backtrace stopped: previous frame inner to this frame (corrupt stack?) 59 60 61 (gdb) print /o 32768 62 $7 = 0100000 (O_PATH) 63 (gdb) print /o 33345 64 $8 = 0101101 (O_TRUNCATE) //截断
然后就找到了问题,qemu牛逼,gdb牛逼