md-bitmap.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * bitmap.h: Copyright (C) Peter T. Breuer (ptb@ot.uc3m.es) 2003
  4. *
  5. * additions: Copyright (C) 2003-2004, Paul Clements, SteelEye Technology, Inc.
  6. */
  7. #ifndef BITMAP_H
  8. #define BITMAP_H 1
  9. #define BITMAP_MAGIC 0x6d746962
  10. /*
  11. * version 3 is host-endian order, this is deprecated and not used for new
  12. * array
  13. */
  14. #define BITMAP_MAJOR_LO 3
  15. #define BITMAP_MAJOR_HOSTENDIAN 3
  16. /* version 4 is little-endian order, the default value */
  17. #define BITMAP_MAJOR_HI 4
  18. /* version 5 is only used for cluster */
  19. #define BITMAP_MAJOR_CLUSTERED 5
  20. /* version 6 is only used for lockless bitmap */
  21. #define BITMAP_MAJOR_LOCKLESS 6
  22. /* use these for bitmap->flags and bitmap->sb->state bit-fields */
  23. enum bitmap_state {
  24. BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */
  25. BITMAP_WRITE_ERROR = 2, /* A write error has occurred */
  26. BITMAP_FIRST_USE = 3, /* llbitmap is just created */
  27. BITMAP_CLEAN = 4, /* llbitmap is created with assume_clean */
  28. BITMAP_DAEMON_BUSY = 5, /* llbitmap daemon is not finished after daemon_sleep */
  29. BITMAP_HOSTENDIAN =15,
  30. };
  31. /* the superblock at the front of the bitmap file -- little endian */
  32. typedef struct bitmap_super_s {
  33. __le32 magic; /* 0 BITMAP_MAGIC */
  34. __le32 version; /* 4 the bitmap major for now, could change... */
  35. __u8 uuid[16]; /* 8 128 bit uuid - must match md device uuid */
  36. __le64 events; /* 24 event counter for the bitmap (1)*/
  37. __le64 events_cleared;/*32 event counter when last bit cleared (2) */
  38. __le64 sync_size; /* 40 the size of the md device's sync range(3) */
  39. __le32 state; /* 48 bitmap state information */
  40. __le32 chunksize; /* 52 the bitmap chunk size in bytes */
  41. __le32 daemon_sleep; /* 56 seconds between disk flushes */
  42. __le32 write_behind; /* 60 number of outstanding write-behind writes */
  43. __le32 sectors_reserved; /* 64 number of 512-byte sectors that are
  44. * reserved for the bitmap. */
  45. __le32 nodes; /* 68 the maximum number of nodes in cluster. */
  46. __u8 cluster_name[64]; /* 72 cluster name to which this md belongs */
  47. __u8 pad[256 - 136]; /* set to zero */
  48. } bitmap_super_t;
  49. /* notes:
  50. * (1) This event counter is updated before the eventcounter in the md superblock
  51. * When a bitmap is loaded, it is only accepted if this event counter is equal
  52. * to, or one greater than, the event counter in the superblock.
  53. * (2) This event counter is updated when the other one is *if*and*only*if* the
  54. * array is not degraded. As bits are not cleared when the array is degraded,
  55. * this represents the last time that any bits were cleared.
  56. * If a device is being added that has an event count with this value or
  57. * higher, it is accepted as conforming to the bitmap.
  58. * (3)This is the number of sectors represented by the bitmap, and is the range that
  59. * resync happens across. For raid1 and raid5/6 it is the size of individual
  60. * devices. For raid10 it is the size of the array.
  61. */
  62. struct md_bitmap_stats {
  63. u64 events_cleared;
  64. int behind_writes;
  65. bool behind_wait;
  66. unsigned long missing_pages;
  67. unsigned long file_pages;
  68. unsigned long sync_size;
  69. unsigned long pages;
  70. struct file *file;
  71. };
  72. typedef void (md_bitmap_fn)(struct mddev *mddev, sector_t offset,
  73. unsigned long sectors);
  74. struct bitmap_operations {
  75. struct md_submodule_head head;
  76. bool (*enabled)(void *data, bool flush);
  77. int (*create)(struct mddev *mddev);
  78. int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize);
  79. int (*load)(struct mddev *mddev);
  80. void (*destroy)(struct mddev *mddev);
  81. void (*flush)(struct mddev *mddev);
  82. void (*write_all)(struct mddev *mddev);
  83. void (*dirty_bits)(struct mddev *mddev, unsigned long s,
  84. unsigned long e);
  85. void (*unplug)(struct mddev *mddev, bool sync);
  86. void (*daemon_work)(struct mddev *mddev);
  87. void (*start_behind_write)(struct mddev *mddev);
  88. void (*end_behind_write)(struct mddev *mddev);
  89. void (*wait_behind_writes)(struct mddev *mddev);
  90. md_bitmap_fn *start_write;
  91. md_bitmap_fn *end_write;
  92. md_bitmap_fn *start_discard;
  93. md_bitmap_fn *end_discard;
  94. sector_t (*skip_sync_blocks)(struct mddev *mddev, sector_t offset);
  95. bool (*blocks_synced)(struct mddev *mddev, sector_t offset);
  96. bool (*start_sync)(struct mddev *mddev, sector_t offset,
  97. sector_t *blocks, bool degraded);
  98. void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);
  99. void (*cond_end_sync)(struct mddev *mddev, sector_t sector, bool force);
  100. void (*close_sync)(struct mddev *mddev);
  101. void (*update_sb)(void *data);
  102. int (*get_stats)(void *data, struct md_bitmap_stats *stats);
  103. void (*sync_with_cluster)(struct mddev *mddev,
  104. sector_t old_lo, sector_t old_hi,
  105. sector_t new_lo, sector_t new_hi);
  106. void *(*get_from_slot)(struct mddev *mddev, int slot);
  107. int (*copy_from_slot)(struct mddev *mddev, int slot, sector_t *lo,
  108. sector_t *hi, bool clear_bits);
  109. void (*set_pages)(void *data, unsigned long pages);
  110. void (*free)(void *data);
  111. struct attribute_group *group;
  112. };
  113. /* the bitmap API */
  114. static inline bool md_bitmap_registered(struct mddev *mddev)
  115. {
  116. return mddev->bitmap_ops != NULL;
  117. }
  118. static inline bool md_bitmap_enabled(struct mddev *mddev, bool flush)
  119. {
  120. /* bitmap_ops must be registered before creating bitmap. */
  121. if (!md_bitmap_registered(mddev))
  122. return false;
  123. if (!mddev->bitmap)
  124. return false;
  125. return mddev->bitmap_ops->enabled(mddev->bitmap, flush);
  126. }
  127. static inline bool md_bitmap_start_sync(struct mddev *mddev, sector_t offset,
  128. sector_t *blocks, bool degraded)
  129. {
  130. /* always resync if no bitmap */
  131. if (!md_bitmap_enabled(mddev, false)) {
  132. *blocks = 1024;
  133. return true;
  134. }
  135. return mddev->bitmap_ops->start_sync(mddev, offset, blocks, degraded);
  136. }
  137. static inline void md_bitmap_end_sync(struct mddev *mddev, sector_t offset,
  138. sector_t *blocks)
  139. {
  140. if (!md_bitmap_enabled(mddev, false)) {
  141. *blocks = 1024;
  142. return;
  143. }
  144. mddev->bitmap_ops->end_sync(mddev, offset, blocks);
  145. }
  146. #ifdef CONFIG_MD_BITMAP
  147. int md_bitmap_init(void);
  148. void md_bitmap_exit(void);
  149. #else
  150. static inline int md_bitmap_init(void)
  151. {
  152. return 0;
  153. }
  154. static inline void md_bitmap_exit(void)
  155. {
  156. }
  157. #endif
  158. #ifdef CONFIG_MD_LLBITMAP
  159. int md_llbitmap_init(void);
  160. void md_llbitmap_exit(void);
  161. #else
  162. static inline int md_llbitmap_init(void)
  163. {
  164. return 0;
  165. }
  166. static inline void md_llbitmap_exit(void)
  167. {
  168. }
  169. #endif
  170. #endif