* [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit
@ 2020-10-27 12:40 fdmanana
2020-10-27 17:34 ` Josef Bacik
2020-10-29 12:24 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: fdmanana @ 2020-10-27 12:40 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
We do not need anymore to start writeback for delalloc of roots that are
being snapshoted and wait for it to complete. This was done in commit
609e804d771f59 ("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 9ddc959e802bf7
("btrfs: use the file extent tree infrastructure"), which addresses this
scenario involving snapshots as well.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/transaction.c | 49 ++++++------------------------------------
1 file changed, 6 insertions(+), 43 deletions(-)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 52ada47aff50..8f70d7135497 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1956,10 +1956,8 @@ static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
}
}
-static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
+static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info)
{
- struct btrfs_fs_info *fs_info = trans->fs_info;
-
/*
* We use writeback_inodes_sb here because if we used
* 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)
* 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)) {
+ if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC);
- } else {
- struct btrfs_pending_snapshot *pending;
- struct list_head *head = &trans->transaction->pending_snapshots;
-
- /*
- * Flush dellaloc for any root that is going to be snapshotted.
- * This is done to avoid a corrupted version of files, in the
- * snapshots, that had both buffered and direct IO writes (even
- * if they were done sequentially) due to an unordered update of
- * the inode's size on disk.
- */
- list_for_each_entry(pending, head, list) {
- int ret;
-
- ret = btrfs_start_delalloc_snapshot(pending->root);
- if (ret)
- return ret;
- }
- }
return 0;
}
-static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans)
+static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info)
{
- struct btrfs_fs_info *fs_info = trans->fs_info;
-
- if (btrfs_test_opt(fs_info, FLUSHONCOMMIT)) {
+ if (btrfs_test_opt(fs_info, FLUSHONCOMMIT))
btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
- } else {
- struct btrfs_pending_snapshot *pending;
- struct list_head *head = &trans->transaction->pending_snapshots;
-
- /*
- * Wait for any dellaloc that we started previously for the roots
- * that are going to be snapshotted. This is to avoid a corrupted
- * version of files in the snapshots that had both buffered and
- * direct IO writes (even if they were done sequentially).
- */
- list_for_each_entry(pending, head, list)
- btrfs_wait_ordered_extents(pending->root,
- U64_MAX, 0, U64_MAX);
- }
}
int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
@@ -2150,7 +2113,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
extwriter_counter_dec(cur_trans, trans->type);
- ret = btrfs_start_delalloc_flush(trans);
+ ret = btrfs_start_delalloc_flush(fs_info);
if (ret)
goto cleanup_transaction;
@@ -2166,7 +2129,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
if (ret)
goto cleanup_transaction;
- btrfs_wait_delalloc_flush(trans);
+ btrfs_wait_delalloc_flush(fs_info);
/*
* Wait for all ordered extents started by a fast fsync that joined this
--
2.28.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit
2020-10-27 12:40 [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit fdmanana
@ 2020-10-27 17:34 ` Josef Bacik
2020-10-29 12:24 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Josef Bacik @ 2020-10-27 17:34 UTC (permalink / raw)
To: fdmanana, linux-btrfs
On 10/27/20 8:40 AM, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> We do not need anymore to start writeback for delalloc of roots that are
> being snapshoted and wait for it to complete. This was done in commit
> 609e804d771f59 ("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 9ddc959e802bf7
> ("btrfs: use the file extent tree infrastructure"), which addresses this
> scenario involving snapshots as well.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit
2020-10-27 12:40 [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit fdmanana
2020-10-27 17:34 ` Josef Bacik
@ 2020-10-29 12:24 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-10-29 12:24 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Tue, Oct 27, 2020 at 12:40:06PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> We do not need anymore to start writeback for delalloc of roots that are
> being snapshoted and wait for it to complete. This was done in commit
> 609e804d771f59 ("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 9ddc959e802bf7
> ("btrfs: use the file extent tree infrastructure"), which addresses this
> scenario involving snapshots as well.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-29 12:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 12:40 [PATCH] btrfs: do not start and wait for delalloc on snapshot roots on transaction commit fdmanana
2020-10-27 17:34 ` Josef Bacik
2020-10-29 12:24 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).