free-space-cache.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2009 Oracle. All rights reserved.
  4. */
  5. #ifndef BTRFS_FREE_SPACE_CACHE_H
  6. #define BTRFS_FREE_SPACE_CACHE_H
  7. struct btrfs_free_space {
  8. struct rb_node offset_index;
  9. u64 offset;
  10. u64 bytes;
  11. u64 max_extent_size;
  12. unsigned long *bitmap;
  13. struct list_head list;
  14. };
  15. struct btrfs_free_space_ctl {
  16. spinlock_t tree_lock;
  17. struct rb_root free_space_offset;
  18. u64 free_space;
  19. int extents_thresh;
  20. int free_extents;
  21. int total_bitmaps;
  22. int unit;
  23. u64 start;
  24. const struct btrfs_free_space_op *op;
  25. void *private;
  26. struct mutex cache_writeout_mutex;
  27. struct list_head trimming_ranges;
  28. };
  29. struct btrfs_free_space_op {
  30. void (*recalc_thresholds)(struct btrfs_free_space_ctl *ctl);
  31. bool (*use_bitmap)(struct btrfs_free_space_ctl *ctl,
  32. struct btrfs_free_space *info);
  33. };
  34. struct btrfs_io_ctl {
  35. void *cur, *orig;
  36. struct page *page;
  37. struct page **pages;
  38. struct btrfs_fs_info *fs_info;
  39. struct inode *inode;
  40. unsigned long size;
  41. int index;
  42. int num_pages;
  43. int entries;
  44. int bitmaps;
  45. unsigned check_crcs:1;
  46. };
  47. struct inode *lookup_free_space_inode(
  48. struct btrfs_block_group_cache *block_group,
  49. struct btrfs_path *path);
  50. int create_free_space_inode(struct btrfs_trans_handle *trans,
  51. struct btrfs_block_group_cache *block_group,
  52. struct btrfs_path *path);
  53. int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
  54. struct btrfs_block_rsv *rsv);
  55. int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
  56. struct btrfs_block_group_cache *block_group,
  57. struct inode *inode);
  58. int load_free_space_cache(struct btrfs_block_group_cache *block_group);
  59. int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
  60. struct btrfs_block_group_cache *block_group,
  61. struct btrfs_path *path);
  62. int btrfs_write_out_cache(struct btrfs_trans_handle *trans,
  63. struct btrfs_block_group_cache *block_group,
  64. struct btrfs_path *path);
  65. struct inode *lookup_free_ino_inode(struct btrfs_root *root,
  66. struct btrfs_path *path);
  67. int create_free_ino_inode(struct btrfs_root *root,
  68. struct btrfs_trans_handle *trans,
  69. struct btrfs_path *path);
  70. int load_free_ino_cache(struct btrfs_fs_info *fs_info,
  71. struct btrfs_root *root);
  72. int btrfs_write_out_ino_cache(struct btrfs_root *root,
  73. struct btrfs_trans_handle *trans,
  74. struct btrfs_path *path,
  75. struct inode *inode);
  76. void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group);
  77. int __btrfs_add_free_space(struct btrfs_fs_info *fs_info,
  78. struct btrfs_free_space_ctl *ctl,
  79. u64 bytenr, u64 size);
  80. int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
  81. u64 bytenr, u64 size);
  82. int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
  83. u64 bytenr, u64 size);
  84. void __btrfs_remove_free_space_cache(struct btrfs_free_space_ctl *ctl);
  85. void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
  86. *block_group);
  87. u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
  88. u64 offset, u64 bytes, u64 empty_size,
  89. u64 *max_extent_size);
  90. u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root);
  91. void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
  92. u64 bytes);
  93. int btrfs_find_space_cluster(struct btrfs_block_group_cache *block_group,
  94. struct btrfs_free_cluster *cluster,
  95. u64 offset, u64 bytes, u64 empty_size);
  96. void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster);
  97. u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
  98. struct btrfs_free_cluster *cluster, u64 bytes,
  99. u64 min_start, u64 *max_extent_size);
  100. int btrfs_return_cluster_to_free_space(
  101. struct btrfs_block_group_cache *block_group,
  102. struct btrfs_free_cluster *cluster);
  103. int btrfs_trim_block_group(struct btrfs_block_group_cache *block_group,
  104. u64 *trimmed, u64 start, u64 end, u64 minlen);
  105. /* Support functions for running our sanity tests */
  106. #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
  107. int test_add_free_space_entry(struct btrfs_block_group_cache *cache,
  108. u64 offset, u64 bytes, bool bitmap);
  109. int test_check_exists(struct btrfs_block_group_cache *cache,
  110. u64 offset, u64 bytes);
  111. #endif
  112. #endif