Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: relocation: output warning message for leftover v1 space cache before aborting current data balance
@ 2020-12-29  0:38 Qu Wenruo
  2020-12-29  9:27 ` Stéphane Lesimple
  2020-12-30  0:56 ` Qu Wenruo
  0 siblings, 2 replies; 13+ messages in thread
From: Qu Wenruo @ 2020-12-29  0:38 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Stéphane Lesimple

In delete_v1_space_cache(), if we find a leaf whose owner is tree root,
and we can't grab the free space cache inode, then we return -ENOENT.

However this would make the caller, add_data_references(), to consider
this as a critical error, and abort current data balance.

This happens for fs using free space cache v2, while still has v1 data
left.

For v2 free space cache, we no longer load v1 data, making btrfs_igrab()
no longer work for root tree to grab v1 free space cache inodes.

The proper fix for the problem is to delete v1 space cache completely
during v2 convert.

We can't just ignore the -ENOENT error, as for root tree we don't use
reloc tree to replace its data references, but rely on COW.
This means, we have no way to relocate the leftover v1 data, and block
the relocation.

This patch will just workaround it by outputting a warning message,
showing the user how to manually solve it.

Reported-by: Stéphane Lesimple <stephane_btrfs2@lesimple.fr>
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/relocation.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 19b7db8b2117..42746b59268d 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3027,6 +3027,25 @@ int add_data_references(struct reloc_control *rc,
 		ret = delete_v1_space_cache(eb, rc->block_group,
 					    extent_key->objectid);
 		free_extent_buffer(eb);
+		/*
+		 * This happens when the fs is converted to use v2 space cache,
+		 * but some v1 data is still left.
+		 * In that case, we can't delete the v1 space cache data as we
+		 * can't grab the free space cache inode anymore.
+		 *
+		 * And we can't ignore the error, as for root tree (where v1
+		 * space cache is) we don't do reloc tree to replace the data
+		 * to the new location, thus the old data will still be there,
+		 * blocking the data chunk to be relocated.
+		 *
+		 * Here we just warn user about the problem, and provide a
+		 * workaround.
+		 * The proper fix is in the v2 convert mount, which should
+		 * completely remove v1 data.
+		 */
+		if (ret == -ENOENT)
+			btrfs_warn(fs_info,
+"leftover v1 space cache found, please use btrfs-check --clear-space-cache v1 to clean it up");
 		if (ret < 0)
 			break;
 		ret = __add_tree_block(rc, ref_node->val, blocksize, blocks);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-30  8:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-29  0:38 [PATCH] btrfs: relocation: output warning message for leftover v1 space cache before aborting current data balance Qu Wenruo
2020-12-29  9:27 ` Stéphane Lesimple
2020-12-29 10:29   ` Qu Wenruo
2020-12-29 11:08     ` Stéphane Lesimple
2020-12-29 11:30       ` Qu Wenruo
2020-12-29 12:30         ` Stéphane Lesimple
2020-12-29 12:41           ` Qu Wenruo
2020-12-29 12:51             ` Stéphane Lesimple
2020-12-29 13:06               ` Qu Wenruo
2020-12-29 13:17                 ` Stéphane Lesimple
2020-12-30  5:49                   ` Qu Wenruo
2020-12-30  8:39                     ` Stéphane Lesimple
2020-12-30  0:56 ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox