@@ -37,6 +37,7 @@ struct flakey_c {
37
37
};
38
38
39
39
enum feature_flag_bits {
40
+ ERROR_READS ,
40
41
DROP_WRITES ,
41
42
ERROR_WRITES
42
43
};
@@ -53,7 +54,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
53
54
const char * arg_name ;
54
55
55
56
static const struct dm_arg _args [] = {
56
- {0 , 6 , "Invalid number of feature args" },
57
+ {0 , 7 , "Invalid number of feature args" },
57
58
{1 , UINT_MAX , "Invalid corrupt bio byte" },
58
59
{0 , 255 , "Invalid corrupt value to write into bio byte (0-255)" },
59
60
{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,
76
77
return - EINVAL ;
77
78
}
78
79
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
+
79
91
/*
80
92
* drop_writes
81
93
*/
@@ -171,6 +183,12 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
171
183
return - EINVAL ;
172
184
}
173
185
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
+
174
192
return 0 ;
175
193
}
176
194
@@ -346,8 +364,7 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
346
364
* Otherwise, flakey_end_io() will decide if the reads should be modified.
347
365
*/
348
366
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 ))
351
368
return DM_MAPIO_KILL ;
352
369
goto map_bio ;
353
370
}
@@ -373,11 +390,6 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
373
390
}
374
391
goto map_bio ;
375
392
}
376
-
377
- /*
378
- * By default, error all I/O.
379
- */
380
- return DM_MAPIO_KILL ;
381
393
}
382
394
383
395
map_bio :
@@ -404,8 +416,8 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio,
404
416
*/
405
417
corrupt_bio_data (bio , fc );
406
418
}
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 )) {
409
421
/*
410
422
* Error read during the down_interval if drop_writes
411
423
* and error_writes were not configured.
@@ -422,7 +434,7 @@ static void flakey_status(struct dm_target *ti, status_type_t type,
422
434
{
423
435
unsigned int sz = 0 ;
424
436
struct flakey_c * fc = ti -> private ;
425
- unsigned int drop_writes , error_writes ;
437
+ unsigned int error_reads , drop_writes , error_writes ;
426
438
427
439
switch (type ) {
428
440
case STATUSTYPE_INFO :
@@ -434,10 +446,13 @@ static void flakey_status(struct dm_target *ti, status_type_t type,
434
446
(unsigned long long )fc -> start , fc -> up_interval ,
435
447
fc -> down_interval );
436
448
449
+ error_reads = test_bit (ERROR_READS , & fc -> flags );
437
450
drop_writes = test_bit (DROP_WRITES , & fc -> flags );
438
451
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 );
440
453
454
+ if (error_reads )
455
+ DMEMIT (" error_reads" );
441
456
if (drop_writes )
442
457
DMEMIT (" drop_writes" );
443
458
else if (error_writes )
0 commit comments