1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2ff875738SArtur Paszkiewicz #ifndef _RAID5_LOG_H 3ff875738SArtur Paszkiewicz #define _RAID5_LOG_H 4ff875738SArtur Paszkiewicz 5*ed0c6a5fSLogan Gunthorpe int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev); 6*ed0c6a5fSLogan Gunthorpe void r5l_exit_log(struct r5conf *conf); 7*ed0c6a5fSLogan Gunthorpe int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh); 8*ed0c6a5fSLogan Gunthorpe void r5l_write_stripe_run(struct r5l_log *log); 9*ed0c6a5fSLogan Gunthorpe void r5l_flush_stripe_to_raid(struct r5l_log *log); 10*ed0c6a5fSLogan Gunthorpe void r5l_stripe_write_finished(struct stripe_head *sh); 11*ed0c6a5fSLogan Gunthorpe int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio); 12*ed0c6a5fSLogan Gunthorpe void r5l_quiesce(struct r5l_log *log, int quiesce); 13*ed0c6a5fSLogan Gunthorpe bool r5l_log_disk_error(struct r5conf *conf); 14*ed0c6a5fSLogan Gunthorpe bool r5c_is_writeback(struct r5l_log *log); 15*ed0c6a5fSLogan Gunthorpe int r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh, 16ff875738SArtur Paszkiewicz struct stripe_head_state *s, int disks); 17*ed0c6a5fSLogan Gunthorpe void r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh, 18ff875738SArtur Paszkiewicz struct stripe_head_state *s); 19*ed0c6a5fSLogan Gunthorpe void r5c_release_extra_page(struct stripe_head *sh); 20*ed0c6a5fSLogan Gunthorpe void r5c_use_extra_page(struct stripe_head *sh); 21*ed0c6a5fSLogan Gunthorpe void r5l_wake_reclaim(struct r5l_log *log, sector_t space); 22*ed0c6a5fSLogan Gunthorpe void r5c_handle_cached_data_endio(struct r5conf *conf, 23bd83d0a2SNeilBrown struct stripe_head *sh, int disks); 24*ed0c6a5fSLogan Gunthorpe int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh); 25*ed0c6a5fSLogan Gunthorpe void r5c_make_stripe_write_out(struct stripe_head *sh); 26*ed0c6a5fSLogan Gunthorpe void r5c_flush_cache(struct r5conf *conf, int num); 27*ed0c6a5fSLogan Gunthorpe void r5c_check_stripe_cache_usage(struct r5conf *conf); 28*ed0c6a5fSLogan Gunthorpe void r5c_check_cached_full_stripe(struct r5conf *conf); 29ff875738SArtur Paszkiewicz extern struct md_sysfs_entry r5c_journal_mode; 30*ed0c6a5fSLogan Gunthorpe void r5c_update_on_rdev_error(struct mddev *mddev, struct md_rdev *rdev); 31*ed0c6a5fSLogan Gunthorpe bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect); 32*ed0c6a5fSLogan Gunthorpe int r5l_start(struct r5l_log *log); 33ff875738SArtur Paszkiewicz 34*ed0c6a5fSLogan Gunthorpe struct dma_async_tx_descriptor * 353418d036SArtur Paszkiewicz ops_run_partial_parity(struct stripe_head *sh, struct raid5_percpu *percpu, 363418d036SArtur Paszkiewicz struct dma_async_tx_descriptor *tx); 37*ed0c6a5fSLogan Gunthorpe int ppl_init_log(struct r5conf *conf); 38*ed0c6a5fSLogan Gunthorpe void ppl_exit_log(struct r5conf *conf); 39*ed0c6a5fSLogan Gunthorpe int ppl_write_stripe(struct r5conf *conf, struct stripe_head *sh); 40*ed0c6a5fSLogan Gunthorpe void ppl_write_stripe_run(struct r5conf *conf); 41*ed0c6a5fSLogan Gunthorpe void ppl_stripe_write_finished(struct stripe_head *sh); 42*ed0c6a5fSLogan Gunthorpe int ppl_modify_log(struct r5conf *conf, struct md_rdev *rdev, bool add); 43*ed0c6a5fSLogan Gunthorpe void ppl_quiesce(struct r5conf *conf, int quiesce); 44*ed0c6a5fSLogan Gunthorpe int ppl_handle_flush_request(struct r5l_log *log, struct bio *bio); 45a596d086SMariusz Dabrowski extern struct md_sysfs_entry ppl_write_hint; 463418d036SArtur Paszkiewicz 47e254de6bSShaohua Li static inline bool raid5_has_log(struct r5conf *conf) 48e254de6bSShaohua Li { 49e254de6bSShaohua Li return test_bit(MD_HAS_JOURNAL, &conf->mddev->flags); 50e254de6bSShaohua Li } 51e254de6bSShaohua Li 523418d036SArtur Paszkiewicz static inline bool raid5_has_ppl(struct r5conf *conf) 533418d036SArtur Paszkiewicz { 543418d036SArtur Paszkiewicz return test_bit(MD_HAS_PPL, &conf->mddev->flags); 553418d036SArtur Paszkiewicz } 563418d036SArtur Paszkiewicz 57ff875738SArtur Paszkiewicz static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s) 58ff875738SArtur Paszkiewicz { 59ff875738SArtur Paszkiewicz struct r5conf *conf = sh->raid_conf; 60ff875738SArtur Paszkiewicz 61ff875738SArtur Paszkiewicz if (conf->log) { 62ff875738SArtur Paszkiewicz if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) { 63ff875738SArtur Paszkiewicz /* writing out phase */ 64ff875738SArtur Paszkiewicz if (s->waiting_extra_page) 65ff875738SArtur Paszkiewicz return 0; 66ff875738SArtur Paszkiewicz return r5l_write_stripe(conf->log, sh); 67ff875738SArtur Paszkiewicz } else if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) { 68ff875738SArtur Paszkiewicz /* caching phase */ 69ff875738SArtur Paszkiewicz return r5c_cache_data(conf->log, sh); 70ff875738SArtur Paszkiewicz } 713418d036SArtur Paszkiewicz } else if (raid5_has_ppl(conf)) { 723418d036SArtur Paszkiewicz return ppl_write_stripe(conf, sh); 73ff875738SArtur Paszkiewicz } 74ff875738SArtur Paszkiewicz 75ff875738SArtur Paszkiewicz return -EAGAIN; 76ff875738SArtur Paszkiewicz } 77ff875738SArtur Paszkiewicz 78ff875738SArtur Paszkiewicz static inline void log_stripe_write_finished(struct stripe_head *sh) 79ff875738SArtur Paszkiewicz { 80ff875738SArtur Paszkiewicz struct r5conf *conf = sh->raid_conf; 81ff875738SArtur Paszkiewicz 82ff875738SArtur Paszkiewicz if (conf->log) 83ff875738SArtur Paszkiewicz r5l_stripe_write_finished(sh); 843418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 853418d036SArtur Paszkiewicz ppl_stripe_write_finished(sh); 86ff875738SArtur Paszkiewicz } 87ff875738SArtur Paszkiewicz 88ff875738SArtur Paszkiewicz static inline void log_write_stripe_run(struct r5conf *conf) 89ff875738SArtur Paszkiewicz { 90ff875738SArtur Paszkiewicz if (conf->log) 91ff875738SArtur Paszkiewicz r5l_write_stripe_run(conf->log); 923418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 933418d036SArtur Paszkiewicz ppl_write_stripe_run(conf); 94ff875738SArtur Paszkiewicz } 95ff875738SArtur Paszkiewicz 961532d9e8STomasz Majchrzak static inline void log_flush_stripe_to_raid(struct r5conf *conf) 971532d9e8STomasz Majchrzak { 981532d9e8STomasz Majchrzak if (conf->log) 991532d9e8STomasz Majchrzak r5l_flush_stripe_to_raid(conf->log); 1001532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 1011532d9e8STomasz Majchrzak ppl_write_stripe_run(conf); 1021532d9e8STomasz Majchrzak } 1031532d9e8STomasz Majchrzak 1041532d9e8STomasz Majchrzak static inline int log_handle_flush_request(struct r5conf *conf, struct bio *bio) 1051532d9e8STomasz Majchrzak { 1061532d9e8STomasz Majchrzak int ret = -ENODEV; 1071532d9e8STomasz Majchrzak 1081532d9e8STomasz Majchrzak if (conf->log) 1091532d9e8STomasz Majchrzak ret = r5l_handle_flush_request(conf->log, bio); 1101532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 111f4bc0c81SArtur Paszkiewicz ret = ppl_handle_flush_request(conf->log, bio); 1121532d9e8STomasz Majchrzak 1131532d9e8STomasz Majchrzak return ret; 1141532d9e8STomasz Majchrzak } 1151532d9e8STomasz Majchrzak 1161532d9e8STomasz Majchrzak static inline void log_quiesce(struct r5conf *conf, int quiesce) 1171532d9e8STomasz Majchrzak { 1181532d9e8STomasz Majchrzak if (conf->log) 1191532d9e8STomasz Majchrzak r5l_quiesce(conf->log, quiesce); 1201532d9e8STomasz Majchrzak else if (raid5_has_ppl(conf)) 1211532d9e8STomasz Majchrzak ppl_quiesce(conf, quiesce); 1221532d9e8STomasz Majchrzak } 1231532d9e8STomasz Majchrzak 124ff875738SArtur Paszkiewicz static inline void log_exit(struct r5conf *conf) 125ff875738SArtur Paszkiewicz { 126ff875738SArtur Paszkiewicz if (conf->log) 127ff875738SArtur Paszkiewicz r5l_exit_log(conf); 1283418d036SArtur Paszkiewicz else if (raid5_has_ppl(conf)) 1293418d036SArtur Paszkiewicz ppl_exit_log(conf); 130ff875738SArtur Paszkiewicz } 131ff875738SArtur Paszkiewicz 132845b9e22SArtur Paszkiewicz static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev, 133845b9e22SArtur Paszkiewicz bool ppl) 134ff875738SArtur Paszkiewicz { 135ff875738SArtur Paszkiewicz if (journal_dev) 136ff875738SArtur Paszkiewicz return r5l_init_log(conf, journal_dev); 137845b9e22SArtur Paszkiewicz else if (ppl) 1383418d036SArtur Paszkiewicz return ppl_init_log(conf); 139ff875738SArtur Paszkiewicz 140ff875738SArtur Paszkiewicz return 0; 141ff875738SArtur Paszkiewicz } 142ff875738SArtur Paszkiewicz 1436358c239SArtur Paszkiewicz static inline int log_modify(struct r5conf *conf, struct md_rdev *rdev, bool add) 1446358c239SArtur Paszkiewicz { 1456358c239SArtur Paszkiewicz if (raid5_has_ppl(conf)) 1466358c239SArtur Paszkiewicz return ppl_modify_log(conf, rdev, add); 1476358c239SArtur Paszkiewicz 1486358c239SArtur Paszkiewicz return 0; 1496358c239SArtur Paszkiewicz } 1506358c239SArtur Paszkiewicz 151ff875738SArtur Paszkiewicz #endif 152