dm-dirty-log.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (C) 2003 Sistina Software
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * Device-Mapper dirty region log.
  6. *
  7. * This file is released under the LGPL.
  8. */
  9. #ifndef _LINUX_DM_DIRTY_LOG
  10. #define _LINUX_DM_DIRTY_LOG
  11. #ifdef __KERNEL__
  12. #include <linux/types.h>
  13. #include <linux/device-mapper.h>
  14. typedef sector_t region_t;
  15. struct dm_dirty_log_type;
  16. struct dm_dirty_log {
  17. struct dm_dirty_log_type *type;
  18. int (*flush_callback_fn)(struct dm_target *ti);
  19. void *context;
  20. };
  21. struct dm_dirty_log_type {
  22. const char *name;
  23. struct module *module;
  24. /* For internal device-mapper use */
  25. struct list_head list;
  26. int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
  27. unsigned argc, char **argv);
  28. void (*dtr)(struct dm_dirty_log *log);
  29. /*
  30. * There are times when we don't want the log to touch
  31. * the disk.
  32. */
  33. int (*presuspend)(struct dm_dirty_log *log);
  34. int (*postsuspend)(struct dm_dirty_log *log);
  35. int (*resume)(struct dm_dirty_log *log);
  36. /*
  37. * Retrieves the smallest size of region that the log can
  38. * deal with.
  39. */
  40. uint32_t (*get_region_size)(struct dm_dirty_log *log);
  41. /*
  42. * A predicate to say whether a region is clean or not.
  43. * May block.
  44. */
  45. int (*is_clean)(struct dm_dirty_log *log, region_t region);
  46. /*
  47. * Returns: 0, 1, -EWOULDBLOCK, < 0
  48. *
  49. * A predicate function to check the area given by
  50. * [sector, sector + len) is in sync.
  51. *
  52. * If -EWOULDBLOCK is returned the state of the region is
  53. * unknown, typically this will result in a read being
  54. * passed to a daemon to deal with, since a daemon is
  55. * allowed to block.
  56. */
  57. int (*in_sync)(struct dm_dirty_log *log, region_t region,
  58. int can_block);
  59. /*
  60. * Flush the current log state (eg, to disk). This
  61. * function may block.
  62. */
  63. int (*flush)(struct dm_dirty_log *log);
  64. /*
  65. * Mark an area as clean or dirty. These functions may
  66. * block, though for performance reasons blocking should
  67. * be extremely rare (eg, allocating another chunk of
  68. * memory for some reason).
  69. */
  70. void (*mark_region)(struct dm_dirty_log *log, region_t region);
  71. void (*clear_region)(struct dm_dirty_log *log, region_t region);
  72. /*
  73. * Returns: <0 (error), 0 (no region), 1 (region)
  74. *
  75. * The mirrord will need perform recovery on regions of
  76. * the mirror that are in the NOSYNC state. This
  77. * function asks the log to tell the caller about the
  78. * next region that this machine should recover.
  79. *
  80. * Do not confuse this function with 'in_sync()', one
  81. * tells you if an area is synchronised, the other
  82. * assigns recovery work.
  83. */
  84. int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
  85. /*
  86. * This notifies the log that the resync status of a region
  87. * has changed. It also clears the region from the recovering
  88. * list (if present).
  89. */
  90. void (*set_region_sync)(struct dm_dirty_log *log,
  91. region_t region, int in_sync);
  92. /*
  93. * Returns the number of regions that are in sync.
  94. */
  95. region_t (*get_sync_count)(struct dm_dirty_log *log);
  96. /*
  97. * Support function for mirror status requests.
  98. */
  99. int (*status)(struct dm_dirty_log *log, status_type_t status_type,
  100. char *result, unsigned maxlen);
  101. /*
  102. * is_remote_recovering is necessary for cluster mirroring. It provides
  103. * a way to detect recovery on another node, so we aren't writing
  104. * concurrently. This function is likely to block (when a cluster log
  105. * is used).
  106. *
  107. * Returns: 0, 1
  108. */
  109. int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
  110. };
  111. int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
  112. int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
  113. /*
  114. * Make sure you use these two functions, rather than calling
  115. * type->constructor/destructor() directly.
  116. */
  117. struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
  118. struct dm_target *ti,
  119. int (*flush_callback_fn)(struct dm_target *ti),
  120. unsigned argc, char **argv);
  121. void dm_dirty_log_destroy(struct dm_dirty_log *log);
  122. #endif /* __KERNEL__ */
  123. #endif /* _LINUX_DM_DIRTY_LOG_H */