raid10.h 5.0 KB

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