dm-log.h 3.3 KB

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