raid1.h 5.0 KB

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