13407ef52SJosef Bacik /* 23407ef52SJosef Bacik * Copyright (C) 2003 Sistina Software (UK) Limited. 3a3998799SMike Snitzer * Copyright (C) 2004, 2010-2011 Red Hat, Inc. All rights reserved. 43407ef52SJosef Bacik * 53407ef52SJosef Bacik * This file is released under the GPL. 63407ef52SJosef Bacik */ 73407ef52SJosef Bacik 83407ef52SJosef Bacik #include <linux/device-mapper.h> 93407ef52SJosef Bacik 103407ef52SJosef Bacik #include <linux/module.h> 113407ef52SJosef Bacik #include <linux/init.h> 123407ef52SJosef Bacik #include <linux/blkdev.h> 133407ef52SJosef Bacik #include <linux/bio.h> 143407ef52SJosef Bacik #include <linux/slab.h> 153407ef52SJosef Bacik 163407ef52SJosef Bacik #define DM_MSG_PREFIX "flakey" 173407ef52SJosef Bacik 18a3998799SMike Snitzer #define all_corrupt_bio_flags_match(bio, fc) \ 19a3998799SMike Snitzer (((bio)->bi_rw & (fc)->corrupt_bio_flags) == (fc)->corrupt_bio_flags) 20a3998799SMike Snitzer 213407ef52SJosef Bacik /* 223407ef52SJosef Bacik * Flakey: Used for testing only, simulates intermittent, 233407ef52SJosef Bacik * catastrophic device failure. 243407ef52SJosef Bacik */ 253407ef52SJosef Bacik struct flakey_c { 263407ef52SJosef Bacik struct dm_dev *dev; 273407ef52SJosef Bacik unsigned long start_time; 283407ef52SJosef Bacik sector_t start; 293407ef52SJosef Bacik unsigned up_interval; 303407ef52SJosef Bacik unsigned down_interval; 31b26f5e3dSMike Snitzer unsigned long flags; 32a3998799SMike Snitzer unsigned corrupt_bio_byte; 33a3998799SMike Snitzer unsigned corrupt_bio_rw; 34a3998799SMike Snitzer unsigned corrupt_bio_value; 35a3998799SMike Snitzer unsigned corrupt_bio_flags; 363407ef52SJosef Bacik }; 373407ef52SJosef Bacik 38b26f5e3dSMike Snitzer enum feature_flag_bits { 39b26f5e3dSMike Snitzer DROP_WRITES 40b26f5e3dSMike Snitzer }; 41b26f5e3dSMike Snitzer 42b26f5e3dSMike Snitzer static int parse_features(struct dm_arg_set *as, struct flakey_c *fc, 43b26f5e3dSMike Snitzer struct dm_target *ti) 44dfd068b0SMike Snitzer { 45dfd068b0SMike Snitzer int r; 46dfd068b0SMike Snitzer unsigned argc; 47dfd068b0SMike Snitzer const char *arg_name; 48dfd068b0SMike Snitzer 49dfd068b0SMike Snitzer static struct dm_arg _args[] = { 50a3998799SMike Snitzer {0, 6, "Invalid number of feature args"}, 51a3998799SMike Snitzer {1, UINT_MAX, "Invalid corrupt bio byte"}, 52a3998799SMike Snitzer {0, 255, "Invalid corrupt value to write into bio byte (0-255)"}, 53a3998799SMike Snitzer {0, UINT_MAX, "Invalid corrupt bio flags mask"}, 54dfd068b0SMike Snitzer }; 55dfd068b0SMike Snitzer 56dfd068b0SMike Snitzer /* No feature arguments supplied. */ 57dfd068b0SMike Snitzer if (!as->argc) 58dfd068b0SMike Snitzer return 0; 59dfd068b0SMike Snitzer 60dfd068b0SMike Snitzer r = dm_read_arg_group(_args, as, &argc, &ti->error); 61dfd068b0SMike Snitzer if (r) 62a3998799SMike Snitzer return r; 63dfd068b0SMike Snitzer 64a3998799SMike Snitzer while (argc) { 65dfd068b0SMike Snitzer arg_name = dm_shift_arg(as); 66dfd068b0SMike Snitzer argc--; 67dfd068b0SMike Snitzer 68b26f5e3dSMike Snitzer /* 69b26f5e3dSMike Snitzer * drop_writes 70b26f5e3dSMike Snitzer */ 71b26f5e3dSMike Snitzer if (!strcasecmp(arg_name, "drop_writes")) { 72b26f5e3dSMike Snitzer if (test_and_set_bit(DROP_WRITES, &fc->flags)) { 73b26f5e3dSMike Snitzer ti->error = "Feature drop_writes duplicated"; 74b26f5e3dSMike Snitzer return -EINVAL; 75b26f5e3dSMike Snitzer } 76b26f5e3dSMike Snitzer 77b26f5e3dSMike Snitzer continue; 78b26f5e3dSMike Snitzer } 79b26f5e3dSMike Snitzer 80a3998799SMike Snitzer /* 81a3998799SMike Snitzer * corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags> 82a3998799SMike Snitzer */ 83a3998799SMike Snitzer if (!strcasecmp(arg_name, "corrupt_bio_byte")) { 8468e58a29SMike Snitzer if (!argc) { 85a3998799SMike Snitzer ti->error = "Feature corrupt_bio_byte requires parameters"; 8668e58a29SMike Snitzer return -EINVAL; 8768e58a29SMike Snitzer } 88a3998799SMike Snitzer 89a3998799SMike Snitzer r = dm_read_arg(_args + 1, as, &fc->corrupt_bio_byte, &ti->error); 90a3998799SMike Snitzer if (r) 91a3998799SMike Snitzer return r; 92a3998799SMike Snitzer argc--; 93a3998799SMike Snitzer 94a3998799SMike Snitzer /* 95a3998799SMike Snitzer * Direction r or w? 96a3998799SMike Snitzer */ 97a3998799SMike Snitzer arg_name = dm_shift_arg(as); 98a3998799SMike Snitzer if (!strcasecmp(arg_name, "w")) 99a3998799SMike Snitzer fc->corrupt_bio_rw = WRITE; 100a3998799SMike Snitzer else if (!strcasecmp(arg_name, "r")) 101a3998799SMike Snitzer fc->corrupt_bio_rw = READ; 102a3998799SMike Snitzer else { 103a3998799SMike Snitzer ti->error = "Invalid corrupt bio direction (r or w)"; 104a3998799SMike Snitzer return -EINVAL; 105a3998799SMike Snitzer } 106a3998799SMike Snitzer argc--; 107a3998799SMike Snitzer 108a3998799SMike Snitzer /* 109a3998799SMike Snitzer * Value of byte (0-255) to write in place of correct one. 110a3998799SMike Snitzer */ 111a3998799SMike Snitzer r = dm_read_arg(_args + 2, as, &fc->corrupt_bio_value, &ti->error); 112a3998799SMike Snitzer if (r) 113a3998799SMike Snitzer return r; 114a3998799SMike Snitzer argc--; 115a3998799SMike Snitzer 116a3998799SMike Snitzer /* 117a3998799SMike Snitzer * Only corrupt bios with these flags set. 118a3998799SMike Snitzer */ 119a3998799SMike Snitzer r = dm_read_arg(_args + 3, as, &fc->corrupt_bio_flags, &ti->error); 120a3998799SMike Snitzer if (r) 121a3998799SMike Snitzer return r; 122a3998799SMike Snitzer argc--; 123a3998799SMike Snitzer 124a3998799SMike Snitzer continue; 125dfd068b0SMike Snitzer } 126dfd068b0SMike Snitzer 127a3998799SMike Snitzer ti->error = "Unrecognised flakey feature requested"; 128a3998799SMike Snitzer return -EINVAL; 129a3998799SMike Snitzer } 130a3998799SMike Snitzer 131a3998799SMike Snitzer if (test_bit(DROP_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) { 132a3998799SMike Snitzer ti->error = "drop_writes is incompatible with corrupt_bio_byte with the WRITE flag set"; 133a3998799SMike Snitzer return -EINVAL; 134a3998799SMike Snitzer } 135a3998799SMike Snitzer 136a3998799SMike Snitzer return 0; 137dfd068b0SMike Snitzer } 138dfd068b0SMike Snitzer 1393407ef52SJosef Bacik /* 140dfd068b0SMike Snitzer * Construct a flakey mapping: 141dfd068b0SMike Snitzer * <dev_path> <offset> <up interval> <down interval> [<#feature args> [<arg>]*] 142b26f5e3dSMike Snitzer * 143b26f5e3dSMike Snitzer * Feature args: 144b26f5e3dSMike Snitzer * [drop_writes] 145a3998799SMike Snitzer * [corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>] 146a3998799SMike Snitzer * 147a3998799SMike Snitzer * Nth_byte starts from 1 for the first byte. 148a3998799SMike Snitzer * Direction is r for READ or w for WRITE. 149a3998799SMike Snitzer * bio_flags is ignored if 0. 1503407ef52SJosef Bacik */ 1513407ef52SJosef Bacik static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv) 1523407ef52SJosef Bacik { 153dfd068b0SMike Snitzer static struct dm_arg _args[] = { 154dfd068b0SMike Snitzer {0, UINT_MAX, "Invalid up interval"}, 155dfd068b0SMike Snitzer {0, UINT_MAX, "Invalid down interval"}, 156dfd068b0SMike Snitzer }; 1573407ef52SJosef Bacik 158dfd068b0SMike Snitzer int r; 159dfd068b0SMike Snitzer struct flakey_c *fc; 160dfd068b0SMike Snitzer unsigned long long tmpll; 161dfd068b0SMike Snitzer struct dm_arg_set as; 162dfd068b0SMike Snitzer const char *devname; 163*31998ef1SMikulas Patocka char dummy; 164dfd068b0SMike Snitzer 165dfd068b0SMike Snitzer as.argc = argc; 166dfd068b0SMike Snitzer as.argv = argv; 167dfd068b0SMike Snitzer 168dfd068b0SMike Snitzer if (argc < 4) { 169dfd068b0SMike Snitzer ti->error = "Invalid argument count"; 1703407ef52SJosef Bacik return -EINVAL; 1713407ef52SJosef Bacik } 1723407ef52SJosef Bacik 173b26f5e3dSMike Snitzer fc = kzalloc(sizeof(*fc), GFP_KERNEL); 1743407ef52SJosef Bacik if (!fc) { 175dfd068b0SMike Snitzer ti->error = "Cannot allocate linear context"; 1763407ef52SJosef Bacik return -ENOMEM; 1773407ef52SJosef Bacik } 1783407ef52SJosef Bacik fc->start_time = jiffies; 1793407ef52SJosef Bacik 180dfd068b0SMike Snitzer devname = dm_shift_arg(&as); 1813407ef52SJosef Bacik 182*31998ef1SMikulas Patocka if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) { 183dfd068b0SMike Snitzer ti->error = "Invalid device sector"; 1843407ef52SJosef Bacik goto bad; 1853407ef52SJosef Bacik } 186dfd068b0SMike Snitzer fc->start = tmpll; 1873407ef52SJosef Bacik 188dfd068b0SMike Snitzer r = dm_read_arg(_args, &as, &fc->up_interval, &ti->error); 189dfd068b0SMike Snitzer if (r) 1903407ef52SJosef Bacik goto bad; 191dfd068b0SMike Snitzer 192dfd068b0SMike Snitzer r = dm_read_arg(_args, &as, &fc->down_interval, &ti->error); 193dfd068b0SMike Snitzer if (r) 194dfd068b0SMike Snitzer goto bad; 1953407ef52SJosef Bacik 1963407ef52SJosef Bacik if (!(fc->up_interval + fc->down_interval)) { 197dfd068b0SMike Snitzer ti->error = "Total (up + down) interval is zero"; 1983407ef52SJosef Bacik goto bad; 1993407ef52SJosef Bacik } 2003407ef52SJosef Bacik 2013407ef52SJosef Bacik if (fc->up_interval + fc->down_interval < fc->up_interval) { 202dfd068b0SMike Snitzer ti->error = "Interval overflow"; 2033407ef52SJosef Bacik goto bad; 2043407ef52SJosef Bacik } 2053407ef52SJosef Bacik 206b26f5e3dSMike Snitzer r = parse_features(&as, fc, ti); 207dfd068b0SMike Snitzer if (r) 208dfd068b0SMike Snitzer goto bad; 209dfd068b0SMike Snitzer 210dfd068b0SMike Snitzer if (dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev)) { 211dfd068b0SMike Snitzer ti->error = "Device lookup failed"; 2123407ef52SJosef Bacik goto bad; 2133407ef52SJosef Bacik } 2143407ef52SJosef Bacik 2153407ef52SJosef Bacik ti->num_flush_requests = 1; 21630e4171bSMike Snitzer ti->num_discard_requests = 1; 2173407ef52SJosef Bacik ti->private = fc; 2183407ef52SJosef Bacik return 0; 2193407ef52SJosef Bacik 2203407ef52SJosef Bacik bad: 2213407ef52SJosef Bacik kfree(fc); 2223407ef52SJosef Bacik return -EINVAL; 2233407ef52SJosef Bacik } 2243407ef52SJosef Bacik 2253407ef52SJosef Bacik static void flakey_dtr(struct dm_target *ti) 2263407ef52SJosef Bacik { 2273407ef52SJosef Bacik struct flakey_c *fc = ti->private; 2283407ef52SJosef Bacik 2293407ef52SJosef Bacik dm_put_device(ti, fc->dev); 2303407ef52SJosef Bacik kfree(fc); 2313407ef52SJosef Bacik } 2323407ef52SJosef Bacik 2333407ef52SJosef Bacik static sector_t flakey_map_sector(struct dm_target *ti, sector_t bi_sector) 2343407ef52SJosef Bacik { 2353407ef52SJosef Bacik struct flakey_c *fc = ti->private; 2363407ef52SJosef Bacik 23730e4171bSMike Snitzer return fc->start + dm_target_offset(ti, bi_sector); 2383407ef52SJosef Bacik } 2393407ef52SJosef Bacik 2403407ef52SJosef Bacik static void flakey_map_bio(struct dm_target *ti, struct bio *bio) 2413407ef52SJosef Bacik { 2423407ef52SJosef Bacik struct flakey_c *fc = ti->private; 2433407ef52SJosef Bacik 2443407ef52SJosef Bacik bio->bi_bdev = fc->dev->bdev; 2453407ef52SJosef Bacik if (bio_sectors(bio)) 2463407ef52SJosef Bacik bio->bi_sector = flakey_map_sector(ti, bio->bi_sector); 2473407ef52SJosef Bacik } 2483407ef52SJosef Bacik 249a3998799SMike Snitzer static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc) 250a3998799SMike Snitzer { 251a3998799SMike Snitzer unsigned bio_bytes = bio_cur_bytes(bio); 252a3998799SMike Snitzer char *data = bio_data(bio); 253a3998799SMike Snitzer 254a3998799SMike Snitzer /* 255a3998799SMike Snitzer * Overwrite the Nth byte of the data returned. 256a3998799SMike Snitzer */ 257a3998799SMike Snitzer if (data && bio_bytes >= fc->corrupt_bio_byte) { 258a3998799SMike Snitzer data[fc->corrupt_bio_byte - 1] = fc->corrupt_bio_value; 259a3998799SMike Snitzer 260a3998799SMike Snitzer DMDEBUG("Corrupting data bio=%p by writing %u to byte %u " 261a3998799SMike Snitzer "(rw=%c bi_rw=%lu bi_sector=%llu cur_bytes=%u)\n", 262a3998799SMike Snitzer bio, fc->corrupt_bio_value, fc->corrupt_bio_byte, 263a3998799SMike Snitzer (bio_data_dir(bio) == WRITE) ? 'w' : 'r', 264a3998799SMike Snitzer bio->bi_rw, (unsigned long long)bio->bi_sector, bio_bytes); 265a3998799SMike Snitzer } 266a3998799SMike Snitzer } 267a3998799SMike Snitzer 2683407ef52SJosef Bacik static int flakey_map(struct dm_target *ti, struct bio *bio, 2693407ef52SJosef Bacik union map_info *map_context) 2703407ef52SJosef Bacik { 2713407ef52SJosef Bacik struct flakey_c *fc = ti->private; 2723407ef52SJosef Bacik unsigned elapsed; 2733407ef52SJosef Bacik 2743407ef52SJosef Bacik /* Are we alive ? */ 2753407ef52SJosef Bacik elapsed = (jiffies - fc->start_time) / HZ; 276b26f5e3dSMike Snitzer if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) { 277a3998799SMike Snitzer /* 278a3998799SMike Snitzer * Flag this bio as submitted while down. 279a3998799SMike Snitzer */ 280a3998799SMike Snitzer map_context->ll = 1; 2813407ef52SJosef Bacik 282b26f5e3dSMike Snitzer /* 283a3998799SMike Snitzer * Map reads as normal. 284a3998799SMike Snitzer */ 285a3998799SMike Snitzer if (bio_data_dir(bio) == READ) 286a3998799SMike Snitzer goto map_bio; 287a3998799SMike Snitzer 288a3998799SMike Snitzer /* 289a3998799SMike Snitzer * Drop writes? 290b26f5e3dSMike Snitzer */ 291b26f5e3dSMike Snitzer if (test_bit(DROP_WRITES, &fc->flags)) { 292b26f5e3dSMike Snitzer bio_endio(bio, 0); 293b26f5e3dSMike Snitzer return DM_MAPIO_SUBMITTED; 294b26f5e3dSMike Snitzer } 295a3998799SMike Snitzer 296a3998799SMike Snitzer /* 297a3998799SMike Snitzer * Corrupt matching writes. 298a3998799SMike Snitzer */ 299a3998799SMike Snitzer if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == WRITE)) { 300a3998799SMike Snitzer if (all_corrupt_bio_flags_match(bio, fc)) 301a3998799SMike Snitzer corrupt_bio_data(bio, fc); 302b26f5e3dSMike Snitzer goto map_bio; 303b26f5e3dSMike Snitzer } 304b26f5e3dSMike Snitzer 305b26f5e3dSMike Snitzer /* 306a3998799SMike Snitzer * By default, error all I/O. 307b26f5e3dSMike Snitzer */ 308b26f5e3dSMike Snitzer return -EIO; 309b26f5e3dSMike Snitzer } 310b26f5e3dSMike Snitzer 311b26f5e3dSMike Snitzer map_bio: 3123407ef52SJosef Bacik flakey_map_bio(ti, bio); 3133407ef52SJosef Bacik 3143407ef52SJosef Bacik return DM_MAPIO_REMAPPED; 3153407ef52SJosef Bacik } 3163407ef52SJosef Bacik 317a3998799SMike Snitzer static int flakey_end_io(struct dm_target *ti, struct bio *bio, 318a3998799SMike Snitzer int error, union map_info *map_context) 319a3998799SMike Snitzer { 320a3998799SMike Snitzer struct flakey_c *fc = ti->private; 321a3998799SMike Snitzer unsigned bio_submitted_while_down = map_context->ll; 322a3998799SMike Snitzer 323a3998799SMike Snitzer /* 324a3998799SMike Snitzer * Corrupt successful READs while in down state. 325a3998799SMike Snitzer * If flags were specified, only corrupt those that match. 326a3998799SMike Snitzer */ 3271212268fSMike Snitzer if (fc->corrupt_bio_byte && !error && bio_submitted_while_down && 328a3998799SMike Snitzer (bio_data_dir(bio) == READ) && (fc->corrupt_bio_rw == READ) && 329a3998799SMike Snitzer all_corrupt_bio_flags_match(bio, fc)) 330a3998799SMike Snitzer corrupt_bio_data(bio, fc); 331a3998799SMike Snitzer 332a3998799SMike Snitzer return error; 333a3998799SMike Snitzer } 334a3998799SMike Snitzer 3353407ef52SJosef Bacik static int flakey_status(struct dm_target *ti, status_type_t type, 3363407ef52SJosef Bacik char *result, unsigned int maxlen) 3373407ef52SJosef Bacik { 338b26f5e3dSMike Snitzer unsigned sz = 0; 3393407ef52SJosef Bacik struct flakey_c *fc = ti->private; 340b26f5e3dSMike Snitzer unsigned drop_writes; 3413407ef52SJosef Bacik 3423407ef52SJosef Bacik switch (type) { 3433407ef52SJosef Bacik case STATUSTYPE_INFO: 3443407ef52SJosef Bacik result[0] = '\0'; 3453407ef52SJosef Bacik break; 3463407ef52SJosef Bacik 3473407ef52SJosef Bacik case STATUSTYPE_TABLE: 348b26f5e3dSMike Snitzer DMEMIT("%s %llu %u %u ", fc->dev->name, 3493407ef52SJosef Bacik (unsigned long long)fc->start, fc->up_interval, 3503407ef52SJosef Bacik fc->down_interval); 351b26f5e3dSMike Snitzer 352b26f5e3dSMike Snitzer drop_writes = test_bit(DROP_WRITES, &fc->flags); 353a3998799SMike Snitzer DMEMIT("%u ", drop_writes + (fc->corrupt_bio_byte > 0) * 5); 354a3998799SMike Snitzer 355b26f5e3dSMike Snitzer if (drop_writes) 356b26f5e3dSMike Snitzer DMEMIT("drop_writes "); 357a3998799SMike Snitzer 358a3998799SMike Snitzer if (fc->corrupt_bio_byte) 359a3998799SMike Snitzer DMEMIT("corrupt_bio_byte %u %c %u %u ", 360a3998799SMike Snitzer fc->corrupt_bio_byte, 361a3998799SMike Snitzer (fc->corrupt_bio_rw == WRITE) ? 'w' : 'r', 362a3998799SMike Snitzer fc->corrupt_bio_value, fc->corrupt_bio_flags); 363a3998799SMike Snitzer 3643407ef52SJosef Bacik break; 3653407ef52SJosef Bacik } 3663407ef52SJosef Bacik return 0; 3673407ef52SJosef Bacik } 3683407ef52SJosef Bacik 3693407ef52SJosef Bacik static int flakey_ioctl(struct dm_target *ti, unsigned int cmd, unsigned long arg) 3703407ef52SJosef Bacik { 3713407ef52SJosef Bacik struct flakey_c *fc = ti->private; 372ec8013beSPaolo Bonzini struct dm_dev *dev = fc->dev; 373ec8013beSPaolo Bonzini int r = 0; 3743407ef52SJosef Bacik 375ec8013beSPaolo Bonzini /* 376ec8013beSPaolo Bonzini * Only pass ioctls through if the device sizes match exactly. 377ec8013beSPaolo Bonzini */ 378ec8013beSPaolo Bonzini if (fc->start || 379ec8013beSPaolo Bonzini ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) 380ec8013beSPaolo Bonzini r = scsi_verify_blk_ioctl(NULL, cmd); 381ec8013beSPaolo Bonzini 382ec8013beSPaolo Bonzini return r ? : __blkdev_driver_ioctl(dev->bdev, dev->mode, cmd, arg); 3833407ef52SJosef Bacik } 3843407ef52SJosef Bacik 3853407ef52SJosef Bacik static int flakey_merge(struct dm_target *ti, struct bvec_merge_data *bvm, 3863407ef52SJosef Bacik struct bio_vec *biovec, int max_size) 3873407ef52SJosef Bacik { 3883407ef52SJosef Bacik struct flakey_c *fc = ti->private; 3893407ef52SJosef Bacik struct request_queue *q = bdev_get_queue(fc->dev->bdev); 3903407ef52SJosef Bacik 3913407ef52SJosef Bacik if (!q->merge_bvec_fn) 3923407ef52SJosef Bacik return max_size; 3933407ef52SJosef Bacik 3943407ef52SJosef Bacik bvm->bi_bdev = fc->dev->bdev; 3953407ef52SJosef Bacik bvm->bi_sector = flakey_map_sector(ti, bvm->bi_sector); 3963407ef52SJosef Bacik 3973407ef52SJosef Bacik return min(max_size, q->merge_bvec_fn(q, bvm, biovec)); 3983407ef52SJosef Bacik } 3993407ef52SJosef Bacik 4003407ef52SJosef Bacik static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data) 4013407ef52SJosef Bacik { 4023407ef52SJosef Bacik struct flakey_c *fc = ti->private; 4033407ef52SJosef Bacik 4043407ef52SJosef Bacik return fn(ti, fc->dev, fc->start, ti->len, data); 4053407ef52SJosef Bacik } 4063407ef52SJosef Bacik 4073407ef52SJosef Bacik static struct target_type flakey_target = { 4083407ef52SJosef Bacik .name = "flakey", 409dfd068b0SMike Snitzer .version = {1, 2, 0}, 4103407ef52SJosef Bacik .module = THIS_MODULE, 4113407ef52SJosef Bacik .ctr = flakey_ctr, 4123407ef52SJosef Bacik .dtr = flakey_dtr, 4133407ef52SJosef Bacik .map = flakey_map, 414a3998799SMike Snitzer .end_io = flakey_end_io, 4153407ef52SJosef Bacik .status = flakey_status, 4163407ef52SJosef Bacik .ioctl = flakey_ioctl, 4173407ef52SJosef Bacik .merge = flakey_merge, 4183407ef52SJosef Bacik .iterate_devices = flakey_iterate_devices, 4193407ef52SJosef Bacik }; 4203407ef52SJosef Bacik 4213407ef52SJosef Bacik static int __init dm_flakey_init(void) 4223407ef52SJosef Bacik { 4233407ef52SJosef Bacik int r = dm_register_target(&flakey_target); 4243407ef52SJosef Bacik 4253407ef52SJosef Bacik if (r < 0) 4263407ef52SJosef Bacik DMERR("register failed %d", r); 4273407ef52SJosef Bacik 4283407ef52SJosef Bacik return r; 4293407ef52SJosef Bacik } 4303407ef52SJosef Bacik 4313407ef52SJosef Bacik static void __exit dm_flakey_exit(void) 4323407ef52SJosef Bacik { 4333407ef52SJosef Bacik dm_unregister_target(&flakey_target); 4343407ef52SJosef Bacik } 4353407ef52SJosef Bacik 4363407ef52SJosef Bacik /* Module hooks */ 4373407ef52SJosef Bacik module_init(dm_flakey_init); 4383407ef52SJosef Bacik module_exit(dm_flakey_exit); 4393407ef52SJosef Bacik 4403407ef52SJosef Bacik MODULE_DESCRIPTION(DM_NAME " flakey target"); 4413407ef52SJosef Bacik MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>"); 4423407ef52SJosef Bacik MODULE_LICENSE("GPL"); 443