Skip to contentSkip to conversation

Simulating faulty disk

DISCUSSION Yathindra 2 participants 17 messages Oct 20, 2011 – Oct 22, 2011 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Yathindra

author
#0 lore raw

Hi,

I'm trying to simulate a faulty disk behavior on linux. Basically, I want to inject various disk failure patterns such as medium errors, unresponsive disk etc.

What is the best way to go about it. I heard about scsi_debug driver but it can only simulate medium errors on fixed sector 0x1234. Also, scsi fault injection using Systemtap seems to be a user space tool limited to files.

Any suggestions is greatly appreciated.

Thanks,
Yathi

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#2 lore raw

Hi Bryan,

I saw this too but it does not have features to delay the commands. And it works only at the file level.

I thought about scsi_debug driver but it seems to able to inject medium errors on sector 0x1234 only. I'm not sure why that limitation exists though.

Thanks,
Yathi

Quoted 36 lines · Bryan Mesich
Quoted 6 lines · Yathindra

Hi,

I'm trying to simulate a faulty disk behavior on linux. Basically, I want to inject various disk failure patterns
such as medium errors, unresponsive disk etc.

Quoted 7 lines

What is the best way to go about it. I heard about scsi_debug driver but it can only simulate medium
errors on fixed sector 0x1234. Also, scsi fault injection using Systemtap seems to be a user space tool
limited to files.

Any suggestions is greatly appreciated.

I saw this go by the linux-scsi list a while back thinking it might be useful sometime down the road:

http://lwn.net/Articles/265187/

I think the project is hosted on sourceforge.net at the following URL:

http://scsifaultinjtst.sourceforge.net/

I had also read through part of a paper that was co-authored by the same person (from linux symposium 2008):

http://www.linuxsymposium.org/archives/OLS/Reprints-2008/tanaka-reprint.pdf

Doesn't look like there has been much activity since 2009, but it looks like it has the functionality you need.

Bryan

Quoted 2 lines

Thanks,
Yathi

author
#3 lore raw

Hi,

Can anybody with experience in using scsi_debug driver tell me if it can be used to inject medium errors on various file/disk blocks.

And also, can it delay commands so we can simulate an unresponsive disk.

Thanks,
Yathi

Quoted 48 lines · Yathindra

Hi Bryan,

I saw this too but it does not have features to delay the commands. And it works only at the file level.

I thought about scsi_debug driver but it seems to able to inject medium errors on sector 0x1234 only. I'm not sure why that limitation exists though.

Thanks,
Yathi

Quoted 37 lines · Bryan Mesich
Quoted 6 lines · Yathindra

Hi,

I'm trying to simulate a faulty disk behavior on linux. Basically, I want to inject various disk failure patterns
such as medium errors, unresponsive disk etc.

Quoted 7 lines

What is the best way to go about it. I heard about scsi_debug driver but it can only simulate medium
errors on fixed sector 0x1234. Also, scsi fault injection using Systemtap seems to be a user space tool
limited to files.

Any suggestions is greatly appreciated.

I saw this go by the linux-scsi list a while back thinking it might be useful sometime down the road:

http://lwn.net/Articles/265187/

I think the project is hosted on sourceforge.net at the following URL:

http://scsifaultinjtst.sourceforge.net/

I had also read through part of a paper that was co-authored by the same person (from linux symposium 2008):

http://www.linuxsymposium.org/archives/OLS/Reprints-2008/tanaka-reprint.pdf

Doesn't look like there has been much activity since 2009, but it looks like it has the functionality you need.

Bryan

Quoted 2 lines

Thanks,
Yathi

#4 lore raw
In reply to Yathindra
Quoted 3 lines · Yathindra

I'm trying to simulate a faulty disk behavior on linux. Basically, I want to inject various disk failure patterns
such as medium errors, unresponsive disk etc.

If using a device-mapper device is acceptable for your purpose there are the dm-flakey and dm-delay targets that can add delays, drop and corrupt writes and introduce intermittent I/O errors.

The targets can be stacked to give devices having any combination of these behaviours.

Regards,
Bryn.

author
#5 lore raw

Hi Bryn,

Thanks for that info. Could you please tell me where I can find more details about using it.

Thanks again,
Yathi

Quoted 11 lines · Bryn M. Reeves
Quoted 3 lines · Yathindra

I'm trying to simulate a faulty disk behavior on linux. Basically, I want to inject various disk failure patterns
such as medium errors, unresponsive disk etc.

If using a device-mapper device is acceptable for your purpose there are the dm-flakey and dm-delay targets that can add delays, drop and corrupt writes and introduce intermittent I/O errors.

The targets can be stacked to give devices having any combination of these behaviours.

Regards,
Bryn.

