raid-stripe-tree.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #define BTRFS_RST_SUPP_BLOCK_GROUP_MASK (BTRFS_BLOCK_GROUP_DUP | \
  11. BTRFS_BLOCK_GROUP_RAID1_MASK | \
  12. BTRFS_BLOCK_GROUP_RAID0 | \
  13. BTRFS_BLOCK_GROUP_RAID10)
  14. struct btrfs_io_context;
  15. struct btrfs_io_stripe;
  16. struct btrfs_fs_info;
  17. struct btrfs_ordered_extent;
  18. struct btrfs_trans_handle;
  19. int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length);
  20. int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
  21. u64 logical, u64 *length, u64 map_type,
  22. u32 stripe_index, struct btrfs_io_stripe *stripe);
  23. int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
  24. struct btrfs_ordered_extent *ordered_extent);
  25. static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
  26. u64 map_type)
  27. {
  28. u64 type = map_type & BTRFS_BLOCK_GROUP_TYPE_MASK;
  29. u64 profile = map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK;
  30. if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE))
  31. return false;
  32. if (type != BTRFS_BLOCK_GROUP_DATA)
  33. return false;
  34. if (profile & BTRFS_RST_SUPP_BLOCK_GROUP_MASK)
  35. return true;
  36. return false;
  37. }
  38. static inline int btrfs_num_raid_stripes(u32 item_size)
  39. {
  40. return item_size / sizeof(struct btrfs_raid_stride);
  41. }
  42. #endif