Notifier 错误注入¶
Notifier 错误注入提供了向指定的 notifier 链回调注入人工错误的能力。它有助于测试 notifier 调用链失败的错误处理,而这很少被执行。有一些内核模块可以用于测试以下 notifiers。
PM notifier
内存热插拔 notifier
powerpc pSeries 重新配置 notifier
Netdevice notifier
PM notifier 错误注入模块¶
此功能通过 debugfs 接口控制
/sys/kernel/debug/notifier-error-inject/pm/actions/<notifier 事件>/error
可以失败的 PM notifier 事件包括
PM_HIBERNATION_PREPARE
PM_SUSPEND_PREPARE
PM_RESTORE_PREPARE
示例:注入 PM 挂起错误 (-12 = -ENOMEM)
# cd /sys/kernel/debug/notifier-error-inject/pm/
# echo -12 > actions/PM_SUSPEND_PREPARE/error
# echo mem > /sys/power/state
bash: echo: write error: Cannot allocate memory
内存热插拔 notifier 错误注入模块¶
此功能通过 debugfs 接口控制
/sys/kernel/debug/notifier-error-inject/memory/actions/<notifier 事件>/error
可以失败的内存 notifier 事件包括
MEM_GOING_ONLINE
MEM_GOING_OFFLINE
示例:注入内存热插拔离线错误 (-12 == -ENOMEM)
# cd /sys/kernel/debug/notifier-error-inject/memory
# echo -12 > actions/MEM_GOING_OFFLINE/error
# echo offline > /sys/devices/system/memory/memoryXXX/state
bash: echo: write error: Cannot allocate memory
powerpc pSeries 重新配置 notifier 错误注入模块¶
此功能通过 debugfs 接口控制
/sys/kernel/debug/notifier-error-inject/pSeries-reconfig/actions/<notifier 事件>/error
可以失败的 pSeries 重新配置 notifier 事件包括
PSERIES_RECONFIG_ADD
PSERIES_RECONFIG_REMOVE
PSERIES_DRCONF_MEM_ADD
PSERIES_DRCONF_MEM_REMOVE
Netdevice notifier 错误注入模块¶
此功能通过 debugfs 接口控制
/sys/kernel/debug/notifier-error-inject/netdev/actions/<notifier 事件>/error
可以失败的 Netdevice notifier 事件包括
NETDEV_REGISTER
NETDEV_CHANGEMTU
NETDEV_CHANGENAME
NETDEV_PRE_UP
NETDEV_PRE_TYPE_CHANGE
NETDEV_POST_INIT
NETDEV_PRECHANGEMTU
NETDEV_PRECHANGEUPPER
NETDEV_CHANGEUPPER
示例:注入 netdevice mtu 更改错误 (-22 == -EINVAL)
# cd /sys/kernel/debug/notifier-error-inject/netdev
# echo -22 > actions/NETDEV_CHANGEMTU/error
# ip link set eth0 mtu 1024
RTNETLINK answers: Invalid argument
更多使用示例¶
有一些 tools/testing/selftests 使用了 notifier 错误注入功能,用于 CPU 和内存 notifiers。
tools/testing/selftests/cpu-hotplug/cpu-on-off-test.sh
tools/testing/selftests/memory-hotplug/mem-on-off-test.sh
这些脚本首先执行简单的在线和离线测试,然后如果 notifier 错误注入模块可用,则执行故障注入测试。