dm flakey: error READ bios during the down_interval
authorMike Snitzer <snitzer@redhat.com>
Fri, 29 Jul 2016 17:19:55 +0000 (13:19 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 20 Nov 2016 01:01:30 +0000 (01:01 +0000)
commit 99f3c90d0d85708e7401a81ce3314e50bf7f2819 upstream.

When the corrupt_bio_byte feature was introduced it caused READ bios to
no longer be errored with -EIO during the down_interval.  This had to do
with the complexity of needing to submit READs if the corrupt_bio_byte
feature was used.

Fix it so READ bios are properly errored with -EIO; doing so early in
flakey_map() as long as there isn't a match for the corrupt_bio_byte
feature.

Fixes: a3998799fb4df ("dm flakey: add corrupt_bio_byte feature")
Reported-by: Akira Hayakawa <ruby.wktk@gmail.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
[bwh: Backported to 3.2: in flakey_end_io(), keep using
 bio_submitted_while_down instead of pb->bio_submitted]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/md/dm-flakey.c

index 746b5e8..63226d1 100644 (file)
@@ -279,10 +279,16 @@ static int flakey_map(struct dm_target *ti, struct bio *bio,
                map_context->ll = 1;
 
                /*
-                * 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?
@@ -321,12 +327,13 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio,
 
        /*
         * Corrupt successful READs while in down state.
-        * If flags were specified, only corrupt those that match.
         */
-       if (fc->corrupt_bio_byte && !error && bio_submitted_while_down &&
-           (bio_data_dir(bio) == READ) && (fc->corrupt_bio_rw == READ) &&
-           all_corrupt_bio_flags_match(bio, fc))
-               corrupt_bio_data(bio, fc);
+       if (!error && bio_submitted_while_down && (bio_data_dir(bio) == READ)) {
+               if (fc->corrupt_bio_byte)
+                       corrupt_bio_data(bio, fc);
+               else
+                       return -EIO;
+       }
 
        return error;
 }