raid1.h 5.5 KB

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