Skip to content

Commit 81f7eb0

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: destroy qgroup extent records on transaction abort
We clean up the delayed references when we abort a transaction but we leave the pending qgroup extent records behind, leaking memory. This patch destroys the extent records when we destroy the delayed refs and makes sure ensure they're gone before releasing the transaction. Fixes: 3368d00 ("btrfs: qgroup: Record possible quota-related extent for qgroup.") CC: [email protected] # 4.4+ Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Jeff Mahoney <[email protected]> [ Rebased to latest upstream, remove to_qgroup() helper, use rbtree_postorder_for_each_entry_safe() wrapper ] Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 52e29e3 commit 81f7eb0

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

fs/btrfs/disk-io.c

+1
Original file line numberDiff line numberDiff line change
@@ -4276,6 +4276,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
42764276
cond_resched();
42774277
spin_lock(&delayed_refs->lock);
42784278
}
4279+
btrfs_qgroup_destroy_extent_records(trans);
42794280

42804281
spin_unlock(&delayed_refs->lock);
42814282

fs/btrfs/qgroup.c

+13
Original file line numberDiff line numberDiff line change
@@ -4002,3 +4002,16 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
40024002
}
40034003
return ret;
40044004
}
4005+
4006+
void btrfs_qgroup_destroy_extent_records(struct btrfs_transaction *trans)
4007+
{
4008+
struct btrfs_qgroup_extent_record *entry;
4009+
struct btrfs_qgroup_extent_record *next;
4010+
struct rb_root *root;
4011+
4012+
root = &trans->delayed_refs.dirty_extent_root;
4013+
rbtree_postorder_for_each_entry_safe(entry, next, root, node) {
4014+
ulist_free(entry->old_roots);
4015+
kfree(entry);
4016+
}
4017+
}

fs/btrfs/qgroup.h

+1
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,6 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_trans_handle *trans,
414414
u64 last_snapshot);
415415
int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
416416
struct btrfs_root *root, struct extent_buffer *eb);
417+
void btrfs_qgroup_destroy_extent_records(struct btrfs_transaction *trans);
417418

418419
#endif

fs/btrfs/transaction.c

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
121121
BUG_ON(!list_empty(&transaction->list));
122122
WARN_ON(!RB_EMPTY_ROOT(
123123
&transaction->delayed_refs.href_root.rb_root));
124+
WARN_ON(!RB_EMPTY_ROOT(
125+
&transaction->delayed_refs.dirty_extent_root));
124126
if (transaction->delayed_refs.pending_csums)
125127
btrfs_err(transaction->fs_info,
126128
"pending csums is %llu",

0 commit comments

Comments
 (0)