@@ -37,6 +37,7 @@ struct flakey_c {
3737};
3838
3939enum 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
383395map_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