btrfs: fix a bug with the squotas code and cleanup.
cover btrfs: fix a bug with the squotas code and cleanup.
From: Filipe Manana <[email protected]>
Fix a bug during log replay (regardless if quotas are enabled or not) and a cleanup.
Filipe Manana (2):
btrfs: fix lost error return value in btrfs_alloc_logged_file_extent()
btrfs: qgroup: make btrfs_record_squota_delta() return void
fs/btrfs/extent-tree.c | 11 ++++------- fs/btrfs/qgroup.c | 14 +++++--------- fs/btrfs/qgroup.h | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-)
Signature · 1 line
2.47.2
PATCH 1/2 btrfs: fix lost error return value in btrfs_alloc_logged_file_extent()
From: Filipe Manana <[email protected]>
If we fail to allocate a reserved file extent we then call btrfs_record_squota_delta() and assign its return value to 'ret', discarding the error from the failed allocation attempt and allowing log replay to proceed as if no errors happened, resulting in some replayed file extent item to point to an unallocated extent. At the moment btrfs_record_squota_delta() always returns 0 (success).
--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +2 -1
@@ -5227,7 +5227,8 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, offset, ins, 1, root_objectid);if (ret)btrfs_pin_extent (trans, ins->objectid, ins->offset); - ret =btrfs_record_squota_delta (fs_info, &delta); +else + ret =btrfs_record_squota_delta (fs_info, &delta);btrfs_put_block_group (block_group);return ret; }
Signature · 1 line
2.47.2
PATCH 2/2 btrfs: qgroup: make btrfs_record_squota_delta() return void
In reply to [email protected]From: Filipe Manana <[email protected]>
The function never returns any error, so simplify it and its callers by making it return void.
--- fs/btrfs/extent-tree.c | 10 +++------- fs/btrfs/qgroup.c | 14 +++++--------- fs/btrfs/qgroup.h | 4 ++-- 3 files changed, 10 insertions(+), 18 deletions(-)
fs/btrfs/extent-tree.c +3 -7
@@ -1658,7 +1658,7 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, href->owning_root);free_head_ref_squota_rsv (trans->fs_info, href);if (!ret) - ret =btrfs_record_squota_delta (trans->fs_info, &delta); +btrfs_record_squota_delta (trans->fs_info, &delta); }else if (node->action ==BTRFS_ADD_DELAYED_REF ) { ret =__btrfs_inc_extent_ref (trans, node, extent_op); }else if (node->action ==BTRFS_DROP_DELAYED_REF ) {
@@ -3180,11 +3180,7 @@ static int do_free_extent_accounting(struct btrfs_trans_handle *trans, } } - ret =btrfs_record_squota_delta (trans->fs_info, delta); -if (unlikely (ret)) { -btrfs_abort_transaction (trans, ret); -return ret; - } +btrfs_record_squota_delta (trans->fs_info, delta);/* If remapped, FST has already been taken care of in remove_range_from_remap_tree(). */ if (!remapped) {
@@ -5228,7 +5224,7 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,if (ret)btrfs_pin_extent (trans, ins->objectid, ins->offset);else - ret =btrfs_record_squota_delta (fs_info, &delta); +btrfs_record_squota_delta (fs_info, &delta);btrfs_put_block_group (block_group);return ret; }
fs/btrfs/qgroup.c +5 -9
@@ -4966,10 +4966,9 @@ void btrfs_qgroup_destroy_extent_records(struct btrfs_transaction *trans)xa_destroy (&trans->delayed_refs.dirty_extents); } -int btrfs_record_squota_delta (struct btrfs_fs_info *fs_info, -const struct btrfs_squota_delta *delta) +void btrfs_record_squota_delta (struct btrfs_fs_info *fs_info, +const struct btrfs_squota_delta *delta) { -int ret;struct btrfs_qgroup *qgroup;struct btrfs_qgroup *qg;LIST_HEAD (qgroup_list);
@@ -4979,24 +4978,22 @@ int btrfs_record_squota_delta(struct btrfs_fs_info *fs_info,if (btrfs_qgroup_mode (fs_info) !=BTRFS_QGROUP_MODE_SIMPLE && !test_bit (BTRFS_FS_SQUOTA_ENABLING , &fs_info->flags)) -return 0 ; +return ;if (!btrfs_is_fstree (root)) -return 0 ; +return ;/* If the extent predates enabling quotas, don't count it. */ if (delta->generation < fs_info->qgroup_enable_gen) -return 0 ; +return ;spin_lock (&fs_info->qgroup_lock); qgroup =find_qgroup_rb (fs_info, root);if (WARN_ON_ONCE (!qgroup)) {btrfs_warn (fs_info,"squota failed to find qgroup for root %llu" , root); - ret =0 ; goto out; } - ret =0 ;qgroup_iterator_add (&qgroup_list, qgroup);list_for_each_entry (qg, &qgroup_list, iterator) {struct btrfs_qgroup_list *glist;
@@ -5022,5 +5019,4 @@ int btrfs_record_squota_delta(struct btrfs_fs_info *fs_info, out:spin_unlock (&fs_info->qgroup_lock); -return ret; }
fs/btrfs/qgroup.h +2 -2
@@ -427,7 +427,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *eb);void btrfs_qgroup_destroy_extent_records (struct btrfs_transaction *trans);bool btrfs_check_quota_leak (const struct btrfs_fs_info *fs_info); -int btrfs_record_squota_delta (struct btrfs_fs_info *fs_info, -const struct btrfs_squota_delta *delta); +void btrfs_record_squota_delta (struct btrfs_fs_info *fs_info, +const struct btrfs_squota_delta *delta);#endif
Signature · 1 line
2.47.2
Quoted 4 lines · 在 2026/10/5 22:43, [email protected] 写道:
From: Filipe Manana <[email protected]>
Fix a bug during log replay (regardless if quotas are enabled or not) and a cleanup.
Thanks,
Qu
Quoted 10 lines
Filipe Manana (2):
btrfs: fix lost error return value inbtrfs_alloc_logged_file_extent()
btrfs: qgroup: makebtrfs_record_squota_delta()return voidfs/btrfs/extent-tree.c | 11 ++++------- fs/btrfs/qgroup.c | 14 +++++--------- fs/btrfs/qgroup.h | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-)