md-bitmap.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. typedef __u16 bitmap_counter_t;
  11. #define COUNTER_BITS 16
  12. #define COUNTER_BIT_SHIFT 4
  13. #define COUNTER_BYTE_SHIFT (COUNTER_BIT_SHIFT - 3)
  14. #define NEEDED_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 1)))
  15. #define RESYNC_MASK ((bitmap_counter_t) (1 << (COUNTER_BITS - 2)))
  16. #define COUNTER_MAX ((bitmap_counter_t) RESYNC_MASK - 1)
  17. /* use these for bitmap->flags and bitmap->sb->state bit-fields */
  18. enum bitmap_state {
  19. BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */
  20. BITMAP_WRITE_ERROR = 2, /* A write error has occurred */
  21. BITMAP_HOSTENDIAN =15,
  22. };
  23. /* the superblock at the front of the bitmap file -- little endian */
  24. typedef struct bitmap_super_s {
  25. __le32 magic; /* 0 BITMAP_MAGIC */
  26. __le32 version; /* 4 the bitmap major for now, could change... */
  27. __u8 uuid[16]; /* 8 128 bit uuid - must match md device uuid */
  28. __le64 events; /* 24 event counter for the bitmap (1)*/
  29. __le64 events_cleared;/*32 event counter when last bit cleared (2) */
  30. __le64 sync_size; /* 40 the size of the md device's sync range(3) */
  31. __le32 state; /* 48 bitmap state information */
  32. __le32 chunksize; /* 52 the bitmap chunk size in bytes */
  33. __le32 daemon_sleep; /* 56 seconds between disk flushes */
  34. __le32 write_behind; /* 60 number of outstanding write-behind writes */
  35. __le32 sectors_reserved; /* 64 number of 512-byte sectors that are
  36. * reserved for the bitmap. */
  37. __le32 nodes; /* 68 the maximum number of nodes in cluster. */
  38. __u8 cluster_name[64]; /* 72 cluster name to which this md belongs */
  39. __u8 pad[256 - 136]; /* set to zero */
  40. } bitmap_super_t;
  41. /* notes:
  42. * (1) This event counter is updated before the eventcounter in the md superblock
  43. * When a bitmap is loaded, it is only accepted if this event counter is equal
  44. * to, or one greater than, the event counter in the superblock.
  45. * (2) This event counter is updated when the other one is *if*and*only*if* the
  46. * array is not degraded. As bits are not cleared when the array is degraded,
  47. * this represents the last time that any bits were cleared.
  48. * If a device is being added that has an event count with this value or
  49. * higher, it is accepted as conforming to the bitmap.
  50. * (3)This is the number of sectors represented by the bitmap, and is the range that
  51. * resync happens across. For raid1 and raid5/6 it is the size of individual
  52. * devices. For raid10 it is the size of the array.
  53. */
  54. struct md_bitmap_stats {
  55. u64 events_cleared;
  56. int behind_writes;
  57. bool behind_wait;
  58. unsigned long missing_pages;
  59. unsigned long file_pages;
  60. unsigned long sync_size;
  61. unsigned long pages;
  62. struct file *file;
  63. };
  64. struct bitmap_operations {
  65. bool (*enabled)(struct mddev *mddev);
  66. int (*create)(struct mddev *mddev, int slot);
  67. int (*resize)(struct mddev *mddev, sector_t blocks, int chunksize,
  68. bool init);
  69. int (*load)(struct mddev *mddev);
  70. void (*destroy)(struct mddev *mddev);
  71. void (*flush)(struct mddev *mddev);
  72. void (*write_all)(struct mddev *mddev);
  73. void (*dirty_bits)(struct mddev *mddev, unsigned long s,
  74. unsigned long e);
  75. void (*unplug)(struct mddev *mddev, bool sync);
  76. void (*daemon_work)(struct mddev *mddev);
  77. void (*start_behind_write)(struct mddev *mddev);
  78. void (*end_behind_write)(struct mddev *mddev);
  79. void (*wait_behind_writes)(struct mddev *mddev);
  80. int (*startwrite)(struct mddev *mddev, sector_t offset,
  81. unsigned long sectors);
  82. void (*endwrite)(struct mddev *mddev, sector_t offset,
  83. unsigned long sectors);
  84. bool (*start_sync)(struct mddev *mddev, sector_t offset,
  85. sector_t *blocks, bool degraded);
  86. void (*end_sync)(struct mddev *mddev, sector_t offset, sector_t *blocks);
  87. void (*cond_end_sync)(struct mddev *mddev, sector_t sector, bool force);
  88. void (*close_sync)(struct mddev *mddev);
  89. void (*update_sb)(void *data);
  90. int (*get_stats)(void *data, struct md_bitmap_stats *stats);
  91. void (*sync_with_cluster)(struct mddev *mddev,
  92. sector_t old_lo, sector_t old_hi,
  93. sector_t new_lo, sector_t new_hi);
  94. void *(*get_from_slot)(struct mddev *mddev, int slot);
  95. int (*copy_from_slot)(struct mddev *mddev, int slot, sector_t *lo,
  96. sector_t *hi, bool clear_bits);
  97. void (*set_pages)(void *data, unsigned long pages);
  98. void (*free)(void *data);
  99. };
  100. /* the bitmap API */
  101. void mddev_set_bitmap_ops(struct mddev *mddev);
  102. #endif