device-mapper.h 6.8 KB

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