1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ff875738SArtur Paszkiewicz #ifndef _RAID5_LOG_H 3ff875738SArtur Paszkiewicz #define _RAID5_LOG_H 4ff875738SArtur Paszkiewicz 5ff875738SArtur Paszkiewicz extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev); 6ff875738SArtur Paszkiewicz extern void r5l_exit_log(struct r5conf *conf); 7ff875738SArtur Paszkiewicz extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh); 8ff875738SArtur Paszkiewicz extern void r5l_write_stripe_run(struct r5l_log *log); 9ff875738SArtur Paszkiewicz extern void r5l_flush_stripe_to_raid(struct r5l_log *log); 10ff875738SArtur Paszkiewicz extern void r5l_stripe_write_finished(struct stripe_head *sh); 11ff875738SArtur Paszkiewicz extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio); 12b03e0ccbSNeilBrown extern void r5l_quiesce(struct r5l_log *log, int quiesce); 13ff875738SArtur Paszkiewicz extern bool r5l_log_disk_error(struct r5conf *conf); 14ff875738SArtur Paszkiewicz extern bool r5c_is_writeback(struct r5l_log *log); 15ff875738SArtur Paszkiewicz extern int 16ff875738SArtur Paszkiewicz r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh, 17ff875738SArtur Paszkiewicz struct stripe_head_state *s, int disks); 18ff875738SArtur Paszkiewicz extern void 19ff875738SArtur Paszkiewicz r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh, 20ff875738SArtur Paszkiewicz struct stripe_head_state *s); 21ff875738SArtur Paszkiewicz extern void r5c_release_extra_page(struct stripe_head *sh); 22ff875738SArtur Paszkiewicz extern void r5c_use_extra_page(struct stripe_head *sh); 23ff875738SArtur Paszkiewicz extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space); 24ff875738SArtur Paszkiewicz extern void r5c_handle_cached_data_endio(struct r5conf *conf, 25bd83d0a2SNeilBrown struct stripe_head *sh, int disks); 26ff875738SArtur Paszkiewicz extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh); 27ff875738SArtur Paszkiewicz extern void r5c_make_stripe_write_out(struct stripe_head *sh); 28ff875738SArtur Paszkiewicz extern void r5c_flush_cache(struct r5conf *conf, int num); 29ff875738SArtur Paszkiewicz extern void r5c_check_stripe_cache_usage(struct r5conf *conf); 30ff875738SArtur Paszkiewicz extern void r5c_check_cached_full_stripe(struct r5conf *conf); 31ff875738SArtur Paszkiewicz extern struct md_sysfs_entry r5c_journal_mode; 3270d466f7SSong Liu extern void r5c_update_on_rdev_error(struct mddev *mddev, 3370d466f7SSong Liu struct md_rdev *rdev); 34ff875738SArtur Paszkiewicz extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect); 35d5d885fdSSong Liu extern int r5l_start(struct r5l_log *log); 36ff875738SArtur Paszkiewicz 373418d036SArtur Paszkiewicz extern struct dma_async_tx_descriptor * 383418d036SArtur Paszkiewicz ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu, 393418d036SArtur Paszkiewicz struct dma_async_tx_descriptor *tx); 403418d036SArtur Paszkiewicz extern int ppl_init_log(struct r5conf *conf); 413418d036SArtur Paszkiewicz extern void ppl_exit_log(struct r5conf *conf); 423418d036SArtur Paszkiewicz extern int ppl_write_stripe(struct r5conf *conf, struct stripe_head *sh); 433418d036SArtur Paszkiewicz extern void ppl_write_stripe_run(struct r5conf *conf); 443418d036SArtur Paszkiewicz extern void ppl_stripe_write_finished(struct stripe_head *sh); 456358c239SArtur Paszkiewicz extern int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add); 46*1532d9e8STomasz Majchrzak extern void ppl_quiesce(struct r5conf *conf, int quiesce); 473418d036SArtur Paszkiewicz 483418d036SArtur Paszkiewicz static inline bool raid5_has_ppl(struct r5conf *conf) 493418d036SArtur Paszkiewicz { 503418d036SArtur Paszkiewicz return test_bit(MD_HAS_PPL, &conf->mddev->flags); 513418d036SArtur Paszkiewicz } 523418d036SArtur Paszkiewicz 53ff875738SArtur Paszkiewicz static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s) 54ff875738SArtur Paszkiewicz { 55ff875738SArtur Paszkiewicz struct r5conf *conf = sh->raid_conf; 56ff875738SArtur Paszkiewicz 57ff875738SArtur Paszkiewicz if (conf->log) { 58ff875738SArtur Paszkiewicz if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) { 59ff875738SArtur Paszkiewicz /* writing out phase */ 60ff875738SArtur Paszkiewicz if (s->waiting_extra_page) 61ff875738SArtur Paszkiewicz return 0; 62ff875738SArtur Paszkiewicz return r5l_write_stripe(conf->log, sh); 63ff875738SArtur Paszkiewicz } else if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) { 64ff875738SArtur Paszkiewicz /* caching phase */ 65ff875738SArtur Paszkiewicz return r5c_cache_data(conf->log, sh); 66ff875738SArtur Paszkiewicz } 673418d036SArtur Paszkiewicz } else if (raid5_has_ppl(conf)) { 683418d036SArtur Paszkiewicz return ppl_write_stripe(conf, sh); 69ff875738SArtur Paszkiewicz } 70ff875738SArtur Paszkiewicz 71ff875738SArtur Paszkiewicz return -EAGAIN; 72ff875738SArtur Paszkiewicz } 73ff875738SArtur Paszkiewicz 74ff875738SArtur Paszkiewicz static inline void log_stripe_write_finished(struct stripe_head *sh) 75ff875738SArtur Paszkiewicz { 76ff875738SArtur Paszkiewicz struct r5conf *conf = sh->raid_conf; 77ff875738SArtur Paszkiewicz 78ff875738SArtur Paszkiewicz if (conf->log) 79ff875738SArtur Paszkiewicz r5l_stripe_write_finished(sh); 803418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 813418d036SArtur Paszkiewicz ppl_stripe_write_finished(sh); 82ff875738SArtur Paszkiewicz } 83ff875738SArtur Paszkiewicz 84ff875738SArtur Paszkiewicz static inline void log_write_stripe_run(struct r5conf *conf) 85ff875738SArtur Paszkiewicz { 86ff875738SArtur Paszkiewicz if (conf->log) 87ff875738SArtur Paszkiewicz r5l_write_stripe_run(conf->log); 883418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 893418d036SArtur Paszkiewicz ppl_write_stripe_run(conf); 90ff875738SArtur Paszkiewicz } 91ff875738SArtur Paszkiewicz 92*1532d9e8STomasz Majchrzak static inline void log_flush_stripe_to_raid(struct r5conf *conf) 93*1532d9e8STomasz Majchrzak { 94*1532d9e8STomasz Majchrzak if (conf->log) 95*1532d9e8STomasz Majchrzak r5l_flush_stripe_to_raid(conf->log); 96*1532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 97*1532d9e8STomasz Majchrzak ppl_write_stripe_run(conf); 98*1532d9e8STomasz Majchrzak } 99*1532d9e8STomasz Majchrzak 100*1532d9e8STomasz Majchrzak static inline int log_handle_flush_request(struct r5conf *conf, struct bio *bio) 101*1532d9e8STomasz Majchrzak { 102*1532d9e8STomasz Majchrzak int ret = -ENODEV; 103*1532d9e8STomasz Majchrzak 104*1532d9e8STomasz Majchrzak if (conf->log) 105*1532d9e8STomasz Majchrzak ret = r5l_handle_flush_request(conf->log, bio); 106*1532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 107*1532d9e8STomasz Majchrzak ret = 0; 108*1532d9e8STomasz Majchrzak 109*1532d9e8STomasz Majchrzak return ret; 110*1532d9e8STomasz Majchrzak } 111*1532d9e8STomasz Majchrzak 112*1532d9e8STomasz Majchrzak static inline void log_quiesce(struct r5conf *conf, int quiesce) 113*1532d9e8STomasz Majchrzak { 114*1532d9e8STomasz Majchrzak if (conf->log) 115*1532d9e8STomasz Majchrzak r5l_quiesce(conf->log, quiesce); 116*1532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 117*1532d9e8STomasz Majchrzak ppl_quiesce(conf, quiesce); 118*1532d9e8STomasz Majchrzak } 119*1532d9e8STomasz Majchrzak 120ff875738SArtur Paszkiewicz static inline void log_exit(struct r5conf *conf) 121ff875738SArtur Paszkiewicz { 122ff875738SArtur Paszkiewicz if (conf->log) 123ff875738SArtur Paszkiewicz r5l_exit_log(conf); 1243418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 1253418d036SArtur Paszkiewicz ppl_exit_log(conf); 126ff875738SArtur Paszkiewicz } 127ff875738SArtur Paszkiewicz 128845b9e22SArtur Paszkiewicz static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev, 129845b9e22SArtur Paszkiewicz bool ppl) 130ff875738SArtur Paszkiewicz { 131ff875738SArtur Paszkiewicz if (journal_dev) 132ff875738SArtur Paszkiewicz return r5l_init_log(conf, journal_dev); 133845b9e22SArtur Paszkiewicz else if (ppl) 1343418d036SArtur Paszkiewicz return ppl_init_log(conf); 135ff875738SArtur Paszkiewicz 136ff875738SArtur Paszkiewicz return 0; 137ff875738SArtur Paszkiewicz } 138ff875738SArtur Paszkiewicz 1396358c239SArtur Paszkiewicz static inline int log_modify(struct r5conf *conf, struct md_rdev *rdev, bool add) 1406358c239SArtur Paszkiewicz { 1416358c239SArtur Paszkiewicz if (raid5_has_ppl(conf)) 1426358c239SArtur Paszkiewicz return ppl_modify_log(conf, rdev, add); 1436358c239SArtur Paszkiewicz 1446358c239SArtur Paszkiewicz return 0; 1456358c239SArtur Paszkiewicz } 1466358c239SArtur Paszkiewicz 147ff875738SArtur Paszkiewicz #endif 148