Skip to content

Commit aa7d7bc

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm flakey: add an "error_reads" option
dm-flakey returns error on reads if no other argument is specified. This commit simplifies associated logic while formalizing an "error_reads" argument and an ERROR_READS flag. If no argument is specified, set ERROR_READS flag so that it behaves just like before this commit. Signed-off-by: Mikulas Patocka <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent e3675dc commit aa7d7bc

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

Documentation/admin-guide/device-mapper/dm-flakey.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Optional feature parameters:
3939
If no feature parameters are present, during the periods of
4040
unreliability, all I/O returns errors.
4141

42+
error_reads:
43+
All read I/O is failed with an error signalled.
44+
Write I/O is handled correctly.
45+
4246
drop_writes:
4347
All write I/O is silently ignored.
4448
Read I/O is handled correctly.

drivers/md/dm-flakey.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct flakey_c {
3737
};
3838

3939
enum feature_flag_bits {
40+
ERROR_READS,
4041
DROP_WRITES,
4142
ERROR_WRITES
4243
};
@@ -53,7 +54,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
5354
const char *arg_name;
5455

5556
static const struct dm_arg _args[] = {
56-
{0, 6, "Invalid number of feature args"},
57+
{0, 7, "Invalid number of feature args"},
5758
{1, UINT_MAX, "Invalid corrupt bio byte"},
5859
{0, 255, "Invalid corrupt value to write into bio byte (0-255)"},
5960
{0, UINT_MAX, "Invalid corrupt bio flags mask"},
@@ -76,6 +77,17 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
7677
return -EINVAL;
7778
}
7879

80+
/*
81+
* error_reads
82+
*/
83+
if (!strcasecmp(arg_name, "error_reads")) {
84+
if (test_and_set_bit(ERROR_READS, &fc->flags)) {
85+
ti->error = "Feature error_reads duplicated";
86+
return -EINVAL;
87+
}
88+
continue;
89+
}
90+
7991
/*
8092
* drop_writes
8193
*/
@@ -171,6 +183,12 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
171183
return -EINVAL;
172184
}
173185

186+
if (!fc->corrupt_bio_byte && !test_bit(ERROR_READS, &fc->flags) &&
187+
!test_bit(DROP_WRITES, &fc->flags) && !test_bit(ERROR_WRITES, &fc->flags)) {
188+
set_bit(ERROR_WRITES, &fc->flags);
189+
set_bit(ERROR_READS, &fc->flags);
190+
}
191+
174192
return 0;
175193
}
176194

@@ -346,8 +364,7 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
346364
* Otherwise, flakey_end_io() will decide if the reads should be modified.
347365
*/
348366
if (bio_data_dir(bio) == READ) {
349-
if (!fc->corrupt_bio_byte && !test_bit(DROP_WRITES, &fc->flags) &&
350-
!test_bit(ERROR_WRITES, &fc->flags))
367+
if (test_bit(ERROR_READS, &fc->flags))
351368
return DM_MAPIO_KILL;
352369
goto map_bio;
353370
}
@@ -373,11 +390,6 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
373390
}
374391
goto map_bio;
375392
}
376-
377-
/*
378-
* By default, error all I/O.
379-
*/
380-
return DM_MAPIO_KILL;
381393
}
382394

383395
map_bio:
@@ -404,8 +416,8 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio,
404416
*/
405417
corrupt_bio_data(bio, fc);
406418
}
407-
} else if (!test_bit(DROP_WRITES, &fc->flags) &&
408-
!test_bit(ERROR_WRITES, &fc->flags)) {
419+
}
420+
if (test_bit(ERROR_READS, &fc->flags)) {
409421
/*
410422
* Error read during the down_interval if drop_writes
411423
* and error_writes were not configured.
@@ -422,7 +434,7 @@ static void flakey_status(struct dm_target *ti, status_type_t type,
422434
{
423435
unsigned int sz = 0;
424436
struct flakey_c *fc = ti->private;
425-
unsigned int drop_writes, error_writes;
437+
unsigned int error_reads, drop_writes, error_writes;
426438

427439
switch (type) {
428440
case STATUSTYPE_INFO:
@@ -434,10 +446,13 @@ static void flakey_status(struct dm_target *ti, status_type_t type,
434446
(unsigned long long)fc->start, fc->up_interval,
435447
fc->down_interval);
436448

449+
error_reads = test_bit(ERROR_READS, &fc->flags);
437450
drop_writes = test_bit(DROP_WRITES, &fc->flags);
438451
error_writes = test_bit(ERROR_WRITES, &fc->flags);
439-
DMEMIT(" %u", drop_writes + error_writes + (fc->corrupt_bio_byte > 0) * 5);
452+
DMEMIT(" %u", error_reads + drop_writes + error_writes + (fc->corrupt_bio_byte > 0) * 5);
440453

454+
if (error_reads)
455+
DMEMIT(" error_reads");
441456
if (drop_writes)
442457
DMEMIT(" drop_writes");
443458
else if (error_writes)

0 commit comments

Comments
 (0)