raid1.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /* A separate list of r1bio which just need raid_end_bio_io called.
  45. * This mustn't happen for writes which had any errors if the superblock
  46. * needs to be written.
  47. */
  48. struct list_head bio_end_io_list;
  49. /* queue pending writes to be submitted on unplug */
  50. struct bio_list pending_bio_list;
  51. int pending_count;
  52. /* for use when syncing mirrors:
  53. * We don't allow both normal IO and resync/recovery IO at
  54. * the same time - resync/recovery can only happen when there
  55. * is no other IO. So when either is active, the other has to wait.
  56. * See more details description in raid1.c near raise_barrier().
  57. */
  58. wait_queue_head_t wait_barrier;
  59. spinlock_t resync_lock;
  60. int nr_pending;
  61. int nr_waiting;
  62. int nr_queued;
  63. int barrier;
  64. /* Set to 1 if a full sync is needed, (fresh device added).
  65. * Cleared when a sync completes.
  66. */
  67. int fullsync;
  68. /* When the same as mddev->recovery_disabled we don't allow
  69. * recovery to be attempted as we expect a read error.
  70. */
  71. int recovery_disabled;
  72. /* poolinfo contains information about the content of the
  73. * mempools - it changes when the array grows or shrinks
  74. */
  75. struct pool_info *poolinfo;
  76. mempool_t *r1bio_pool;
  77. mempool_t *r1buf_pool;
  78. /* temporary buffer to synchronous IO when attempting to repair
  79. * a read error.
  80. */
  81. struct page *tmppage;
  82. /* When taking over an array from a different personality, we store
  83. * the new thread here until we fully activate the array.
  84. */
  85. struct md_thread *thread;
  86. };
  87. /*
  88. * this is our 'private' RAID1 bio.
  89. *
  90. * it contains information about what kind of IO operations were started
  91. * for this RAID1 operation, and about their status:
  92. */
  93. struct r1bio {
  94. atomic_t remaining; /* 'have we finished' count,
  95. * used from IRQ handlers
  96. */
  97. atomic_t behind_remaining; /* number of write-behind ios remaining
  98. * in this BehindIO request
  99. */
  100. sector_t sector;
  101. int sectors;
  102. unsigned long state;
  103. struct mddev *mddev;
  104. /*
  105. * original bio going to /dev/mdx
  106. */
  107. struct bio *master_bio;
  108. /*
  109. * if the IO is in READ direction, then this is where we read
  110. */
  111. int read_disk;
  112. struct list_head retry_list;
  113. /* Next two are only valid when R1BIO_BehindIO is set */
  114. struct bio_vec *behind_bvecs;
  115. int behind_page_count;
  116. /*
  117. * if the IO is in WRITE direction, then multiple bios are used.
  118. * We choose the number when they are allocated.
  119. */
  120. struct bio *bios[0];
  121. /* DO NOT PUT ANY NEW FIELDS HERE - bios array is contiguously alloced*/
  122. };
  123. /* when we get a read error on a read-only array, we redirect to another
  124. * device without failing the first device, or trying to over-write to
  125. * correct the read error. To keep track of bad blocks on a per-bio
  126. * level, we store IO_BLOCKED in the appropriate 'bios' pointer
  127. */
  128. #define IO_BLOCKED ((struct bio *)1)
  129. /* When we successfully write to a known bad-block, we need to remove the
  130. * bad-block marking which must be done from process context. So we record
  131. * the success by setting bios[n] to IO_MADE_GOOD
  132. */
  133. #define IO_MADE_GOOD ((struct bio *)2)
  134. #define BIO_SPECIAL(bio) ((unsigned long)bio <= 2)
  135. /* bits for r1bio.state */
  136. #define R1BIO_Uptodate 0
  137. #define R1BIO_IsSync 1
  138. #define R1BIO_Degraded 2
  139. #define R1BIO_BehindIO 3
  140. /* Set ReadError on bios that experience a readerror so that
  141. * raid1d knows what to do with them.
  142. */
  143. #define R1BIO_ReadError 4
  144. /* For write-behind requests, we call bi_end_io when
  145. * the last non-write-behind device completes, providing
  146. * any write was successful. Otherwise we call when
  147. * any write-behind write succeeds, otherwise we call
  148. * with failure when last write completes (and all failed).
  149. * Record that bi_end_io was called with this flag...
  150. */
  151. #define R1BIO_Returned 6
  152. /* If a write for this request means we can clear some
  153. * known-bad-block records, we set this flag
  154. */
  155. #define R1BIO_MadeGood 7
  156. #define R1BIO_WriteError 8
  157. extern int md_raid1_congested(struct mddev *mddev, int bits);
  158. #endif