Skip to content

Commit

Permalink
dm flakey: fix logic when corrupting a bio
Browse files Browse the repository at this point in the history
commit aa56b9b upstream.

If "corrupt_bio_byte" is set to corrupt reads and corrupt_bio_flags is
used, dm-flakey would erroneously return all writes as errors. Likewise,
if "corrupt_bio_byte" is set to corrupt writes, dm-flakey would return
errors for all reads.

Fix the logic so that if fc->corrupt_bio_byte is non-zero, dm-flakey
will not abort reads on writes with an error.

Cc: [email protected]
Signed-off-by: Mikulas Patocka <[email protected]>
Reviewed-by: Sweet Tea Dorminy <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Mikulas Patocka authored and gregkh committed Mar 10, 2023
1 parent b57ba4e commit ea60308
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions drivers/md/dm-flakey.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,11 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
/*
* Corrupt matching writes.
*/
if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == WRITE)) {
if (all_corrupt_bio_flags_match(bio, fc))
corrupt_bio_data(bio, fc);
if (fc->corrupt_bio_byte) {
if (fc->corrupt_bio_rw == WRITE) {
if (all_corrupt_bio_flags_match(bio, fc))
corrupt_bio_data(bio, fc);
}
goto map_bio;
}

Expand All @@ -389,13 +391,14 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio,
return DM_ENDIO_DONE;

if (!*error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
all_corrupt_bio_flags_match(bio, fc)) {
/*
* Corrupt successful matching READs while in down state.
*/
corrupt_bio_data(bio, fc);

if (fc->corrupt_bio_byte) {
if ((fc->corrupt_bio_rw == READ) &&
all_corrupt_bio_flags_match(bio, fc)) {
/*
* Corrupt successful matching READs while in down state.
*/
corrupt_bio_data(bio, fc);
}
} else if (!test_bit(DROP_WRITES, &fc->flags) &&
!test_bit(ERROR_WRITES, &fc->flags)) {
/*
Expand Down

0 comments on commit ea60308

Please sign in to comment.