device-mapper.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * Copyright (C) 2001 Sistina Software (UK) Limited.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This file is released under the LGPL.
  6. */
  7. #ifndef _LINUX_DEVICE_MAPPER_H
  8. #define _LINUX_DEVICE_MAPPER_H
  9. #include <linux/bio.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/dm-ioctl.h>
  12. #include <linux/math64.h>
  13. #include <linux/ratelimit.h>
  14. #include <linux/android_kabi.h>
  15. struct dm_dev;
  16. struct dm_target;
  17. struct dm_table;
  18. struct dm_report_zones_args;
  19. struct mapped_device;
  20. struct bio_vec;
  21. enum dax_access_mode;
  22. /*
  23. * Type of table, mapped_device's mempool and request_queue
  24. */
  25. enum dm_queue_mode {
  26. DM_TYPE_NONE = 0,
  27. DM_TYPE_BIO_BASED = 1,
  28. DM_TYPE_REQUEST_BASED = 2,
  29. DM_TYPE_DAX_BIO_BASED = 3,
  30. };
  31. typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE, STATUSTYPE_IMA } status_type_t;
  32. union map_info {
  33. void *ptr;
  34. };
  35. /*
  36. * In the constructor the target parameter will already have the
  37. * table, type, begin and len fields filled in.
  38. */
  39. typedef int (*dm_ctr_fn) (struct dm_target *target,
  40. unsigned int argc, char **argv);
  41. /*
  42. * The destructor doesn't need to free the dm_target, just
  43. * anything hidden ti->private.
  44. */
  45. typedef void (*dm_dtr_fn) (struct dm_target *ti);
  46. /*
  47. * The map function must return:
  48. * < 0: error
  49. * = 0: The target will handle the io by resubmitting it later
  50. * = 1: simple remap complete
  51. * = 2: The target wants to push back the io
  52. */
  53. typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio);
  54. typedef int (*dm_clone_and_map_request_fn) (struct dm_target *ti,
  55. struct request *rq,
  56. union map_info *map_context,
  57. struct request **clone);
  58. typedef void (*dm_release_clone_request_fn) (struct request *clone,
  59. union map_info *map_context);
  60. /*
  61. * Returns:
  62. * < 0 : error (currently ignored)
  63. * 0 : ended successfully
  64. * 1 : for some reason the io has still not completed (eg,
  65. * multipath target might want to requeue a failed io).
  66. * 2 : The target wants to push back the io
  67. */
  68. typedef int (*dm_endio_fn) (struct dm_target *ti,
  69. struct bio *bio, blk_status_t *error);
  70. typedef int (*dm_request_endio_fn) (struct dm_target *ti,
  71. struct request *clone, blk_status_t error,
  72. union map_info *map_context);
  73. typedef void (*dm_presuspend_fn) (struct dm_target *ti);
  74. typedef void (*dm_presuspend_undo_fn) (struct dm_target *ti);
  75. typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
  76. typedef int (*dm_preresume_fn) (struct dm_target *ti);
  77. typedef void (*dm_resume_fn) (struct dm_target *ti);
  78. typedef void (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
  79. unsigned int status_flags, char *result, unsigned int maxlen);
  80. typedef int (*dm_message_fn) (struct dm_target *ti, unsigned int argc, char **argv,
  81. char *result, unsigned int maxlen);
  82. typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti, struct block_device **bdev);
  83. #ifdef CONFIG_BLK_DEV_ZONED
  84. typedef int (*dm_report_zones_fn) (struct dm_target *ti,
  85. struct dm_report_zones_args *args,
  86. unsigned int nr_zones);
  87. #else
  88. /*
  89. * Define dm_report_zones_fn so that targets can assign to NULL if
  90. * CONFIG_BLK_DEV_ZONED disabled. Otherwise each target needs to do
  91. * awkward #ifdefs in their target_type, etc.
  92. */
  93. typedef int (*dm_report_zones_fn) (struct dm_target *dummy);
  94. #endif
  95. /*
  96. * These iteration functions are typically used to check (and combine)
  97. * properties of underlying devices.
  98. * E.g. Does at least one underlying device support flush?
  99. * Does any underlying device not support WRITE_SAME?
  100. *
  101. * The callout function is called once for each contiguous section of
  102. * an underlying device. State can be maintained in *data.
  103. * Return non-zero to stop iterating through any further devices.
  104. */
  105. typedef int (*iterate_devices_callout_fn) (struct dm_target *ti,
  106. struct dm_dev *dev,
  107. sector_t start, sector_t len,
  108. void *data);
  109. /*
  110. * This function must iterate through each section of device used by the
  111. * target until it encounters a non-zero return code, which it then returns.
  112. * Returns zero if no callout returned non-zero.
  113. */
  114. typedef int (*dm_iterate_devices_fn) (struct dm_target *ti,
  115. iterate_devices_callout_fn fn,
  116. void *data);
  117. typedef void (*dm_io_hints_fn) (struct dm_target *ti,
  118. struct queue_limits *limits);
  119. /*
  120. * Returns:
  121. * 0: The target can handle the next I/O immediately.
  122. * 1: The target can't handle the next I/O immediately.
  123. */
  124. typedef int (*dm_busy_fn) (struct dm_target *ti);
  125. /*
  126. * Returns:
  127. * < 0 : error
  128. * >= 0 : the number of bytes accessible at the address
  129. */
  130. typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff,
  131. long nr_pages, enum dax_access_mode node, void **kaddr,
  132. pfn_t *pfn);
  133. typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff,
  134. size_t nr_pages);
  135. /*
  136. * Returns:
  137. * != 0 : number of bytes transferred
  138. * 0 : recovery write failed
  139. */
  140. typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff,
  141. void *addr, size_t bytes, struct iov_iter *i);
  142. void dm_error(const char *message);
  143. struct dm_dev {
  144. struct block_device *bdev;
  145. struct dax_device *dax_dev;
  146. fmode_t mode;
  147. char name[16];
  148. };
  149. dev_t dm_get_dev_t(const char *path);
  150. /*
  151. * Constructors should call these functions to ensure destination devices
  152. * are opened/closed correctly.
  153. */
  154. int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
  155. struct dm_dev **result);
  156. void dm_put_device(struct dm_target *ti, struct dm_dev *d);
  157. /*
  158. * Information about a target type
  159. */
  160. struct target_type {
  161. uint64_t features;
  162. const char *name;
  163. struct module *module;
  164. unsigned int version[3];
  165. dm_ctr_fn ctr;
  166. dm_dtr_fn dtr;
  167. dm_map_fn map;
  168. dm_clone_and_map_request_fn clone_and_map_rq;
  169. dm_release_clone_request_fn release_clone_rq;
  170. dm_endio_fn end_io;
  171. dm_request_endio_fn rq_end_io;
  172. dm_presuspend_fn presuspend;
  173. dm_presuspend_undo_fn presuspend_undo;
  174. dm_postsuspend_fn postsuspend;
  175. dm_preresume_fn preresume;
  176. dm_resume_fn resume;
  177. dm_status_fn status;
  178. dm_message_fn message;
  179. dm_prepare_ioctl_fn prepare_ioctl;
  180. dm_report_zones_fn report_zones;
  181. dm_busy_fn busy;
  182. dm_iterate_devices_fn iterate_devices;
  183. dm_io_hints_fn io_hints;
  184. dm_dax_direct_access_fn direct_access;
  185. dm_dax_zero_page_range_fn dax_zero_page_range;
  186. dm_dax_recovery_write_fn dax_recovery_write;
  187. ANDROID_KABI_RESERVE(1);
  188. ANDROID_KABI_RESERVE(2);
  189. /* For internal device-mapper use. */
  190. struct list_head list;
  191. };
  192. /*
  193. * Target features
  194. */
  195. /*
  196. * Any table that contains an instance of this target must have only one.
  197. */
  198. #define DM_TARGET_SINGLETON 0x00000001
  199. #define dm_target_needs_singleton(type) ((type)->features & DM_TARGET_SINGLETON)
  200. /*
  201. * Indicates that a target does not support read-only devices.
  202. */
  203. #define DM_TARGET_ALWAYS_WRITEABLE 0x00000002
  204. #define dm_target_always_writeable(type) \
  205. ((type)->features & DM_TARGET_ALWAYS_WRITEABLE)
  206. /*
  207. * Any device that contains a table with an instance of this target may never
  208. * have tables containing any different target type.
  209. */
  210. #define DM_TARGET_IMMUTABLE 0x00000004
  211. #define dm_target_is_immutable(type) ((type)->features & DM_TARGET_IMMUTABLE)
  212. /*
  213. * Indicates that a target may replace any target; even immutable targets.
  214. * .map, .map_rq, .clone_and_map_rq and .release_clone_rq are all defined.
  215. */
  216. #define DM_TARGET_WILDCARD 0x00000008
  217. #define dm_target_is_wildcard(type) ((type)->features & DM_TARGET_WILDCARD)
  218. /*
  219. * A target implements own bio data integrity.
  220. */
  221. #define DM_TARGET_INTEGRITY 0x00000010
  222. #define dm_target_has_integrity(type) ((type)->features & DM_TARGET_INTEGRITY)
  223. /*
  224. * A target passes integrity data to the lower device.
  225. */
  226. #define DM_TARGET_PASSES_INTEGRITY 0x00000020
  227. #define dm_target_passes_integrity(type) ((type)->features & DM_TARGET_PASSES_INTEGRITY)
  228. /*
  229. * Indicates support for zoned block devices:
  230. * - DM_TARGET_ZONED_HM: the target also supports host-managed zoned
  231. * block devices but does not support combining different zoned models.
  232. * - DM_TARGET_MIXED_ZONED_MODEL: the target supports combining multiple
  233. * devices with different zoned models.
  234. */
  235. #ifdef CONFIG_BLK_DEV_ZONED
  236. #define DM_TARGET_ZONED_HM 0x00000040
  237. #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)
  238. #else
  239. #define DM_TARGET_ZONED_HM 0x00000000
  240. #define dm_target_supports_zoned_hm(type) (false)
  241. #endif
  242. /*
  243. * A target handles REQ_NOWAIT
  244. */
  245. #define DM_TARGET_NOWAIT 0x00000080
  246. #define dm_target_supports_nowait(type) ((type)->features & DM_TARGET_NOWAIT)
  247. /*
  248. * A target supports passing through inline crypto support.
  249. */
  250. #define DM_TARGET_PASSES_CRYPTO 0x00000100
  251. #define dm_target_passes_crypto(type) ((type)->features & DM_TARGET_PASSES_CRYPTO)
  252. #ifdef CONFIG_BLK_DEV_ZONED
  253. #define DM_TARGET_MIXED_ZONED_MODEL 0x00000200
  254. #define dm_target_supports_mixed_zoned_model(type) \
  255. ((type)->features & DM_TARGET_MIXED_ZONED_MODEL)
  256. #else
  257. #define DM_TARGET_MIXED_ZONED_MODEL 0x00000000
  258. #define dm_target_supports_mixed_zoned_model(type) (false)
  259. #endif
  260. struct dm_target {
  261. struct dm_table *table;
  262. struct target_type *type;
  263. /* target limits */
  264. sector_t begin;
  265. sector_t len;
  266. /* If non-zero, maximum size of I/O submitted to a target. */
  267. uint32_t max_io_len;
  268. /*
  269. * A number of zero-length barrier bios that will be submitted
  270. * to the target for the purpose of flushing cache.
  271. *
  272. * The bio number can be accessed with dm_bio_get_target_bio_nr.
  273. * It is a responsibility of the target driver to remap these bios
  274. * to the real underlying devices.
  275. */
  276. unsigned int num_flush_bios;
  277. /*
  278. * The number of discard bios that will be submitted to the target.
  279. * The bio number can be accessed with dm_bio_get_target_bio_nr.
  280. */
  281. unsigned int num_discard_bios;
  282. /*
  283. * The number of secure erase bios that will be submitted to the target.
  284. * The bio number can be accessed with dm_bio_get_target_bio_nr.
  285. */
  286. unsigned int num_secure_erase_bios;
  287. /*
  288. * The number of WRITE ZEROES bios that will be submitted to the target.
  289. * The bio number can be accessed with dm_bio_get_target_bio_nr.
  290. */
  291. unsigned int num_write_zeroes_bios;
  292. /*
  293. * The minimum number of extra bytes allocated in each io for the
  294. * target to use.
  295. */
  296. unsigned int per_io_data_size;
  297. /* target specific data */
  298. void *private;
  299. /* Used to provide an error string from the ctr */
  300. char *error;
  301. /*
  302. * Set if this target needs to receive flushes regardless of
  303. * whether or not its underlying devices have support.
  304. */
  305. bool flush_supported:1;
  306. /*
  307. * Set if this target needs to receive discards regardless of
  308. * whether or not its underlying devices have support.
  309. */
  310. bool discards_supported:1;
  311. /*
  312. * Set if we need to limit the number of in-flight bios when swapping.
  313. */
  314. bool limit_swap_bios:1;
  315. /*
  316. * Set if this target implements a zoned device and needs emulation of
  317. * zone append operations using regular writes.
  318. */
  319. bool emulate_zone_append:1;
  320. /*
  321. * Set if the target will submit IO using dm_submit_bio_remap()
  322. * after returning DM_MAPIO_SUBMITTED from its map function.
  323. */
  324. bool accounts_remapped_io:1;
  325. /*
  326. * Set if the target will submit the DM bio without first calling
  327. * bio_set_dev(). NOTE: ideally a target should _not_ need this.
  328. */
  329. bool needs_bio_set_dev:1;
  330. ANDROID_KABI_RESERVE(1);
  331. ANDROID_KABI_RESERVE(2);
  332. };
  333. void *dm_per_bio_data(struct bio *bio, size_t data_size);
  334. struct bio *dm_bio_from_per_bio_data(void *data, size_t data_size);
  335. unsigned int dm_bio_get_target_bio_nr(const struct bio *bio);
  336. u64 dm_start_time_ns_from_clone(struct bio *bio);
  337. int dm_register_target(struct target_type *t);
  338. void dm_unregister_target(struct target_type *t);
  339. /*
  340. * Target argument parsing.
  341. */
  342. struct dm_arg_set {
  343. unsigned int argc;
  344. char **argv;
  345. };
  346. /*
  347. * The minimum and maximum value of a numeric argument, together with
  348. * the error message to use if the number is found to be outside that range.
  349. */
  350. struct dm_arg {
  351. unsigned int min;
  352. unsigned int max;
  353. char *error;
  354. };
  355. /*
  356. * Validate the next argument, either returning it as *value or, if invalid,
  357. * returning -EINVAL and setting *error.
  358. */
  359. int dm_read_arg(const struct dm_arg *arg, struct dm_arg_set *arg_set,
  360. unsigned int *value, char **error);
  361. /*
  362. * Process the next argument as the start of a group containing between
  363. * arg->min and arg->max further arguments. Either return the size as
  364. * *num_args or, if invalid, return -EINVAL and set *error.
  365. */
  366. int dm_read_arg_group(const struct dm_arg *arg, struct dm_arg_set *arg_set,
  367. unsigned int *num_args, char **error);
  368. /*
  369. * Return the current argument and shift to the next.
  370. */
  371. const char *dm_shift_arg(struct dm_arg_set *as);
  372. /*
  373. * Move through num_args arguments.
  374. */
  375. void dm_consume_args(struct dm_arg_set *as, unsigned int num_args);
  376. /*-----------------------------------------------------------------
  377. * Functions for creating and manipulating mapped devices.
  378. * Drop the reference with dm_put when you finish with the object.
  379. *---------------------------------------------------------------*/
  380. /*
  381. * DM_ANY_MINOR chooses the next available minor number.
  382. */
  383. #define DM_ANY_MINOR (-1)
  384. int dm_create(int minor, struct mapped_device **md);
  385. /*
  386. * Reference counting for md.
  387. */
  388. struct mapped_device *dm_get_md(dev_t dev);
  389. void dm_get(struct mapped_device *md);
  390. int dm_hold(struct mapped_device *md);
  391. void dm_put(struct mapped_device *md);
  392. /*
  393. * An arbitrary pointer may be stored alongside a mapped device.
  394. */
  395. void dm_set_mdptr(struct mapped_device *md, void *ptr);
  396. void *dm_get_mdptr(struct mapped_device *md);
  397. /*
  398. * A device can still be used while suspended, but I/O is deferred.
  399. */
  400. int dm_suspend(struct mapped_device *md, unsigned int suspend_flags);
  401. int dm_resume(struct mapped_device *md);
  402. /*
  403. * Event functions.
  404. */
  405. uint32_t dm_get_event_nr(struct mapped_device *md);
  406. int dm_wait_event(struct mapped_device *md, int event_nr);
  407. uint32_t dm_next_uevent_seq(struct mapped_device *md);
  408. void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
  409. /*
  410. * Info functions.
  411. */
  412. const char *dm_device_name(struct mapped_device *md);
  413. int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
  414. struct gendisk *dm_disk(struct mapped_device *md);
  415. int dm_suspended(struct dm_target *ti);
  416. int dm_post_suspending(struct dm_target *ti);
  417. int dm_noflush_suspending(struct dm_target *ti);
  418. void dm_accept_partial_bio(struct bio *bio, unsigned int n_sectors);
  419. void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone);
  420. union map_info *dm_get_rq_mapinfo(struct request *rq);
  421. #ifdef CONFIG_BLK_DEV_ZONED
  422. struct dm_report_zones_args {
  423. struct dm_target *tgt;
  424. sector_t next_sector;
  425. void *orig_data;
  426. report_zones_cb orig_cb;
  427. unsigned int zone_idx;
  428. /* must be filled by ->report_zones before calling dm_report_zones_cb */
  429. sector_t start;
  430. };
  431. int dm_report_zones(struct block_device *bdev, sector_t start, sector_t sector,
  432. struct dm_report_zones_args *args, unsigned int nr_zones);
  433. #endif /* CONFIG_BLK_DEV_ZONED */
  434. /*
  435. * Device mapper functions to parse and create devices specified by the
  436. * parameter "dm-mod.create="
  437. */
  438. int __init dm_early_create(struct dm_ioctl *dmi,
  439. struct dm_target_spec **spec_array,
  440. char **target_params_array);
  441. struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
  442. /*
  443. * Geometry functions.
  444. */
  445. int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
  446. int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
  447. /*-----------------------------------------------------------------
  448. * Functions for manipulating device-mapper tables.
  449. *---------------------------------------------------------------*/
  450. /*
  451. * First create an empty table.
  452. */
  453. int dm_table_create(struct dm_table **result, fmode_t mode,
  454. unsigned int num_targets, struct mapped_device *md);
  455. /*
  456. * Then call this once for each target.
  457. */
  458. int dm_table_add_target(struct dm_table *t, const char *type,
  459. sector_t start, sector_t len, char *params);
  460. /*
  461. * Target can use this to set the table's type.
  462. * Can only ever be called from a target's ctr.
  463. * Useful for "hybrid" target (supports both bio-based
  464. * and request-based).
  465. */
  466. void dm_table_set_type(struct dm_table *t, enum dm_queue_mode type);
  467. /*
  468. * Finally call this to make the table ready for use.
  469. */
  470. int dm_table_complete(struct dm_table *t);
  471. /*
  472. * Destroy the table when finished.
  473. */
  474. void dm_table_destroy(struct dm_table *t);
  475. /*
  476. * Target may require that it is never sent I/O larger than len.
  477. */
  478. int __must_check dm_set_target_max_io_len(struct dm_target *ti, sector_t len);
  479. /*
  480. * Table reference counting.
  481. */
  482. struct dm_table *dm_get_live_table(struct mapped_device *md, int *srcu_idx);
  483. void dm_put_live_table(struct mapped_device *md, int srcu_idx);
  484. void dm_sync_table(struct mapped_device *md);
  485. /*
  486. * Queries
  487. */
  488. sector_t dm_table_get_size(struct dm_table *t);
  489. fmode_t dm_table_get_mode(struct dm_table *t);
  490. struct mapped_device *dm_table_get_md(struct dm_table *t);
  491. const char *dm_table_device_name(struct dm_table *t);
  492. /*
  493. * Trigger an event.
  494. */
  495. void dm_table_event(struct dm_table *t);
  496. /*
  497. * Run the queue for request-based targets.
  498. */
  499. void dm_table_run_md_queue_async(struct dm_table *t);
  500. /*
  501. * The device must be suspended before calling this method.
  502. * Returns the previous table, which the caller must destroy.
  503. */
  504. struct dm_table *dm_swap_table(struct mapped_device *md,
  505. struct dm_table *t);
  506. /*
  507. * Table blk_crypto_profile functions
  508. */
  509. void dm_destroy_crypto_profile(struct blk_crypto_profile *profile);
  510. /*-----------------------------------------------------------------
  511. * Macros.
  512. *---------------------------------------------------------------*/
  513. #define DM_NAME "device-mapper"
  514. #define DM_FMT(fmt) DM_NAME ": " DM_MSG_PREFIX ": " fmt "\n"
  515. #define DMCRIT(fmt, ...) pr_crit(DM_FMT(fmt), ##__VA_ARGS__)
  516. #define DMERR(fmt, ...) pr_err(DM_FMT(fmt), ##__VA_ARGS__)
  517. #define DMERR_LIMIT(fmt, ...) pr_err_ratelimited(DM_FMT(fmt), ##__VA_ARGS__)
  518. #define DMWARN(fmt, ...) pr_warn(DM_FMT(fmt), ##__VA_ARGS__)
  519. #define DMWARN_LIMIT(fmt, ...) pr_warn_ratelimited(DM_FMT(fmt), ##__VA_ARGS__)
  520. #define DMINFO(fmt, ...) pr_info(DM_FMT(fmt), ##__VA_ARGS__)
  521. #define DMINFO_LIMIT(fmt, ...) pr_info_ratelimited(DM_FMT(fmt), ##__VA_ARGS__)
  522. #define DMDEBUG(fmt, ...) pr_debug(DM_FMT(fmt), ##__VA_ARGS__)
  523. #define DMDEBUG_LIMIT(fmt, ...) pr_debug_ratelimited(DM_FMT(fmt), ##__VA_ARGS__)
  524. #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
  525. 0 : scnprintf(result + sz, maxlen - sz, x))
  526. #define DMEMIT_TARGET_NAME_VERSION(y) \
  527. DMEMIT("target_name=%s,target_version=%u.%u.%u", \
  528. (y)->name, (y)->version[0], (y)->version[1], (y)->version[2])
  529. /*
  530. * Definitions of return values from target end_io function.
  531. */
  532. #define DM_ENDIO_DONE 0
  533. #define DM_ENDIO_INCOMPLETE 1
  534. #define DM_ENDIO_REQUEUE 2
  535. #define DM_ENDIO_DELAY_REQUEUE 3
  536. /*
  537. * Definitions of return values from target map function.
  538. */
  539. #define DM_MAPIO_SUBMITTED 0
  540. #define DM_MAPIO_REMAPPED 1
  541. #define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
  542. #define DM_MAPIO_DELAY_REQUEUE DM_ENDIO_DELAY_REQUEUE
  543. #define DM_MAPIO_KILL 4
  544. #define dm_sector_div64(x, y)( \
  545. { \
  546. u64 _res; \
  547. (x) = div64_u64_rem(x, y, &_res); \
  548. _res; \
  549. } \
  550. )
  551. /*
  552. * Ceiling(n / sz)
  553. */
  554. #define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
  555. #define dm_sector_div_up(n, sz) ( \
  556. { \
  557. sector_t _r = ((n) + (sz) - 1); \
  558. sector_div(_r, (sz)); \
  559. _r; \
  560. } \
  561. )
  562. /*
  563. * ceiling(n / size) * size
  564. */
  565. #define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
  566. /*
  567. * Sector offset taken relative to the start of the target instead of
  568. * relative to the start of the device.
  569. */
  570. #define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
  571. static inline sector_t to_sector(unsigned long long n)
  572. {
  573. return (n >> SECTOR_SHIFT);
  574. }
  575. static inline unsigned long to_bytes(sector_t n)
  576. {
  577. return (n << SECTOR_SHIFT);
  578. }
  579. #endif /* _LINUX_DEVICE_MAPPER_H */