raid1.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_pending;
  78. atomic_t *nr_waiting;
  79. atomic_t *nr_queued;
  80. atomic_t *barrier;
  81. int array_frozen;
  82. /* Set to 1 if a full sync is needed, (fresh device added).
  83. * Cleared when a sync completes.
  84. */
  85. int fullsync;
  86. /* When the same as mddev->recovery_disabled we don't allow
  87. * recovery to be attempted as we expect a read error.
  88. */
  89. int recovery_disabled;
  90. /* poolinfo contains information about the content of the
  91. * mempools - it changes when the array grows or shrinks
  92. */
  93. struct pool_info *poolinfo;
  94. mempool_t *r1bio_pool;
  95. mempool_t *r1buf_pool;
  96. /* temporary buffer to synchronous IO when attempting to repair
  97. * a read error.
  98. */
  99. struct page *tmppage;
  100. /* When taking over an array from a different personality, we store
  101. * the new thread here until we fully activate the array.
  102. */
  103. struct md_thread *thread;
  104. /* Keep track of cluster resync window to send to other
  105. * nodes.
  106. */
  107. sector_t cluster_sync_low;
  108. sector_t cluster_sync_high;
  109. };
  110. /*
  111. * this is our 'private' RAID1 bio.
  112. *
  113. * it contains information about what kind of IO operations were started
  114. * for this RAID1 operation, and about their status:
  115. */
  116. struct r1bio {
  117. atomic_t remaining; /* 'have we finished' count,
  118. * used from IRQ handlers
  119. */
  120. atomic_t behind_remaining; /* number of write-behind ios remaining
  121. * in this BehindIO request
  122. */
  123. sector_t sector;
  124. int sectors;
  125. unsigned long state;
  126. struct mddev *mddev;
  127. /*
  128. * original bio going to /dev/mdx
  129. */
  130. struct bio *master_bio;
  131. /*
  132. * if the IO is in READ direction, then this is where we read
  133. */
  134. int read_disk;
  135. struct list_head retry_list;
  136. /* Next two are only valid when R1BIO_BehindIO is set */
  137. struct bio_vec *behind_bvecs;
  138. int behind_page_count;
  139. /*
  140. * if the IO is in WRITE direction, then multiple bios are used.
  141. * We choose the number when they are allocated.
  142. */
  143. struct bio *bios[0];
  144. /* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/
  145. };
  146. /* bits for r1bio.state */
  147. enum r1bio_state {
  148. R1BIO_Uptodate,
  149. R1BIO_IsSync,
  150. R1BIO_Degraded,
  151. R1BIO_BehindIO,
  152. /* Set ReadError on bios that experience a readerror so that
  153. * raid1d knows what to do with them.
  154. */
  155. R1BIO_ReadError,
  156. /* For write-behind requests, we call bi_end_io when
  157. * the last non-write-behind device completes, providing
  158. * any write was successful. Otherwise we call when
  159. * any write-behind write succeeds, otherwise we call
  160. * with failure when last write completes (and all failed).
  161. * Record that bi_end_io was called with this flag...
  162. */
  163. R1BIO_Returned,
  164. /* If a write for this request means we can clear some
  165. * known-bad-block records, we set this flag
  166. */
  167. R1BIO_MadeGood,
  168. R1BIO_WriteError,
  169. R1BIO_FailFast,
  170. };
  171. static inline int sector_to_idx(sector_t sector)
  172. {
  173. return hash_long(sector >> BARRIER_UNIT_SECTOR_BITS,
  174. BARRIER_BUCKETS_NR_BITS);
  175. }
  176. #endif