diff mbox series

btrfs: fix re-dirty process of tree-log nodes

Message ID 20211129024930.1574325-1-naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix re-dirty process of tree-log nodes | expand

Commit Message

Naohiro Aota Nov. 29, 2021, 2:49 a.m. UTC
For zoned btrfs, we re-dirty a freeing tree node to ensure btrfs write
the region and not to leave a write hole on a zoned device. Current
code failed to re-dirty a node when the tree-log tree's depth >=
2. This leads to a transaction abort with -EAGAIN.

Fix the issue by properly re-dirty a node on walking up the tree.

Link: https://github.com/kdave/btrfs-progs/issues/415
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/tree-log.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn Nov. 29, 2021, 7:57 a.m. UTC | #1
On 29/11/2021 03:51, Naohiro Aota wrote:
> For zoned btrfs, we re-dirty a freeing tree node to ensure btrfs write
> the region and not to leave a write hole on a zoned device. Current
> code failed to re-dirty a node when the tree-log tree's depth >=
> 2. This leads to a transaction abort with -EAGAIN.
> 

I'd rephrase the above to:

For zoned btrfs, we re-dirty a freed tree node to ensure btrfs 
can write the region and does not leave a hole on write on a zoned
device. The current code fails to failed to re-dirty a node when the
tree-log tree's depth was greater or equal to 2. This lead to a 
transaction abort with -EAGAIN.


> Fix the issue by properly re-dirty a node on walking up the tree.
> 
> Link: https://github.com/kdave/btrfs-progs/issues/415
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Shouldn't we mark this for stable (v5.15)? After all the reporter did
hit the problem on 5.15.
David Sterba Nov. 29, 2021, 12:19 p.m. UTC | #2
On Mon, Nov 29, 2021 at 11:49:30AM +0900, Naohiro Aota wrote:
> For zoned btrfs, we re-dirty a freeing tree node to ensure btrfs write
> the region and not to leave a write hole on a zoned device. Current
> code failed to re-dirty a node when the tree-log tree's depth >=
> 2. This leads to a transaction abort with -EAGAIN.
> 
> Fix the issue by properly re-dirty a node on walking up the tree.
> 
> Link: https://github.com/kdave/btrfs-progs/issues/415

Can you please add more information from the issue that's relevant to
the problem? Eg. the stacktraces, reproducer etc.
Naohiro Aota Nov. 30, 2021, 1:51 a.m. UTC | #3
On Mon, Nov 29, 2021 at 07:57:39AM +0000, Johannes Thumshirn wrote:
> On 29/11/2021 03:51, Naohiro Aota wrote:
> > For zoned btrfs, we re-dirty a freeing tree node to ensure btrfs write
> > the region and not to leave a write hole on a zoned device. Current
> > code failed to re-dirty a node when the tree-log tree's depth >=
> > 2. This leads to a transaction abort with -EAGAIN.
> > 
> 
> I'd rephrase the above to:
> 
> For zoned btrfs, we re-dirty a freed tree node to ensure btrfs 
> can write the region and does not leave a hole on write on a zoned
> device. The current code fails to failed to re-dirty a node when the
> tree-log tree's depth was greater or equal to 2. This lead to a 
> transaction abort with -EAGAIN.
> 
> 
> > Fix the issue by properly re-dirty a node on walking up the tree.
> > 
> > Link: https://github.com/kdave/btrfs-progs/issues/415
> > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> > ---
> 
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> 
> Shouldn't we mark this for stable (v5.15)? After all the reporter did
> hit the problem on 5.15.
> 

Oops, I've added the fixes tag and the stable tag to the commit, but
somehow I forgot to update the patch file. I'll resend the patch with
your fix with for the commit log. Thanks.
Naohiro Aota Nov. 30, 2021, 1:51 a.m. UTC | #4
On Mon, Nov 29, 2021 at 01:19:39PM +0100, David Sterba wrote:
> On Mon, Nov 29, 2021 at 11:49:30AM +0900, Naohiro Aota wrote:
> > For zoned btrfs, we re-dirty a freeing tree node to ensure btrfs write
> > the region and not to leave a write hole on a zoned device. Current
> > code failed to re-dirty a node when the tree-log tree's depth >=
> > 2. This leads to a transaction abort with -EAGAIN.
> > 
> > Fix the issue by properly re-dirty a node on walking up the tree.
> > 
> > Link: https://github.com/kdave/btrfs-progs/issues/415
> 
> Can you please add more information from the issue that's relevant to
> the problem? Eg. the stacktraces, reproducer etc.

Sure. I'll revise the patch with the fixes tags.

Thanks,
diff mbox series

Patch

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index de79e15a7c6a..a42e132f35f5 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -2890,6 +2890,8 @@  static noinline int walk_up_log_tree(struct btrfs_trans_handle *trans,
 						     path->nodes[*level]->len);
 					if (ret)
 						return ret;
+					btrfs_redirty_list_add(trans->transaction,
+							       next);
 				} else {
 					if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
 						clear_extent_buffer_dirty(next);
@@ -2970,6 +2972,8 @@  static int walk_log_tree(struct btrfs_trans_handle *trans,
 						next->start, next->len);
 				if (ret)
 					goto out;
+				btrfs_redirty_list_add(trans->transaction,
+						       next);
 			} else {
 				if (test_and_clear_bit(EXTENT_BUFFER_DIRTY, &next->bflags))
 					clear_extent_buffer_dirty(next);
@@ -3420,8 +3424,6 @@  static void free_log_tree(struct btrfs_trans_handle *trans,
 			  EXTENT_DIRTY | EXTENT_NEW | EXTENT_NEED_WAIT);
 	extent_io_tree_release(&log->log_csum_range);
 
-	if (trans && log->node)
-		btrfs_redirty_list_add(trans->transaction, log->node);
 	btrfs_put_root(log);
 }