raid-stripe-tree.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2023 Western Digital Corporation or its affiliates.
  4. */
  5. #ifndef BTRFS_RAID_STRIPE_TREE_H
  6. #define BTRFS_RAID_STRIPE_TREE_H
  7. #include <linux/types.h>
  8. #include <uapi/linux/btrfs_tree.h>
  9. #include "fs.h"
  10. #include "accessors.h"
  11. #define BTRFS_RST_SUPP_BLOCK_GROUP_MASK (BTRFS_BLOCK_GROUP_DUP | \
  12. BTRFS_BLOCK_GROUP_RAID1_MASK | \
  13. BTRFS_BLOCK_GROUP_RAID0 | \
  14. BTRFS_BLOCK_GROUP_RAID10)
  15. struct btrfs_io_context;
  16. struct btrfs_io_stripe;
  17. struct btrfs_fs_info;
  18. struct btrfs_ordered_extent;
  19. struct btrfs_trans_handle;
  20. int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length);
  21. int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
  22. u64 logical, u64 *length, u64 map_type,
  23. u32 stripe_index, struct btrfs_io_stripe *stripe);
  24. int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
  25. struct btrfs_ordered_extent *ordered_extent);
  26. #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
  27. int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
  28. struct btrfs_io_context *bioc);
  29. #endif
  30. static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
  31. u64 map_type)
  32. {
  33. u64 type = map_type & BTRFS_BLOCK_GROUP_TYPE_MASK;
  34. u64 profile = map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK;
  35. if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE))
  36. return false;
  37. if (type != BTRFS_BLOCK_GROUP_DATA)
  38. return false;
  39. if (profile & BTRFS_RST_SUPP_BLOCK_GROUP_MASK)
  40. return true;
  41. return false;
  42. }
  43. static inline int btrfs_num_raid_stripes(u32 item_size)
  44. {
  45. return item_size / sizeof(struct btrfs_raid_stride);
  46. }
  47. #endif