No title delete lock Revision 333964363564 (Fri Mar 22 2019 at 18:04) - Diff Link to this snippet: https://friendpaste.com/45NhhVPko5txKuuzDPqhyK Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.cindex 3f180b857e20..1e7f2e2ba4f0 100644--- a/fs/btrfs/inode.c+++ b/fs/btrfs/inode.c@@ -2912,6 +2912,26 @@ static void btrfs_release_delalloc_bytes(struct btrfs_fs_info *fs_info, btrfs_put_block_group(cache); } +static struct btrfs_trans_handle *finish_io_join_trans(struct inode *inode)+{+ struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);+ struct btrfs_root *root = BTRFS_I(inode)->root;+ bool nolock = false;++ if (btrfs_is_free_space_inode(BTRFS_I(inode))) {+ nolock = true;+ } else if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {+ spin_lock(&fs_info->trans_lock);+ if (fs_info->running_transaction &&+ fs_info->running_transaction->state >=+ TRANS_STATE_COMMIT_START)+ nolock = true;+ spin_unlock(&fs_info->trans_lock);+ }++ if (nolock)+ return btrfs_join_transaction_nolock(root);++ return btrfs_join_transaction(root);+}+ /* as ordered data IO finishes, this gets called so we can finish * an ordered extent if the range of bytes in the file it covers are * fully written.@@ -2928,7 +2948,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) int compress_type = 0; int ret = 0; u64 logical_len = ordered_extent->len;- bool nolock; bool truncated = false; bool range_locked = false; bool clear_new_delalloc_bytes = false;@@ -2939,8 +2958,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) !test_bit(BTRFS_ORDERED_DIRECT, &ordered_extent->flags)) clear_new_delalloc_bytes = true; - nolock = btrfs_is_free_space_inode(BTRFS_I(inode));- if (test_bit(BTRFS_ORDERED_IOERR, &ordered_extent->flags)) { ret = -EIO; goto out;@@ -2970,10 +2987,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset, ordered_extent->len); btrfs_ordered_update_i_size(inode, 0, ordered_extent);- if (nolock)- trans = btrfs_join_transaction_nolock(root);- else- trans = btrfs_join_transaction(root);+ trans = finish_io_join_trans(inode); if (IS_ERR(trans)) { ret = PTR_ERR(trans); trans = NULL;@@ -3005,10 +3019,7 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent) EXTENT_DEFRAG, 0, 0, &cached_state); } - if (nolock)- trans = btrfs_join_transaction_nolock(root);- else- trans = btrfs_join_transaction(root);+ trans = finish_io_join_trans(inode); if (IS_ERR(trans)) { ret = PTR_ERR(trans); trans = NULL;diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.cindex acdad6d658f5..d776990fe8e5 100644--- a/fs/btrfs/transaction.c+++ b/fs/btrfs/transaction.c@@ -1888,17 +1888,8 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) {- /*- * We use writeback_inodes_sb here because if we used- * btrfs_start_delalloc_roots we would deadlock with fs freeze.- * Currently are holding the fs freeze lock, if we do an async flush- * we'll do btrfs_join_transaction() and deadlock because we need to- * wait for the fs freeze lock. Using the direct flushing we benefit- * from already being in a transaction and our join_transaction doesn't- * have to re-take the fs freeze lock.- */ if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))- writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);+ return btrfs_start_delalloc_roots(fs_info, -1); return 0; }