diff options
-rw-r--r-- | fs/bcachefs/util.c | 9 | ||||
-rw-r--r-- | fs/bcachefs/util.h | 8 |
2 files changed, 15 insertions, 2 deletions
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index 7a4436fd4441..95f46dc3e3be 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -690,11 +690,10 @@ void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter) } #ifdef CONFIG_BCACHEFS_DEBUG -void bch2_corrupt_bio(struct bio *bio) +void bch2_corrupt_bio_offset(struct bio *bio, u32 offset) { struct bvec_iter iter; struct bio_vec bv; - unsigned offset = get_random_u32_below(bio->bi_iter.bi_size / sizeof(u64)); bio_for_each_segment(bv, bio, iter) { unsigned u64s = bv.bv_len / sizeof(u64); @@ -708,6 +707,12 @@ void bch2_corrupt_bio(struct bio *bio) offset -= u64s; } } + +void bch2_corrupt_bio(struct bio *bio) +{ + bch2_corrupt_bio_offset(bio, + get_random_u32_below(bio->bi_iter.bi_size / sizeof(u64))); +} #endif void bch2_bio_to_text(struct printbuf *out, struct bio *bio) diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 6488f098d140..36fe58c71c9f 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -410,6 +410,14 @@ void memcpy_to_bio(struct bio *, struct bvec_iter, const void *); void memcpy_from_bio(void *, struct bio *, struct bvec_iter); #ifdef CONFIG_BCACHEFS_DEBUG +void bch2_corrupt_bio_offset(struct bio *, u32); +static inline void bch2_maybe_corrupt_bio_offset(struct bio *bio, unsigned ratio, + unsigned offset) +{ + if (ratio && !get_random_u32_below(ratio)) + bch2_corrupt_bio_offset(bio, offset); +} + void bch2_corrupt_bio(struct bio *); static inline void bch2_maybe_corrupt_bio(struct bio *bio, unsigned ratio) |