#6 lore raw
Quoted 7 lines · Yathindra

Hi Bryn,

Thanks for that info. Could you please tell me where I can find more details about using it.

Thanks again,
Yathi

There's a couple of brief files describing the targets in the Documentation/device-mapper directory:

http://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
http://www.kernel.org/doc/Documentation/device-mapper/delay.txt

They both work like the linear target (except that they introduce the specified faults according to their parameters).

To set up a device with both you'd need to use a pair of stacked devices so something like:

dmsetup create d0 --table="0 $SECTORS delay $DEVICE 0 500" dmsetup create f0 --table="0 $SECTORS flakey /dev/mapper/d0 0 9 1"

This will create a device /dev/mapper/f0 that is drops out for 1s in every 10 and has a 500ms delay on reads and writes. SECTORS is the size of the underlying device in sectors (use e.g. $(blockdev --getsize)).

You can optionally specify separate delays/device for writes to the delay layer and write loss / write corruption for the flakey layer - see the doc files and also the comments above flakey_ctr and delay_ctr for more details.

Regards,
Bryn.

author
#7 lore raw

Thanks so much Bryn. Appreciate it.

Quoted 28 lines · Bryn M. Reeves
Quoted 7 lines · Yathindra

Hi Bryn,

Thanks for that info. Could you please tell me where I can find more details about using it.

Thanks again,
Yathi

There's a couple of brief files describing the targets in the Documentation/device-mapper directory:

http://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
http://www.kernel.org/doc/Documentation/device-mapper/delay.txt

They both work like the linear target (except that they introduce the specified faults according to their parameters).

To set up a device with both you'd need to use a pair of stacked devices so something like:

dmsetup create d0 --table="0 $SECTORS delay $DEVICE 0 500" dmsetup create f0 --table="0 $SECTORS flakey /dev/mapper/d0 0 9 1"

This will create a device /dev/mapper/f0 that is drops out for 1s in every 10 and has a 500ms delay on reads and writes. SECTORS is the size of the underlying device in sectors (use e.g. $(blockdev --getsize)).

You can optionally specify separate delays/device for writes to the delay layer and write loss / write corruption for the flakey layer - see the doc files and also the comments above flakey_ctr and delay_ctr for more details.

Regards,
Bryn.

author
#8 lore raw
In reply to Bryn M. Reeves

Hi Bryn,

Sorry to disturb you again. I tried to create a delay device below but it failed.

Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"

device-mapper: reload ioctl failed: Invalid argument Command failed

In /var/log/messages I see this,
device-mapper: ioctl: error adding target to table

Quoted 1 line

uname -r

2.6.32-24-generic-pae

Quoted 1 line

dmsetup --version

Library version:   1.02.39 (2009-10-26)
Driver version:    4.15.0

Am I doing something wrong.

Thanks,
Yathi

Quoted 28 lines · Bryn M. Reeves
Quoted 7 lines · Yathindra

Hi Bryn,

Thanks for that info. Could you please tell me where I can find more details about using it.

Thanks again,
Yathi

There's a couple of brief files describing the targets in the Documentation/device-mapper directory:

http://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
http://www.kernel.org/doc/Documentation/device-mapper/delay.txt

They both work like the linear target (except that they introduce the specified faults according to their parameters).

To set up a device with both you'd need to use a pair of stacked devices so something like:

dmsetup create d0 --table="0 $SECTORS delay $DEVICE 0 500" dmsetup create f0 --table="0 $SECTORS flakey /dev/mapper/d0 0 9 1"

This will create a device /dev/mapper/f0 that is drops out for 1s in every 10 and has a 500ms delay on reads and writes. SECTORS is the size of the underlying device in sectors (use e.g. $(blockdev --getsize)).

You can optionally specify separate delays/device for writes to the delay layer and write loss / write corruption for the flakey layer - see the doc files and also the comments above flakey_ctr and delay_ctr for more details.

Regards,
Bryn.

#9 lore raw
Quoted 7 lines · Yathindra
Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

In /var/log/messages I see this,
device-mapper: ioctl: error adding target to table

I don't see this here:

# dmsetup create d0 --table="0 `blockdev --getsize /dev/sdb` delay /dev/sdb 0 500"
# dmsetup info -c d0
Name             Maj Min Stat Open Targ Event  UUID 

d0 253 3 L--w 1 1 0

# dmsetup create f0 --table="0 `blockdev --getsize /dev/mapper/d0` flakey /dev/mapper/d0 0 9 1"
# dmsetup info -c f0
Name             Maj Min Stat Open Targ Event  UUID 

f0 253 4 L--w 0 1 0

This is using the f15 2.6.40.3 (aka kernel-3.0) with a locally compiled dm-delay since it's not enabled in the Fedora kernels.

