如何在测试期间模拟出现故障的磁盘? [英] How can I simulate a failed disk during testing?

查看:39
本文介绍了如何在测试期间模拟出现故障的磁盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux VM(Vmware 工作站或类似的)中,如何模拟以前工作的磁盘上的故障?

In a Linux VM (Vmware workstation or similar), how can I simulate a failure on a previously working disc?

我在生产中遇到过光盘出现故障的情况(可能是控制器、电缆或固件问题).显然,这是不可预测或不可重复的,我想测试我的监控以确保它正确发出警报.

I have a situation happening in production where a disc fails (probably a controller, cable or firmware problem). Obviously this is not predictable or reproducible, I want to test my monitoring to ensure that it alerts correctly.

理想情况下,我希望能够模拟写入失败但读取成功以及完全失败的情况,即 scsi 接口将错误报告回内核.

I'd ideally like to be able to simulate a situation where it fails writes but succeeds reads, as well as a complete failure, i.e. the scsi interface reports errors back to the kernel.

推荐答案

可以在多个层模拟磁盘错误.如果您正在测试单个用户空间程序,可能最简单的方法是插入适当的调用(例如 write())并让它们有时返回错误.libfiu 故障注入库可以做到这一点使用它的fiu-run 工具.

There are several layers at which a disk error can be simulated. If you are testing a single user-space program, probably the simplest approach is to interpose the appropriate calls (e.g. write()) and have them sometimes return an error. The libfiu fault-injection library can do this using its fiu-run tool.

另一种方法是使用内核驱动程序,该驱动程序可以将数据传入/传出另一个设备,但在此过程中会注入错误.然后您可以挂载设备并从任何应用程序使用它,就好像它是一个有故障的磁盘一样.fsdisk 驱动程序就是一个例子.

Another approach is to use a kernel driver that can pass through data to/from another device, but inject faults along the way. You can then mount the device and use it from any application as if it was a faulty disk. The fsdisk driver is an example of this.

还有一个故障注入基础设施已合并到 Linux 内核中,尽管您可能需要重新配置内核以启用它.它记录在 Documentation/fault-injection/fault-injection.txt.这对于测试内核代码很有用.

There is also a fault injection infrastructure that has been merged in to the Linux kernel, although you will probably need to reconfigure your kernel to enable it. It is documented in Documentation/fault-injection/fault-injection.txt. This is useful for testing kernel code.

还可以使用 SystemTap 在内核级别注入故障.请参阅SCSI 故障注入测试使用 SystemTap 注入内核错误.

It is also possible to use SystemTap to inject faults at the kernel level. See The SCSI fault injection test and Kernel Fault injection using SystemTap.

这篇关于如何在测试期间模拟出现故障的磁盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