【文件存储】Ceph Kernel module dynamic debug
增加内核的ceph模块的日志打印
ceph在内核的通用模块主要有三个:
# ceph.ko 模块路径
/usr/src/kernels/3.10.0-862.el7.x86_64/fs/ceph
# rbd.ko 模块路径
/usr/src/kernels/3.10.0-862.el7.x86_64/drivers/block
# libceph.ko模块路径
/usr/src/kernels/3.10.0-862.el7.x86_64/net/ceph
编译libceph.ko如下,编译其他的模块类似
make CONFIG_BLK_DEV_LIBCEPH=m -C /usr/src/kernels/3.10.0-862.el7.x86_64 M=/kernel/linux-3.10.0-862.11.6.el7
其中路径/usr/src/kernels/3.10.0-862.el7.x86_64是指取出该目录下的makefile来编译/kernel/linux-3.10.0-862.11.6.el7目录下的源码
编出来的ko文件即在对应目录/kernel/linux-3.10.0-862.11.6.el7/net/ceph之下
此时需要将.ko文件放置在/usr/lib/modules/3.10.0-862.el7.x86_64/kernel/net/ceph/目录下,并更新依赖depmod -a,这个时候系统加载就可以从该目录下加载需要的驱动文件
pr_debug:通过调用 printk 的指定log级别输出,通过调用 printk 的指定log级别输出:
/*
* These can be used to print at the various log levels.
* All of these will print unconditionally, although note that pr_debug()
* and other debug macros are compiled out unless either DEBUG is defined
* or CONFIG_DYNAMIC_DEBUG is set.
*/
#define pr_emerg(fmt, ...) \
printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
#define pr_alert(fmt, ...) \
printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_crit(fmt, ...) \
printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...) \
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
#define pr_warning(fmt, ...) \
printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
#define pr_warn pr_warning
#define pr_notice(fmt, ...) \
printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
#define pr_info(fmt, ...) \
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
Dynamic Debug介绍
模式分类
Linux Kernel里的Dynamic Debug支持好几种配置模式,介绍如下:
1、func:输出指定函数的log
echo -n 'func xxx +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'func xxx -p' > /sys/kernel/debug/dynamic_debug/control
2、file:输出指定文件的log
echo -n 'file xxx.c +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file xxx.c -p' > /sys/kernel/debug/dynamic_debug/control
例如:ceph_common.c,则会打印该文件内的所有log
3. module:输出指定模块的log
echo -n 'module libceph +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'module libceph -p' > /sys/kernel/debug/dynamic_debug/control
比如:libceph/ceph,则会打印libceph或ceph模块的所有log,当前ceph相关的就这两个模块。
4、format
输出符合指定格式的log
echo -n 'format xxx +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'format xxx -p' > /sys/kernel/debug/dynamic_debug/control
比如:get_session,则只会打印匹配这个字符串的log
5、line:输出指定行号的log
echo -n 'file xxx line xxx +p' > /sys/kernel/debug/dynamic_debug/control
echo -n 'file xxx line xxx -p' > /sys/kernel/debug/dynamic_debug/control
比如:100-200,则只会打印指定文件里100行-200行内的log
不同line指定的含义介绍如下:
line 1603 // exactly line 1603
line 1600-1605 // the six lines from line 1600 to line 1605
line -1605 // the 1605 lines from line 1 to line 1605
line 1600- // all lines from line 1600 to the end of the file
Flag说明上述+-号含义如下:
\- remove the given flags
\+ add the given flags
= set the flags to the given flags
支持的flag有:
p enables the pr_debug() callsite.
f Include the function name in the printed message
l Include line number in the printed message
m Include module name in the printed message
t Include thread ID in messages not generated from interrupt context
_ No flags are set. (Or'd with others on input)
打开内核的deubg系统调试模块:确保系统可以使用dynamic 功能:
sudo cat /boot/config-'uname -r' | grep DYNAMIC_DEBUG
显示如下则表明系统调试功能可用:
[root@node1 ~]# sudo cat /boot/config-3.10.0-123.el7.x86_64 | grep DYNAMIC_DEBUG
CONFIG_DYNAMIC_DEBUG=y
挂载debugfs,并打开想要输出的日志模块:
# 开启libceph模块的调试
echo "module libceph +p" >/sys/kernel/debug/dynamic_debug/control
# 关闭libceph模块的调试
echo "module libceph -p" >/sys/kernel/debug/dynamic_debug/control
# 开启ceph模块的调试
echo "module ceph +p" >/sys/kernel/debug/dynamic_debug/control
# 关闭ceph模块的调试
echo "module ceph -p" >/sys/kernel/debug/dynamic_debug/control
通过echo "7 7 7 7" > /proc/sys/kernel/printk
设置内核打印日志级别 0~7, 默认 4 4 1 7。其级别消息如下所示:
#define KERN_EMERG 0 /*紧急事件消息,系统崩溃之前提示,表示系统不可用*/
#define KERN_ALERT 1 /*报告消息,表示必须立即采取措施*/
#define KERN_CRIT 2 /*临界条件,通常涉及严重的硬件或软件操作失败*/
#define KERN_ERR 3 /*错误条件,驱动程序常用KERN_ERR来报告硬件的错误*/
#define KERN_WARNING 4 /*警告条件,对可能出现问题的情况进行警告*/
#define KERN_NOTICE 5 /*正常但又重要的条件,用于提醒。常用于与安全相关的消息*/
#define KERN_INFO 6 /*提示信息,如驱动程序启动时,打印硬件信息*/
#define KERN_DEBUG" 7 /*调试级别的消息*/
以上四个数分别对应如下:
- 控制台日志级别:优先级高于该值的消息将被打印至控制台
- 默认的消息日志级别:将用该优先级来打印没有优先级的消息
- 最低的控制台日志级别:控制台日志级别可被设置的最小值(最高优先级)
- 默认的控制台日志级别:控制台日志级别的缺省值
通过命令dmesg -wT
来实时查看内核挂载cephfs的日志打印,同样该方法可以适用于内核各个日志模块。关于内核方式挂载cephfs详细可以查看内核方式挂载cephfs
调整内核的日志打印之后,dmesg中的日志如下:
[Tue May 7 21:53:40 2019] ceph: do_getattr inode ffff8b8813848330 mask As mode 040777
[Tue May 7 21:53:40 2019] ceph: __ceph_caps_issued_mask ffff8b8813848330 cap ffff8b9ea6d8a078 issued pAsLsXs (mask As)
[Tue May 7 21:53:40 2019] ceph: __touch_cap ffff8b8813848330 cap ffff8b9ea6d8a078 mds0
[Tue May 7 21:53:40 2019] ceph: do_getattr inode ffff8b8813848330 mask pAsLsXsFs mode 040777
[Tue May 7 21:53:40 2019] ceph: do_request on ffff8ba49a7c6c00
[Tue May 7 21:53:40 2019] ceph: reserve caps ctx=ffff8ba49a7c6f50 need=1
[Tue May 7 21:53:40 2019] ceph: reserve caps ctx=ffff8ba49a7c6f50 1025 = 2 used + 1 resv + 1022 avail
[Tue May 7 21:53:40 2019] ceph: __register_request ffff8ba49a7c6c00 tid 48775
[Tue May 7 21:53:40 2019] ceph: __choose_mds ffff8b8813848330 is_hash=0 (0) mode 0
[Tue May 7 21:53:40 2019] ceph: choose_mds ffff8b8813848330 1.fffffffffffffffe mds0 (auth cap ffff8b9ea6d8a078)
[Tue May 7 21:53:40 2019] ceph: lookup_mds_session ffff8ba5857da800 8
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 8 -> 9
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 9 -> 10
[Tue May 7 21:53:40 2019] ceph: do_request mds0 session ffff8ba5857da800 state open
[Tue May 7 21:53:40 2019] ceph: prepare_send_request ffff8ba49a7c6c00 tid 48775 getattr (attempt 1)
[Tue May 7 21:53:40 2019] ceph: inode ffff8b8813848330 1.fffffffffffffffe
[Tue May 7 21:53:40 2019] ceph: r_parent = (null)
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 10 -> 11
[Tue May 7 21:53:40 2019] ceph: mdsc con_get ffff8ba5857da800 ok (11)
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 11 -> 12
[Tue May 7 21:53:40 2019] ceph: mdsc con_get ffff8ba5857da800 ok (12)
[Tue May 7 21:53:40 2019] ceph: mdsc put_session ffff8ba5857da800 12 -> 11
[Tue May 7 21:53:40 2019] ceph: do_request waiting
[Tue May 7 21:53:40 2019] ceph: mdsc con_put ffff8ba5857da800 (10)
[Tue May 7 21:53:40 2019] ceph: mdsc put_session ffff8ba5857da800 11 -> 10
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 10 -> 11
[Tue May 7 21:53:40 2019] ceph: mdsc con_get ffff8ba5857da800 ok (11)
[Tue May 7 21:53:40 2019] ceph: mdsc con_put ffff8ba5857da800 (10)
[Tue May 7 21:53:40 2019] ceph: mdsc put_session ffff8ba5857da800 11 -> 10
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 10 -> 11
[Tue May 7 21:53:40 2019] ceph: mdsc con_get ffff8ba5857da800 ok (11)
[Tue May 7 21:53:40 2019] ceph: mdsc get_session ffff8ba5857da800 11 -> 12
[Tue May 7 21:53:40 2019] ceph: mdsc con_get ffff8ba5857da800 ok (12)
[Tue May 7 21:53:40 2019] ceph: handle_caps from mds0
参考资料
2. Ceph Kernel module dynamic debug