dm-dirty-log.h 3.9 KB

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