dm flakey: error READ bios during the down_interval
[cascardo/linux.git] / drivers / md / dm-flakey.c
index 29b99fb..19db13e 100644 (file)
@@ -289,10 +289,16 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
                pb->bio_submitted = true;
 
                /*
-                * Map reads as normal.
+                * Map reads as normal only if corrupt_bio_byte set.
                 */
-               if (bio_data_dir(bio) == READ)
-                       goto map_bio;
+               if (bio_data_dir(bio) == READ) {
+                       /* If flags were specified, only corrupt those that match. */
+                       if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
+                           all_corrupt_bio_flags_match(bio, fc))
+                               goto map_bio;
+                       else
+                               return -EIO;
+               }
 
                /*
                 * Drop writes?
@@ -330,12 +336,13 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)
 
        /*
         * Corrupt successful READs while in down state.
-        * If flags were specified, only corrupt those that match.
         */
-       if (fc->corrupt_bio_byte && !error && pb->bio_submitted &&
-           (bio_data_dir(bio) == READ) && (fc->corrupt_bio_rw == READ) &&
-           all_corrupt_bio_flags_match(bio, fc))
-               corrupt_bio_data(bio, fc);
+       if (!error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
+               if (fc->corrupt_bio_byte)
+                       corrupt_bio_data(bio, fc);
+               else
+                       return -EIO;
+       }
 
        return error;
 }