raid1.h 4.9 KB

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