device-mapper.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Copyright (C) 2001 Sistina Software (UK) Limited.
  3. * Copyright (C) 2004 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. #ifdef __KERNEL__
  10. struct dm_target;
  11. struct dm_table;
  12. struct dm_dev;
  13. struct mapped_device;
  14. typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
  15. union map_info {
  16. void *ptr;
  17. unsigned long long ll;
  18. };
  19. /*
  20. * In the constructor the target parameter will already have the
  21. * table, type, begin and len fields filled in.
  22. */
  23. typedef int (*dm_ctr_fn) (struct dm_target *target,
  24. unsigned int argc, char **argv);
  25. /*
  26. * The destructor doesn't need to free the dm_target, just
  27. * anything hidden ti->private.
  28. */
  29. typedef void (*dm_dtr_fn) (struct dm_target *ti);
  30. /*
  31. * The map function must return:
  32. * < 0: error
  33. * = 0: The target will handle the io by resubmitting it later
  34. * > 0: simple remap complete
  35. */
  36. typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
  37. union map_info *map_context);
  38. /*
  39. * Returns:
  40. * < 0 : error (currently ignored)
  41. * 0 : ended successfully
  42. * 1 : for some reason the io has still not completed (eg,
  43. * multipath target might want to requeue a failed io).
  44. */
  45. typedef int (*dm_endio_fn) (struct dm_target *ti,
  46. struct bio *bio, int error,
  47. union map_info *map_context);
  48. typedef void (*dm_presuspend_fn) (struct dm_target *ti);
  49. typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
  50. typedef void (*dm_resume_fn) (struct dm_target *ti);
  51. typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
  52. char *result, unsigned int maxlen);
  53. typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
  54. void dm_error(const char *message);
  55. /*
  56. * Constructors should call these functions to ensure destination devices
  57. * are opened/closed correctly.
  58. * FIXME: too many arguments.
  59. */
  60. int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
  61. sector_t len, int mode, struct dm_dev **result);
  62. void dm_put_device(struct dm_target *ti, struct dm_dev *d);
  63. /*
  64. * Information about a target type
  65. */
  66. struct target_type {
  67. const char *name;
  68. struct module *module;
  69. unsigned version[3];
  70. dm_ctr_fn ctr;
  71. dm_dtr_fn dtr;
  72. dm_map_fn map;
  73. dm_endio_fn end_io;
  74. dm_presuspend_fn presuspend;
  75. dm_postsuspend_fn postsuspend;
  76. dm_resume_fn resume;
  77. dm_status_fn status;
  78. dm_message_fn message;
  79. };
  80. struct io_restrictions {
  81. unsigned int max_sectors;
  82. unsigned short max_phys_segments;
  83. unsigned short max_hw_segments;
  84. unsigned short hardsect_size;
  85. unsigned int max_segment_size;
  86. unsigned long seg_boundary_mask;
  87. unsigned char no_cluster; /* inverted so that 0 is default */
  88. };
  89. struct dm_target {
  90. struct dm_table *table;
  91. struct target_type *type;
  92. /* target limits */
  93. sector_t begin;
  94. sector_t len;
  95. /* FIXME: turn this into a mask, and merge with io_restrictions */
  96. /* Always a power of 2 */
  97. sector_t split_io;
  98. /*
  99. * These are automatically filled in by
  100. * dm_table_get_device.
  101. */
  102. struct io_restrictions limits;
  103. /* target specific data */
  104. void *private;
  105. /* Used to provide an error string from the ctr */
  106. char *error;
  107. };
  108. int dm_register_target(struct target_type *t);
  109. int dm_unregister_target(struct target_type *t);
  110. /*-----------------------------------------------------------------
  111. * Functions for creating and manipulating mapped devices.
  112. * Drop the reference with dm_put when you finish with the object.
  113. *---------------------------------------------------------------*/
  114. /*
  115. * DM_ANY_MINOR chooses the next available minor number.
  116. */
  117. #define DM_ANY_MINOR (-1)
  118. int dm_create(int minor, struct mapped_device **md);
  119. /*
  120. * Reference counting for md.
  121. */
  122. struct mapped_device *dm_get_md(dev_t dev);
  123. void dm_get(struct mapped_device *md);
  124. void dm_put(struct mapped_device *md);
  125. /*
  126. * An arbitrary pointer may be stored alongside a mapped device.
  127. */
  128. void dm_set_mdptr(struct mapped_device *md, void *ptr);
  129. void *dm_get_mdptr(struct mapped_device *md);
  130. /*
  131. * A device can still be used while suspended, but I/O is deferred.
  132. */
  133. int dm_suspend(struct mapped_device *md, int with_lockfs);
  134. int dm_resume(struct mapped_device *md);
  135. /*
  136. * Event functions.
  137. */
  138. uint32_t dm_get_event_nr(struct mapped_device *md);
  139. int dm_wait_event(struct mapped_device *md, int event_nr);
  140. /*
  141. * Info functions.
  142. */
  143. const char *dm_device_name(struct mapped_device *md);
  144. struct gendisk *dm_disk(struct mapped_device *md);
  145. int dm_suspended(struct mapped_device *md);
  146. /*
  147. * Geometry functions.
  148. */
  149. int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
  150. int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
  151. /*-----------------------------------------------------------------
  152. * Functions for manipulating device-mapper tables.
  153. *---------------------------------------------------------------*/
  154. /*
  155. * First create an empty table.
  156. */
  157. int dm_table_create(struct dm_table **result, int mode,
  158. unsigned num_targets, struct mapped_device *md);
  159. /*
  160. * Then call this once for each target.
  161. */
  162. int dm_table_add_target(struct dm_table *t, const char *type,
  163. sector_t start, sector_t len, char *params);
  164. /*
  165. * Finally call this to make the table ready for use.
  166. */
  167. int dm_table_complete(struct dm_table *t);
  168. /*
  169. * Table reference counting.
  170. */
  171. struct dm_table *dm_get_table(struct mapped_device *md);
  172. void dm_table_get(struct dm_table *t);
  173. void dm_table_put(struct dm_table *t);
  174. /*
  175. * Queries
  176. */
  177. sector_t dm_table_get_size(struct dm_table *t);
  178. unsigned int dm_table_get_num_targets(struct dm_table *t);
  179. int dm_table_get_mode(struct dm_table *t);
  180. struct mapped_device *dm_table_get_md(struct dm_table *t);
  181. /*
  182. * Trigger an event.
  183. */
  184. void dm_table_event(struct dm_table *t);
  185. /*
  186. * The device must be suspended before calling this method.
  187. */
  188. int dm_swap_table(struct mapped_device *md, struct dm_table *t);
  189. /*
  190. * Prepare a table for a device that will error all I/O.
  191. * To make it active, call dm_suspend(), dm_swap_table() then dm_resume().
  192. */
  193. int dm_create_error_table(struct dm_table **result, struct mapped_device *md);
  194. #endif /* __KERNEL__ */
  195. #endif /* _LINUX_DEVICE_MAPPER_H */