raid5-log.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _RAID5_LOG_H
  3. #define _RAID5_LOG_H
  4. extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
  5. extern void r5l_exit_log(struct r5conf *conf);
  6. extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
  7. extern void r5l_write_stripe_run(struct r5l_log *log);
  8. extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
  9. extern void r5l_stripe_write_finished(struct stripe_head *sh);
  10. extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
  11. extern void r5l_quiesce(struct r5l_log *log, int quiesce);
  12. extern bool r5l_log_disk_error(struct r5conf *conf);
  13. extern bool r5c_is_writeback(struct r5l_log *log);
  14. extern int
  15. r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
  16. struct stripe_head_state *s, int disks);
  17. extern void
  18. r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh,
  19. struct stripe_head_state *s);
  20. extern void r5c_release_extra_page(struct stripe_head *sh);
  21. extern void r5c_use_extra_page(struct stripe_head *sh);
  22. extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
  23. extern void r5c_handle_cached_data_endio(struct r5conf *conf,
  24. struct stripe_head *sh, int disks);
  25. extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh);
  26. extern void r5c_make_stripe_write_out(struct stripe_head *sh);
  27. extern void r5c_flush_cache(struct r5conf *conf, int num);
  28. extern void r5c_check_stripe_cache_usage(struct r5conf *conf);
  29. extern void r5c_check_cached_full_stripe(struct r5conf *conf);
  30. extern struct md_sysfs_entry r5c_journal_mode;
  31. extern void r5c_update_on_rdev_error(struct mddev *mddev,
  32. struct md_rdev *rdev);
  33. extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect);
  34. extern int r5l_start(struct r5l_log *log);
  35. extern struct dma_async_tx_descriptor *
  36. ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu,
  37. struct dma_async_tx_descriptor *tx);
  38. extern int ppl_init_log(struct r5conf *conf);
  39. extern void ppl_exit_log(struct r5conf *conf);
  40. extern int ppl_write_stripe(struct r5conf *conf, struct stripe_head *sh);
  41. extern void ppl_write_stripe_run(struct r5conf *conf);
  42. extern void ppl_stripe_write_finished(struct stripe_head *sh);
  43. extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add);
  44. extern void ppl_quiesce(struct r5conf *conf, int quiesce);
  45. extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio);
  46. extern struct md_sysfs_entry ppl_write_hint;
  47. static inline bool raid5_has_log(struct r5conf *conf)
  48. {
  49. return test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
  50. }
  51. static inline bool raid5_has_ppl(struct r5conf *conf)
  52. {
  53. return test_bit(MD_HAS_PPL, &conf->mddev->flags);
  54. }
  55. static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s)
  56. {
  57. struct r5conf *conf = sh->raid_conf;
  58. if (conf->log) {
  59. if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) {
  60. /* writing out phase */
  61. if (s->waiting_extra_page)
  62. return 0;
  63. return r5l_write_stripe(conf->log, sh);
  64. } else if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) {
  65. /* caching phase */
  66. return r5c_cache_data(conf->log, sh);
  67. }
  68. } else if (raid5_has_ppl(conf)) {
  69. return ppl_write_stripe(conf, sh);
  70. }
  71. return -EAGAIN;
  72. }
  73. static inline void log_stripe_write_finished(struct stripe_head *sh)
  74. {
  75. struct r5conf *conf = sh->raid_conf;
  76. if (conf->log)
  77. r5l_stripe_write_finished(sh);
  78. else if (raid5_has_ppl(conf))
  79. ppl_stripe_write_finished(sh);
  80. }
  81. static inline void log_write_stripe_run(struct r5conf *conf)
  82. {
  83. if (conf->log)
  84. r5l_write_stripe_run(conf->log);
  85. else if (raid5_has_ppl(conf))
  86. ppl_write_stripe_run(conf);
  87. }
  88. static inline void log_flush_stripe_to_raid(struct r5conf *conf)
  89. {
  90. if (conf->log)
  91. r5l_flush_stripe_to_raid(conf->log);
  92. else if (raid5_has_ppl(conf))
  93. ppl_write_stripe_run(conf);
  94. }
  95. static inline int log_handle_flush_request(struct r5conf *conf, struct bio *bio)
  96. {
  97. int ret = -ENODEV;
  98. if (conf->log)
  99. ret = r5l_handle_flush_request(conf->log, bio);
  100. else if (raid5_has_ppl(conf))
  101. ret = ppl_handle_flush_request(conf->log, bio);
  102. return ret;
  103. }
  104. static inline void log_quiesce(struct r5conf *conf, int quiesce)
  105. {
  106. if (conf->log)
  107. r5l_quiesce(conf->log, quiesce);
  108. else if (raid5_has_ppl(conf))
  109. ppl_quiesce(conf, quiesce);
  110. }
  111. static inline void log_exit(struct r5conf *conf)
  112. {
  113. if (conf->log)
  114. r5l_exit_log(conf);
  115. else if (raid5_has_ppl(conf))
  116. ppl_exit_log(conf);
  117. }
  118. static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev,
  119. bool ppl)
  120. {
  121. if (journal_dev)
  122. return r5l_init_log(conf, journal_dev);
  123. else if (ppl)
  124. return ppl_init_log(conf);
  125. return 0;
  126. }
  127. static inline int log_modify(struct r5conf *conf, struct md_rdev *rdev, bool add)
  128. {
  129. if (raid5_has_ppl(conf))
  130. return ppl_modify_log(conf, rdev, add);
  131. return 0;
  132. }
  133. #endif