btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent()
Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions: 1. btrfs_qgroup_insert_dirty_extent_nolock() Almost the same with original code. For delayed_ref usage, which has delayed refs locked. Change the return value type to int, since caller never needs the pointer, but only needs to know if they need to free the allocated memory. 2. btrfs_qgroup_insert_dirty_extent() The more encapsulated version. Will do the delayed_refs lock, memory allocation, quota enabled check and other things. The original design is to keep exported functions to minimal, but since more btrfs hacks exposed, like replacing path in balance, we need to record dirty extents manually, so we have to add such functions. Also, add comment for both functions, to info developers how to keep qgroup correct when doing hacks. Cc: Mark Fasheh <mfasheh@suse.de> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-and-Tested-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Chris Mason <clm@fb.com>
This commit is contained in:
@ -8521,35 +8521,6 @@ reada:
|
||||
wc->reada_slot = slot;
|
||||
}
|
||||
|
||||
/*
|
||||
* These may not be seen by the usual inc/dec ref code so we have to
|
||||
* add them here.
|
||||
*/
|
||||
static int record_one_subtree_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root, u64 bytenr,
|
||||
u64 num_bytes)
|
||||
{
|
||||
struct btrfs_qgroup_extent_record *qrecord;
|
||||
struct btrfs_delayed_ref_root *delayed_refs;
|
||||
|
||||
qrecord = kmalloc(sizeof(*qrecord), GFP_NOFS);
|
||||
if (!qrecord)
|
||||
return -ENOMEM;
|
||||
|
||||
qrecord->bytenr = bytenr;
|
||||
qrecord->num_bytes = num_bytes;
|
||||
qrecord->old_roots = NULL;
|
||||
|
||||
delayed_refs = &trans->transaction->delayed_refs;
|
||||
spin_lock(&delayed_refs->lock);
|
||||
if (btrfs_qgroup_insert_dirty_extent(trans->fs_info,
|
||||
delayed_refs, qrecord))
|
||||
kfree(qrecord);
|
||||
spin_unlock(&delayed_refs->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int account_leaf_items(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root,
|
||||
struct extent_buffer *eb)
|
||||
@ -8583,7 +8554,8 @@ static int account_leaf_items(struct btrfs_trans_handle *trans,
|
||||
|
||||
num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi);
|
||||
|
||||
ret = record_one_subtree_extent(trans, root, bytenr, num_bytes);
|
||||
ret = btrfs_qgroup_insert_dirty_extent(trans, root->fs_info,
|
||||
bytenr, num_bytes, GFP_NOFS);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
@ -8732,8 +8704,9 @@ walk_down:
|
||||
btrfs_set_lock_blocking_rw(eb, BTRFS_READ_LOCK);
|
||||
path->locks[level] = BTRFS_READ_LOCK_BLOCKING;
|
||||
|
||||
ret = record_one_subtree_extent(trans, root, child_bytenr,
|
||||
root->nodesize);
|
||||
ret = btrfs_qgroup_insert_dirty_extent(trans,
|
||||
root->fs_info, child_bytenr,
|
||||
root->nodesize, GFP_NOFS);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
|
Reference in New Issue
Block a user