btrfs: qgroup API cleanups
cover btrfs: qgroup API cleanups
From: Filipe Manana <[email protected]>
Remove some unnecessary qgroup functions and exports and make the API simpler.
Filipe Manana (4):
btrfs: removed unused qgroup functions for pertrans reservation and freeing
btrfs: collapse __btrfs_qgroup_free_meta() into btrfs_qgroup_free_meta_prealloc()
btrfs: collapse __btrfs_qgroup_reserve_meta() into btrfs_qgroup_reserve_meta_prealloc()
btrfs: unexport btrfs_qgroup_reserve_meta()
fs/btrfs/delayed-inode.c | 3 +-- fs/btrfs/qgroup.c | 27 ++++++++++++++------------ fs/btrfs/qgroup.h | 42 +++------------------------------------- 3 files changed, 19 insertions(+), 53 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/4 btrfs: removed unused qgroup functions for pertrans reservation and freeing
From: Filipe Manana <[email protected]>
They have no more users since commit a6496849671a ("btrfs: fix start transaction qgroup rsv double free"), so remove them.
--- fs/btrfs/qgroup.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-)
fs/btrfs/qgroup.h +1 -16
@@ -397,14 +397,7 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,int __btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes,enum btrfs_qgroup_rsv_type type,bool enforce,bool noflush); -/* Reserve metadata space for pertrans and prealloc type */ -static inline int btrfs_qgroup_reserve_meta_pertrans (struct btrfs_root *root, -int num_bytes,bool enforce) -{ -return __btrfs_qgroup_reserve_meta (root, num_bytes, -BTRFS_QGROUP_RSV_META_PERTRANS , - enforce, false); -} +static inline int btrfs_qgroup_reserve_meta_prealloc (struct btrfs_root *root,int num_bytes,bool enforce,bool noflush)
@@ -417,14 +410,6 @@ static inline int btrfs_qgroup_reserve_meta_prealloc(struct btrfs_root *root,void __btrfs_qgroup_free_meta (struct btrfs_root *root,int num_bytes,enum btrfs_qgroup_rsv_type type); -/* Free per-transaction meta reservation for error handling */ -static inline void btrfs_qgroup_free_meta_pertrans (struct btrfs_root *root, -int num_bytes) -{ -__btrfs_qgroup_free_meta (root, num_bytes, -BTRFS_QGROUP_RSV_META_PERTRANS ); -} -/* Pre-allocated meta reservation can be freed at need */ static inline void btrfs_qgroup_free_meta_prealloc (struct btrfs_root *root,int num_bytes)
Signature · 1 line
2.47.2
PATCH 2/4 btrfs: collapse __btrfs_qgroup_free_meta() into btrfs_qgroup_free_meta_prealloc()
In reply to [email protected]From: Filipe Manana <[email protected]>
Since __btrfs_qgroup_free_meta() is only called by btrfs_qgroup_free_meta_prealloc(), which is a simple inline wrapper, get rid of the later and rename __btrfs_qgroup_free_meta() to the later.
--- fs/btrfs/qgroup.c | 12 +++++++----- fs/btrfs/qgroup.h | 10 +--------- 2 files changed, 8 insertions(+), 14 deletions(-)
fs/btrfs/qgroup.c +7 -5
@@ -4551,8 +4551,7 @@ void btrfs_qgroup_free_meta_all_pertrans(struct btrfs_root *root) BTRFS_QGROUP_RSV_META_PERTRANS); } -void __btrfs_qgroup_free_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type) +void btrfs_qgroup_free_meta_prealloc (struct btrfs_root *root,int num_bytes) {struct btrfs_fs_info *fs_info = root->fs_info;
@@ -4565,10 +4564,13 @@ void __btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes,* which can lead to underflow. * Here ensure we will only free what we really have reserved. */ - num_bytes =sub_root_meta_rsv (root, num_bytes, type); + num_bytes =sub_root_meta_rsv (root, num_bytes, +BTRFS_QGROUP_RSV_META_PREALLOC );BUG_ON (num_bytes !=round_down (num_bytes, fs_info->nodesize)); -trace_btrfs_qgroup_meta_reserve (root, -(s64 )num_bytes, type); -btrfs_qgroup_free_refroot (fs_info,btrfs_root_id (root), num_bytes, type); +trace_btrfs_qgroup_meta_reserve (root, -(s64 )num_bytes, +BTRFS_QGROUP_RSV_META_PREALLOC ); +btrfs_qgroup_free_refroot (fs_info,btrfs_root_id (root), num_bytes, +BTRFS_QGROUP_RSV_META_PREALLOC ); } static void qgroup_convert_meta(struct btrfs_fs_info *fs_info, u64 ref_root,
fs/btrfs/qgroup.h +1 -9
@@ -407,16 +407,8 @@ static inline int btrfs_qgroup_reserve_meta_prealloc(struct btrfs_root *root, enforce, noflush); } -void __btrfs_qgroup_free_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type); -/* Pre-allocated meta reservation can be freed at need */ -static inline void btrfs_qgroup_free_meta_prealloc (struct btrfs_root *root, -int num_bytes) -{ -__btrfs_qgroup_free_meta (root, num_bytes, -BTRFS_QGROUP_RSV_META_PREALLOC ); -} +void btrfs_qgroup_free_meta_prealloc (struct btrfs_root *root,int num_bytes);void btrfs_qgroup_free_meta_all_pertrans (struct btrfs_root *root);void btrfs_qgroup_convert_reserved_meta (struct btrfs_root *root,int num_bytes);
Signature · 1 line
2.47.2
PATCH 3/4 btrfs: collapse __btrfs_qgroup_reserve_meta() into btrfs_qgroup_reserve_meta_prealloc()
In reply to [email protected]From: Filipe Manana <[email protected]>
Since __btrfs_qgroup_reserve_meta() is only called by btrfs_qgroup_reserve_meta_prealloc(), which is a simple inline wrapper, get rid of the later and rename __btrfs_qgroup_reserve_meta() to the later.
--- fs/btrfs/qgroup.c | 11 ++++++----- fs/btrfs/qgroup.h | 15 ++------------- 2 files changed, 8 insertions(+), 18 deletions(-)
fs/btrfs/qgroup.c +6 -5
@@ -4516,20 +4516,21 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,return ret; } -int __btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type,bool enforce, -bool noflush) +int btrfs_qgroup_reserve_meta_prealloc (struct btrfs_root *root,int num_bytes, +bool enforce,bool noflush) {int ret; - ret =btrfs_qgroup_reserve_meta (root, num_bytes, type, enforce); + ret =btrfs_qgroup_reserve_meta (root, num_bytes, +BTRFS_QGROUP_RSV_META_PREALLOC , enforce);if ((ret <=0 && ret != -EDQUOT ) || noflush)return ret; ret =try_flush_qgroup (root);if (ret <0 )return ret; -return btrfs_qgroup_reserve_meta (root, num_bytes, type, enforce); +return btrfs_qgroup_reserve_meta (root, num_bytes, +BTRFS_QGROUP_RSV_META_PREALLOC , enforce); }/*
fs/btrfs/qgroup.h +2 -13
@@ -394,19 +394,8 @@ int btrfs_qgroup_free_data(struct btrfs_inode *inode, u64 len, u64 *freed);int btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes,enum btrfs_qgroup_rsv_type type,bool enforce); -int __btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type,bool enforce, -bool noflush); - -static inline int btrfs_qgroup_reserve_meta_prealloc (struct btrfs_root *root, -int num_bytes,bool enforce, -bool noflush) -{ -return __btrfs_qgroup_reserve_meta (root, num_bytes, -BTRFS_QGROUP_RSV_META_PREALLOC , - enforce, noflush); -} - +int btrfs_qgroup_reserve_meta_prealloc (struct btrfs_root *root,int num_bytes, +bool enforce,bool noflush);/* Pre-allocated meta reservation can be freed at need */ void btrfs_qgroup_free_meta_prealloc (struct btrfs_root *root,int num_bytes);
Signature · 1 line
2.47.2
PATCH 4/4 btrfs: unexport btrfs_qgroup_reserve_meta()
In reply to [email protected]From: Filipe Manana <[email protected]>
There's only one caller outside qgroup.c of btrfs_qgroup_reserve_meta() and we have btrfs_qgroup_reserve_meta_prealloc() is a wrapper around that function. Make that caller use btrfs_qgroup_reserve_meta_prealloc() and unexport btrfs_qgroup_reserve_meta(), simplifying the external API.
--- fs/btrfs/delayed-inode.c | 3 +-- fs/btrfs/qgroup.c | 4 ++-- fs/btrfs/qgroup.h | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-)
fs/btrfs/delayed-inode.c +1 -2
@@ -596,8 +596,7 @@ static int btrfs_delayed_inode_reserve_metadata(*/ if (!src_rsv || (!trans->bytes_reserved && src_rsv->type !=BTRFS_BLOCK_RSV_DELALLOC )) { - ret =btrfs_qgroup_reserve_meta (root, num_bytes, -BTRFS_QGROUP_RSV_META_PREALLOC , true); + ret =btrfs_qgroup_reserve_meta_prealloc (root, num_bytes, true, true);if (ret <0 )return ret; ret = btrfs_block_rsv_add(fs_info, dst_rsv, num_bytes,
fs/btrfs/qgroup.c +2 -2
@@ -4489,8 +4489,8 @@ static int sub_root_meta_rsv(struct btrfs_root *root, int num_bytes,return num_bytes; } -int btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type,bool enforce) +static int btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes, +enum btrfs_qgroup_rsv_type type,bool enforce) {struct btrfs_fs_info *fs_info = root->fs_info;int ret;
fs/btrfs/qgroup.h +0 -2
@@ -392,8 +392,6 @@ int btrfs_qgroup_release_data(struct btrfs_inode *inode, u64 start, u64 len, u64int btrfs_qgroup_free_data (struct btrfs_inode *inode,struct extent_changeset *reserved,u64 start,u64 len,u64 *freed); -int btrfs_qgroup_reserve_meta (struct btrfs_root *root,int num_bytes, -enum btrfs_qgroup_rsv_type type,bool enforce);int btrfs_qgroup_reserve_meta_prealloc (struct btrfs_root *root,int num_bytes,bool enforce,bool noflush);/* Pre-allocated meta reservation can be freed at need */
Signature · 1 line
2.47.2
Quoted 4 lines · 在 2026/3/18 06:16, [email protected] 写道:
From: Filipe Manana <[email protected]>
Remove some unnecessary qgroup functions and exports and make the API simpler.
Thanks,
Qu
Quoted 12 lines
Filipe Manana (4):
btrfs: removed unused qgroup functions for pertrans reservation and freeing
btrfs: collapse__btrfs_qgroup_free_meta()intobtrfs_qgroup_free_meta_prealloc()
btrfs: collapse__btrfs_qgroup_reserve_meta()intobtrfs_qgroup_reserve_meta_prealloc()
btrfs: unexportbtrfs_qgroup_reserve_meta()fs/btrfs/delayed-inode.c | 3 +-- fs/btrfs/qgroup.c | 27 ++++++++++++++------------ fs/btrfs/qgroup.h | 42 +++------------------------------------- 3 files changed, 19 insertions(+), 53 deletions(-)