Lines Matching refs:fc

21 #define all_corrupt_bio_flags_match(bio, fc)	\  argument
22 (((bio)->bi_opf & (fc)->corrupt_bio_flags) == (fc)->corrupt_bio_flags)
54 static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, in parse_features() argument
89 if (test_and_set_bit(ERROR_READS, &fc->flags)) { in parse_features()
100 if (test_and_set_bit(DROP_WRITES, &fc->flags)) { in parse_features()
103 } else if (test_bit(ERROR_WRITES, &fc->flags)) { in parse_features()
115 if (test_and_set_bit(ERROR_WRITES, &fc->flags)) { in parse_features()
119 } else if (test_bit(DROP_WRITES, &fc->flags)) { in parse_features()
131 if (fc->corrupt_bio_byte) { in parse_features()
139 r = dm_read_arg(_args + 1, as, &fc->corrupt_bio_byte, &ti->error); in parse_features()
149 fc->corrupt_bio_rw = WRITE; in parse_features()
151 fc->corrupt_bio_rw = READ; in parse_features()
161 r = dm_read_arg(_args + 2, as, &fc->corrupt_bio_value, &ti->error); in parse_features()
169 BUILD_BUG_ON(sizeof(fc->corrupt_bio_flags) != in parse_features()
172 (__force unsigned int *)&fc->corrupt_bio_flags, in parse_features()
182 if (fc->random_read_corrupt) { in parse_features()
189 r = dm_read_arg(_args + 4, as, &fc->random_read_corrupt, &ti->error); in parse_features()
198 if (fc->random_write_corrupt) { in parse_features()
205 r = dm_read_arg(_args + 4, as, &fc->random_write_corrupt, &ti->error); in parse_features()
217 if (test_bit(DROP_WRITES, &fc->flags) && in parse_features()
218 ((fc->corrupt_bio_byte && fc->corrupt_bio_rw == WRITE) || in parse_features()
219 fc->random_write_corrupt)) { in parse_features()
223 } else if (test_bit(ERROR_WRITES, &fc->flags) && in parse_features()
224 ((fc->corrupt_bio_byte && fc->corrupt_bio_rw == WRITE) || in parse_features()
225 fc->random_write_corrupt)) { in parse_features()
228 } else if (test_bit(ERROR_READS, &fc->flags) && in parse_features()
229 ((fc->corrupt_bio_byte && fc->corrupt_bio_rw == READ) || in parse_features()
230 fc->random_read_corrupt)) { in parse_features()
235 if (!fc->corrupt_bio_byte && !test_bit(ERROR_READS, &fc->flags) && in parse_features()
236 !test_bit(DROP_WRITES, &fc->flags) && !test_bit(ERROR_WRITES, &fc->flags) && in parse_features()
237 !fc->random_read_corrupt && !fc->random_write_corrupt) { in parse_features()
239 set_bit(ERROR_WRITES, &fc->flags); in parse_features()
240 set_bit(ERROR_READS, &fc->flags); in parse_features()
266 struct flakey_c *fc; in flakey_ctr() local
280 fc = kzalloc(sizeof(*fc), GFP_KERNEL); in flakey_ctr()
281 if (!fc) { in flakey_ctr()
285 fc->start_time = jiffies; in flakey_ctr()
294 fc->start = tmpll; in flakey_ctr()
296 r = dm_read_arg(_args, &as, &fc->up_interval, &ti->error); in flakey_ctr()
300 r = dm_read_arg(_args + 1, &as, &fc->down_interval, &ti->error); in flakey_ctr()
304 if (!(fc->up_interval + fc->down_interval)) { in flakey_ctr()
310 if (fc->up_interval + fc->down_interval < fc->up_interval) { in flakey_ctr()
316 r = parse_features(&as, fc, ti); in flakey_ctr()
320 r = dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev); in flakey_ctr()
329 ti->private = fc; in flakey_ctr()
333 kfree(fc); in flakey_ctr()
339 struct flakey_c *fc = ti->private; in flakey_dtr() local
341 dm_put_device(ti, fc->dev); in flakey_dtr()
342 kfree(fc); in flakey_dtr()
347 struct flakey_c *fc = ti->private; in flakey_map_sector() local
349 return fc->start + dm_target_offset(ti, bi_sector); in flakey_map_sector()
354 struct flakey_c *fc = ti->private; in flakey_map_bio() local
356 bio_set_dev(bio, fc->dev->bdev); in flakey_map_bio()
388 static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc, in corrupt_bio_data() argument
391 unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1; in corrupt_bio_data()
393 corrupt_bio_common(bio, corrupt_bio_byte, fc->corrupt_bio_value, start); in corrupt_bio_data()
428 static struct bio *clone_bio(struct dm_target *ti, struct flakey_c *fc, struct bio *bio) in clone_bio() argument
444 bio_init(clone, fc->dev->bdev, clone->bi_inline_vecs, nr_iovecs, bio->bi_opf); in clone_bio()
495 struct flakey_c *fc = ti->private; in flakey_map() local
505 elapsed = (jiffies - fc->start_time) / HZ; in flakey_map()
506 if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) { in flakey_map()
519 if (test_bit(ERROR_READS, &fc->flags)) in flakey_map()
527 if (test_bit(DROP_WRITES, &fc->flags)) { in flakey_map()
530 } else if (test_bit(ERROR_WRITES, &fc->flags)) { in flakey_map()
542 if (fc->corrupt_bio_byte && fc->corrupt_bio_rw == WRITE) { in flakey_map()
543 if (all_corrupt_bio_flags_match(bio, fc)) in flakey_map()
546 if (fc->random_write_corrupt) { in flakey_map()
549 if (rem < fc->random_write_corrupt) in flakey_map()
553 struct bio *clone = clone_bio(ti, fc, bio); in flakey_map()
556 corrupt_bio_data(clone, fc, in flakey_map()
576 struct flakey_c *fc = ti->private; in flakey_end_io() local
583 if (fc->corrupt_bio_byte) { in flakey_end_io()
584 if ((fc->corrupt_bio_rw == READ) && in flakey_end_io()
585 all_corrupt_bio_flags_match(bio, fc)) { in flakey_end_io()
589 corrupt_bio_data(bio, fc, pb->saved_iter); in flakey_end_io()
592 if (fc->random_read_corrupt) { in flakey_end_io()
595 if (rem < fc->random_read_corrupt) in flakey_end_io()
607 struct flakey_c *fc = ti->private; in flakey_status() local
616 DMEMIT("%s %llu %u %u", fc->dev->name, in flakey_status()
617 (unsigned long long)fc->start, fc->up_interval, in flakey_status()
618 fc->down_interval); in flakey_status()
620 error_reads = test_bit(ERROR_READS, &fc->flags); in flakey_status()
621 drop_writes = test_bit(DROP_WRITES, &fc->flags); in flakey_status()
622 error_writes = test_bit(ERROR_WRITES, &fc->flags); in flakey_status()
624 (fc->corrupt_bio_byte > 0) * 5 + in flakey_status()
625 (fc->random_read_corrupt > 0) * 2 + in flakey_status()
626 (fc->random_write_corrupt > 0) * 2); in flakey_status()
635 if (fc->corrupt_bio_byte) in flakey_status()
637 fc->corrupt_bio_byte, in flakey_status()
638 (fc->corrupt_bio_rw == WRITE) ? 'w' : 'r', in flakey_status()
639 fc->corrupt_bio_value, fc->corrupt_bio_flags); in flakey_status()
641 if (fc->random_read_corrupt > 0) in flakey_status()
642 DMEMIT(" random_read_corrupt %u", fc->random_read_corrupt); in flakey_status()
643 if (fc->random_write_corrupt > 0) in flakey_status()
644 DMEMIT(" random_write_corrupt %u", fc->random_write_corrupt); in flakey_status()
658 struct flakey_c *fc = ti->private; in flakey_prepare_ioctl() local
660 *bdev = fc->dev->bdev; in flakey_prepare_ioctl()
665 if (fc->start || ti->len != bdev_nr_sectors((*bdev))) in flakey_prepare_ioctl()
674 struct flakey_c *fc = ti->private; in flakey_report_zones() local
676 return dm_report_zones(fc->dev->bdev, fc->start, in flakey_report_zones()
686 struct flakey_c *fc = ti->private; in flakey_iterate_devices() local
688 return fn(ti, fc->dev, fc->start, ti->len, data); in flakey_iterate_devices()