Misc transaction cleanups
cover Misc transaction cleanups
Here are a bunch of transaction-related cleanups all of them present no functional changes. The first 2 patches could be more interesting - the first one moves trans_release_metadata to transaction.c and makes it static and the second one opencodes btrfs_write_and_wait_marked_extents in its sole caller to make the chall chain shorter. The rest of the patches just kill the extraneous fs_info argument since they also take either a btrfs_trans_handle or btrfs_transaction pointer which already contain fs_info.
The modified functions are all called from btrfs_commit_transaction. With this series applied the only function which remain that still take fs_info and some type of transaction reference are:
btrfs_finish_extent_commitbtrfs_qgroup_account_extentsbtrfs_run_delayed_refs
The reason I haven't touched them is that David expressed some reservation about mass cleaning of functions which are more or less public interface. And the above 3 are such functions. David if you don't objec to converting those 3 I will keep them in mind when doing further cleanups in the transaction area.
Nikolay Borisov (14):
btrfs: Make btrfs_trans_release_metadata private to transaction.c
btrfs: Open code btrfs_write_and_wait_marked_extents
btrfs: Remove fs_info argument from btrfs_trans_release_metadata
btrfs: Remove fs_info argument from btrfs_create_pending_block_groups
btrfs: Don't pass fs_info arg to btrfs_start_dirty_block_groups
btrfs: Don't pass fs_info to __btrfs_run_delayed_items
btrfs: Don't pass fs_info to btrfs_run_delayed_items/_nr
btrfs: Don't pass fs_info to commit_fs_roots
btrfs: Don't pass fs_info to commit_cowonly_roots
btrfs: Remove root argument of cleanup_transaction
btrfs: Remove fs_info argument from switch_commit_roots
btrfs: Remove fs_info argument from
create_pending_snapshots/create_pending_snapshot
btrfs: Remove fs_info argument from
btrfs_update_commit_device_bytes_used
btrfs: Remove fs_info argument of btrfs_write_and_wait_transaction
fs/btrfs/ctree.h | 8 +-- fs/btrfs/delayed-inode.c | 14 +++-- fs/btrfs/delayed-inode.h | 6 +-- fs/btrfs/extent-tree.c | 34 +++--------- fs/btrfs/transaction.c | 134 ++++++++++++++++++++++++++--------------------- fs/btrfs/tree-log.c | 12 ++--- fs/btrfs/volumes.c | 10 ++-- fs/btrfs/volumes.h | 3 +- 8 files changed, 101 insertions(+), 120 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/14 btrfs: Make btrfs_trans_release_metadata private to transaction.c
This function is only ever used in __btrfs_end_transaction and btrfs_commit_transaction so there is no need to export it via header. Let's move it closer to where it's used, make it static and remove it from the header. No functional changes
--- fs/btrfs/ctree.h | 2 -- fs/btrfs/extent-tree.c | 18 ------------------ fs/btrfs/transaction.c | 19 +++++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-)
fs/btrfs/ctree.h +0 -2
@@ -2748,8 +2748,6 @@ void btrfs_delalloc_release_space(struct inode *inode, struct extent_changeset *reserved, u64 start, u64 len);void btrfs_free_reserved_data_space_noquota (struct inode *inode,u64 start,u64 len); -void btrfs_trans_release_metadata (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info);void btrfs_trans_release_chunk_metadata (struct btrfs_trans_handle *trans);int btrfs_orphan_reserve_metadata (struct btrfs_trans_handle *trans,struct btrfs_inode *inode);
fs/btrfs/extent-tree.c +0 -18
@@ -5893,24 +5893,6 @@ static void release_global_block_rsv(struct btrfs_fs_info *fs_info)WARN_ON (fs_info->delayed_block_rsv.reserved >0 ); } -void btrfs_trans_release_metadata (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) -{ -if (!trans->block_rsv) { -ASSERT (!trans->bytes_reserved); -return ; - } - -if (!trans->bytes_reserved) -return ; - -ASSERT (trans->block_rsv == &fs_info->trans_block_rsv); -trace_btrfs_space_reservation (fs_info,"transaction" , - trans->transid, trans->bytes_reserved,0 ); -btrfs_block_rsv_release (fs_info, trans->block_rsv, - trans->bytes_reserved); - trans->bytes_reserved =0 ; -}/* * To be called after all the new block groups attached to the transaction
fs/btrfs/transaction.c +19 -0
@@ -818,6 +818,25 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)return should_end_transaction (trans); } +static void btrfs_trans_release_metadata (struct btrfs_trans_handle *trans, +struct btrfs_fs_info *fs_info) +{ +if (!trans->block_rsv) { +ASSERT (!trans->bytes_reserved); +return ; + } + +if (!trans->bytes_reserved) +return ; + +ASSERT (trans->block_rsv == &fs_info->trans_block_rsv); +trace_btrfs_space_reservation (fs_info,"transaction" , + trans->transid, trans->bytes_reserved,0 ); +btrfs_block_rsv_release (fs_info, trans->block_rsv, + trans->bytes_reserved); + trans->bytes_reserved =0 ; +} +static int __btrfs_end_transaction (struct btrfs_trans_handle *trans,int throttle) {
Signature · 1 line
2.7.4
PATCH 2/14 btrfs: Open code btrfs_write_and_wait_marked_extents
In reply to Nikolay Borisovbtrfs_write_and_wait_transaction is essentially a wrapper of btrfs_write_and_wait_marked_extents with the addition of calling clear_btree_io_tree. Having the code split doesn't really bring any benefit. Open code the later into the former and add proper documentation header.
--- fs/btrfs/transaction.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-)
fs/btrfs/transaction.c +16 -24
@@ -1082,41 +1082,33 @@ int btrfs_wait_tree_log_extents(struct btrfs_root *log_root, int mark)return err; } -/* -* when btree blocks are allocated, they have some corresponding bits set for -* them in one of two extent_io trees. This is used to make sure all of -* those extents are on disk for transaction or log commit + +/* btrfs_write_and_wait_transaction - When btree blocks are allocated the +* corresponding extents are marked dirty. This function ensures such extents +* are persisted on disk for * transaction or log commit. +* +* @trans: transaction whose dirty pages we'd like to write */ -static int btrfs_write_and_wait_marked_extents (struct btrfs_fs_info *fs_info, -struct extent_io_tree *dirty_pages,int mark) +static int btrfs_write_and_wait_transaction (struct btrfs_trans_handle *trans, +struct btrfs_fs_info *fs_info) { -int ret; -int ret2; +struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages;struct blk_plug plug; +int ret, ret2;blk_start_plug (&plug); - ret =btrfs_write_marked_extents (fs_info, dirty_pages, mark); + ret =btrfs_write_marked_extents (fs_info, dirty_pages,EXTENT_DIRTY );blk_finish_plug (&plug); ret2 =btrfs_wait_extents (fs_info, dirty_pages); +clear_btree_io_tree (&trans->transaction->dirty_pages); +if (ret)return ret; -if (ret2) +else if (ret2)return ret2; -return 0 ; -} - -static int btrfs_write_and_wait_transaction (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) -{ -int ret; - - ret =btrfs_write_and_wait_marked_extents (fs_info, - &trans->transaction->dirty_pages, -EXTENT_DIRTY ); -clear_btree_io_tree (&trans->transaction->dirty_pages); - -return ret; +else +return 0 ; }/*
Signature · 1 line
2.7.4
PATCH 3/14 btrfs: Remove fs_info argument from btrfs_trans_release_metadata
In reply to Nikolay BorisovAll current callers of this function just get a reference to the trans->fs_info member and pass it as the second argument. Collapse this into the function itself. No functional changes
--- fs/btrfs/transaction.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/btrfs/transaction.c +8 -6
@@ -818,9 +818,11 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)return should_end_transaction (trans); } -static void btrfs_trans_release_metadata (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +static void btrfs_trans_release_metadata (struct btrfs_trans_handle *trans) + { +struct btrfs_fs_info *fs_info = trans->fs_info; +if (!trans->block_rsv) {ASSERT (!trans->bytes_reserved);return ;
@@ -854,7 +856,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,return 0 ; } -btrfs_trans_release_metadata (trans, info); +btrfs_trans_release_metadata (trans); trans->block_rsv =NULL ;if (!list_empty (&trans->new_bgs))
@@ -875,7 +877,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, must_run_delayed_refs =2 ; } -btrfs_trans_release_metadata (trans, info); +btrfs_trans_release_metadata (trans); trans->block_rsv =NULL ;if (!list_empty (&trans->new_bgs))
@@ -1968,7 +1970,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)return ret; } -btrfs_trans_release_metadata (trans, fs_info); +btrfs_trans_release_metadata (trans); trans->block_rsv =NULL ; cur_trans = trans->transaction;
@@ -2322,7 +2324,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) scrub_continue:btrfs_scrub_continue (fs_info); cleanup_transaction: -btrfs_trans_release_metadata (trans, fs_info); +btrfs_trans_release_metadata (trans);btrfs_trans_release_chunk_metadata (trans); trans->block_rsv =NULL ;btrfs_warn (fs_info,"Skipping commit of aborted transaction." );
Signature · 1 line
2.7.4
PATCH 4/14 btrfs: Remove fs_info argument from btrfs_create_pending_block_groups
In reply to Nikolay BorisovIt can be referenced from the passed transaciton so no point in passing it as function argument. No functional changes
--- fs/btrfs/ctree.h | 3 +-- fs/btrfs/extent-tree.c | 10 +++++----- fs/btrfs/transaction.c | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-)
fs/btrfs/ctree.h +1 -2
@@ -2712,8 +2712,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,void btrfs_delete_unused_bgs (struct btrfs_fs_info *fs_info);void btrfs_get_block_group_trimming (struct btrfs_block_group_cache *cache);void btrfs_put_block_group_trimming (struct btrfs_block_group_cache *cache); -void btrfs_create_pending_block_groups (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info); +void btrfs_create_pending_block_groups (struct btrfs_trans_handle *trans);u64 btrfs_data_alloc_profile (struct btrfs_fs_info *fs_info);u64 btrfs_metadata_alloc_profile (struct btrfs_fs_info *fs_info);u64 btrfs_system_alloc_profile (struct btrfs_fs_info *fs_info);
fs/btrfs/extent-tree.c +5 -5
@@ -3086,7 +3086,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,if (run_all) {if (!list_empty (&trans->new_bgs)) -btrfs_create_pending_block_groups (trans, fs_info); +btrfs_create_pending_block_groups (trans);spin_lock (&delayed_refs->lock); node =rb_first (&delayed_refs->href_root);
@@ -3686,7 +3686,7 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans,* make sure all the block groups on our dirty list actually * exist */ -btrfs_create_pending_block_groups (trans, fs_info); +btrfs_create_pending_block_groups (trans);if (!path) { path =btrfs_alloc_path ();
@@ -4706,7 +4706,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,*/ if (trans->can_flush_pending_bgs && trans->chunk_bytes_reserved >= (u64 )SZ_2M ) { -btrfs_create_pending_block_groups (trans, fs_info); +btrfs_create_pending_block_groups (trans);btrfs_trans_release_chunk_metadata (trans); }return ret;
@@ -10130,9 +10130,9 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)return ret; } -void btrfs_create_pending_block_groups (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +void btrfs_create_pending_block_groups (struct btrfs_trans_handle *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_block_group_cache *block_group, *tmp;struct btrfs_root *extent_root = fs_info->extent_root;struct btrfs_block_group_item item;
fs/btrfs/transaction.c +3 -3
@@ -860,7 +860,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, trans->block_rsv =NULL ;if (!list_empty (&trans->new_bgs)) -btrfs_create_pending_block_groups (trans, info); +btrfs_create_pending_block_groups (trans); trans->delayed_ref_updates =0 ;if (!trans->sync) {
@@ -881,7 +881,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, trans->block_rsv =NULL ;if (!list_empty (&trans->new_bgs)) -btrfs_create_pending_block_groups (trans, info); +btrfs_create_pending_block_groups (trans);btrfs_trans_release_chunk_metadata (trans);
@@ -1983,7 +1983,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)smp_wmb ();if (!list_empty (&trans->new_bgs)) -btrfs_create_pending_block_groups (trans, fs_info); +btrfs_create_pending_block_groups (trans); ret =btrfs_run_delayed_refs (trans, fs_info,0 );if (ret) {
Signature · 1 line
2.7.4
PATCH 5/14 btrfs: Don't pass fs_info arg to btrfs_start_dirty_block_groups
In reply to Nikolay BorisovIt can be referenced from the passed transaction so no point in passing it as a function argument. No functional changes
--- fs/btrfs/ctree.h | 3 +-- fs/btrfs/extent-tree.c | 4 ++-- fs/btrfs/transaction.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +1 -2
@@ -2690,8 +2690,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid, u64 owner, u64 offset); -int btrfs_start_dirty_block_groups (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info); +int btrfs_start_dirty_block_groups (struct btrfs_trans_handle *trans);int btrfs_write_dirty_block_groups (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info); int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
fs/btrfs/extent-tree.c +2 -2
@@ -3660,9 +3660,9 @@ int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,* the commit latency by getting rid of the easy block groups while * we're still allowing others to join the commit. */ -int btrfs_start_dirty_block_groups (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +int btrfs_start_dirty_block_groups (struct btrfs_trans_handle *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_block_group_cache *cache;struct btrfs_transaction *cur_trans = trans->transaction;int ret =0 ;
fs/btrfs/transaction.c +1 -1
@@ -2014,7 +2014,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)mutex_unlock (&fs_info->ro_block_group_mutex);if (run_it) - ret =btrfs_start_dirty_block_groups (trans, fs_info); + ret =btrfs_start_dirty_block_groups (trans); }if (ret) {btrfs_end_transaction (trans);
Signature · 1 line
2.7.4
PATCH 6/14 btrfs: Don't pass fs_info to __btrfs_run_delayed_items
In reply to Nikolay BorisovWe already pass the transactino handle, which contains a refrence to the fs_info so grab it from there. No functional changes
--- fs/btrfs/delayed-inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/delayed-inode.c +4 -4
@@ -1114,9 +1114,9 @@ __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,* Returns < 0 on error and returns with an aborted transaction with any * outstanding delayed items cleaned up. */ -static int __btrfs_run_delayed_items (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,int nr) +static int __btrfs_run_delayed_items (struct btrfs_trans_handle *trans,int nr) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_delayed_root *delayed_root;struct btrfs_delayed_node *curr_node, *prev_node;struct btrfs_path *path;
@@ -1164,13 +1164,13 @@ static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans,int btrfs_run_delayed_items (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info) { -return __btrfs_run_delayed_items (trans, fs_info,-1 ); +return __btrfs_run_delayed_items (trans,-1 ); }int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,int nr) { -return __btrfs_run_delayed_items (trans, fs_info, nr); +return __btrfs_run_delayed_items (trans, nr); } int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
Signature · 1 line
2.7.4
PATCH 7/14 btrfs: Don't pass fs_info to btrfs_run_delayed_items/_nr
In reply to Nikolay BorisovWe already pass the transaction which has a reference to the fs_info, so use that. No functional changes
--- fs/btrfs/delayed-inode.c | 6 ++---- fs/btrfs/delayed-inode.h | 6 ++---- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/transaction.c | 8 ++++---- fs/btrfs/tree-log.c | 12 ++++-------- 5 files changed, 13 insertions(+), 21 deletions(-)
fs/btrfs/delayed-inode.c +2 -4
@@ -1161,14 +1161,12 @@ static int __btrfs_run_delayed_items(struct btrfs_trans_handle *trans, int nr)return ret; } -int btrfs_run_delayed_items (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +int btrfs_run_delayed_items (struct btrfs_trans_handle *trans) {return __btrfs_run_delayed_items (trans,-1 ); } -int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,int nr) +int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans,int nr) {return __btrfs_run_delayed_items (trans, nr); }
fs/btrfs/delayed-inode.h +2 -4
@@ -111,10 +111,8 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,int btrfs_inode_delayed_dir_index_count (struct btrfs_inode *inode); -int btrfs_run_delayed_items (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info); -int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,int nr); +int btrfs_run_delayed_items (struct btrfs_trans_handle *trans); +int btrfs_run_delayed_items_nr (struct btrfs_trans_handle *trans,int nr);void btrfs_balance_delayed_items (struct btrfs_fs_info *fs_info);
fs/btrfs/extent-tree.c +1 -1
@@ -4994,7 +4994,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, ret =PTR_ERR (trans);break ; } - ret =btrfs_run_delayed_items_nr (trans, fs_info, nr); + ret =btrfs_run_delayed_items_nr (trans, nr);btrfs_end_transaction (trans);break ;case FLUSH_DELALLOC :
fs/btrfs/transaction.c +4 -4
@@ -1529,7 +1529,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,* otherwise we corrupt the FS during * snapshot */ - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);if (ret) {/* Transaction aborted */ btrfs_abort_transaction (trans, ret); goto fail;
@@ -2066,7 +2066,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)if (ret) goto cleanup_transaction; - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);if (ret) goto cleanup_transaction;
@@ -2074,7 +2074,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) extwriter_counter_read(cur_trans) == 0);/* some pending stuffs might be added after the previous flush. */ - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);if (ret) goto cleanup_transaction;
@@ -2127,7 +2127,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* because all the tree which are snapshoted will be forced to COW * the nodes and leaves. */ - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);if (ret) {mutex_unlock (&fs_info->reloc_mutex); goto scrub_continue;
fs/btrfs/tree-log.c +4 -8
@@ -852,7 +852,6 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,struct btrfs_inode *dir, struct btrfs_dir_item *di) { - struct btrfs_fs_info *fs_info = root->fs_info; struct inode *inode;char *name;int name_len;
@@ -886,7 +885,7 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,if (ret) goto out;else - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans); out:kfree (name);iput (inode);
@@ -1004,7 +1003,6 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans, u64 ref_index, char *name, int namelen, int *search_done) { - struct btrfs_fs_info *fs_info = root->fs_info; int ret;char *victim_name;int victim_name_len;
@@ -1062,7 +1060,7 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,kfree (victim_name);if (ret)return ret; - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);if (ret)return ret; *search_done =1 ;
@@ -1133,8 +1131,7 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans, victim_name_len);if (!ret) ret =btrfs_run_delayed_items ( - trans, - fs_info); + trans); }iput (victim_parent);kfree (victim_name);
@@ -1991,7 +1988,6 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,struct inode *dir, struct btrfs_key *dir_key) { - struct btrfs_fs_info *fs_info = root->fs_info; int ret;struct extent_buffer *eb;int slot;
@@ -2055,7 +2051,7 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans, ret =btrfs_unlink_inode (trans, root,BTRFS_I (dir),BTRFS_I (inode), name, name_len);if (!ret) - ret =btrfs_run_delayed_items (trans, fs_info); + ret =btrfs_run_delayed_items (trans);kfree (name);iput (inode);if (ret)
Signature · 1 line
2.7.4
PATCH 8/14 btrfs: Don't pass fs_info to commit_fs_roots
In reply to Nikolay BorisovWe already pass the transaction handle which has a reference to the fs_info. No functional changes
--- fs/btrfs/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +4 -4
@@ -1256,9 +1256,9 @@ void btrfs_add_dead_root(struct btrfs_root *root)/* * update all the cowonly tree roots on disk */ -static noinline int commit_fs_roots(struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_root *gang[8 ];int i;int ret;
@@ -1376,7 +1376,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,*/ mutex_lock (&fs_info->tree_log_mutex); - ret =commit_fs_roots (trans, fs_info); + ret =commit_fs_roots (trans);if (ret) goto out; ret =btrfs_qgroup_account_extents (trans, fs_info);
@@ -2162,7 +2162,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)*/ mutex_lock (&fs_info->tree_log_mutex); - ret =commit_fs_roots (trans, fs_info); + ret =commit_fs_roots (trans);if (ret) {mutex_unlock (&fs_info->tree_log_mutex);mutex_unlock (&fs_info->reloc_mutex);
Signature · 1 line
2.7.4
PATCH 9/14 btrfs: Don't pass fs_info to commit_cowonly_roots
In reply to Nikolay BorisovWe already pass a transaction handle which refrences the fs_info so we can grab it from there. No functional changes
--- fs/btrfs/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +4 -4
@@ -1160,9 +1160,9 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans,* failures will cause the file system to go offline. We still need * to clean up the delayed refs. */ -static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct list_head *dirty_bgs = &trans->transaction->dirty_bgs;struct list_head *io_bgs = &trans->transaction->io_bgs;struct list_head *next;
@@ -1402,7 +1402,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,* like chunk and root tree, as they won't affect qgroup. * And we don't write super to avoid half committed status. */ - ret =commit_cowonly_roots (trans, fs_info); + ret =commit_cowonly_roots (trans);if (ret) goto out;switch_commit_roots (trans->transaction, fs_info);
@@ -2202,7 +2202,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) goto scrub_continue; } - ret =commit_cowonly_roots (trans, fs_info); + ret =commit_cowonly_roots (trans);if (ret) {mutex_unlock (&fs_info->tree_log_mutex);mutex_unlock (&fs_info->reloc_mutex);
Signature · 1 line
2.7.4
PATCH 10/14 btrfs: Remove root argument of cleanup_transaction
In reply to Nikolay BorisovThe only thing the passed root is used for is:
1. get a reference to the fs_info and to
2. call trace_btrfs_transaction_commit.
We can achieve 1) by simply referring to the fs_info from passed trans object. As far as 2) is concerned cleanup_transaction is called from only one place and the 'root' argument passed is the one from the trans handle. No functional changes.
--- fs/btrfs/transaction.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/btrfs/transaction.c +4 -5
@@ -1866,10 +1866,9 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, } -static void cleanup_transaction (struct btrfs_trans_handle *trans, -struct btrfs_root *root,int err) +static void cleanup_transaction (struct btrfs_trans_handle *trans,int err) { -struct btrfs_fs_info *fs_info = root->fs_info; +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_transaction *cur_trans = trans->transaction;DEFINE_WAIT (wait);
@@ -1909,7 +1908,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,btrfs_put_transaction (cur_trans);btrfs_put_transaction (cur_trans); -trace_btrfs_transaction_commit (root); +trace_btrfs_transaction_commit (trans->root);if (current->journal_info == trans) current->journal_info =NULL ;
@@ -2330,7 +2329,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)btrfs_warn (fs_info,"Skipping commit of aborted transaction." );if (current->journal_info == trans) current->journal_info =NULL ; -cleanup_transaction (trans, trans->root, ret); +cleanup_transaction (trans, ret);return ret; }
Signature · 1 line
2.7.4
PATCH 11/14 btrfs: Remove fs_info argument from switch_commit_roots
In reply to Nikolay BorisovWe already have the fs_info from the passed transaction so use it directly. No functional changes
--- fs/btrfs/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +4 -4
@@ -126,9 +126,9 @@ static void clear_btree_io_tree(struct extent_io_tree *tree)spin_unlock (&tree->lock); } -static noinline void switch_commit_roots(struct btrfs_transaction *trans, -struct btrfs_fs_info *fs_info) +static noinline void switch_commit_roots(struct btrfs_transaction *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_root *root, *tmp;down_write (&fs_info->commit_root_sem);
@@ -1405,7 +1405,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, ret =commit_cowonly_roots (trans);if (ret) goto out; -switch_commit_roots (trans->transaction, fs_info); +switch_commit_roots (trans->transaction); ret =btrfs_write_and_wait_transaction (trans, fs_info);if (ret) btrfs_handle_fs_error(fs_info, ret,
@@ -2233,7 +2233,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)list_add_tail (&fs_info->chunk_root->dirty_list, &cur_trans->switch_commits); -switch_commit_roots (cur_trans, fs_info); +switch_commit_roots (cur_trans);ASSERT (list_empty (&cur_trans->dirty_bgs));ASSERT (list_empty (&cur_trans->io_bgs));
Signature · 1 line
2.7.4
PATCH 12/14 btrfs: Remove fs_info argument from create_pending_snapshots/create_pending_snapshot
In reply to Nikolay BorisovWe already pass the trans handle which has a reference to fs_info to create_pending_snapshot so we can refer to it directly. Doing this obviates the need to pass the fs_info to create_pending_snapshots as well. No functional changes.
--- fs/btrfs/transaction.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/transaction.c +5 -5
@@ -1435,9 +1435,10 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,* the creation of the pending snapshots, just return 0. */ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info,struct btrfs_pending_snapshot *pending) { + +struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_key key;struct btrfs_root_item *new_root_item;struct btrfs_root *tree_root = fs_info->tree_root;
@@ -1704,8 +1705,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,/* * create all the snapshots we've scheduled for creation */ -static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) {struct btrfs_pending_snapshot *pending, *next;struct list_head *head = &trans->transaction->pending_snapshots;
@@ -1713,7 +1713,7 @@ static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,list_for_each_entry_safe (pending, next, head, list) {list_del (&pending->list); - ret =create_pending_snapshot (trans, fs_info, pending); + ret =create_pending_snapshot (trans, pending);if (ret)break ; }
@@ -2110,7 +2110,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)* deal with them in create_pending_snapshot(), which is the * core function of the snapshot creation. */ - ret =create_pending_snapshots (trans, fs_info); + ret =create_pending_snapshots (trans);if (ret) {mutex_unlock (&fs_info->reloc_mutex); goto scrub_continue;
Signature · 1 line
2.7.4
PATCH 13/14 btrfs: Remove fs_info argument from btrfs_update_commit_device_bytes_used
In reply to Nikolay BorisovWe already pass the btrfs_transaction which references fs_info so no need to pass the later as an argument. Also use the opportunity to shorten transaction->trans. No functional changes
--- fs/btrfs/transaction.c | 2 +- fs/btrfs/volumes.c | 10 +++++----- fs/btrfs/volumes.h | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-)
fs/btrfs/transaction.c +1 -1
@@ -2245,7 +2245,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) sizeof(*fs_info->super_copy));btrfs_update_commit_device_size (fs_info); -btrfs_update_commit_device_bytes_used (fs_info, cur_trans); +btrfs_update_commit_device_bytes_used (cur_trans);clear_bit (BTRFS_FS_LOG1_ERR , &fs_info->flags);clear_bit (BTRFS_FS_LOG2_ERR , &fs_info->flags);
fs/btrfs/volumes.c +5 -5
@@ -5229,7 +5229,7 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)/* * There could be two corrupted data stripes, we need * to loop retry in order to rebuild the correct data. -* +* * Fail a stripe at a time on every retry except the * stripe under reconstruction. */
@@ -7387,20 +7387,20 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info) }/* Must be invoked during the transaction commit */ -void btrfs_update_commit_device_bytes_used (struct btrfs_fs_info *fs_info, -struct btrfs_transaction *transaction) +void btrfs_update_commit_device_bytes_used (struct btrfs_transaction *trans) { +struct btrfs_fs_info *fs_info = trans->fs_info;struct extent_map *em;struct map_lookup *map;struct btrfs_device *dev;int i; -if (list_empty (&transaction->pending_chunks)) +if (list_empty (&trans->pending_chunks))return ;/* In order to kick the device replace finish process */ mutex_lock (&fs_info->chunk_mutex); -list_for_each_entry (em, &transaction->pending_chunks, list) { +list_for_each_entry (em, &trans->pending_chunks, list) { map = em->map_lookup;for (i =0 ; i < map->num_stripes; i++) {
fs/btrfs/volumes.h +1 -2
@@ -569,8 +569,7 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags) }void btrfs_update_commit_device_size (struct btrfs_fs_info *fs_info); -void btrfs_update_commit_device_bytes_used (struct btrfs_fs_info *fs_info, -struct btrfs_transaction *transaction); +void btrfs_update_commit_device_bytes_used (struct btrfs_transaction *trans);struct list_head *btrfs_get_fs_uuids (void );void btrfs_set_fs_info_ptr (struct btrfs_fs_info *fs_info);
Signature · 1 line
2.7.4
PATCH 14/14 btrfs: Remove fs_info argument of btrfs_write_and_wait_transaction
In reply to Nikolay BorisovWe already pass btrfs_trans_handle which contains a reference to the fs_info so use that. No functional changes
--- fs/btrfs/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/transaction.c +4 -4
@@ -1091,10 +1091,10 @@ int btrfs_wait_tree_log_extents(struct btrfs_root *log_root, int mark)* * @trans: transaction whose dirty pages we'd like to write */ -static int btrfs_write_and_wait_transaction (struct btrfs_trans_handle *trans, -struct btrfs_fs_info *fs_info) +static int btrfs_write_and_wait_transaction (struct btrfs_trans_handle *trans) {struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; +struct btrfs_fs_info *fs_info = trans->fs_info;struct blk_plug plug;int ret, ret2;
@@ -1406,7 +1406,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,if (ret) goto out;switch_commit_roots (trans->transaction); - ret =btrfs_write_and_wait_transaction (trans, fs_info); + ret =btrfs_write_and_wait_transaction (trans);if (ret)btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction for qgroup" );
@@ -2260,7 +2260,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)wake_up (&fs_info->transaction_wait); - ret =btrfs_write_and_wait_transaction (trans, fs_info); + ret =btrfs_write_and_wait_transaction (trans);if (ret) {btrfs_handle_fs_error (fs_info, ret,"Error while writing out transaction" );
Signature · 1 line
2.7.4
Quoted 17 lines · Nikolay Borisov
Here are a bunch of transaction-related cleanups all of them present no functional changes. The first 2 patches could be more interesting - the first one moves
trans_release_metadatatotransaction.cand makes it static and the second one opencodesbtrfs_write_and_wait_marked_extentsin its sole caller to make the chall chain shorter. The rest of the patches just kill the extraneousfs_infoargument since they also take either abtrfs_trans_handleorbtrfs_transactionpointer which already containfs_info.The modified functions are all called from
btrfs_commit_transaction. With this series applied the only function which remain that still takefs_infoand some type of transaction reference are:
btrfs_finish_extent_commitbtrfs_qgroup_account_extentsbtrfs_run_delayed_refs
Quoted 4 lines
The reason I haven't touched them is that David expressed some reservation about mass cleaning of functions which are more or less public interface. And the above 3 are such functions. David if you don't objec to converting those 3 I will keep them in mind when doing further cleanups in the transaction area.
I think all 3 functions don't need the explicit fs_info parameter, the main object for the functions is the transaction. I don't have a good example for the API function that should keep both parameters, nothing in transaction.h and nothing after a few quick greps. For functions like add_delayed_ref_head, removing the fs_info would be a welcome change as the number of parameters is high already (more than 10).
The patchset has been added to misc-next, briefly checking the effects on stack consumption, there are several -8 deltas. Which is good.