raid1.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #ifndef _RAID1_H
  2. #define _RAID1_H
  3. /*
  4. * each barrier unit size is 64MB fow now
  5. * note: it must be larger than RESYNC_DEPTH
  6. */
  7. #define BARRIER_UNIT_SECTOR_BITS 17
  8. #define BARRIER_UNIT_SECTOR_SIZE (1<<17)
  9. /*
  10. * In struct r1conf, the following members are related to I/O barrier
  11. * buckets,
  12. * atomic_t *nr_pending;
  13. * atomic_t *nr_waiting;
  14. * atomic_t *nr_queued;
  15. * atomic_t *barrier;
  16. * Each of them points to array of atomic_t variables, each array is
  17. * designed to have BARRIER_BUCKETS_NR elements and occupy a single
  18. * memory page. The data width of atomic_t variables is 4 bytes, equal
  19. * to 1<<(ilog2(sizeof(atomic_t))), BARRIER_BUCKETS_NR_BITS is defined
  20. * as (PAGE_SHIFT - ilog2(sizeof(int))) to make sure an array of
  21. * atomic_t variables with BARRIER_BUCKETS_NR elements just exactly
  22. * occupies a single memory page.
  23. */
  24. #define BARRIER_BUCKETS_NR_BITS (PAGE_SHIFT - ilog2(sizeof(atomic_t)))
  25. #define BARRIER_BUCKETS_NR (1<<BARRIER_BUCKETS_NR_BITS)
  26. struct raid1_info {
  27. struct md_rdev *rdev;
  28. sector_t head_position;
  29. /* When choose the best device for a read (read_balance())
  30. * we try to keep sequential reads one the same device
  31. */
  32. sector_t next_seq_sect;
  33. sector_t seq_start;
  34. };
  35. /*
  36. * memory pools need a pointer to the mddev, so they can force an unplug
  37. * when memory is tight, and a count of the number of drives that the
  38. * pool was allocated for, so they know how much to allocate and free.
  39. * mddev->raid_disks cannot be used, as it can change while a pool is active
  40. * These two datums are stored in a kmalloced struct.
  41. * The 'raid_disks' here is twice the raid_disks in r1conf.
  42. * This allows space for each 'real' device can have a replacement in the
  43. * second half of the array.
  44. */
  45. struct pool_info {
  46. struct mddev *mddev;
  47. int raid_disks;
  48. };
  49. struct r1conf {
  50. struct mddev *mddev;
  51. struct raid1_info *mirrors; /* twice 'raid_disks' to
  52. * allow for replacements.
  53. */
  54. int raid_disks;
  55. spinlock_t device_lock;
  56. /* list of 'struct r1bio' that need to be processed by raid1d,
  57. * whether to retry a read, writeout a resync or recovery
  58. * block, or anything else.
  59. */
  60. struct list_head retry_list;
  61. /* A separate list of r1bio which just need raid_end_bio_io called.
  62. * This mustn't happen for writes which had any errors if the superblock
  63. * needs to be written.
  64. */
  65. struct list_head bio_end_io_list;
  66. /* queue pending writes to be submitted on unplug */
  67. struct bio_list pending_bio_list;
  68. int pending_count;
  69. /* for use when syncing mirrors:
  70. * We don't allow both normal IO and resync/recovery IO at
  71. * the same time - resync/recovery can only happen when there
  72. * is no other IO. So when either is active, the other has to wait.
  73. * See more details description in raid1.c near raise_barrier().
  74. */
  75. wait_queue_head_t wait_barrier;
  76. spinlock_t resync_lock;
  77. atomic_t nr_sync_pending;
  78. atomic_t *nr_pending;
  79. atomic_t *nr_waiting;
  80. atomic_t *nr_queued;
  81. atomic_t *barrier;
  82. int array_frozen;
  83. /* Set to 1 if a full sync is needed, (fresh device added).
  84. * Cleared when a sync completes.
  85. */
  86. int fullsync;
  87. /* When the same as mddev->recovery_disabled we don't allow
  88. * recovery to be attempted as we expect a read error.
  89. */
  90. int recovery_disabled;
  91. /* poolinfo contains information about the content of the
  92. * mempools - it changes when the array grows or shrinks
  93. */
  94. struct pool_info *poolinfo;
  95. mempool_t *r1bio_pool;
  96. mempool_t *r1buf_pool;
  97. struct bio_set *bio_split;
  98. /* temporary buffer to synchronous IO when attempting to repair
  99. * a read error.
  100. */
  101. struct page *tmppage;
  102. /* When taking over an array from a different personality, we store
  103. * the new thread here until we fully activate the array.
  104. */
  105. struct md_thread *thread;
  106. /* Keep track of cluster resync window to send to other
  107. * nodes.
  108. */
  109. sector_t cluster_sync_low;
  110. sector_t cluster_sync_high;
  111. };
  112. /*
  113. * this is our 'private' RAID1 bio.
  114. *
  115. * it contains information about what kind of IO operations were started
  116. * for this RAID1 operation, and about their status:
  117. */
  118. struct r1bio {
  119. atomic_t remaining; /* 'have we finished' count,
  120. * used from IRQ handlers
  121. */
  122. atomic_t behind_remaining; /* number of write-behind ios remaining
  123. * in this BehindIO request
  124. */
  125. sector_t sector;
  126. int sectors;
  127. unsigned long state;
  128. struct mddev *mddev;
  129. /*
  130. * original bio going to /dev/mdx
  131. */
  132. struct bio *master_bio;
  133. /*
  134. * if the IO is in READ direction, then this is where we read
  135. */
  136. int read_disk;
  137. struct list_head retry_list;
  138. /*
  139. * When R1BIO_BehindIO is set, we store pages for write behind
  140. * in behind_master_bio.
  141. */
  142. struct bio *behind_master_bio;
  143. /*
  144. * if the IO is in WRITE direction, then multiple bios are used.
  145. * We choose the number when they are allocated.
  146. */
  147. struct bio *bios[0];
  148. /* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/
  149. };
  150. /* bits for r1bio.state */
  151. enum r1bio_state {
  152. R1BIO_Uptodate,
  153. R1BIO_IsSync,
  154. R1BIO_Degraded,
  155. R1BIO_BehindIO,
  156. /* Set ReadError on bios that experience a readerror so that
  157. * raid1d knows what to do with them.
  158. */
  159. R1BIO_ReadError,
  160. /* For write-behind requests, we call bi_end_io when
  161. * the last non-write-behind device completes, providing
  162. * any write was successful. Otherwise we call when
  163. * any write-behind write succeeds, otherwise we call
  164. * with failure when last write completes (and all failed).
  165. * Record that bi_end_io was called with this flag...
  166. */
  167. R1BIO_Returned,
  168. /* If a write for this request means we can clear some
  169. * known-bad-block records, we set this flag
  170. */
  171. R1BIO_MadeGood,
  172. R1BIO_WriteError,
  173. R1BIO_FailFast,
  174. };
  175. static inline int sector_to_idx(sector_t sector)
  176. {
  177. return hash_long(sector >> BARRIER_UNIT_SECTOR_BITS,
  178. BARRIER_BUCKETS_NR_BITS);
  179. }
  180. #endif