bug fixes for error handling
cover bug fixes for error handling
These two fixes are for error handling after we abort a transaction.
One is a memory leak fix, and the other one is a NULL pointer fix.
Liu Bo (2):
Btrfs: fix memory leak of log roots
Btrfs: fix NULL pointer after aborting a transaction
fs/btrfs/disk-io.c | 5 +++++ fs/btrfs/transaction.c | 8 +++++++- fs/btrfs/tree-log.c | 6 ++++-- 3 files changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.7
PATCH 1/2 Btrfs: fix memory leak of log roots
When we abort a transaction while fsyncing, we'll skip freeing log roots part of committing a transaction, which leads to memory leak.
This adds a 'free log roots' in putting super when no more users hold references on log roots, so it's safe and clean.
--- fs/btrfs/disk-io.c | 5 +++++ fs/btrfs/tree-log.c | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +5 -0
@@ -3195,6 +3195,11 @@ void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)if (btrfs_root_refs (&root->root_item) ==0 )synchronize_srcu (&fs_info->subvol_srcu); +if (fs_info->fs_state &BTRFS_SUPER_FLAG_ERROR ) { +btrfs_free_log (NULL , root); +btrfs_free_log_root_tree (NULL , fs_info); + } +__btrfs_remove_free_space_cache (root->free_ino_pinned);__btrfs_remove_free_space_cache (root->free_ino_ctl);free_fs_root (root);
fs/btrfs/tree-log.c +4 -2
@@ -2461,8 +2461,10 @@ static void free_log_tree(struct btrfs_trans_handle *trans, .process_func = process_one_buffer }; - ret =walk_log_tree (trans, log, &wc); -BUG_ON (ret); +if (trans) { + ret =walk_log_tree (trans, log, &wc); +BUG_ON (ret); + }while (1 ) { ret = find_first_extent_bit(&log->dirty_log_pages,
Signature · 1 line
1.7.7
PATCH 2/2 Btrfs: fix NULL pointer after aborting a transaction
In reply to Liu BoWhile doing cleanup work on an aborted transaction, we've set the global running transaction pointer to NULL _before_ waiting all other transaction handles to finish, so others'd hit NULL pointer crash when referencing the global running transaction pointer.
This first sets a hint to avoid new transaction handle joining, then waits other existing handles to abort or finish so that we can safely set the above global pointer to NULL.
--- fs/btrfs/transaction.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
fs/btrfs/transaction.c +7 -1
@@ -1387,6 +1387,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, struct btrfs_root *root, int err) {struct btrfs_transaction *cur_trans = trans->transaction; +DEFINE_WAIT (wait);WARN_ON (trans->use_count >1 );
@@ -1395,8 +1396,13 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,spin_lock (&root->fs_info->trans_lock);list_del_init (&cur_trans->list);if (cur_trans == root->fs_info->running_transaction) { + root->fs_info->trans_no_join =1 ; +spin_unlock (&root->fs_info->trans_lock); +wait_event (cur_trans->writer_wait, +atomic_read (&cur_trans->num_writers) ==1 ); + +spin_lock (&root->fs_info->trans_lock); root->fs_info->running_transaction =NULL ; - root->fs_info->trans_no_join =0 ; }spin_unlock (&root->fs_info->trans_lock);
Signature · 1 line
1.7.7