1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _RAID5_LOG_H
3 #define _RAID5_LOG_H
4 
5 extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
6 extern void r5l_exit_log(struct r5conf *conf);
7 extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
8 extern void r5l_write_stripe_run(struct r5l_log *log);
9 extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
10 extern void r5l_stripe_write_finished(struct stripe_head *sh);
11 extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
12 extern void r5l_quiesce(struct r5l_log *log, int quiesce);
13 extern bool r5l_log_disk_error(struct r5conf *conf);
14 extern bool r5c_is_writeback(struct r5l_log *log);
15 extern int
16 r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
17 		      struct stripe_head_state *s, int disks);
18 extern void
19 r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh,
20 			    struct stripe_head_state *s);
21 extern void r5c_release_extra_page(struct stripe_head *sh);
22 extern void r5c_use_extra_page(struct stripe_head *sh);
23 extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
24 extern void r5c_handle_cached_data_endio(struct r5conf *conf,
25 	struct stripe_head *sh, int disks);
26 extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh);
27 extern void r5c_make_stripe_write_out(struct stripe_head *sh);
28 extern void r5c_flush_cache(struct r5conf *conf, int num);
29 extern void r5c_check_stripe_cache_usage(struct r5conf *conf);
30 extern void r5c_check_cached_full_stripe(struct r5conf *conf);
31 extern struct md_sysfs_entry r5c_journal_mode;
32 extern void r5c_update_on_rdev_error(struct mddev *mddev,
33 				     struct md_rdev *rdev);
34 extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect);
35 extern int r5l_start(struct r5l_log *log);
36 
37 extern struct dma_async_tx_descriptor *
38 ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu,
39 		       struct dma_async_tx_descriptor *tx);
40 extern int ppl_init_log(struct r5conf *conf);
41 extern void ppl_exit_log(struct r5conf *conf);
42 extern int ppl_write_stripe(struct r5conf *conf, struct stripe_head *sh);
43 extern void ppl_write_stripe_run(struct r5conf *conf);
44 extern void ppl_stripe_write_finished(struct stripe_head *sh);
45 extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add);
46 extern void ppl_quiesce(struct r5conf *conf, int quiesce);
47 extern int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio);
48 
raid5_has_log(struct r5conf * conf)49 static inline bool raid5_has_log(struct r5conf *conf)
50 {
51 	return test_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
52 }
53 
raid5_has_ppl(struct r5conf * conf)54 static inline bool raid5_has_ppl(struct r5conf *conf)
55 {
56 	return test_bit(MD_HAS_PPL, &conf->mddev->flags);
57 }
58 
log_stripe(struct stripe_head * sh,struct stripe_head_state * s)59 static 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 		}
73 	} else if (raid5_has_ppl(conf)) {
74 		return ppl_write_stripe(conf, sh);
75 	}
76 
77 	return -EAGAIN;
78 }
79 
log_stripe_write_finished(struct stripe_head * sh)80 static 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);
86 	else if (raid5_has_ppl(conf))
87 		ppl_stripe_write_finished(sh);
88 }
89 
log_write_stripe_run(struct r5conf * conf)90 static inline void log_write_stripe_run(struct r5conf *conf)
91 {
92 	if (conf->log)
93 		r5l_write_stripe_run(conf->log);
94 	else if (raid5_has_ppl(conf))
95 		ppl_write_stripe_run(conf);
96 }
97 
log_flush_stripe_to_raid(struct r5conf * conf)98 static 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 
log_handle_flush_request(struct r5conf * conf,struct bio * bio)106 static 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))
113 		ret = ppl_handle_flush_request(conf->log, bio);
114 
115 	return ret;
116 }
117 
log_quiesce(struct r5conf * conf,int quiesce)118 static 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 
log_exit(struct r5conf * conf)126 static inline void log_exit(struct r5conf *conf)
127 {
128 	if (conf->log)
129 		r5l_exit_log(conf);
130 	else if (raid5_has_ppl(conf))
131 		ppl_exit_log(conf);
132 }
133 
log_init(struct r5conf * conf,struct md_rdev * journal_dev,bool ppl)134 static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev,
135 			   bool ppl)
136 {
137 	if (journal_dev)
138 		return r5l_init_log(conf, journal_dev);
139 	else if (ppl)
140 		return ppl_init_log(conf);
141 
142 	return 0;
143 }
144 
log_modify(struct r5conf * conf,struct md_rdev * rdev,bool add)145 static 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 
153 #endif
154