device-mapper.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct dm_target;
  10. struct dm_table;
  11. struct dm_dev;
  12. typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
  13. union map_info {
  14. void *ptr;
  15. unsigned long long ll;
  16. };
  17. /*
  18. * In the constructor the target parameter will already have the
  19. * table, type, begin and len fields filled in.
  20. */
  21. typedef int (*dm_ctr_fn) (struct dm_target *target,
  22. unsigned int argc, char **argv);
  23. /*
  24. * The destructor doesn't need to free the dm_target, just
  25. * anything hidden ti->private.
  26. */
  27. typedef void (*dm_dtr_fn) (struct dm_target *ti);
  28. /*
  29. * The map function must return:
  30. * < 0: error
  31. * = 0: The target will handle the io by resubmitting it later
  32. * > 0: simple remap complete
  33. */
  34. typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
  35. union map_info *map_context);
  36. /*
  37. * Returns:
  38. * < 0 : error (currently ignored)
  39. * 0 : ended successfully
  40. * 1 : for some reason the io has still not completed (eg,
  41. * multipath target might want to requeue a failed io).
  42. */
  43. typedef int (*dm_endio_fn) (struct dm_target *ti,
  44. struct bio *bio, int error,
  45. union map_info *map_context);
  46. typedef void (*dm_presuspend_fn) (struct dm_target *ti);
  47. typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
  48. typedef void (*dm_resume_fn) (struct dm_target *ti);
  49. typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
  50. char *result, unsigned int maxlen);
  51. typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
  52. void dm_error(const char *message);
  53. /*
  54. * Constructors should call these functions to ensure destination devices
  55. * are opened/closed correctly.
  56. * FIXME: too many arguments.
  57. */
  58. int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
  59. sector_t len, int mode, struct dm_dev **result);
  60. void dm_put_device(struct dm_target *ti, struct dm_dev *d);
  61. /*
  62. * Information about a target type
  63. */
  64. struct target_type {
  65. const char *name;
  66. struct module *module;
  67. unsigned version[3];
  68. dm_ctr_fn ctr;
  69. dm_dtr_fn dtr;
  70. dm_map_fn map;
  71. dm_endio_fn end_io;
  72. dm_presuspend_fn presuspend;
  73. dm_postsuspend_fn postsuspend;
  74. dm_resume_fn resume;
  75. dm_status_fn status;
  76. dm_message_fn message;
  77. };
  78. struct io_restrictions {
  79. unsigned short max_sectors;
  80. unsigned short max_phys_segments;
  81. unsigned short max_hw_segments;
  82. unsigned short hardsect_size;
  83. unsigned int max_segment_size;
  84. unsigned long seg_boundary_mask;
  85. };
  86. struct dm_target {
  87. struct dm_table *table;
  88. struct target_type *type;
  89. /* target limits */
  90. sector_t begin;
  91. sector_t len;
  92. /* FIXME: turn this into a mask, and merge with io_restrictions */
  93. /* Always a power of 2 */
  94. sector_t split_io;
  95. /*
  96. * These are automatically filled in by
  97. * dm_table_get_device.
  98. */
  99. struct io_restrictions limits;
  100. /* target specific data */
  101. void *private;
  102. /* Used to provide an error string from the ctr */
  103. char *error;
  104. };
  105. int dm_register_target(struct target_type *t);
  106. int dm_unregister_target(struct target_type *t);
  107. #endif /* _LINUX_DEVICE_MAPPER_H */