Skip to content

Commit ce8ea7c

Browse files
josefbacikkdave
authored andcommitted
btrfs: don't call btrfs_start_delalloc_roots in flushoncommit
We're holding the sb_start_intwrite lock at this point, and doing async filemap_flush of the inodes will result in a deadlock if we freeze the fs during this operation. This is because we could do a btrfs_join_transaction() in the thread we are waiting on which would block at sb_start_intwrite, and thus deadlock. Using writeback_inodes_sb() side steps the problem by not introducing all of these extra locking dependencies. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0e0adbc commit ce8ea7c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/btrfs/transaction.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,8 +1916,17 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
19161916

19171917
static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
19181918
{
1919+
/*
1920+
* We use writeback_inodes_sb here because if we used
1921+
* btrfs_start_delalloc_roots we would deadlock with fs freeze.
1922+
* Currently are holding the fs freeze lock, if we do an async flush
1923+
* we'll do btrfs_join_transaction() and deadlock because we need to
1924+
* wait for the fs freeze lock. Using the direct flushing we benefit
1925+
* from already being in a transaction and our join_transaction doesn't
1926+
* have to re-take the fs freeze lock.
1927+
*/
19191928
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
1920-
return btrfs_start_delalloc_roots(fs_info, 1, -1);
1929+
writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
19211930
return 0;
19221931
}
19231932

0 commit comments

Comments
 (0)