raid10.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _RAID10_H
  3. #define _RAID10_H
  4. /* Note: raid10_info.rdev can be set to NULL asynchronously by
  5. * raid10_remove_disk.
  6. * There are three safe ways to access raid10_info.rdev.
  7. * 1/ when holding mddev->reconfig_mutex
  8. * 2/ when resync/recovery/reshape is known to be happening - i.e. in code
  9. * that is called as part of performing resync/recovery/reshape.
  10. * 3/ while holding rcu_read_lock(), use rcu_dereference to get the pointer
  11. * and if it is non-NULL, increment rdev->nr_pending before dropping the
  12. * RCU lock.
  13. * When .rdev is set to NULL, the nr_pending count checked again and if it has
  14. * been incremented, the pointer is put back in .rdev.
  15. */
  16. struct raid10_info {
  17. struct md_rdev *rdev, *replacement;
  18. sector_t head_position;
  19. int recovery_disabled; /* matches
  20. * mddev->recovery_disabled
  21. * when we shouldn't try
  22. * recovering this device.
  23. */
  24. };
  25. struct r10conf {
  26. struct mddev *mddev;
  27. struct raid10_info *mirrors;
  28. struct raid10_info *mirrors_new, *mirrors_old;
  29. spinlock_t device_lock;
  30. /* geometry */
  31. struct geom {
  32. int raid_disks;
  33. int near_copies; /* number of copies laid out
  34. * raid0 style */
  35. int far_copies; /* number of copies laid out
  36. * at large strides across drives
  37. */
  38. int far_offset; /* far_copies are offset by 1
  39. * stripe instead of many
  40. */
  41. sector_t stride; /* distance between far copies.
  42. * This is size / far_copies unless
  43. * far_offset, in which case it is
  44. * 1 stripe.
  45. */
  46. int far_set_size; /* The number of devices in a set,
  47. * where a 'set' are devices that
  48. * contain far/offset copies of
  49. * each other.
  50. */
  51. int chunk_shift; /* shift from chunks to sectors */
  52. sector_t chunk_mask;
  53. } prev, geo;
  54. int copies; /* near_copies * far_copies.
  55. * must be <= raid_disks
  56. */
  57. sector_t dev_sectors; /* temp copy of
  58. * mddev->dev_sectors */
  59. sector_t reshape_progress;
  60. sector_t reshape_safe;
  61. unsigned long reshape_checkpoint;
  62. sector_t offset_diff;
  63. struct list_head retry_list;
  64. /* A separate list of r1bio which just need raid_end_bio_io called.
  65. * This mustn't happen for writes which had any errors if the superblock
  66. * needs to be written.
  67. */
  68. struct list_head bio_end_io_list;
  69. /* queue pending writes and submit them on unplug */
  70. struct bio_list pending_bio_list;
  71. int pending_count;
  72. spinlock_t resync_lock;
  73. atomic_t nr_pending;
  74. int nr_waiting;
  75. int nr_queued;
  76. int barrier;
  77. int array_freeze_pending;
  78. sector_t next_resync;
  79. int fullsync; /* set to 1 if a full sync is needed,
  80. * (fresh device added).
  81. * Cleared when a sync completes.
  82. */
  83. int have_replacement; /* There is at least one
  84. * replacement device.
  85. */
  86. wait_queue_head_t wait_barrier;
  87. mempool_t r10bio_pool;
  88. mempool_t r10buf_pool;
  89. struct page *tmppage;
  90. struct bio_set bio_split;
  91. /* When taking over an array from a different personality, we store
  92. * the new thread here until we fully activate the array.
  93. */
  94. struct md_thread *thread;
  95. /*
  96. * Keep track of cluster resync window to send to other nodes.
  97. */
  98. sector_t cluster_sync_low;
  99. sector_t cluster_sync_high;
  100. };
  101. /*
  102. * this is our 'private' RAID10 bio.
  103. *
  104. * it contains information about what kind of IO operations were started
  105. * for this RAID10 operation, and about their status:
  106. */
  107. struct r10bio {
  108. atomic_t remaining; /* 'have we finished' count,
  109. * used from IRQ handlers
  110. */
  111. sector_t sector; /* virtual sector number */
  112. int sectors;
  113. unsigned long state;
  114. struct mddev *mddev;
  115. /*
  116. * original bio going to /dev/mdx
  117. */
  118. struct bio *master_bio;
  119. /*
  120. * if the IO is in READ direction, then this is where we read
  121. */
  122. int read_slot;
  123. struct list_head retry_list;
  124. /*
  125. * if the IO is in WRITE direction, then multiple bios are used,
  126. * one for each copy.
  127. * When resyncing we also use one for each copy.
  128. * When reconstructing, we use 2 bios, one for read, one for write.
  129. * We choose the number when they are allocated.
  130. * We sometimes need an extra bio to write to the replacement.
  131. */
  132. struct r10dev {
  133. struct bio *bio;
  134. union {
  135. struct bio *repl_bio; /* used for resync and
  136. * writes */
  137. struct md_rdev *rdev; /* used for reads
  138. * (read_slot >= 0) */
  139. };
  140. sector_t addr;
  141. int devnum;
  142. } devs[0];
  143. };
  144. /* bits for r10bio.state */
  145. enum r10bio_state {
  146. R10BIO_Uptodate,
  147. R10BIO_IsSync,
  148. R10BIO_IsRecover,
  149. R10BIO_IsReshape,
  150. R10BIO_Degraded,
  151. /* Set ReadError on bios that experience a read error
  152. * so that raid10d knows what to do with them.
  153. */
  154. R10BIO_ReadError,
  155. /* If a write for this request means we can clear some
  156. * known-bad-block records, we set this flag.
  157. */
  158. R10BIO_MadeGood,
  159. R10BIO_WriteError,
  160. /* During a reshape we might be performing IO on the
  161. * 'previous' part of the array, in which case this
  162. * flag is set
  163. */
  164. R10BIO_Previous,
  165. /* failfast devices did receive failfast requests. */
  166. R10BIO_FailFast,
  167. };
  168. #endif