Might want to move this thread over to dm-devel if you're having trouble with it.

Regards,
Bryn.

author
#10 lore raw

Oh I see. Maybe dm-delay is not enabled in ubuntu either.

Could you please tell me how I could enable it.

Thanks,
Yathi

Quoted 26 lines · Bryn M. Reeves
Quoted 7 lines · Yathindra
Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

In /var/log/messages I see this,
device-mapper: ioctl: error adding target to table

I don't see this here:

# dmsetup create d0 --table="0 `blockdev --getsize /dev/sdb` delay /dev/sdb 0 500"
# dmsetup info -c d0
Name             Maj Min Stat Open Targ Event  UUID
d0               253   3 L--w    1    1      0
# dmsetup create f0 --table="0 `blockdev --getsize /dev/mapper/d0` flakey /dev/mapper/d0 0 9 1"
# dmsetup info -c f0
Name             Maj Min Stat Open Targ Event  UUID
f0               253   4 L--w    0    1      0

This is using the f15 2.6.40.3 (aka kernel-3.0) with a locally compiled dm-delay since it's not enabled in the Fedora kernels.

Might want to move this thread over to dm-devel if you're having trouble with it.

Regards,
Bryn.

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 11 lines · Yathindra

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"
dmsetup create f0 --table="0 blockdev --getsize /dev/mapper/d0 flakey /dev/mapper/d0 0 9 1"
mkfs -t ext3 /dev/mapper/f0
...
...
ext2fs_mkdir: Attempt to read block from filesystem resulted in short read while creating root dir

Can we even mount such a device ?

It's a flakey device :)

With that table you'll have a device that is failing write I/Os for 1s in every ten. If that coincides with mkfs trying to write to the device it will create a corrupted file system.

Depending on what you are trying to test you may want to put data on the device first.

Regards,
Bryn.

author
#14 lore raw

Ok :) Bryn is there a more elaborate document which shows simple examples to work with device mapper. For a newbie like me it would be really helpful.

Thanks,
Yathi

Quoted 21 lines · Bryn M. Reeves
Quoted 11 lines · Yathindra

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"
dmsetup create f0 --table="0 blockdev --getsize /dev/mapper/d0 flakey /dev/mapper/d0 0 9 1"
mkfs -t ext3 /dev/mapper/f0
...
...
ext2fs_mkdir: Attempt to read block from filesystem resulted in short read while creating root dir

Can we even mount such a device ?

It's a flakey device :)

With that table you'll have a device that is failing write I/Os for 1s in every ten. If that coincides with mkfs trying to write to the device it will create a corrupted file system.

Depending on what you are trying to test you may want to put data on the device first.

Regards,
Bryn.

author
#15 lore raw
Quoted 1 line

mount -t ext3 /dev/sdb /mnt

Copied some data into /mnt

Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"

device-mapper: reload ioctl failed: Invalid argument Command failed

Quoted 2 lines

umount /mnt
dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"

Worked.

Basically, am trying to test how regular userspace commands to read/write files behave when I/O fails. For this, I need to put a file system and then carry on testing.

But as seen from above, dmsetup is failing to create a flakey/delay device when /dev/sdb has a filesystem on top of it. Is there any workaround ?

Thanks,
Yathi

Quoted 29 lines · Yathindra

Ok :) Bryn is there a more elaborate document which shows simple examples to work with device mapper. For a newbie like me it would be really helpful.

Thanks,
Yathi

Quoted 21 lines · Bryn M. Reeves
Quoted 11 lines · Yathindra

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500"
dmsetup create f0 --table="0 blockdev --getsize /dev/mapper/d0 flakey /dev/mapper/d0 0 9 1"
mkfs -t ext3 /dev/mapper/f0
...
...
ext2fs_mkdir: Attempt to read block from filesystem resulted in short read while creating root dir

Can we even mount such a device ?

It's a flakey device :)

With that table you'll have a device that is failing write I/Os for 1s in every ten. If that coincides with mkfs trying to write to the device it will create a corrupted file system.

Depending on what you are trying to test you may want to put data on the device first.

Regards,
Bryn.

#16 lore raw
Quoted 6 lines · Yathindra
Quoted 1 line

mount -t ext3 /dev/sdb /mnt

Copied some data into /mnt

Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

You can't create a mapped device on something while it is mounted as device-mapper needs to open it exclusively.

Quoted 3 lines

But as seen from above, dmsetup is failing to create a flakey/delay device when /dev/sdb
has a filesystem on top of it. Is there any workaround ?

Set up the file system the way you want it on sdb first. Then unmount it and create the device-mapper devices and mount that.

Regards,
Bryn.

author
#17 lore raw

Is there any way we can create a regular scsi device and then dynamically change its personality to delay or flakey ?
Or
Is there a way to dynamically change the parameters of flakey/delay device.

