dm flakey: add features
cover dm flakey: add features
Add "drop_writes", "corrupt_bio_byte" and "debug" features to the flakey target. This work was motivated by a need to test the checksum support of the new DM multisnapshot target.
I was able to successfully test multisnap checksums with the following:
load a previously created multisnapshot pool that has a valid multisnap metadata superblock, when reading write 1 to the 352rd byte of the bio (352 happens to the offset to an unused compat_flags field in 'struct multisnap_super_block; the change causes the multisnap crc code to notice):
echo "0 20971520 flakey 254:16 2048 0 5 5 corrupt_bio_byte 352 0 1 debug" | dmsetup create multisnap-metadata echo "0 209715200 multisnap-pool 253:0 253:1 128 32" | dmsetup create pool
device-mapper: reload ioctl failed: Cannot allocate memory
Command failed
(NOTE: I need to cleanup the multisnapshot code so it doesn't throw errors on the floor, checksum failure returns -EILSEQ not -ENOMEM)
The kernel log showed:
corrupting data bio=ffff88007c8d5140 by writing 1 to byte 352 (rw=0 flags=0 bi_sector=2056 cur_bytes=4096) multisnap sb_check failed csum 4189028790 wanted 227629054
superblock validator check failed for block 0
couldn't lock superblocktm_open_with_sm failed
device-mapper: table: 253:2: multisnap-pool: Error creating metadata object
device-mapper: ioctl: error adding target to table
Mike Snitzer (9):
dm: factor out target argument parsing helpers
dm flakey: use dm_target_offset() and support discards
dm flakey: start of adding features
dm flakey: add drop_writes feature
dm flakey: add corrupt_bio_byte feature
dm flakey: add corrupt_bio_byte read support
dm flakey: switch corrupt_bio_data_dir to corrupt_bio_flags dm flakey: add ability to specify the corrupting value to be written dm flakey: add debug feature to control debug output
drivers/md/dm-flakey.c | 203 +++++++++++++++++++++++++++++++++++++--- drivers/md/dm-mpath.c | 119 ++++++++----------------- drivers/md/dm-table.c | 40 ++++++++ include/linux/device-mapper.h | 18 ++++ 4 files changed, 282 insertions(+), 98 deletions(-)
PATCH 1/9 dm: factor out target argument parsing helpers
Other targets may need to handle target arguments with a variable count (as are widely used in the multipath target).
--- drivers/md/dm-mpath.c | 119 +++++++++++++---------------------------- drivers/md/dm-table.c | 40 ++++++++++++++ include/linux/device-mapper.h | 18 ++++++ 3 files changed, 95 insertions(+), 82 deletions(-)
drivers/md/dm-mpath.c +37 -82
@@ -505,69 +505,24 @@ static void trigger_event(struct work_struct *work)* <#paths> <#per-path selector args> * [<path> [<arg>]* ]+ ]+ *---------------------------------------------------------------*/ -struct param { -unsigned min; -unsigned max; -char *error; -}; - -static int read_param (struct param *param,char *str,unsigned *v,char **error) -{ -if (!str || - (sscanf (str,"%u" , v) !=1 ) || - (*v < param->min) || - (*v > param->max)) { - *error = param->error; -return -EINVAL ; - } - -return 0 ; -} - -struct arg_set { -unsigned argc; -char **argv; -}; - -static char *shift (struct arg_set *as) -{ -char *r; - -if (as->argc) { - as->argc--; - r = *as->argv; - as->argv++; -return r; - } - -return NULL ; -} - -static void consume (struct arg_set *as,unsigned n) -{ -BUG_ON (as->argc < n); - as->argc -= n; - as->argv += n; -} - -static int parse_path_selector (struct arg_set *as,struct priority_group *pg, +static int parse_path_selector (struct dm_arg_set *as,struct priority_group *pg,struct dm_target *ti) {int r;struct path_selector_type *pst;unsigned ps_argc; -static struct param _params[] = { +static struct dm_arg _args[] = { {0 ,1024 ,"invalid number of path selector args" }, }; - pst =dm_get_path_selector (shift (as)); + pst =dm_get_path_selector (dm_shift_arg (as));if (!pst) { ti->error ="unknown path selector type" ;return -EINVAL ; } - r =read_param (_params,shift (as), &ps_argc, &ti->error); + r =dm_read_arg (_args,dm_shift_arg (as), &ps_argc, &ti->error);if (r) {dm_put_path_selector (pst);return -EINVAL ;
@@ -587,12 +542,12 @@ static int parse_path_selector(struct arg_set *as, struct priority_group *pg, } pg->ps.type = pst; -consume (as, ps_argc); +dm_consume_args (as, ps_argc);return 0 ; } -static struct pgpath *parse_path (struct arg_set *as,struct path_selector *ps, +static struct pgpath *parse_path (struct dm_arg_set *as,struct path_selector *ps,struct dm_target *ti) {int r;
@@ -609,7 +564,7 @@ static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,if (!p)return ERR_PTR (-ENOMEM ); - r =dm_get_device (ti,shift (as),dm_table_get_mode (ti->table), + r =dm_get_device (ti,dm_shift_arg (as),dm_table_get_mode (ti->table), &p->path.dev);if (r) { ti->error ="error getting device" ;
@@ -660,16 +615,16 @@ static struct pgpath *parse_path(struct arg_set *as, struct path_selector *ps,return ERR_PTR (r); } -static struct priority_group *parse_priority_group (struct arg_set *as, +static struct priority_group *parse_priority_group (struct dm_arg_set *as,struct multipath *m) { -static struct param _params[] = { +static struct dm_arg _args[] = { {1 ,1024 ,"invalid number of paths" }, {0 ,1024 ,"invalid number of selector args" } };int r; -unsigned i, nr_selector_args, nr_params; +unsigned i, nr_selector_args, nr_args;struct priority_group *pg;struct dm_target *ti = m->ti;
@@ -693,26 +648,26 @@ static struct priority_group *parse_priority_group(struct arg_set *as,/* * read the paths */ - r =read_param (_params,shift (as), &pg->nr_pgpaths, &ti->error); + r =dm_read_arg (_args,dm_shift_arg (as), &pg->nr_pgpaths, &ti->error);if (r) goto bad; - r =read_param (_params +1 ,shift (as), &nr_selector_args, &ti->error); + r =dm_read_arg (_args +1 ,dm_shift_arg (as), &nr_selector_args, &ti->error);if (r) goto bad; - nr_params =1 + nr_selector_args; + nr_args =1 + nr_selector_args;for (i =0 ; i < pg->nr_pgpaths; i++) {struct pgpath *pgpath; -struct arg_set path_args; +struct dm_arg_set path_args; -if (as->argc < nr_params) { +if (as->argc < nr_args) { ti->error ="not enough path parameters" ; r = -EINVAL ; goto bad; } - path_args.argc = nr_params; + path_args.argc = nr_args; path_args.argv = as->argv; pgpath =parse_path (&path_args, &pg->ps, ti);
@@ -723,7 +678,7 @@ static struct priority_group *parse_priority_group(struct arg_set *as, pgpath->pg = pg;list_add_tail (&pgpath->list, &pg->pgpaths); -consume (as, nr_params); +dm_consume_args (as, nr_args); }return pg;
@@ -733,17 +688,17 @@ static struct priority_group *parse_priority_group(struct arg_set *as,return ERR_PTR (r); } -static int parse_hw_handler (struct arg_set *as,struct multipath *m) +static int parse_hw_handler (struct dm_arg_set *as,struct multipath *m) {unsigned hw_argc;int ret;struct dm_target *ti = m->ti; -static struct param _params[] = { +static struct dm_arg _args[] = { {0 ,1024 ,"invalid number of hardware handler args" }, }; -if (read_param (_params,shift (as), &hw_argc, &ti->error)) +if (dm_read_arg (_args,dm_shift_arg (as), &hw_argc, &ti->error))return -EINVAL ;if (!hw_argc)
@@ -754,7 +709,7 @@ static int parse_hw_handler(struct arg_set *as, struct multipath *m)return -EINVAL ; } - m->hw_handler_name =kstrdup (shift (as),GFP_KERNEL ); + m->hw_handler_name =kstrdup (dm_shift_arg (as),GFP_KERNEL );request_module ("scsi_dh_%s" , m->hw_handler_name);if (scsi_dh_handler_exist (m->hw_handler_name) ==0 ) { ti->error ="unknown hardware handler type" ;
@@ -778,7 +733,7 @@ static int parse_hw_handler(struct arg_set *as, struct multipath *m)for (i =0 , p+=j+1 ; i <= hw_argc -2 ; i++, p+=j+1 ) j =sprintf (p,"%s" , as->argv[i]); } -consume (as, hw_argc -1 ); +dm_consume_args (as, hw_argc -1 );return 0 ; fail:
@@ -787,20 +742,20 @@ fail:return ret; } -static int parse_features (struct arg_set *as,struct multipath *m) +static int parse_features (struct dm_arg_set *as,struct multipath *m) {int r;unsigned argc;struct dm_target *ti = m->ti; -const char *param_name; +const char *arg_name; -static struct param _params[] = { +static struct dm_arg _args[] = { {0 ,5 ,"invalid number of feature args" }, {1 ,50 ,"pg_init_retries must be between 1 and 50" }, {0 ,60000 ,"pg_init_delay_msecs must be between 0 and 60000" }, }; - r =read_param (_params,shift (as), &argc, &ti->error); + r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);if (r)return -EINVAL ;
@@ -808,25 +763,25 @@ static int parse_features(struct arg_set *as, struct multipath *m)return 0 ; do { - param_name = shift(as); + arg_name = dm_shift_arg(as); argc--; - if (!strnicmp(param_name, MESG_STR("queue_if_no_path"))) { + if (!strnicmp(arg_name, MESG_STR("queue_if_no_path"))) { r = queue_if_no_path(m, 1, 0); continue; } - if (!strnicmp(param_name, MESG_STR("pg_init_retries")) && + if (!strnicmp(arg_name, MESG_STR("pg_init_retries")) && (argc >= 1)) { - r = read_param(_params + 1, shift(as), + r = dm_read_arg(_args + 1, dm_shift_arg(as), &m->pg_init_retries, &ti->error); argc--; continue; } - if (!strnicmp(param_name, MESG_STR("pg_init_delay_msecs")) && + if (!strnicmp(arg_name, MESG_STR("pg_init_delay_msecs")) && (argc >= 1)) { - r = read_param(_params + 2, shift(as), + r = dm_read_arg(_args + 2, dm_shift_arg(as), &m->pg_init_delay_msecs, &ti->error); argc--; continue;
@@ -842,15 +797,15 @@ static int parse_features(struct arg_set *as, struct multipath *m)static int multipath_ctr (struct dm_target *ti,unsigned int argc,char **argv) { -/* target parameters */ -static struct param _params[] = { +/* target arguments */ +static struct dm_arg _args[] = { {0 ,1024 ,"invalid number of priority groups" }, {0 ,1024 ,"invalid initial priority group number" }, };int r;struct multipath *m; -struct arg_set as; +struct dm_arg_set as;unsigned pg_count =0 ;unsigned next_pg_num;
@@ -871,11 +826,11 @@ static int multipath_ctr(struct dm_target *ti, unsigned int argc,if (r) goto bad; - r =read_param (_params,shift (&as), &m->nr_priority_groups, &ti->error); + r =dm_read_arg (_args,dm_shift_arg (&as), &m->nr_priority_groups, &ti->error);if (r) goto bad; - r =read_param (_params +1 ,shift (&as), &next_pg_num, &ti->error); + r =dm_read_arg (_args +1 ,dm_shift_arg (&as), &next_pg_num, &ti->error);if (r) goto bad;
drivers/md/dm-table.c +40 -0
@@ -785,6 +785,46 @@ int dm_table_add_target(struct dm_table *t, const char *type,return r; } +/* +* Target argument parsing helpers. +*/ +int dm_read_arg (struct dm_arg *arg,char *str,unsigned *v,char **error) +{ +if (!str || + (sscanf (str,"%u" , v) !=1 ) || + (*v < arg->min) || + (*v > arg->max)) { + *error = arg->error; +return -EINVAL ; + } + +return 0 ; +} +EXPORT_SYMBOL (dm_read_arg); + +char *dm_shift_arg (struct dm_arg_set *as) +{ +char *r; + +if (as->argc) { + as->argc--; + r = *as->argv; + as->argv++; +return r; + } + +return NULL ; +} +EXPORT_SYMBOL (dm_shift_arg); + +void dm_consume_args (struct dm_arg_set *as,unsigned n) +{ +BUG_ON (as->argc < n); + as->argc -= n; + as->argv += n; +} +EXPORT_SYMBOL (dm_consume_args); +static int dm_table_set_type (struct dm_table *t) {unsigned i;
include/linux/device-mapper.h +18 -0
@@ -202,6 +202,24 @@ struct dm_target_callbacks {int dm_register_target (struct target_type *t);void dm_unregister_target (struct target_type *t); +/* +* Target argument parsing +*/ +struct dm_arg_set { +unsigned argc; +char **argv; +}; + +struct dm_arg { +unsigned min; +unsigned max; +char *error; +}; + +int dm_read_arg (struct dm_arg *arg,char *str,unsigned *v,char **error); +char *dm_shift_arg (struct dm_arg_set *as); +void dm_consume_args (struct dm_arg_set *as,unsigned n); +/*----------------------------------------------------------------- * Functions for creating and manipulating mapped devices. * Drop the reference with dm_put when you finish with the object.
Signature · 1 line
1.7.1
PATCH 2/9 dm flakey: use dm_target_offset() and support discards
In reply to Mike Snitzer--- drivers/md/dm-flakey.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/md/dm-flakey.c +2 -1
@@ -79,6 +79,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) } ti->num_flush_requests =1 ; + ti->num_discard_requests =1 ; ti->private = fc;return 0 ;
@@ -99,7 +100,7 @@ static sector_t flakey_map_sector(struct dm_target *ti, sector_t bi_sector) {struct flakey_c *fc = ti->private; -return fc->start + (bi_sector - ti->begin); +return fc->start +dm_target_offset (ti, bi_sector); }static void flakey_map_bio (struct dm_target *ti,struct bio *bio)
Signature · 1 line
1.7.1
PATCH 3/9 dm flakey: start of adding features
In reply to Mike SnitzerAdd the ability to specify arbitrary feature flags when creating a flakey target. This code uses the same target argument helpers that the multipath target does.
--- drivers/md/dm-flakey.c | 68 ++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 58 insertions(+), 10 deletions(-)
drivers/md/dm-flakey.c +58 -10
@@ -27,15 +27,55 @@ struct flakey_c {unsigned down_interval; }; +static int parse_features (struct dm_arg_set *as,struct dm_target *ti) +{ +int r; +unsigned argc; +const char *arg_name; + +static struct dm_arg _args[] = { + {0 ,0 ,"invalid number of feature args" }, + }; + + r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error); +if (r) +return -EINVAL ; + +if (!argc) +return 0 ; + +while (argc && !r) { + arg_name =dm_shift_arg (as); + argc--; + + ti->error ="Unrecognised flakey feature request" ; + r = -EINVAL ; + } + +return 0 ; +} +/* -* Construct a flakey mapping: <dev_path> <offset> <up interval> <down interval> +* Construct a flakey mapping: +* <dev_path> <offset> <up interval> <down interval> <#feature args> [<arg>]* */ static int flakey_ctr (struct dm_target *ti,unsigned int argc,char **argv) { +static struct dm_arg _args[] = { + {0 ,UINT_MAX ,"dm-flakey: Invalid up interval" }, + {0 ,UINT_MAX ,"dm-flakey: Invalid down interval" }, + }; + +int r;struct flakey_c *fc;unsigned long long tmp; +struct dm_arg_set as; +const char *devname; -if (argc !=4 ) { + as.argc = argc; + as.argv = argv; + +if (argc <5 ) { ti->error ="dm-flakey: Invalid argument count" ;return -EINVAL ; }
@@ -47,21 +87,25 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) } fc->start_time = jiffies; + devname = argv[0 ]; + as.argc--; + as.argv++; +if (sscanf (argv[1 ],"%llu" , &tmp) !=1 ) { ti->error ="dm-flakey: Invalid device sector" ; goto bad; } fc->start = tmp; + as.argc--; + as.argv++; -if (sscanf (argv[2 ],"%u" , &fc->up_interval) !=1 ) { - ti->error ="dm-flakey: Invalid up interval" ; + r =dm_read_arg (_args,dm_shift_arg (&as), &fc->up_interval, &ti->error); +if (r) goto bad; - } -if (sscanf (argv[3 ],"%u" , &fc->down_interval) !=1 ) { - ti->error ="dm-flakey: Invalid down interval" ; + r =dm_read_arg (_args,dm_shift_arg (&as), &fc->down_interval, &ti->error); +if (r) goto bad; - }if (!(fc->up_interval + fc->down_interval)) { ti->error ="dm-flakey: Total (up + down) interval is zero" ;
@@ -73,7 +117,11 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad; } -if (dm_get_device (ti, argv[0 ],dm_table_get_mode (ti->table), &fc->dev)) { + r =parse_features (&as, ti); +if (r) + goto bad; + +if (dm_get_device (ti, devname,dm_table_get_mode (ti->table), &fc->dev)) { ti->error ="dm-flakey: Device lookup failed" ; goto bad; }
@@ -178,7 +226,7 @@ static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_static struct target_type flakey_target = { .name ="flakey" , - .version = {1 ,1 ,0 }, + .version = {1 ,2 ,0 }, .module =THIS_MODULE , .ctr = flakey_ctr, .dtr = flakey_dtr,
Signature · 1 line
1.7.1
PATCH 4/9 dm flakey: add drop_writes feature
In reply to Mike SnitzerAdd 'drop_writes' feature that will silently drop writes (when the device is "down"). Reads are not touched.
--- drivers/md/dm-flakey.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 39 insertions(+), 8 deletions(-)
drivers/md/dm-flakey.c +39 -8
@@ -14,6 +14,7 @@#include <linux/slab.h> #define DM_MSG_PREFIX "flakey" +#define MESG_STR (x) x, sizeof(x)/* * Flakey: Used for testing only, simulates intermittent,
@@ -25,16 +26,22 @@ struct flakey_c {sector_t start;unsigned up_interval;unsigned down_interval; +unsigned long flags; }; -static int parse_features (struct dm_arg_set *as,struct dm_target *ti) +enum feature_flag_bits { +DROP_WRITES +}; + +static int parse_features (struct dm_arg_set *as,struct flakey_c *fc, +struct dm_target *ti) {int r;unsigned argc;const char *arg_name;static struct dm_arg _args[] = { - {0 ,0 ,"invalid number of feature args" }, + {0 ,1 ,"invalid number of feature args" }, }; r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);
@@ -48,6 +55,11 @@ static int parse_features(struct dm_arg_set *as, struct dm_target *ti) arg_name =dm_shift_arg (as); argc--; +if (!strnicmp (arg_name,MESG_STR ("drop_writes" ))) { +set_bit (DROP_WRITES , &fc->flags); +continue ; + } + ti->error ="Unrecognised flakey feature request" ; r = -EINVAL ; }
@@ -80,7 +92,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)return -EINVAL ; } - fc =kmalloc (sizeof (*fc),GFP_KERNEL ); + fc =kzalloc (sizeof (*fc),GFP_KERNEL );if (!fc) { ti->error ="dm-flakey: Cannot allocate linear context" ;return -ENOMEM ;
@@ -117,7 +129,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) goto bad; } - r =parse_features (&as, ti); + r =parse_features (&as, fc, ti);if (r) goto bad;
@@ -168,9 +180,21 @@ static int flakey_map(struct dm_target *ti, struct bio *bio,/* Are we alive ? */ elapsed = (jiffies - fc->start_time) /HZ ; -if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) +if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) { +unsigned rw =bio_data_dir (bio); +if (test_bit (DROP_WRITES , &fc->flags)) { +/* drop writes but don't error reads */ +if (rw ==WRITE ) { +bio_endio (bio,0 ); +return DM_MAPIO_SUBMITTED ; + }else + goto map_bio; + } +/* default, when down without features, is to error all IO */ return -EIO ; + } +map_bio:flakey_map_bio (ti, bio);return DM_MAPIO_REMAPPED ;
@@ -179,7 +203,9 @@ static int flakey_map(struct dm_target *ti, struct bio *bio,static int flakey_status (struct dm_target *ti,status_type_t type,char *result,unsigned int maxlen) { +unsigned sz =0 ;struct flakey_c *fc = ti->private; +unsigned drop_writes;switch (type) {case STATUSTYPE_INFO :
@@ -187,9 +213,14 @@ static int flakey_status(struct dm_target *ti, status_type_t type,break ;case STATUSTYPE_TABLE : -snprintf (result, maxlen,"%s %llu %u %u" , fc->dev->name, - (unsigned long long )fc->start, fc->up_interval, - fc->down_interval); +DMEMIT ("%s %llu %u %u " , fc->dev->name, + (unsigned long long )fc->start, fc->up_interval, + fc->down_interval); + + drop_writes =test_bit (DROP_WRITES , &fc->flags); +DMEMIT ("%u " , drop_writes); +if (drop_writes) +DMEMIT ("drop_writes " );break ; }return 0 ;
Signature · 1 line
1.7.1
PATCH 5/9 dm flakey: add corrupt_bio_byte feature
In reply to Mike SnitzerAdd 'corrupt_bio_byte' feature that will write 0 to the specified Nth byte of each bio (when the device is "down").
--- drivers/md/dm-flakey.c | 35 +++++++++++++++++++++++++++++++++-- 1 files changed, 33 insertions(+), 2 deletions(-)
drivers/md/dm-flakey.c +33 -2
@@ -27,6 +27,7 @@ struct flakey_c {unsigned up_interval;unsigned down_interval;unsigned long flags; +unsigned corrupt_bio_byte; };enum feature_flag_bits {
@@ -41,7 +42,8 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,const char *arg_name;static struct dm_arg _args[] = { - {0 ,1 ,"invalid number of feature args" }, + {0 ,3 ,"invalid number of feature args" }, + {1 ,UINT_MAX ,"invalid corrupt bio byte value" }, }; r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);
@@ -55,6 +57,15 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, arg_name =dm_shift_arg (as); argc--; +/* corrupt_bio_byte <Nth byte> */ +if (!strnicmp (arg_name,MESG_STR ("corrupt_bio_byte" )) && + (argc >=1 )) { + r =dm_read_arg (_args +1 ,dm_shift_arg (as), + &fc->corrupt_bio_byte, &ti->error); + argc--; +continue ; + } +if (!strnicmp (arg_name,MESG_STR ("drop_writes" ))) {set_bit (DROP_WRITES , &fc->flags);continue ;
@@ -172,6 +183,16 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio) bio->bi_sector =flakey_map_sector (ti, bio->bi_sector); } +static void corrupt_bio_data (struct bio *bio,struct flakey_c *fc) +{ +unsigned bio_bytes =bio_cur_bytes (bio); +char *data =bio_data (bio); + +/* write 0 to the specified Nth byte of the bio */ +if (data && bio_bytes >= fc->corrupt_bio_byte) + data[fc->corrupt_bio_byte-1 ] =0 ; +} +static int flakey_map (struct dm_target *ti,struct bio *bio,union map_info *map_context) {
@@ -182,6 +203,12 @@ static int flakey_map(struct dm_target *ti, struct bio *bio, elapsed = (jiffies - fc->start_time) /HZ ;if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {unsigned rw =bio_data_dir (bio); +if (fc->corrupt_bio_byte) { +/* corrupt writes but don't touch reads */ +if (rw ==WRITE ) +corrupt_bio_data (bio, fc); + goto map_bio; + }if (test_bit (DROP_WRITES , &fc->flags)) {/* drop writes but don't error reads */ if (rw ==WRITE ) {
@@ -218,7 +245,11 @@ static int flakey_status(struct dm_target *ti, status_type_t type, fc->down_interval); drop_writes =test_bit (DROP_WRITES , &fc->flags); -DMEMIT ("%u " , drop_writes); +DMEMIT ("%u " , drop_writes + + (fc->corrupt_bio_byte >0 ) *2 ); + +if (fc->corrupt_bio_byte) +DMEMIT ("corrupt_bio_byte %u " , fc->corrupt_bio_byte);if (drop_writes)DMEMIT ("drop_writes " );break ;
Signature · 1 line
1.7.1
PATCH 6/9 dm flakey: add corrupt_bio_byte read support
In reply to Mike SnitzerUse .end_io hook to corrupt_bio_data() after reads complete.
--- drivers/md/dm-flakey.c | 40 ++++++++++++++++++++++++++++++++++------ 1 files changed, 34 insertions(+), 6 deletions(-)
drivers/md/dm-flakey.c +34 -6
@@ -28,6 +28,7 @@ struct flakey_c {unsigned down_interval;unsigned long flags;unsigned corrupt_bio_byte; +unsigned corrupt_bio_data_dir; };enum feature_flag_bits {
@@ -42,8 +43,9 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,const char *arg_name;static struct dm_arg _args[] = { - {0 ,3 ,"invalid number of feature args" }, + {0 ,4 ,"invalid number of feature args" }, {1 ,UINT_MAX ,"invalid corrupt bio byte value" }, + {0 ,1 ,"invalid corrupt bio data direction" }, }; r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);
@@ -57,12 +59,20 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, arg_name =dm_shift_arg (as); argc--; -/* corrupt_bio_byte <Nth byte> */ +/* corrupt_bio_byte <Nth byte> <READ=0|WRITE=1> */ +/* snitm: could also allow user to only corrupt bios that +* have specific bi_rw flag(s), e.g.: (REQ_WRITE|REQ_META)? +*/ if (!strnicmp (arg_name,MESG_STR ("corrupt_bio_byte" )) && (argc >=1 )) { r =dm_read_arg (_args +1 ,dm_shift_arg (as), &fc->corrupt_bio_byte, &ti->error); argc--; + +/* corrupt reads or writes? */ + r =dm_read_arg (_args +2 ,dm_shift_arg (as), + &fc->corrupt_bio_data_dir, &ti->error); + argc--;continue ; }
@@ -204,9 +214,11 @@ static int flakey_map(struct dm_target *ti, struct bio *bio,if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {unsigned rw =bio_data_dir (bio);if (fc->corrupt_bio_byte) { -/* corrupt writes but don't touch reads */ -if (rw ==WRITE ) +/* only corrupt either reads or writes */ +if (rw ==WRITE && rw == fc->corrupt_bio_data_dir)corrupt_bio_data (bio, fc); +/* flag this bio as submitted while down */ + map_context->ll =1 ; goto map_bio; }if (test_bit (DROP_WRITES , &fc->flags)) {
@@ -227,6 +239,20 @@ map_bio:return DM_MAPIO_REMAPPED ; } +static int flakey_end_io (struct dm_target *ti,struct bio *bio, +int error,union map_info *map_context) +{ +struct flakey_c *fc = ti->private; +unsigned bio_submitted_while_down = map_context->ll; +unsigned rw =bio_data_dir (bio); + +if (!error && bio_submitted_while_down) +if (rw ==READ && rw == fc->corrupt_bio_data_dir) +corrupt_bio_data (bio, fc); + +return error; +} +static int flakey_status (struct dm_target *ti,status_type_t type,char *result,unsigned int maxlen) {
@@ -246,10 +272,11 @@ static int flakey_status(struct dm_target *ti, status_type_t type, drop_writes =test_bit (DROP_WRITES , &fc->flags);DMEMIT ("%u " , drop_writes + - (fc->corrupt_bio_byte >0 ) *2 ); + (fc->corrupt_bio_byte >0 ) *3 );if (fc->corrupt_bio_byte) -DMEMIT ("corrupt_bio_byte %u " , fc->corrupt_bio_byte); +DMEMIT ("corrupt_bio_byte %u %u " , fc->corrupt_bio_byte, + fc->corrupt_bio_data_dir);if (drop_writes)DMEMIT ("drop_writes " );break ;
@@ -293,6 +320,7 @@ static struct target_type flakey_target = { .ctr = flakey_ctr, .dtr = flakey_dtr, .map = flakey_map, + .end_io = flakey_end_io, .status = flakey_status, .ioctl = flakey_ioctl, .merge = flakey_merge,
Signature · 1 line
1.7.1
PATCH 7/9 dm flakey: switch corrupt_bio_data_dir to corrupt_bio_flags
In reply to Mike SnitzerUser may specify a series of bio->bi_rw flags that must be seen in order to trigger corruption (e.g. 33 = REQ_WRITE|REQ_META).
--- drivers/md/dm-flakey.c | 35 ++++++++++++++++++++++------------- 1 files changed, 22 insertions(+), 13 deletions(-)
drivers/md/dm-flakey.c +22 -13
@@ -28,7 +28,7 @@ struct flakey_c {unsigned down_interval;unsigned long flags;unsigned corrupt_bio_byte; -unsigned corrupt_bio_data_dir; +unsigned corrupt_bio_flags; };enum feature_flag_bits {
@@ -45,7 +45,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,static struct dm_arg _args[] = { {0 ,4 ,"invalid number of feature args" }, {1 ,UINT_MAX ,"invalid corrupt bio byte value" }, - {0 ,1 ,"invalid corrupt bio data direction" }, + {0 ,UINT_MAX ,"invalid corrupt bio flags mask" }, }; r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);
@@ -59,19 +59,19 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, arg_name =dm_shift_arg (as); argc--; -/* corrupt_bio_byte <Nth byte> <READ=0|WRITE=1> */ -/* snitm: could also allow user to only corrupt bios that -* have specific bi_rw flag(s), e.g.: (REQ_WRITE|REQ_META)? -*/ +/* corrupt_bio_byte <Nth byte> <bio_flags> */ if (!strnicmp (arg_name,MESG_STR ("corrupt_bio_byte" )) && (argc >=1 )) { r =dm_read_arg (_args +1 ,dm_shift_arg (as), &fc->corrupt_bio_byte, &ti->error); argc--; -/* corrupt reads or writes? */ +/* +* Only corrupt bios that have specific bi_rw flag(s), +* e.g.: READ=0 or REQ_WRITE=1|REQ_META=32 +*/ r =dm_read_arg (_args +2 ,dm_shift_arg (as), - &fc->corrupt_bio_data_dir, &ti->error); + &fc->corrupt_bio_flags, &ti->error); argc--;continue ; }
@@ -193,14 +193,20 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio) bio->bi_sector =flakey_map_sector (ti, bio->bi_sector); } +#define corrupt_bio_data_dir (fc) ((fc)->corrupt_bio_flags & 1) +#define all_corrupt_bio_flags_match (fc, bio) \ + (((bio)->bi_rw & (fc)->corrupt_bio_flags) == (fc)->corrupt_bio_flags) +static void corrupt_bio_data (struct bio *bio,struct flakey_c *fc) {unsigned bio_bytes =bio_cur_bytes (bio);char *data =bio_data (bio);/* write 0 to the specified Nth byte of the bio */ -if (data && bio_bytes >= fc->corrupt_bio_byte) +if (data && bio_bytes >= fc->corrupt_bio_byte) { data[fc->corrupt_bio_byte-1 ] =0 ; +printk ("corrupting data rw=%lu\n" ,bio_data_dir (bio)); + } } static int flakey_map(struct dm_target *ti, struct bio *bio,
@@ -214,9 +220,11 @@ static int flakey_map(struct dm_target *ti, struct bio *bio,if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {unsigned rw =bio_data_dir (bio);if (fc->corrupt_bio_byte) { -/* only corrupt either reads or writes */ -if (rw ==WRITE && rw == fc->corrupt_bio_data_dir) +/* corrupt matching writes, defer reads until end_io */ +if (rw ==WRITE && rw ==corrupt_bio_data_dir (fc) && +all_corrupt_bio_flags_match (fc, bio))corrupt_bio_data (bio, fc); +/* flag this bio as submitted while down */ map_context->ll =1 ; goto map_bio;
@@ -247,7 +255,8 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio,unsigned rw =bio_data_dir (bio);if (!error && bio_submitted_while_down) -if (rw ==READ && rw == fc->corrupt_bio_data_dir) +if (rw ==READ && rw ==corrupt_bio_data_dir (fc) && +all_corrupt_bio_flags_match (fc, bio))corrupt_bio_data (bio, fc);return error;
@@ -276,7 +285,7 @@ static int flakey_status(struct dm_target *ti, status_type_t type,if (fc->corrupt_bio_byte)DMEMIT ("corrupt_bio_byte %u %u " , fc->corrupt_bio_byte, - fc->corrupt_bio_data_dir); + fc->corrupt_bio_flags);if (drop_writes)DMEMIT ("drop_writes " );break ;
Signature · 1 line
1.7.1
PATCH 8/9 dm flakey: add ability to specify the corrupting value to be written
In reply to Mike SnitzerAdd additional corrupting value argument to corrupt_bio_byte feature. A value of either 0 or 1 will be written to the specified byte in the bio. Allowing other arbitrary corrupting values didn't seem necessary.
--- drivers/md/dm-flakey.c | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-)
drivers/md/dm-flakey.c +19 -8
@@ -29,6 +29,7 @@ struct flakey_c {unsigned long flags;unsigned corrupt_bio_byte;unsigned corrupt_bio_flags; +unsigned corrupt_bio_value; };enum feature_flag_bits {
@@ -43,9 +44,10 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,const char *arg_name;static struct dm_arg _args[] = { - {0 ,4 ,"invalid number of feature args" }, + {0 ,5 ,"invalid number of feature args" }, {1 ,UINT_MAX ,"invalid corrupt bio byte value" }, {0 ,UINT_MAX ,"invalid corrupt bio flags mask" }, + {0 ,1 ,"invalid value to corrupt bio" }, }; r =dm_read_arg (_args,dm_shift_arg (as), &argc, &ti->error);
@@ -59,7 +61,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, arg_name =dm_shift_arg (as); argc--; -/* corrupt_bio_byte <Nth byte> <bio_flags> */ +/* corrupt_bio_byte <Nth byte> <bio_flags> <value> */ if (!strnicmp (arg_name,MESG_STR ("corrupt_bio_byte" )) && (argc >=1 )) { r = dm_read_arg(_args + 1, dm_shift_arg(as),
@@ -73,6 +75,11 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, r =dm_read_arg (_args +2 ,dm_shift_arg (as), &fc->corrupt_bio_flags, &ti->error); argc--; + +/* allow user to write a 0 or 1 to the specified byte */ + r =dm_read_arg (_args +3 ,dm_shift_arg (as), + &fc->corrupt_bio_value, &ti->error); + argc--;continue ; }
@@ -202,10 +209,14 @@ static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)unsigned bio_bytes =bio_cur_bytes (bio);char *data =bio_data (bio); -/* write 0 to the specified Nth byte of the bio */ +/* write to the specified Nth byte of the bio */ if (data && bio_bytes >= fc->corrupt_bio_byte) { - data[fc->corrupt_bio_byte-1 ] =0 ; -printk ("corrupting data rw=%lu\n" ,bio_data_dir (bio)); + data[fc->corrupt_bio_byte-1 ] = fc->corrupt_bio_value; + +printk ("corrupting data bio=%p by writing %u to byte %u " +"(rw=%lu flags=%lu bi_sector=%lu cur_bytes=%u)\n" , + bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, +bio_data_dir (bio), bio->bi_rw, bio->bi_sector, bio_bytes); } }
@@ -281,11 +292,11 @@ static int flakey_status(struct dm_target *ti, status_type_t type, drop_writes =test_bit (DROP_WRITES , &fc->flags);DMEMIT ("%u " , drop_writes + - (fc->corrupt_bio_byte >0 ) *3 ); + (fc->corrupt_bio_byte >0 ) *4 );if (fc->corrupt_bio_byte) -DMEMIT ("corrupt_bio_byte %u %u " , fc->corrupt_bio_byte, - fc->corrupt_bio_flags); +DMEMIT ("corrupt_bio_byte %u %u %u " , fc->corrupt_bio_byte, + fc->corrupt_bio_flags, fc->corrupt_bio_value);if (drop_writes)DMEMIT ("drop_writes " );break ;
Signature · 1 line
1.7.1
PATCH 9/9 dm flakey: add debug feature to control debug output
In reply to Mike Snitzer--- drivers/md/dm-flakey.c | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-)
drivers/md/dm-flakey.c +20 -8
@@ -33,7 +33,8 @@ struct flakey_c { };enum feature_flag_bits { -DROP_WRITES +DROP_WRITES , +FLAKEY_DEBUG }; static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
@@ -44,7 +45,7 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,const char *arg_name;static struct dm_arg _args[] = { - {0 ,5 ,"invalid number of feature args" }, + {0 ,6 ,"invalid number of feature args" }, {1 ,UINT_MAX ,"invalid corrupt bio byte value" }, {0 ,UINT_MAX ,"invalid corrupt bio flags mask" }, {0 ,1 ,"invalid value to corrupt bio" },
@@ -88,6 +89,11 @@ static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,continue ; } +if (!strnicmp (arg_name,MESG_STR ("debug" ))) { +set_bit (FLAKEY_DEBUG , &fc->flags); +continue ; + } + ti->error ="Unrecognised flakey feature request" ; r = -EINVAL ; }
@@ -213,10 +219,12 @@ static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)if (data && bio_bytes >= fc->corrupt_bio_byte) { data[fc->corrupt_bio_byte-1 ] = fc->corrupt_bio_value; -printk ("corrupting data bio=%p by writing %u to byte %u " -"(rw=%lu flags=%lu bi_sector=%lu cur_bytes=%u)\n" , - bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, -bio_data_dir (bio), bio->bi_rw, bio->bi_sector, bio_bytes); +if (test_bit (FLAKEY_DEBUG , &fc->flags)) +printk ("corrupting data bio=%p by writing %u to byte %u " +"(rw=%lu flags=%lu bi_sector=%lu cur_bytes=%u)\n" , + bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, +bio_data_dir (bio), bio->bi_rw, bio->bi_sector, + bio_bytes); } }
@@ -278,7 +286,7 @@ static int flakey_status(struct dm_target *ti, status_type_t type, {unsigned sz =0 ;struct flakey_c *fc = ti->private; -unsigned drop_writes; +unsigned drop_writes, flakey_debug;switch (type) {case STATUSTYPE_INFO :
@@ -291,14 +299,18 @@ static int flakey_status(struct dm_target *ti, status_type_t type, fc->down_interval); drop_writes =test_bit (DROP_WRITES , &fc->flags); + flakey_debug =test_bit (FLAKEY_DEBUG , &fc->flags);DMEMIT ("%u " , drop_writes + - (fc->corrupt_bio_byte >0 ) *4 ); + (fc->corrupt_bio_byte >0 ) *4 + + flakey_debug);if (fc->corrupt_bio_byte)DMEMIT ("corrupt_bio_byte %u %u %u " , fc->corrupt_bio_byte, fc->corrupt_bio_flags, fc->corrupt_bio_value);if (drop_writes)DMEMIT ("drop_writes " ); +if (flakey_debug) +DMEMIT ("debug " );break ; }return 0 ;
Signature · 1 line
1.7.1