On 2020/12/29 上午8:38, Qu Wenruo wrote:
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 <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>

Please discard this patch.

This didn't really solve the problem and may give the end user some false impression.

Thanks,
Qu
---
  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);


Reply via email to