Re: [PATCH 3/4] btrfs: Expoert and move leaf/subtree qgroup helpers to qgroup.c
Reviewed-and-Tested-by: Goldwyn RodriguesOn 10/17/2016 08:31 PM, Qu Wenruo wrote: > Move account_shared_subtree() to qgroup.c and rename it to > btrfs_qgroup_trace_subtree(). > > Do the same thing for account_leaf_items() and rename it to > btrfs_qgroup_trace_leaf_items(). > > Since all these functions are only for qgroup, move them to qgroup.c and > export them is more appropriate. > > Signed-off-by: Qu Wenruo > --- > fs/btrfs/extent-tree.c | 220 > + > fs/btrfs/qgroup.c | 211 +++ > fs/btrfs/qgroup.h | 23 ++ > 3 files changed, 237 insertions(+), 217 deletions(-) > > diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c > index 024eb5d..f7aa49d 100644 > --- a/fs/btrfs/extent-tree.c > +++ b/fs/btrfs/extent-tree.c > @@ -8535,220 +8535,6 @@ reada: > wc->reada_slot = slot; > } > > -static int account_leaf_items(struct btrfs_trans_handle *trans, > - struct btrfs_root *root, > - struct extent_buffer *eb) > -{ > - int nr = btrfs_header_nritems(eb); > - int i, extent_type, ret; > - struct btrfs_key key; > - struct btrfs_file_extent_item *fi; > - u64 bytenr, num_bytes; > - > - /* We can be called directly from walk_up_proc() */ > - if (!test_bit(BTRFS_FS_QUOTA_ENABLED, >fs_info->flags)) > - return 0; > - > - for (i = 0; i < nr; i++) { > - btrfs_item_key_to_cpu(eb, , i); > - > - if (key.type != BTRFS_EXTENT_DATA_KEY) > - continue; > - > - fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); > - /* filter out non qgroup-accountable extents */ > - extent_type = btrfs_file_extent_type(eb, fi); > - > - if (extent_type == BTRFS_FILE_EXTENT_INLINE) > - continue; > - > - bytenr = btrfs_file_extent_disk_bytenr(eb, fi); > - if (!bytenr) > - continue; > - > - num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); > - > - ret = btrfs_qgroup_trace_extent(trans, root->fs_info, > - bytenr, num_bytes, GFP_NOFS); > - if (ret) > - return ret; > - } > - return 0; > -} > - > -/* > - * Walk up the tree from the bottom, freeing leaves and any interior > - * nodes which have had all slots visited. If a node (leaf or > - * interior) is freed, the node above it will have it's slot > - * incremented. The root node will never be freed. > - * > - * At the end of this function, we should have a path which has all > - * slots incremented to the next position for a search. If we need to > - * read a new node it will be NULL and the node above it will have the > - * correct slot selected for a later read. > - * > - * If we increment the root nodes slot counter past the number of > - * elements, 1 is returned to signal completion of the search. > - */ > -static int adjust_slots_upwards(struct btrfs_root *root, > - struct btrfs_path *path, int root_level) > -{ > - int level = 0; > - int nr, slot; > - struct extent_buffer *eb; > - > - if (root_level == 0) > - return 1; > - > - while (level <= root_level) { > - eb = path->nodes[level]; > - nr = btrfs_header_nritems(eb); > - path->slots[level]++; > - slot = path->slots[level]; > - if (slot >= nr || level == 0) { > - /* > - * Don't free the root - we will detect this > - * condition after our loop and return a > - * positive value for caller to stop walking the tree. > - */ > - if (level != root_level) { > - btrfs_tree_unlock_rw(eb, path->locks[level]); > - path->locks[level] = 0; > - > - free_extent_buffer(eb); > - path->nodes[level] = NULL; > - path->slots[level] = 0; > - } > - } else { > - /* > - * We have a valid slot to walk back down > - * from. Stop here so caller can process these > - * new nodes. > - */ > - break; > - } > - > - level++; > - } > - > - eb = path->nodes[root_level]; > - if (path->slots[root_level] >= btrfs_header_nritems(eb)) > - return 1; > - > - return 0; > -} > - > -/* > - * root_eb is the subtree root and is locked before this function is called. > - */ > -static int account_shared_subtree(struct btrfs_trans_handle *trans, > -
[PATCH 3/4] btrfs: Expoert and move leaf/subtree qgroup helpers to qgroup.c
Move account_shared_subtree() to qgroup.c and rename it to btrfs_qgroup_trace_subtree(). Do the same thing for account_leaf_items() and rename it to btrfs_qgroup_trace_leaf_items(). Since all these functions are only for qgroup, move them to qgroup.c and export them is more appropriate. Signed-off-by: Qu Wenruo--- fs/btrfs/extent-tree.c | 220 + fs/btrfs/qgroup.c | 211 +++ fs/btrfs/qgroup.h | 23 ++ 3 files changed, 237 insertions(+), 217 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 024eb5d..f7aa49d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8535,220 +8535,6 @@ reada: wc->reada_slot = slot; } -static int account_leaf_items(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct extent_buffer *eb) -{ - int nr = btrfs_header_nritems(eb); - int i, extent_type, ret; - struct btrfs_key key; - struct btrfs_file_extent_item *fi; - u64 bytenr, num_bytes; - - /* We can be called directly from walk_up_proc() */ - if (!test_bit(BTRFS_FS_QUOTA_ENABLED, >fs_info->flags)) - return 0; - - for (i = 0; i < nr; i++) { - btrfs_item_key_to_cpu(eb, , i); - - if (key.type != BTRFS_EXTENT_DATA_KEY) - continue; - - fi = btrfs_item_ptr(eb, i, struct btrfs_file_extent_item); - /* filter out non qgroup-accountable extents */ - extent_type = btrfs_file_extent_type(eb, fi); - - if (extent_type == BTRFS_FILE_EXTENT_INLINE) - continue; - - bytenr = btrfs_file_extent_disk_bytenr(eb, fi); - if (!bytenr) - continue; - - num_bytes = btrfs_file_extent_disk_num_bytes(eb, fi); - - ret = btrfs_qgroup_trace_extent(trans, root->fs_info, - bytenr, num_bytes, GFP_NOFS); - if (ret) - return ret; - } - return 0; -} - -/* - * Walk up the tree from the bottom, freeing leaves and any interior - * nodes which have had all slots visited. If a node (leaf or - * interior) is freed, the node above it will have it's slot - * incremented. The root node will never be freed. - * - * At the end of this function, we should have a path which has all - * slots incremented to the next position for a search. If we need to - * read a new node it will be NULL and the node above it will have the - * correct slot selected for a later read. - * - * If we increment the root nodes slot counter past the number of - * elements, 1 is returned to signal completion of the search. - */ -static int adjust_slots_upwards(struct btrfs_root *root, - struct btrfs_path *path, int root_level) -{ - int level = 0; - int nr, slot; - struct extent_buffer *eb; - - if (root_level == 0) - return 1; - - while (level <= root_level) { - eb = path->nodes[level]; - nr = btrfs_header_nritems(eb); - path->slots[level]++; - slot = path->slots[level]; - if (slot >= nr || level == 0) { - /* -* Don't free the root - we will detect this -* condition after our loop and return a -* positive value for caller to stop walking the tree. -*/ - if (level != root_level) { - btrfs_tree_unlock_rw(eb, path->locks[level]); - path->locks[level] = 0; - - free_extent_buffer(eb); - path->nodes[level] = NULL; - path->slots[level] = 0; - } - } else { - /* -* We have a valid slot to walk back down -* from. Stop here so caller can process these -* new nodes. -*/ - break; - } - - level++; - } - - eb = path->nodes[root_level]; - if (path->slots[root_level] >= btrfs_header_nritems(eb)) - return 1; - - return 0; -} - -/* - * root_eb is the subtree root and is locked before this function is called. - */ -static int account_shared_subtree(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct extent_buffer *root_eb, - u64 root_gen, - int root_level) -{ - int ret = 0; - int level; -