1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 3 #ifndef BTRFS_BLOCK_RSV_H 3 #ifndef BTRFS_BLOCK_RSV_H 4 #define BTRFS_BLOCK_RSV_H 4 #define BTRFS_BLOCK_RSV_H 5 5 6 #include <linux/types.h> << 7 #include <linux/compiler.h> << 8 #include <linux/spinlock.h> << 9 << 10 struct btrfs_trans_handle; 6 struct btrfs_trans_handle; 11 struct btrfs_root; << 12 struct btrfs_space_info; << 13 struct btrfs_block_rsv; << 14 struct btrfs_fs_info; << 15 enum btrfs_reserve_flush_enum; 7 enum btrfs_reserve_flush_enum; 16 8 17 /* 9 /* 18 * Types of block reserves 10 * Types of block reserves 19 */ 11 */ 20 enum btrfs_rsv_type { !! 12 enum { 21 BTRFS_BLOCK_RSV_GLOBAL, 13 BTRFS_BLOCK_RSV_GLOBAL, 22 BTRFS_BLOCK_RSV_DELALLOC, 14 BTRFS_BLOCK_RSV_DELALLOC, 23 BTRFS_BLOCK_RSV_TRANS, 15 BTRFS_BLOCK_RSV_TRANS, 24 BTRFS_BLOCK_RSV_CHUNK, 16 BTRFS_BLOCK_RSV_CHUNK, 25 BTRFS_BLOCK_RSV_DELOPS, 17 BTRFS_BLOCK_RSV_DELOPS, 26 BTRFS_BLOCK_RSV_DELREFS, 18 BTRFS_BLOCK_RSV_DELREFS, 27 BTRFS_BLOCK_RSV_EMPTY, 19 BTRFS_BLOCK_RSV_EMPTY, 28 BTRFS_BLOCK_RSV_TEMP, 20 BTRFS_BLOCK_RSV_TEMP, 29 }; 21 }; 30 22 31 struct btrfs_block_rsv { 23 struct btrfs_block_rsv { 32 u64 size; 24 u64 size; 33 u64 reserved; 25 u64 reserved; 34 struct btrfs_space_info *space_info; 26 struct btrfs_space_info *space_info; 35 spinlock_t lock; 27 spinlock_t lock; 36 bool full; !! 28 unsigned short full; 37 bool failfast; !! 29 unsigned short type; 38 /* Block reserve type, one of BTRFS_BL !! 30 unsigned short failfast; 39 enum btrfs_rsv_type type:8; << 40 31 41 /* 32 /* 42 * Qgroup equivalent for @size @reserv 33 * Qgroup equivalent for @size @reserved 43 * 34 * 44 * Unlike normal @size/@reserved for i 35 * Unlike normal @size/@reserved for inode rsv, qgroup doesn't care 45 * about things like csum size nor how 36 * about things like csum size nor how many tree blocks it will need to 46 * reserve. 37 * reserve. 47 * 38 * 48 * Qgroup cares more about net change 39 * Qgroup cares more about net change of the extent usage. 49 * 40 * 50 * So for one newly inserted file exte 41 * So for one newly inserted file extent, in worst case it will cause 51 * leaf split and level increase, node 42 * leaf split and level increase, nodesize for each file extent is 52 * already too much. 43 * already too much. 53 * 44 * 54 * In short, qgroup_size/reserved is t 45 * In short, qgroup_size/reserved is the upper limit of possible needed 55 * qgroup metadata reservation. 46 * qgroup metadata reservation. 56 */ 47 */ 57 u64 qgroup_rsv_size; 48 u64 qgroup_rsv_size; 58 u64 qgroup_rsv_reserved; 49 u64 qgroup_rsv_reserved; 59 }; 50 }; 60 51 61 void btrfs_init_block_rsv(struct btrfs_block_r !! 52 void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type); 62 void btrfs_init_root_block_rsv(struct btrfs_ro << 63 struct btrfs_block_rsv *btrfs_alloc_block_rsv( 53 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info, 64 !! 54 unsigned short type); 65 void btrfs_init_metadata_block_rsv(struct btrf 55 void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info, 66 struct btrf 56 struct btrfs_block_rsv *rsv, 67 enum btrfs_ !! 57 unsigned short type); 68 void btrfs_free_block_rsv(struct btrfs_fs_info 58 void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, 69 struct btrfs_block_r 59 struct btrfs_block_rsv *rsv); 70 int btrfs_block_rsv_add(struct btrfs_fs_info * !! 60 int btrfs_block_rsv_add(struct btrfs_root *root, 71 struct btrfs_block_rsv 61 struct btrfs_block_rsv *block_rsv, u64 num_bytes, 72 enum btrfs_reserve_flu 62 enum btrfs_reserve_flush_enum flush); 73 int btrfs_block_rsv_check(struct btrfs_block_r !! 63 int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor); 74 int btrfs_block_rsv_refill(struct btrfs_fs_inf !! 64 int btrfs_block_rsv_refill(struct btrfs_root *root, 75 struct btrfs_block_ !! 65 struct btrfs_block_rsv *block_rsv, u64 min_reserved, 76 enum btrfs_reserve_ 66 enum btrfs_reserve_flush_enum flush); 77 int btrfs_block_rsv_migrate(struct btrfs_block 67 int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, 78 struct btrfs_block 68 struct btrfs_block_rsv *dst_rsv, u64 num_bytes, 79 bool update_size); 69 bool update_size); 80 int btrfs_block_rsv_use_bytes(struct btrfs_blo 70 int btrfs_block_rsv_use_bytes(struct btrfs_block_rsv *block_rsv, u64 num_bytes); >> 71 int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info, >> 72 struct btrfs_block_rsv *dest, u64 num_bytes, >> 73 int min_factor); 81 void btrfs_block_rsv_add_bytes(struct btrfs_bl 74 void btrfs_block_rsv_add_bytes(struct btrfs_block_rsv *block_rsv, 82 u64 num_bytes, 75 u64 num_bytes, bool update_size); 83 u64 btrfs_block_rsv_release(struct btrfs_fs_in !! 76 u64 __btrfs_block_rsv_release(struct btrfs_fs_info *fs_info, 84 struct btrfs_blo 77 struct btrfs_block_rsv *block_rsv, 85 u64 num_bytes, u 78 u64 num_bytes, u64 *qgroup_to_release); 86 void btrfs_update_global_block_rsv(struct btrf 79 void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info); 87 void btrfs_init_global_block_rsv(struct btrfs_ 80 void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info); 88 void btrfs_release_global_block_rsv(struct btr 81 void btrfs_release_global_block_rsv(struct btrfs_fs_info *fs_info); 89 struct btrfs_block_rsv *btrfs_use_block_rsv(st 82 struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, 90 st 83 struct btrfs_root *root, 91 u3 84 u32 blocksize); 92 int btrfs_check_trunc_cache_free_space(const s << 93 struct << 94 static inline void btrfs_unuse_block_rsv(struc << 95 struc << 96 u32 b << 97 { << 98 btrfs_block_rsv_add_bytes(block_rsv, b << 99 btrfs_block_rsv_release(fs_info, block << 100 } << 101 85 102 /* !! 86 static inline void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info, 103 * Fast path to check if the reserve is full, !! 87 struct btrfs_block_rsv *block_rsv, 104 * locks. !! 88 u64 num_bytes) 105 */ << 106 static inline bool btrfs_block_rsv_full(const << 107 { 89 { 108 return data_race(rsv->full); !! 90 __btrfs_block_rsv_release(fs_info, block_rsv, num_bytes, NULL); 109 } 91 } 110 92 111 /* !! 93 static inline void btrfs_unuse_block_rsv(struct btrfs_fs_info *fs_info, 112 * Get the reserved mount of a block reserve i !! 94 struct btrfs_block_rsv *block_rsv, 113 * value is acceptable, instead of accessing i !! 95 u32 blocksize) 114 * warning from KCSAN. << 115 */ << 116 static inline u64 btrfs_block_rsv_reserved(str << 117 { 96 { 118 u64 ret; !! 97 btrfs_block_rsv_add_bytes(block_rsv, blocksize, false); 119 !! 98 btrfs_block_rsv_release(fs_info, block_rsv, 0); 120 spin_lock(&rsv->lock); << 121 ret = rsv->reserved; << 122 spin_unlock(&rsv->lock); << 123 << 124 return ret; << 125 } 99 } 126 100 127 /* 101 /* 128 * Get the size of a block reserve in a contex 102 * Get the size of a block reserve in a context where getting a stale value is 129 * acceptable, instead of accessing it directl 103 * acceptable, instead of accessing it directly and trigger data race warning 130 * from KCSAN. 104 * from KCSAN. 131 */ 105 */ 132 static inline u64 btrfs_block_rsv_size(struct 106 static inline u64 btrfs_block_rsv_size(struct btrfs_block_rsv *rsv) 133 { 107 { 134 u64 ret; 108 u64 ret; 135 109 136 spin_lock(&rsv->lock); 110 spin_lock(&rsv->lock); 137 ret = rsv->size; 111 ret = rsv->size; 138 spin_unlock(&rsv->lock); 112 spin_unlock(&rsv->lock); 139 113 140 return ret; 114 return ret; 141 } 115 } 142 116 143 #endif /* BTRFS_BLOCK_RSV_H */ 117 #endif /* BTRFS_BLOCK_RSV_H */ 144 118
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.