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