raid10.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #ifndef _RAID10_H
  2. #define _RAID10_H
  3. struct mirror_info {
  4. struct md_rdev *rdev, *replacement;
  5. sector_t head_position;
  6. int recovery_disabled; /* matches
  7. * mddev->recovery_disabled
  8. * when we shouldn't try
  9. * recovering this device.
  10. */
  11. };
  12. struct r10conf {
  13. struct mddev *mddev;
  14. struct mirror_info *mirrors;
  15. int raid_disks;
  16. spinlock_t device_lock;
  17. /* geometry */
  18. int near_copies; /* number of copies laid out
  19. * raid0 style */
  20. int far_copies; /* number of copies laid out
  21. * at large strides across drives
  22. */
  23. int far_offset; /* far_copies are offset by 1
  24. * stripe instead of many
  25. */
  26. int copies; /* near_copies * far_copies.
  27. * must be <= raid_disks
  28. */
  29. sector_t stride; /* distance between far copies.
  30. * This is size / far_copies unless
  31. * far_offset, in which case it is
  32. * 1 stripe.
  33. */
  34. sector_t dev_sectors; /* temp copy of
  35. * mddev->dev_sectors */
  36. int chunk_shift; /* shift from chunks to sectors */
  37. sector_t chunk_mask;
  38. struct list_head retry_list;
  39. /* queue pending writes and submit them on unplug */
  40. struct bio_list pending_bio_list;
  41. int pending_count;
  42. spinlock_t resync_lock;
  43. int nr_pending;
  44. int nr_waiting;
  45. int nr_queued;
  46. int barrier;
  47. sector_t next_resync;
  48. int fullsync; /* set to 1 if a full sync is needed,
  49. * (fresh device added).
  50. * Cleared when a sync completes.
  51. */
  52. int have_replacement; /* There is at least one
  53. * replacement device.
  54. */
  55. wait_queue_head_t wait_barrier;
  56. mempool_t *r10bio_pool;
  57. mempool_t *r10buf_pool;
  58. struct page *tmppage;
  59. /* When taking over an array from a different personality, we store
  60. * the new thread here until we fully activate the array.
  61. */
  62. struct md_thread *thread;
  63. };
  64. /*
  65. * this is our 'private' RAID10 bio.
  66. *
  67. * it contains information about what kind of IO operations were started
  68. * for this RAID10 operation, and about their status:
  69. */
  70. struct r10bio {
  71. atomic_t remaining; /* 'have we finished' count,
  72. * used from IRQ handlers
  73. */
  74. sector_t sector; /* virtual sector number */
  75. int sectors;
  76. unsigned long state;
  77. struct mddev *mddev;
  78. /*
  79. * original bio going to /dev/mdx
  80. */
  81. struct bio *master_bio;
  82. /*
  83. * if the IO is in READ direction, then this is where we read
  84. */
  85. int read_slot;
  86. struct list_head retry_list;
  87. /*
  88. * if the IO is in WRITE direction, then multiple bios are used,
  89. * one for each copy.
  90. * When resyncing we also use one for each copy.
  91. * When reconstructing, we use 2 bios, one for read, one for write.
  92. * We choose the number when they are allocated.
  93. * We sometimes need an extra bio to write to the replacement.
  94. */
  95. struct {
  96. struct bio *bio;
  97. union {
  98. struct bio *repl_bio; /* used for resync and
  99. * writes */
  100. struct md_rdev *rdev; /* used for reads
  101. * (read_slot >= 0) */
  102. };
  103. sector_t addr;
  104. int devnum;
  105. } devs[0];
  106. };
  107. /* when we get a read error on a read-only array, we redirect to another
  108. * device without failing the first device, or trying to over-write to
  109. * correct the read error. To keep track of bad blocks on a per-bio
  110. * level, we store IO_BLOCKED in the appropriate 'bios' pointer
  111. */
  112. #define IO_BLOCKED ((struct bio*)1)
  113. /* When we successfully write to a known bad-block, we need to remove the
  114. * bad-block marking which must be done from process context. So we record
  115. * the success by setting devs[n].bio to IO_MADE_GOOD
  116. */
  117. #define IO_MADE_GOOD ((struct bio *)2)
  118. #define BIO_SPECIAL(bio) ((unsigned long)bio <= 2)
  119. /* bits for r10bio.state */
  120. enum r10bio_state {
  121. R10BIO_Uptodate,
  122. R10BIO_IsSync,
  123. R10BIO_IsRecover,
  124. R10BIO_Degraded,
  125. /* Set ReadError on bios that experience a read error
  126. * so that raid10d knows what to do with them.
  127. */
  128. R10BIO_ReadError,
  129. /* If a write for this request means we can clear some
  130. * known-bad-block records, we set this flag.
  131. */
  132. R10BIO_MadeGood,
  133. R10BIO_WriteError,
  134. };
  135. #endif