diff --git a/Makefile b/Makefile index e2497c18..86c73590 100644 --- a/Makefile +++ b/Makefile @@ -253,7 +253,7 @@ libbtrfsutil_objects = libbtrfsutil/errors.o libbtrfsutil/filesystem.o \ libbtrfsutil/stubs.o convert_objects = convert/main.o convert/common.o convert/source-fs.o \ convert/source-ext2.o convert/source-reiserfs.o \ - mkfs/common.o + mkfs/common.o check/clear-cache.o mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o image_objects = image/main.o image/sanitize.o tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadata-uuid.o \ diff --git a/convert/main.c b/convert/main.c index 0a62101d..da6d6cf4 100644 --- a/convert/main.c +++ b/convert/main.c @@ -99,6 +99,7 @@ #include "kernel-shared/disk-io.h" #include "kernel-shared/volumes.h" #include "kernel-shared/transaction.h" +#include "kernel-shared/free-space-tree.h" #include "kernel-shared/file-item.h" #include "crypto/hash.h" #include "common/defs.h" @@ -116,6 +117,7 @@ #include "common/open-utils.h" #include "cmds/commands.h" #include "check/repair.h" +#include "check/clear-cache.h" #include "mkfs/common.h" #include "convert/common.h" #include "convert/source-fs.h" @@ -1348,6 +1350,27 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize, error("unable to open ctree for finalization"); goto fail; } + + /* + * Setup free space tree. + * + * - Clear any v1 cache first + * - Create v2 free space tree + */ + if (mkfs_cfg.features.compat_ro_flags & BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE) { + ret = do_clear_free_space_cache(root->fs_info, 1); + if (ret < 0) { + errno = -ret; + error("failed to clear v1 space cache: %m"); + goto fail; + } + ret = btrfs_create_free_space_tree(root->fs_info); + if (ret < 0) { + errno = -ret; + error("failed to create v2 space cache: %m"); + goto fail; + } + } root->fs_info->finalize_on_close = 1; close_ctree(root); close(fd);