dm-flakey.c (ef87bfc24f9b8da82c89aff493df20f078bc9cb1) dm-flakey.c (a00f5276e26636cbf72f24f79831026d2e2868e7)
1/*
2 * Copyright (C) 2003 Sistina Software (UK) Limited.
3 * Copyright (C) 2004, 2010-2011 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include <linux/device-mapper.h>

--- 273 unchanged lines hidden (view full) ---

282 bio_set_dev(bio, fc->dev->bdev);
283 if (bio_sectors(bio) || bio_op(bio) == REQ_OP_ZONE_RESET)
284 bio->bi_iter.bi_sector =
285 flakey_map_sector(ti, bio->bi_iter.bi_sector);
286}
287
288static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)
289{
1/*
2 * Copyright (C) 2003 Sistina Software (UK) Limited.
3 * Copyright (C) 2004, 2010-2011 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include <linux/device-mapper.h>

--- 273 unchanged lines hidden (view full) ---

282 bio_set_dev(bio, fc->dev->bdev);
283 if (bio_sectors(bio) || bio_op(bio) == REQ_OP_ZONE_RESET)
284 bio->bi_iter.bi_sector =
285 flakey_map_sector(ti, bio->bi_iter.bi_sector);
286}
287
288static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)
289{
290 unsigned bio_bytes = bio_cur_bytes(bio);
291 char *data = bio_data(bio);
290 unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1;
292
291
292 struct bvec_iter iter;
293 struct bio_vec bvec;
294
295 if (!bio_has_data(bio))
296 return;
297
293 /*
298 /*
294 * Overwrite the Nth byte of the data returned.
299 * Overwrite the Nth byte of the bio's data, on whichever page
300 * it falls.
295 */
301 */
296 if (data && bio_bytes >= fc->corrupt_bio_byte) {
297 data[fc->corrupt_bio_byte - 1] = fc->corrupt_bio_value;
298
299 DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
300 "(rw=%c bi_opf=%u bi_sector=%llu cur_bytes=%u)\n",
301 bio, fc->corrupt_bio_value, fc->corrupt_bio_byte,
302 (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
303 (unsigned long long)bio->bi_iter.bi_sector, bio_bytes);
302 bio_for_each_segment(bvec, bio, iter) {
303 if (bio_iter_len(bio, iter) > corrupt_bio_byte) {
304 char *segment = (page_address(bio_iter_page(bio, iter))
305 + bio_iter_offset(bio, iter));
306 segment[corrupt_bio_byte] = fc->corrupt_bio_value;
307 DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
308 "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n",
309 bio, fc->corrupt_bio_value, fc->corrupt_bio_byte,
310 (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
311 (unsigned long long)bio->bi_iter.bi_sector, bio->bi_iter.bi_size);
312 break;
313 }
314 corrupt_bio_byte -= bio_iter_len(bio, iter);
304 }
305}
306
307static int flakey_map(struct dm_target *ti, struct bio *bio)
308{
309 struct flakey_c *fc = ti->private;
310 unsigned elapsed;
311 struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));

--- 205 unchanged lines hidden ---
315 }
316}
317
318static int flakey_map(struct dm_target *ti, struct bio *bio)
319{
320 struct flakey_c *fc = ti->private;
321 unsigned elapsed;
322 struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));

--- 205 unchanged lines hidden ---