blob: bfb81140706140a53af24ccf90420e6cc107cef1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Artur Paszkiewiczff875732017-03-09 09:59:58 +01002#ifndef _RAID5_LOG_H
3#define _RAID5_LOG_H
4
5extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
6extern void r5l_exit_log(struct r5conf *conf);
7extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
8extern void r5l_write_stripe_run(struct r5l_log *log);
9extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
10extern void r5l_stripe_write_finished(struct stripe_head *sh);
11extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
NeilBrownb03e0cc2017-10-19 12:49:15 +110012extern void r5l_quiesce(struct r5l_log *log, int quiesce);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010013extern bool r5l_log_disk_error(struct r5conf *conf);
14extern bool r5c_is_writeback(struct r5l_log *log);
15extern int
16r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
17 struct stripe_head_state *s, int disks);
18extern void
19r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh,
20 struct stripe_head_state *s);
21extern void r5c_release_extra_page(struct stripe_head *sh);
22extern void r5c_use_extra_page(struct stripe_head *sh);
23extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
24extern void r5c_handle_cached_data_endio(struct r5conf *conf,
NeilBrownbd83d0a2017-03-15 14:05:12 +110025 struct stripe_head *sh, int disks);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010026extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh);
27extern void r5c_make_stripe_write_out(struct stripe_head *sh);
28extern void r5c_flush_cache(struct r5conf *conf, int num);
29extern void r5c_check_stripe_cache_usage(struct r5conf *conf);
30extern void r5c_check_cached_full_stripe(struct r5conf *conf);
31extern struct md_sysfs_entry r5c_journal_mode;
Song Liu70d466f2017-05-11 15:28:28 -070032extern void r5c_update_on_rdev_error(struct mddev *mddev,
33 struct md_rdev *rdev);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010034extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect);
Song Liud5d885f2017-11-19 22:17:01 -080035extern int r5l_start(struct r5l_log *log);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010036
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010037extern struct dma_async_tx_descriptor *
38ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu,
39 struct dma_async_tx_descriptor *tx);
40extern int ppl_init_log(struct r5conf *conf);
41extern void ppl_exit_log(struct r5conf *conf);
42extern int ppl_write_stripe(struct r5conf *conf, struct stripe_head *sh);
43extern void ppl_write_stripe_run(struct r5conf *conf);
44extern void ppl_stripe_write_finished(struct stripe_head *sh);
Artur Paszkiewicz6358c232017-03-09 10:00:02 +010045extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add);
Tomasz Majchrzak1532d9e2017-12-27 10:31:40 +010046extern void ppl_quiesce(struct r5conf *conf, int quiesce);
Artur Paszkiewiczf4bc0c82018-02-20 10:10:36 +010047extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio);
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010048
Shaohua Lie254de62018-08-29 11:05:42 -070049static inline bool raid5_has_log(struct r5conf *conf)
50{
51 return test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
52}
53
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010054static inline bool raid5_has_ppl(struct r5conf *conf)
55{
56 return test_bit(MD_HAS_PPL, &conf->mddev->flags);
57}
58
Artur Paszkiewiczff875732017-03-09 09:59:58 +010059static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s)
60{
61 struct r5conf *conf = sh->raid_conf;
62
63 if (conf->log) {
64 if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) {
65 /* writing out phase */
66 if (s->waiting_extra_page)
67 return 0;
68 return r5l_write_stripe(conf->log, sh);
69 } else if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) {
70 /* caching phase */
71 return r5c_cache_data(conf->log, sh);
72 }
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010073 } else if (raid5_has_ppl(conf)) {
74 return ppl_write_stripe(conf, sh);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010075 }
76
77 return -EAGAIN;
78}
79
80static inline void log_stripe_write_finished(struct stripe_head *sh)
81{
82 struct r5conf *conf = sh->raid_conf;
83
84 if (conf->log)
85 r5l_stripe_write_finished(sh);
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010086 else if (raid5_has_ppl(conf))
87 ppl_stripe_write_finished(sh);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010088}
89
90static inline void log_write_stripe_run(struct r5conf *conf)
91{
92 if (conf->log)
93 r5l_write_stripe_run(conf->log);
Artur Paszkiewicz3418d032017-03-09 09:59:59 +010094 else if (raid5_has_ppl(conf))
95 ppl_write_stripe_run(conf);
Artur Paszkiewiczff875732017-03-09 09:59:58 +010096}
97
Tomasz Majchrzak1532d9e2017-12-27 10:31:40 +010098static inline void log_flush_stripe_to_raid(struct r5conf *conf)
99{
100 if (conf->log)
101 r5l_flush_stripe_to_raid(conf->log);
102 else if (raid5_has_ppl(conf))
103 ppl_write_stripe_run(conf);
104}
105
106static inline int log_handle_flush_request(struct r5conf *conf, struct bio *bio)
107{
108 int ret = -ENODEV;
109
110 if (conf->log)
111 ret = r5l_handle_flush_request(conf->log, bio);
112 else if (raid5_has_ppl(conf))
Artur Paszkiewiczf4bc0c82018-02-20 10:10:36 +0100113 ret = ppl_handle_flush_request(conf->log, bio);
Tomasz Majchrzak1532d9e2017-12-27 10:31:40 +0100114
115 return ret;
116}
117
118static inline void log_quiesce(struct r5conf *conf, int quiesce)
119{
120 if (conf->log)
121 r5l_quiesce(conf->log, quiesce);
122 else if (raid5_has_ppl(conf))
123 ppl_quiesce(conf, quiesce);
124}
125
Artur Paszkiewiczff875732017-03-09 09:59:58 +0100126static inline void log_exit(struct r5conf *conf)
127{
128 if (conf->log)
129 r5l_exit_log(conf);
Artur Paszkiewicz3418d032017-03-09 09:59:59 +0100130 else if (raid5_has_ppl(conf))
131 ppl_exit_log(conf);
Artur Paszkiewiczff875732017-03-09 09:59:58 +0100132}
133
Artur Paszkiewicz845b9e22017-04-04 13:13:57 +0200134static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev,
135 bool ppl)
Artur Paszkiewiczff875732017-03-09 09:59:58 +0100136{
137 if (journal_dev)
138 return r5l_init_log(conf, journal_dev);
Artur Paszkiewicz845b9e22017-04-04 13:13:57 +0200139 else if (ppl)
Artur Paszkiewicz3418d032017-03-09 09:59:59 +0100140 return ppl_init_log(conf);
Artur Paszkiewiczff875732017-03-09 09:59:58 +0100141
142 return 0;
143}
144
Artur Paszkiewicz6358c232017-03-09 10:00:02 +0100145static inline int log_modify(struct r5conf *conf, struct md_rdev *rdev, bool add)
146{
147 if (raid5_has_ppl(conf))
148 return ppl_modify_log(conf, rdev, add);
149
150 return 0;
151}
152
Artur Paszkiewiczff875732017-03-09 09:59:58 +0100153#endif