raid1.h 4.4 KB

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