Skip to content

Commit 88090ad

Browse files
fdmananakdave
authored andcommitted
btrfs: do not start and wait for delalloc on snapshot roots on transaction commit
We do not need anymore to start writeback for delalloc of roots that are being snapshotted and wait for it to complete. This was done in commit 609e804 ("Btrfs: fix file corruption after snapshotting due to mix of buffered/DIO writes") to fix a type of file corruption where files in a snapshot end up having their i_size updated in a non-ordered way, leaving implicit file holes, when buffered IO writes that increase a file's size are followed by direct IO writes that also increase the file's size. This is not needed anymore because we now have a more generic mechanism to prevent a non-ordered i_size update since commit 9ddc959 ("btrfs: use the file extent tree infrastructure"), which addresses this scenario involving snapshots as well. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 196d59a commit 88090ad

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

fs/btrfs/transaction.c

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,10 +1956,8 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
19561956
}
19571957
}
19581958

1959-
static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
1959+
static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
19601960
{
1961-
struct btrfs_fs_info *fs_info = trans->fs_info;
1962-
19631961
/*
19641962
* We use writeback_inodes_sb here because if we used
19651963
* btrfs_start_delalloc_roots we would deadlock with fs freeze.
@@ -1969,50 +1967,15 @@ static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
19691967
* from already being in a transaction and our join_transaction doesn't
19701968
* have to re-take the fs freeze lock.
19711969
*/
1972-
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
1970+
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
19731971
writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
1974-
} else {
1975-
struct btrfs_pending_snapshot *pending;
1976-
struct list_head *head = &trans->transaction->pending_snapshots;
1977-
1978-
/*
1979-
* Flush dellaloc for any root that is going to be snapshotted.
1980-
* This is done to avoid a corrupted version of files, in the
1981-
* snapshots, that had both buffered and direct IO writes (even
1982-
* if they were done sequentially) due to an unordered update of
1983-
* the inode's size on disk.
1984-
*/
1985-
list_for_each_entry(pending, head, list) {
1986-
int ret;
1987-
1988-
ret = btrfs_start_delalloc_snapshot(pending->root);
1989-
if (ret)
1990-
return ret;
1991-
}
1992-
}
19931972
return 0;
19941973
}
19951974

1996-
static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans)
1975+
static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
19971976
{
1998-
struct btrfs_fs_info *fs_info = trans->fs_info;
1999-
2000-
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
1977+
if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
20011978
btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
2002-
} else {
2003-
struct btrfs_pending_snapshot *pending;
2004-
struct list_head *head = &trans->transaction->pending_snapshots;
2005-
2006-
/*
2007-
* Wait for any dellaloc that we started previously for the roots
2008-
* that are going to be snapshotted. This is to avoid a corrupted
2009-
* version of files in the snapshots that had both buffered and
2010-
* direct IO writes (even if they were done sequentially).
2011-
*/
2012-
list_for_each_entry(pending, head, list)
2013-
btrfs_wait_ordered_extents(pending->root,
2014-
U64_MAX, 0, U64_MAX);
2015-
}
20161979
}
20171980

20181981
int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
@@ -2150,7 +2113,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
21502113

21512114
extwriter_counter_dec(cur_trans, trans->type);
21522115

2153-
ret = btrfs_start_delalloc_flush(trans);
2116+
ret = btrfs_start_delalloc_flush(fs_info);
21542117
if (ret)
21552118
goto cleanup_transaction;
21562119

@@ -2166,7 +2129,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
21662129
if (ret)
21672130
goto cleanup_transaction;
21682131

2169-
btrfs_wait_delalloc_flush(trans);
2132+
btrfs_wait_delalloc_flush(fs_info);
21702133

21712134
/*
21722135
* Wait for all ordered extents started by a fast fsync that joined this

0 commit comments

Comments
 (0)