dm-flakey.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2003 Sistina Software (UK) Limited.
  4. * Copyright (C) 2004, 2010-2011 Red Hat, Inc. All rights reserved.
  5. *
  6. * This file is released under the GPL.
  7. */
  8. #include <linux/device-mapper.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/bio.h>
  13. #include <linux/slab.h>
  14. #define DM_MSG_PREFIX "flakey"
  15. #define PROBABILITY_BASE 1000000000
  16. #define all_corrupt_bio_flags_match(bio, fc) \
  17. (((bio)->bi_opf & (fc)->corrupt_bio_flags) == (fc)->corrupt_bio_flags)
  18. /*
  19. * Flakey: Used for testing only, simulates intermittent,
  20. * catastrophic device failure.
  21. */
  22. struct flakey_c {
  23. struct dm_dev *dev;
  24. unsigned long start_time;
  25. sector_t start;
  26. unsigned int up_interval;
  27. unsigned int down_interval;
  28. unsigned long flags;
  29. unsigned int corrupt_bio_byte;
  30. unsigned int corrupt_bio_rw;
  31. unsigned int corrupt_bio_value;
  32. blk_opf_t corrupt_bio_flags;
  33. unsigned int random_read_corrupt;
  34. unsigned int random_write_corrupt;
  35. };
  36. enum feature_flag_bits {
  37. ERROR_READS,
  38. DROP_WRITES,
  39. ERROR_WRITES
  40. };
  41. struct per_bio_data {
  42. bool bio_can_corrupt;
  43. struct bvec_iter saved_iter;
  44. };
  45. static int parse_features(struct dm_arg_set *as, struct flakey_c *fc,
  46. struct dm_target *ti)
  47. {
  48. int r = 0;
  49. unsigned int argc = 0;
  50. const char *arg_name;
  51. static const struct dm_arg _args[] = {
  52. {0, 11, "Invalid number of feature args"},
  53. {1, UINT_MAX, "Invalid corrupt bio byte"},
  54. {0, 255, "Invalid corrupt value to write into bio byte (0-255)"},
  55. {0, UINT_MAX, "Invalid corrupt bio flags mask"},
  56. {0, PROBABILITY_BASE, "Invalid random corrupt argument"},
  57. };
  58. if (as->argc && (r = dm_read_arg_group(_args, as, &argc, &ti->error)))
  59. return r;
  60. /* No feature arguments supplied. */
  61. if (!argc)
  62. goto error_all_io;
  63. while (argc) {
  64. arg_name = dm_shift_arg(as);
  65. argc--;
  66. if (!arg_name) {
  67. ti->error = "Insufficient feature arguments";
  68. return -EINVAL;
  69. }
  70. /*
  71. * error_reads
  72. */
  73. if (!strcasecmp(arg_name, "error_reads")) {
  74. if (test_and_set_bit(ERROR_READS, &fc->flags)) {
  75. ti->error = "Feature error_reads duplicated";
  76. return -EINVAL;
  77. }
  78. continue;
  79. }
  80. /*
  81. * drop_writes
  82. */
  83. if (!strcasecmp(arg_name, "drop_writes")) {
  84. if (test_and_set_bit(DROP_WRITES, &fc->flags)) {
  85. ti->error = "Feature drop_writes duplicated";
  86. return -EINVAL;
  87. } else if (test_bit(ERROR_WRITES, &fc->flags)) {
  88. ti->error = "Feature drop_writes conflicts with feature error_writes";
  89. return -EINVAL;
  90. }
  91. continue;
  92. }
  93. /*
  94. * error_writes
  95. */
  96. if (!strcasecmp(arg_name, "error_writes")) {
  97. if (test_and_set_bit(ERROR_WRITES, &fc->flags)) {
  98. ti->error = "Feature error_writes duplicated";
  99. return -EINVAL;
  100. } else if (test_bit(DROP_WRITES, &fc->flags)) {
  101. ti->error = "Feature error_writes conflicts with feature drop_writes";
  102. return -EINVAL;
  103. }
  104. continue;
  105. }
  106. /*
  107. * corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>
  108. */
  109. if (!strcasecmp(arg_name, "corrupt_bio_byte")) {
  110. if (!argc) {
  111. ti->error = "Feature corrupt_bio_byte requires parameters";
  112. return -EINVAL;
  113. }
  114. r = dm_read_arg(_args + 1, as, &fc->corrupt_bio_byte, &ti->error);
  115. if (r)
  116. return r;
  117. argc--;
  118. /*
  119. * Direction r or w?
  120. */
  121. arg_name = dm_shift_arg(as);
  122. if (arg_name && !strcasecmp(arg_name, "w"))
  123. fc->corrupt_bio_rw = WRITE;
  124. else if (arg_name && !strcasecmp(arg_name, "r"))
  125. fc->corrupt_bio_rw = READ;
  126. else {
  127. ti->error = "Invalid corrupt bio direction (r or w)";
  128. return -EINVAL;
  129. }
  130. argc--;
  131. /*
  132. * Value of byte (0-255) to write in place of correct one.
  133. */
  134. r = dm_read_arg(_args + 2, as, &fc->corrupt_bio_value, &ti->error);
  135. if (r)
  136. return r;
  137. argc--;
  138. /*
  139. * Only corrupt bios with these flags set.
  140. */
  141. BUILD_BUG_ON(sizeof(fc->corrupt_bio_flags) !=
  142. sizeof(unsigned int));
  143. r = dm_read_arg(_args + 3, as,
  144. (__force unsigned int *)&fc->corrupt_bio_flags,
  145. &ti->error);
  146. if (r)
  147. return r;
  148. argc--;
  149. continue;
  150. }
  151. if (!strcasecmp(arg_name, "random_read_corrupt")) {
  152. if (!argc) {
  153. ti->error = "Feature random_read_corrupt requires a parameter";
  154. return -EINVAL;
  155. }
  156. r = dm_read_arg(_args + 4, as, &fc->random_read_corrupt, &ti->error);
  157. if (r)
  158. return r;
  159. argc--;
  160. continue;
  161. }
  162. if (!strcasecmp(arg_name, "random_write_corrupt")) {
  163. if (!argc) {
  164. ti->error = "Feature random_write_corrupt requires a parameter";
  165. return -EINVAL;
  166. }
  167. r = dm_read_arg(_args + 4, as, &fc->random_write_corrupt, &ti->error);
  168. if (r)
  169. return r;
  170. argc--;
  171. continue;
  172. }
  173. ti->error = "Unrecognised flakey feature requested";
  174. return -EINVAL;
  175. }
  176. if (test_bit(DROP_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) {
  177. ti->error = "drop_writes is incompatible with corrupt_bio_byte with the WRITE flag set";
  178. return -EINVAL;
  179. } else if (test_bit(ERROR_WRITES, &fc->flags) && (fc->corrupt_bio_rw == WRITE)) {
  180. ti->error = "error_writes is incompatible with corrupt_bio_byte with the WRITE flag set";
  181. return -EINVAL;
  182. }
  183. if (!fc->corrupt_bio_byte && !test_bit(ERROR_READS, &fc->flags) &&
  184. !test_bit(DROP_WRITES, &fc->flags) && !test_bit(ERROR_WRITES, &fc->flags) &&
  185. !fc->random_read_corrupt && !fc->random_write_corrupt) {
  186. error_all_io:
  187. set_bit(ERROR_WRITES, &fc->flags);
  188. set_bit(ERROR_READS, &fc->flags);
  189. }
  190. return 0;
  191. }
  192. /*
  193. * Construct a flakey mapping:
  194. * <dev_path> <offset> <up interval> <down interval> [<#feature args> [<arg>]*]
  195. *
  196. * Feature args:
  197. * [drop_writes]
  198. * [corrupt_bio_byte <Nth_byte> <direction> <value> <bio_flags>]
  199. *
  200. * Nth_byte starts from 1 for the first byte.
  201. * Direction is r for READ or w for WRITE.
  202. * bio_flags is ignored if 0.
  203. */
  204. static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
  205. {
  206. static const struct dm_arg _args[] = {
  207. {0, UINT_MAX, "Invalid up interval"},
  208. {0, UINT_MAX, "Invalid down interval"},
  209. };
  210. int r;
  211. struct flakey_c *fc;
  212. unsigned long long tmpll;
  213. struct dm_arg_set as;
  214. const char *devname;
  215. char dummy;
  216. as.argc = argc;
  217. as.argv = argv;
  218. if (argc < 4) {
  219. ti->error = "Invalid argument count";
  220. return -EINVAL;
  221. }
  222. fc = kzalloc(sizeof(*fc), GFP_KERNEL);
  223. if (!fc) {
  224. ti->error = "Cannot allocate context";
  225. return -ENOMEM;
  226. }
  227. fc->start_time = jiffies;
  228. devname = dm_shift_arg(&as);
  229. r = -EINVAL;
  230. if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
  231. ti->error = "Invalid device sector";
  232. goto bad;
  233. }
  234. fc->start = tmpll;
  235. r = dm_read_arg(_args, &as, &fc->up_interval, &ti->error);
  236. if (r)
  237. goto bad;
  238. r = dm_read_arg(_args, &as, &fc->down_interval, &ti->error);
  239. if (r)
  240. goto bad;
  241. if (!(fc->up_interval + fc->down_interval)) {
  242. ti->error = "Total (up + down) interval is zero";
  243. r = -EINVAL;
  244. goto bad;
  245. }
  246. if (fc->up_interval + fc->down_interval < fc->up_interval) {
  247. ti->error = "Interval overflow";
  248. r = -EINVAL;
  249. goto bad;
  250. }
  251. r = parse_features(&as, fc, ti);
  252. if (r)
  253. goto bad;
  254. r = dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev);
  255. if (r) {
  256. ti->error = "Device lookup failed";
  257. goto bad;
  258. }
  259. ti->num_flush_bios = 1;
  260. ti->num_discard_bios = 1;
  261. ti->per_io_data_size = sizeof(struct per_bio_data);
  262. ti->private = fc;
  263. return 0;
  264. bad:
  265. kfree(fc);
  266. return r;
  267. }
  268. static void flakey_dtr(struct dm_target *ti)
  269. {
  270. struct flakey_c *fc = ti->private;
  271. dm_put_device(ti, fc->dev);
  272. kfree(fc);
  273. }
  274. static sector_t flakey_map_sector(struct dm_target *ti, sector_t bi_sector)
  275. {
  276. struct flakey_c *fc = ti->private;
  277. return fc->start + dm_target_offset(ti, bi_sector);
  278. }
  279. static void flakey_map_bio(struct dm_target *ti, struct bio *bio)
  280. {
  281. struct flakey_c *fc = ti->private;
  282. bio_set_dev(bio, fc->dev->bdev);
  283. bio->bi_iter.bi_sector = flakey_map_sector(ti, bio->bi_iter.bi_sector);
  284. }
  285. static void corrupt_bio_common(struct bio *bio, unsigned int corrupt_bio_byte,
  286. unsigned char corrupt_bio_value,
  287. struct bvec_iter start)
  288. {
  289. struct bvec_iter iter;
  290. struct bio_vec bvec;
  291. /*
  292. * Overwrite the Nth byte of the bio's data, on whichever page
  293. * it falls.
  294. */
  295. __bio_for_each_segment(bvec, bio, iter, start) {
  296. if (bio_iter_len(bio, iter) > corrupt_bio_byte) {
  297. unsigned char *segment = bvec_kmap_local(&bvec);
  298. segment[corrupt_bio_byte] = corrupt_bio_value;
  299. kunmap_local(segment);
  300. DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
  301. "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n",
  302. bio, corrupt_bio_value, corrupt_bio_byte,
  303. (bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
  304. (unsigned long long)start.bi_sector,
  305. start.bi_size);
  306. break;
  307. }
  308. corrupt_bio_byte -= bio_iter_len(bio, iter);
  309. }
  310. }
  311. static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc,
  312. struct bvec_iter start)
  313. {
  314. unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1;
  315. corrupt_bio_common(bio, corrupt_bio_byte, fc->corrupt_bio_value, start);
  316. }
  317. static void corrupt_bio_random(struct bio *bio, struct bvec_iter start)
  318. {
  319. unsigned int corrupt_byte;
  320. unsigned char corrupt_value;
  321. corrupt_byte = get_random_u32() % start.bi_size;
  322. corrupt_value = get_random_u8();
  323. corrupt_bio_common(bio, corrupt_byte, corrupt_value, start);
  324. }
  325. static void clone_free(struct bio *clone)
  326. {
  327. struct folio_iter fi;
  328. if (clone->bi_vcnt > 0) { /* bio_for_each_folio_all crashes with an empty bio */
  329. bio_for_each_folio_all(fi, clone)
  330. folio_put(fi.folio);
  331. }
  332. bio_uninit(clone);
  333. kfree(clone);
  334. }
  335. static void clone_endio(struct bio *clone)
  336. {
  337. struct bio *bio = clone->bi_private;
  338. bio->bi_status = clone->bi_status;
  339. clone_free(clone);
  340. bio_endio(bio);
  341. }
  342. static struct bio *clone_bio(struct dm_target *ti, struct flakey_c *fc, struct bio *bio)
  343. {
  344. struct bio *clone;
  345. unsigned size, remaining_size, nr_iovecs, order;
  346. struct bvec_iter iter = bio->bi_iter;
  347. if (unlikely(bio->bi_iter.bi_size > UIO_MAXIOV << PAGE_SHIFT))
  348. dm_accept_partial_bio(bio, UIO_MAXIOV << PAGE_SHIFT >> SECTOR_SHIFT);
  349. size = bio->bi_iter.bi_size;
  350. nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
  351. clone = bio_kmalloc(nr_iovecs, GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN);
  352. if (!clone)
  353. return NULL;
  354. bio_init(clone, fc->dev->bdev, clone->bi_inline_vecs, nr_iovecs, bio->bi_opf);
  355. clone->bi_iter.bi_sector = flakey_map_sector(ti, bio->bi_iter.bi_sector);
  356. clone->bi_private = bio;
  357. clone->bi_end_io = clone_endio;
  358. remaining_size = size;
  359. order = MAX_PAGE_ORDER;
  360. while (remaining_size) {
  361. struct page *pages;
  362. unsigned size_to_add, to_copy;
  363. unsigned char *virt;
  364. unsigned remaining_order = __fls((remaining_size + PAGE_SIZE - 1) >> PAGE_SHIFT);
  365. order = min(order, remaining_order);
  366. retry_alloc_pages:
  367. pages = alloc_pages(GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN | __GFP_COMP, order);
  368. if (unlikely(!pages)) {
  369. if (order) {
  370. order--;
  371. goto retry_alloc_pages;
  372. }
  373. clone_free(clone);
  374. return NULL;
  375. }
  376. size_to_add = min((unsigned)PAGE_SIZE << order, remaining_size);
  377. virt = page_to_virt(pages);
  378. to_copy = size_to_add;
  379. do {
  380. struct bio_vec bvec = bvec_iter_bvec(bio->bi_io_vec, iter);
  381. unsigned this_step = min(bvec.bv_len, to_copy);
  382. void *map = bvec_kmap_local(&bvec);
  383. memcpy(virt, map, this_step);
  384. kunmap_local(map);
  385. bvec_iter_advance(bio->bi_io_vec, &iter, this_step);
  386. to_copy -= this_step;
  387. virt += this_step;
  388. } while (to_copy);
  389. __bio_add_page(clone, pages, size_to_add, 0);
  390. remaining_size -= size_to_add;
  391. }
  392. return clone;
  393. }
  394. static int flakey_map(struct dm_target *ti, struct bio *bio)
  395. {
  396. struct flakey_c *fc = ti->private;
  397. unsigned int elapsed;
  398. struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
  399. pb->bio_can_corrupt = false;
  400. if (op_is_zone_mgmt(bio_op(bio)))
  401. goto map_bio;
  402. /* Are we alive ? */
  403. elapsed = (jiffies - fc->start_time) / HZ;
  404. if (elapsed % (fc->up_interval + fc->down_interval) >= fc->up_interval) {
  405. bool corrupt_fixed, corrupt_random;
  406. if (bio_has_data(bio)) {
  407. pb->bio_can_corrupt = true;
  408. pb->saved_iter = bio->bi_iter;
  409. }
  410. /*
  411. * Error reads if neither corrupt_bio_byte or drop_writes or error_writes are set.
  412. * Otherwise, flakey_end_io() will decide if the reads should be modified.
  413. */
  414. if (bio_data_dir(bio) == READ) {
  415. if (test_bit(ERROR_READS, &fc->flags))
  416. return DM_MAPIO_KILL;
  417. goto map_bio;
  418. }
  419. /*
  420. * Drop or error writes?
  421. */
  422. if (test_bit(DROP_WRITES, &fc->flags)) {
  423. bio_endio(bio);
  424. return DM_MAPIO_SUBMITTED;
  425. } else if (test_bit(ERROR_WRITES, &fc->flags)) {
  426. bio_io_error(bio);
  427. return DM_MAPIO_SUBMITTED;
  428. }
  429. if (!pb->bio_can_corrupt)
  430. goto map_bio;
  431. /*
  432. * Corrupt matching writes.
  433. */
  434. corrupt_fixed = false;
  435. corrupt_random = false;
  436. if (fc->corrupt_bio_byte && fc->corrupt_bio_rw == WRITE) {
  437. if (all_corrupt_bio_flags_match(bio, fc))
  438. corrupt_fixed = true;
  439. }
  440. if (fc->random_write_corrupt) {
  441. u64 rnd = get_random_u64();
  442. u32 rem = do_div(rnd, PROBABILITY_BASE);
  443. if (rem < fc->random_write_corrupt)
  444. corrupt_random = true;
  445. }
  446. if (corrupt_fixed || corrupt_random) {
  447. struct bio *clone = clone_bio(ti, fc, bio);
  448. if (clone) {
  449. if (corrupt_fixed)
  450. corrupt_bio_data(clone, fc,
  451. clone->bi_iter);
  452. if (corrupt_random)
  453. corrupt_bio_random(clone,
  454. clone->bi_iter);
  455. submit_bio(clone);
  456. return DM_MAPIO_SUBMITTED;
  457. }
  458. }
  459. }
  460. map_bio:
  461. flakey_map_bio(ti, bio);
  462. return DM_MAPIO_REMAPPED;
  463. }
  464. static int flakey_end_io(struct dm_target *ti, struct bio *bio,
  465. blk_status_t *error)
  466. {
  467. struct flakey_c *fc = ti->private;
  468. struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
  469. if (op_is_zone_mgmt(bio_op(bio)))
  470. return DM_ENDIO_DONE;
  471. if (!*error && pb->bio_can_corrupt && (bio_data_dir(bio) == READ)) {
  472. if (fc->corrupt_bio_byte) {
  473. if ((fc->corrupt_bio_rw == READ) &&
  474. all_corrupt_bio_flags_match(bio, fc)) {
  475. /*
  476. * Corrupt successful matching READs while in down state.
  477. */
  478. corrupt_bio_data(bio, fc, pb->saved_iter);
  479. }
  480. }
  481. if (fc->random_read_corrupt) {
  482. u64 rnd = get_random_u64();
  483. u32 rem = do_div(rnd, PROBABILITY_BASE);
  484. if (rem < fc->random_read_corrupt)
  485. corrupt_bio_random(bio, pb->saved_iter);
  486. }
  487. if (test_bit(ERROR_READS, &fc->flags)) {
  488. /*
  489. * Error read during the down_interval if drop_writes
  490. * and error_writes were not configured.
  491. */
  492. *error = BLK_STS_IOERR;
  493. }
  494. }
  495. return DM_ENDIO_DONE;
  496. }
  497. static void flakey_status(struct dm_target *ti, status_type_t type,
  498. unsigned int status_flags, char *result, unsigned int maxlen)
  499. {
  500. unsigned int sz = 0;
  501. struct flakey_c *fc = ti->private;
  502. unsigned int error_reads, drop_writes, error_writes;
  503. switch (type) {
  504. case STATUSTYPE_INFO:
  505. result[0] = '\0';
  506. break;
  507. case STATUSTYPE_TABLE:
  508. DMEMIT("%s %llu %u %u", fc->dev->name,
  509. (unsigned long long)fc->start, fc->up_interval,
  510. fc->down_interval);
  511. error_reads = test_bit(ERROR_READS, &fc->flags);
  512. drop_writes = test_bit(DROP_WRITES, &fc->flags);
  513. error_writes = test_bit(ERROR_WRITES, &fc->flags);
  514. DMEMIT(" %u", error_reads + drop_writes + error_writes +
  515. (fc->corrupt_bio_byte > 0) * 5 +
  516. (fc->random_read_corrupt > 0) * 2 +
  517. (fc->random_write_corrupt > 0) * 2);
  518. if (error_reads)
  519. DMEMIT(" error_reads");
  520. if (drop_writes)
  521. DMEMIT(" drop_writes");
  522. else if (error_writes)
  523. DMEMIT(" error_writes");
  524. if (fc->corrupt_bio_byte)
  525. DMEMIT(" corrupt_bio_byte %u %c %u %u",
  526. fc->corrupt_bio_byte,
  527. (fc->corrupt_bio_rw == WRITE) ? 'w' : 'r',
  528. fc->corrupt_bio_value, fc->corrupt_bio_flags);
  529. if (fc->random_read_corrupt > 0)
  530. DMEMIT(" random_read_corrupt %u", fc->random_read_corrupt);
  531. if (fc->random_write_corrupt > 0)
  532. DMEMIT(" random_write_corrupt %u", fc->random_write_corrupt);
  533. break;
  534. case STATUSTYPE_IMA:
  535. result[0] = '\0';
  536. break;
  537. }
  538. }
  539. static int flakey_prepare_ioctl(struct dm_target *ti, struct block_device **bdev)
  540. {
  541. struct flakey_c *fc = ti->private;
  542. *bdev = fc->dev->bdev;
  543. /*
  544. * Only pass ioctls through if the device sizes match exactly.
  545. */
  546. if (fc->start || ti->len != bdev_nr_sectors((*bdev)))
  547. return 1;
  548. return 0;
  549. }
  550. #ifdef CONFIG_BLK_DEV_ZONED
  551. static int flakey_report_zones(struct dm_target *ti,
  552. struct dm_report_zones_args *args, unsigned int nr_zones)
  553. {
  554. struct flakey_c *fc = ti->private;
  555. return dm_report_zones(fc->dev->bdev, fc->start,
  556. flakey_map_sector(ti, args->next_sector),
  557. args, nr_zones);
  558. }
  559. #else
  560. #define flakey_report_zones NULL
  561. #endif
  562. static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data)
  563. {
  564. struct flakey_c *fc = ti->private;
  565. return fn(ti, fc->dev, fc->start, ti->len, data);
  566. }
  567. static struct target_type flakey_target = {
  568. .name = "flakey",
  569. .version = {1, 5, 0},
  570. .features = DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
  571. .report_zones = flakey_report_zones,
  572. .module = THIS_MODULE,
  573. .ctr = flakey_ctr,
  574. .dtr = flakey_dtr,
  575. .map = flakey_map,
  576. .end_io = flakey_end_io,
  577. .status = flakey_status,
  578. .prepare_ioctl = flakey_prepare_ioctl,
  579. .iterate_devices = flakey_iterate_devices,
  580. };
  581. module_dm(flakey);
  582. MODULE_DESCRIPTION(DM_NAME " flakey target");
  583. MODULE_AUTHOR("Joe Thornber <dm-devel@lists.linux.dev>");
  584. MODULE_LICENSE("GPL");