raid1.h 5.1 KB

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