5

In Ubuntu 14.04 when I try:

sudo dmsetup create test --table '0 123 flakey 1 0 /dev/loop0'

(or the delay target), I get an error:

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

But when I use the error target it succeeds.

How can I create a "flakey" device using dmsetup?

2
  • Leave me a comment @muru if you get a decent answer
    – muru
    Jun 24, 2016 at 20:01
  • @muru: See the accepted answer and my comment there. It turns out that, for me, the argument order was the problem. Jul 1, 2016 at 15:09

2 Answers 2

4
+50

Short answer:

  • Wrong syntax (may be that was for an older version), correct format:

    '<logical_start_sector> <num_sectors> flakey <dev path> <offset> <up interval> <down interval>'
    

    dev_path comes first

  • Unable access to mounted underlying file system. Avoid mount:

    sudo losetup <loop_device> <image_file>
    

Details:

  • I got same error, using loop file system

    ~$ sudo mount -o loop image.iso  ~/Desktop/rmme0
    mount: /dev/loop4 is write-protected, mounting read-only
    
    ~$ sudo dmsetup create test --table '0 123 flakey 1 0 /dev/loop4'
    device-mapper: reload ioctl on test failed: Invalid argument
    Command failed
    

    It was wrong syntax as could find a reference:

    linux-doc (package): /usr/share/doc/linux-doc/device-mapper/dm-flakey.txt

    Table parameters
    ----------------
    <dev path> <offset> <up interval> <down interval> \
        [<num_features> [<feature arguments>]]
    
    Mandatory parameters:
        <dev path>: Full pathname to the underlying block-device, or a
                    "major:minor" device-number.
        <offset>: Starting sector within the device.
        <up interval>: Number of seconds device is available.
        <down interval>: Number of seconds device returns errors.
    
  • So again with:

    ~$ sudo dmsetup -v create test --table '0 123 flakey /dev/loop4 0 10 2'
    device-mapper: reload ioctl on test failed: Device or resource busy
    Command failed
    

    Found this thread: device-mapper: remove ioctl failed: Device or resource busy Command failed. It ended up that message could raise when underlying file system is already mounted.

    So, checked with hard disk partitions

    ~$ sudo dmsetup create test --table '0 123 flakey /dev/sda1 0 10 2'
    ~$ file /dev/mapper/test 
    /dev/mapper/test: symbolic link to ../dm-0
    

    You can verify in detail using verbose flag:

    sudo dmsetup -vvv create test --table '0 123 flakey /dev/sda1 0 10 2'

  • The loop device should not be mounted, so avoid using mount to create it. Alternative way, using losetup:

    sudo losetup /dev/loop4 image.iso
    sudo dmsetup create test --table '0 123 flakey /dev/loop4 0 10 2'
    

Tested on Xubuntu 16.04 (real machine)

2
  • 1
    +1 and ✓. Your answer led to the solution to my problem. It turns out the order of arguments in --table in my question were incorrect. The loop device needs to be specified immediately after "flakey". It's odd that type "error" works with my original argument order. Jul 1, 2016 at 15:07
  • 1
    It is also useful to notice that <dev path> <offset> <up interval> <down interval> are all mandatory parameters (source: kernel.org/doc/html/latest/admin-guide/device-mapper/…), so it's not just that dev path comes first, but there is one additional value that OP didn't have in his example (and you did). May 14, 2021 at 11:14
0

i tried doing this in my previous job where i was testing a storage appliance. The problem with flakey is that it is usually too flakey in the wrong places and causes too harsh an error. You have it set to error every other second which is too harsh for anything but forensic tools.

You need to specify how the device is being flakey, the default is to hard error which is what is preventing you from using it, there are two other options - drop_writes and corrupt_bio_byte

drop writes - will fail all writes but reads succeed

corrupt_bio_byte - is probably what you need as it allows for more subtle breakage that is possible for tools to handle.

The documentation for dmflakey is here https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt

for example:

This should generate cause every 32nd byte of each READ that was 1 to be 0

sudo dmsetup create test --table '0 123 flakey 1 0 /dev/loop0 1 corrupt_bio_byte 32 r 1 0'
5
  • also check you have a compatible kernel and device mapper, if they are of different ages it maybe that they dont both support flakey although it has been around for about 5 years now.
    – Amias
    Jun 29, 2016 at 14:55
  • dmsetup also allows you to create striped or layered devices so you can create one that is normal at the beginning and flakey in the middle, this allows for many more real world usage scenarios than totally flakey.
    – Amias
    Jun 30, 2016 at 13:06
  • I'm sorry, but this doesn't answer my question. You have documented how to use dmsetup to create a flakey filesystem rather than how to solve my problem of "invalid argument". Jun 30, 2016 at 22:03
  • you need to chose which mode you want to use before the arguments can be valid
    – Amias
    Jul 1, 2016 at 10:29
  • I tried the command in your example, including the corrupt_bio_byte mode and still got the error. See Sneetsher's answer and my comment there. Jul 1, 2016 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.