qgroup.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2014 Facebook. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #ifndef __BTRFS_QGROUP__
  19. #define __BTRFS_QGROUP__
  20. #include "ulist.h"
  21. #include "delayed-ref.h"
  22. /*
  23. * Record a dirty extent, and info qgroup to update quota on it
  24. * TODO: Use kmem cache to alloc it.
  25. */
  26. struct btrfs_qgroup_extent_record {
  27. struct rb_node node;
  28. u64 bytenr;
  29. u64 num_bytes;
  30. struct ulist *old_roots;
  31. };
  32. /*
  33. * For qgroup event trace points only
  34. */
  35. #define QGROUP_RESERVE (1<<0)
  36. #define QGROUP_RELEASE (1<<1)
  37. #define QGROUP_FREE (1<<2)
  38. int btrfs_quota_enable(struct btrfs_trans_handle *trans,
  39. struct btrfs_fs_info *fs_info);
  40. int btrfs_quota_disable(struct btrfs_trans_handle *trans,
  41. struct btrfs_fs_info *fs_info);
  42. int btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info);
  43. void btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info);
  44. int btrfs_qgroup_wait_for_completion(struct btrfs_fs_info *fs_info,
  45. bool interruptible);
  46. int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
  47. struct btrfs_fs_info *fs_info, u64 src, u64 dst);
  48. int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
  49. struct btrfs_fs_info *fs_info, u64 src, u64 dst);
  50. int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
  51. struct btrfs_fs_info *fs_info, u64 qgroupid);
  52. int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
  53. struct btrfs_fs_info *fs_info, u64 qgroupid);
  54. int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
  55. struct btrfs_fs_info *fs_info, u64 qgroupid,
  56. struct btrfs_qgroup_limit *limit);
  57. int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
  58. void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
  59. struct btrfs_delayed_extent_op;
  60. int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
  61. struct btrfs_fs_info *fs_info);
  62. /*
  63. * Insert one dirty extent record into @delayed_refs, informing qgroup to
  64. * account that extent at commit trans time.
  65. *
  66. * No lock version, caller must acquire delayed ref lock and allocate memory.
  67. *
  68. * Return 0 for success insert
  69. * Return >0 for existing record, caller can free @record safely.
  70. * Error is not possible
  71. */
  72. int btrfs_qgroup_insert_dirty_extent_nolock(
  73. struct btrfs_fs_info *fs_info,
  74. struct btrfs_delayed_ref_root *delayed_refs,
  75. struct btrfs_qgroup_extent_record *record);
  76. /*
  77. * Insert one dirty extent record into @delayed_refs, informing qgroup to
  78. * account that extent at commit trans time.
  79. *
  80. * Better encapsulated version.
  81. *
  82. * Return 0 if the operation is done.
  83. * Return <0 for error, like memory allocation failure or invalid parameter
  84. * (NULL trans)
  85. */
  86. int btrfs_qgroup_insert_dirty_extent(struct btrfs_trans_handle *trans,
  87. struct btrfs_fs_info *fs_info, u64 bytenr, u64 num_bytes,
  88. gfp_t gfp_flag);
  89. int
  90. btrfs_qgroup_account_extent(struct btrfs_trans_handle *trans,
  91. struct btrfs_fs_info *fs_info,
  92. u64 bytenr, u64 num_bytes,
  93. struct ulist *old_roots, struct ulist *new_roots);
  94. int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans,
  95. struct btrfs_fs_info *fs_info);
  96. int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
  97. struct btrfs_fs_info *fs_info);
  98. int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
  99. struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
  100. struct btrfs_qgroup_inherit *inherit);
  101. void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info,
  102. u64 ref_root, u64 num_bytes);
  103. /*
  104. * TODO: Add proper trace point for it, as btrfs_qgroup_free() is
  105. * called by everywhere, can't provide good trace for delayed ref case.
  106. */
  107. static inline void btrfs_qgroup_free_delayed_ref(struct btrfs_fs_info *fs_info,
  108. u64 ref_root, u64 num_bytes)
  109. {
  110. btrfs_qgroup_free_refroot(fs_info, ref_root, num_bytes);
  111. trace_btrfs_qgroup_free_delayed_ref(fs_info, ref_root, num_bytes);
  112. }
  113. void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
  114. #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
  115. int btrfs_verify_qgroup_counts(struct btrfs_fs_info *fs_info, u64 qgroupid,
  116. u64 rfer, u64 excl);
  117. #endif
  118. /* New io_tree based accurate qgroup reserve API */
  119. int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len);
  120. int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len);
  121. int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len);
  122. int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes);
  123. void btrfs_qgroup_free_meta_all(struct btrfs_root *root);
  124. void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes);
  125. void btrfs_qgroup_check_reserved_leak(struct inode *inode);
  126. #endif /* __BTRFS_QGROUP__ */