So we can start with no errors and then we can inject some errors.

Thanks,
Yathi

Quoted 18 lines · Bryn M. Reeves
Quoted 6 lines · Yathindra
Quoted 1 line

mount -t ext3 /dev/sdb /mnt

Copied some data into /mnt

Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

You can't create a mapped device on something while it is mounted as device-mapper needs to open it exclusively.

Quoted 3 lines

But as seen from above, dmsetup is failing to create a flakey/delay device when /dev/sdb
has a filesystem on top of it. Is there any workaround ?

Set up the file system the way you want it on sdb first. Then unmount it and create the device-mapper devices and mount that.

Regards,
Bryn.

author
#18 lore raw
In reply to Bryn M. Reeves

All I want to do is simulate a delay or flakey device. Mount it. And see how regular read/write commands such as cat, echo, vim etc behave.

*  I created a delay device d0 and mounted it on /mnt
*  Copied few files into /mnt
*  Invoked dd command on /dev/mapper/d0 and it was slow
*  Invoked cat command on some file in /mnt but it was not slow

What is wrong here?

Steps I followed are shown below:
==========================================================

root@nodea:/users/ydev# dmsetup remove_all

#Created a delay device d0

root@nodea:/users/ydev# dmsetup create d0 --table="0 `blockdev --getsize /dev/sdb` delay /dev/sdb 0 500"

#Put a filesystem on top of d0

root@nodea:/users/ydev# mkfs -t ext3 /dev/mapper/d0
mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
....
....
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
....

#Mounted the device-mapper device on /mnt.

root@nodea:/users/ydev# mount -t ext3 /dev/mapper/d0 /mnt

#Copied some arbitrary files into /mnt

root@nodea:/users/ydev# cp -r stap_tests /mnt

#Invoked a dd command to check if it is slowing down and it did as seen below.

root@nodea:/# dd if=/dev/mapper/d0 of=/dev/null bs=400k count=1
1+0 records in
1+0 records out
409600 bytes (410 kB) copied, 1.01523 s, 403 kB/s

#But it did not slow down cat command as seen below.

root@nodea:/mnt/stap_tests# sysctl vm.drop_caches=3
vm.drop_caches = 3
root@nodea:/mnt/stap_tests# time cat 12M > /dev/null
real    0m0.034s
user    0m0.000s
sys     0m0.004s

==========================================================

Thanks,
Yathi

Quoted 18 lines · Bryn M. Reeves
Quoted 6 lines · Yathindra
Quoted 1 line

mount -t ext3 /dev/sdb /mnt

Copied some data into /mnt

Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

You can't create a mapped device on something while it is mounted as device-mapper needs to open it exclusively.

Quoted 3 lines

But as seen from above, dmsetup is failing to create a flakey/delay device when /dev/sdb
has a filesystem on top of it. Is there any workaround ?

Set up the file system the way you want it on sdb first. Then unmount it and create the device-mapper devices and mount that.

Regards,
Bryn.

author
#19 lore raw
In reply to Bryn M. Reeves

Hi Bryn,

I compiled a fresh kernel and enabled flakey and delay modules. Now am able to create disks but it fails to mount.

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay /dev/sdb 0 500" dmsetup create f0 --table="0 blockdev --getsize /dev/mapper/d0 flakey /dev/mapper/d0 0 9 1" mkfs -t ext3 /dev/mapper/f0
...
...
ext2fs_mkdir: Attempt to read block from filesystem resulted in short read while creating root dir

Can we even mount such a device ?

Thanks,
Yathi

Quoted 26 lines · Bryn M. Reeves
Quoted 7 lines · Yathindra
Quoted 1 line

dmsetup create d0 --table="0 blockdev --getsize /dev/sdb delay

/dev/sdb 0 500"
device-mapper: reload ioctl failed: Invalid argument Command failed

In /var/log/messages I see this,
device-mapper: ioctl: error adding target to table

I don't see this here:

# dmsetup create d0 --table="0 `blockdev --getsize /dev/sdb` delay /dev/sdb 0 500"
# dmsetup info -c d0
Name             Maj Min Stat Open Targ Event  UUID
d0               253   3 L--w    1    1      0
# dmsetup create f0 --table="0 `blockdev --getsize /dev/mapper/d0` flakey /dev/mapper/d0 0 9 1"
# dmsetup info -c f0
Name             Maj Min Stat Open Targ Event  UUID
f0               253   4 L--w    0    1      0

This is using the f15 2.6.40.3 (aka kernel-3.0) with a locally compiled dm-delay since it's not enabled in the Fedora kernels.

Might want to move this thread over to dm-devel if you're having trouble with it.

Regards,
Bryn.