19888c340SDavid Sterba /* SPDX-License-Identifier: GPL-2.0 */ 253b381b3SDavid Woodhouse /* 353b381b3SDavid Woodhouse * Copyright (C) 2012 Fusion-io All rights reserved. 453b381b3SDavid Woodhouse * Copyright (C) 2012 Intel Corp. All rights reserved. 553b381b3SDavid Woodhouse */ 653b381b3SDavid Woodhouse 79888c340SDavid Sterba #ifndef BTRFS_RAID56_H 89888c340SDavid Sterba #define BTRFS_RAID56_H 99888c340SDavid Sterba 1072ad8131SDavid Sterba static inline int nr_parity_stripes(const struct map_lookup *map) 1153b381b3SDavid Woodhouse { 1253b381b3SDavid Woodhouse if (map->type & BTRFS_BLOCK_GROUP_RAID5) 1353b381b3SDavid Woodhouse return 1; 1453b381b3SDavid Woodhouse else if (map->type & BTRFS_BLOCK_GROUP_RAID6) 1553b381b3SDavid Woodhouse return 2; 1653b381b3SDavid Woodhouse else 1753b381b3SDavid Woodhouse return 0; 1853b381b3SDavid Woodhouse } 1953b381b3SDavid Woodhouse 2072ad8131SDavid Sterba static inline int nr_data_stripes(const struct map_lookup *map) 2153b381b3SDavid Woodhouse { 2253b381b3SDavid Woodhouse return map->num_stripes - nr_parity_stripes(map); 2353b381b3SDavid Woodhouse } 2453b381b3SDavid Woodhouse #define RAID5_P_STRIPE ((u64)-2) 2553b381b3SDavid Woodhouse #define RAID6_Q_STRIPE ((u64)-1) 2653b381b3SDavid Woodhouse 2753b381b3SDavid Woodhouse #define is_parity_stripe(x) (((x) == RAID5_P_STRIPE) || \ 2853b381b3SDavid Woodhouse ((x) == RAID6_Q_STRIPE)) 2953b381b3SDavid Woodhouse 305a6ac9eaSMiao Xie struct btrfs_raid_bio; 315a6ac9eaSMiao Xie struct btrfs_device; 325a6ac9eaSMiao Xie 332ff7e61eSJeff Mahoney int raid56_parity_recover(struct btrfs_fs_info *fs_info, struct bio *bio, 348e5cfb55SZhao Lei struct btrfs_bio *bbio, u64 stripe_len, 358e5cfb55SZhao Lei int mirror_num, int generic_io); 362ff7e61eSJeff Mahoney int raid56_parity_write(struct btrfs_fs_info *fs_info, struct bio *bio, 378e5cfb55SZhao Lei struct btrfs_bio *bbio, u64 stripe_len); 3853b381b3SDavid Woodhouse 39b4ee1782SOmar Sandoval void raid56_add_scrub_pages(struct btrfs_raid_bio *rbio, struct page *page, 40b4ee1782SOmar Sandoval u64 logical); 41b4ee1782SOmar Sandoval 425a6ac9eaSMiao Xie struct btrfs_raid_bio * 432ff7e61eSJeff Mahoney raid56_parity_alloc_scrub_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, 448e5cfb55SZhao Lei struct btrfs_bio *bbio, u64 stripe_len, 458e5cfb55SZhao Lei struct btrfs_device *scrub_dev, 465a6ac9eaSMiao Xie unsigned long *dbitmap, int stripe_nsectors); 475a6ac9eaSMiao Xie void raid56_parity_submit_scrub_rbio(struct btrfs_raid_bio *rbio); 485a6ac9eaSMiao Xie 49b4ee1782SOmar Sandoval struct btrfs_raid_bio * 502ff7e61eSJeff Mahoney raid56_alloc_missing_rbio(struct btrfs_fs_info *fs_info, struct bio *bio, 51b4ee1782SOmar Sandoval struct btrfs_bio *bbio, u64 length); 52b4ee1782SOmar Sandoval void raid56_submit_missing_rbio(struct btrfs_raid_bio *rbio); 53b4ee1782SOmar Sandoval 5453b381b3SDavid Woodhouse int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info); 5553b381b3SDavid Woodhouse void btrfs_free_stripe_hash_table(struct btrfs_fs_info *info); 569888c340SDavid Sterba 5753b381b3SDavid Woodhouse #endif 58