dm flakey: add an "error_reads" dm-flakey returns error on reads if no other argument is specified. We simplify the logic, introduce an "error_reads" argument and an ERROR_READS flag. If no argument is specified, we set ERROR_READS, so that it behaves just like before this patch. Signed-off-by: Mikulas Patocka --- Documentation/admin-guide/device-mapper/dm-flakey.rst | 4 ++ drivers/md/dm-flakey.c | 28 ++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) Index: linux-2.6/Documentation/admin-guide/device-mapper/dm-flakey.rst =================================================================== --- linux-2.6.orig/Documentation/admin-guide/device-mapper/dm-flakey.rst +++ linux-2.6/Documentation/admin-guide/device-mapper/dm-flakey.rst @@ -39,6 +39,10 @@ Optional feature parameters: If no feature parameters are present, during the periods of unreliability, all I/O returns errors. + error_reads: + All read I/O is failed with an error signalled. + Write I/O is handled correctly. + drop_writes: All write I/O is silently ignored. Read I/O is handled correctly. Index: linux-2.6/drivers/md/dm-flakey.c =================================================================== --- linux-2.6.orig/drivers/md/dm-flakey.c +++ linux-2.6/drivers/md/dm-flakey.c @@ -37,6 +37,7 @@ struct flakey_c { }; enum feature_flag_bits { + ERROR_READS, DROP_WRITES, ERROR_WRITES }; @@ -53,7 +54,7 @@ static int parse_features(struct dm_arg_ const char *arg_name; static const struct dm_arg _args[] = { - {0, 6, "Invalid number of feature args"}, + {0, 7, "Invalid number of feature args"}, {1, UINT_MAX, "Invalid corrupt bio byte"}, {0, 255, "Invalid corrupt value to write into bio byte (0-255)"}, {0, UINT_MAX, "Invalid corrupt bio flags mask"}, @@ -77,6 +78,17 @@ static int parse_features(struct dm_arg_ } /* + * error_reads + */ + if (!strcasecmp(arg_name, "error_reads")) { + if (test_and_set_bit(ERROR_READS, &fc->flags)) { + ti->error = "Feature error_reads duplicated"; + return -EINVAL; + } + continue; + } + + /* * drop_writes */ if (!strcasecmp(arg_name, "drop_writes")) { @@ -171,6 +183,12 @@ static int parse_features(struct dm_arg_ return -EINVAL; } + if (!fc->corrupt_bio_byte && !test_bit(ERROR_READS, &fc->flags) && + !test_bit(DROP_WRITES, &fc->flags) && !test_bit(ERROR_WRITES, &fc->flags)) { + set_bit(ERROR_WRITES, &fc->flags); + set_bit(ERROR_READS, &fc->flags); + } + return 0; } @@ -346,8 +364,7 @@ static int flakey_map(struct dm_target * * Otherwise, flakey_end_io() will decide if the reads should be modified. */ if (bio_data_dir(bio) == READ) { - if (!fc->corrupt_bio_byte && !test_bit(DROP_WRITES, &fc->flags) && - !test_bit(ERROR_WRITES, &fc->flags)) + if (test_bit(ERROR_READS, &fc->flags)) return DM_MAPIO_KILL; goto map_bio; } @@ -373,11 +390,6 @@ static int flakey_map(struct dm_target * } goto map_bio; } - - /* - * By default, error all I/O. - */ - return DM_MAPIO_KILL; } map_bio: