raid5-log.h 4.4 KB

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