Skip to content

Commit 99ed2a6

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: convert: follow the default free space tree setting
[BUG] We got some test failures related to btrfs-convert with subpage, e.g. btrfs/012, the failure would cause the following dmesg: BTRFS warning (device nvme0n1p7): v1 space cache is not supported for page size 16384 with sectorsize 4096 BTRFS error (device nvme0n1p7): open_ctree failed [CAUSE] v1 space cache has tons of hard coded PAGE_SIZE usage, and considering v2 space cache is going to replace it (which is already the new default since v5.15 btrfs-progs), thus for btrfs subpage support, we just simply reject the v1 space cache, and utilize v2 space cache when possible. But there is special catch in btrfs-convert, although we're specifying v2 space cache as the new default for btrfs-convert, it doesn't really follow the specification at all. Thus the converted filesystem will still go v1 space cache. [FIX] It can be a huge change to btrfs-convert to make the initial btrfs image to support v2 cache. Thus this patch would change the fs at the final stage, just before we finalize the btrfs. This patch would drop all the v1 cache created, then call btrfs_create_free_space_tree() to populate the free space tree and commit the superblock with needed compat_ro flags. Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent a79cf3b commit 99ed2a6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ libbtrfsutil_objects = libbtrfsutil/errors.o libbtrfsutil/filesystem.o \
253253
libbtrfsutil/stubs.o
254254
convert_objects = convert/main.o convert/common.o convert/source-fs.o \
255255
convert/source-ext2.o convert/source-reiserfs.o \
256-
mkfs/common.o
256+
mkfs/common.o check/clear-cache.o
257257
mkfs_objects = mkfs/main.o mkfs/common.o mkfs/rootdir.o
258258
image_objects = image/main.o image/sanitize.o
259259
tune_objects = tune/main.o tune/seeding.o tune/change-uuid.o tune/change-metadata-uuid.o \

convert/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
#include "kernel-shared/disk-io.h"
100100
#include "kernel-shared/volumes.h"
101101
#include "kernel-shared/transaction.h"
102+
#include "kernel-shared/free-space-tree.h"
102103
#include "kernel-shared/file-item.h"
103104
#include "crypto/hash.h"
104105
#include "common/defs.h"
@@ -116,6 +117,7 @@
116117
#include "common/open-utils.h"
117118
#include "cmds/commands.h"
118119
#include "check/repair.h"
120+
#include "check/clear-cache.h"
119121
#include "mkfs/common.h"
120122
#include "convert/common.h"
121123
#include "convert/source-fs.h"
@@ -1348,6 +1350,27 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
13481350
error("unable to open ctree for finalization");
13491351
goto fail;
13501352
}
1353+
1354+
/*
1355+
* Setup free space tree.
1356+
*
1357+
* - Clear any v1 cache first
1358+
* - Create v2 free space tree
1359+
*/
1360+
if (mkfs_cfg.features.compat_ro_flags & BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE) {
1361+
ret = do_clear_free_space_cache(root->fs_info, 1);
1362+
if (ret < 0) {
1363+
errno = -ret;
1364+
error("failed to clear v1 space cache: %m");
1365+
goto fail;
1366+
}
1367+
ret = btrfs_create_free_space_tree(root->fs_info);
1368+
if (ret < 0) {
1369+
errno = -ret;
1370+
error("failed to create v2 space cache: %m");
1371+
goto fail;
1372+
}
1373+
}
13511374
root->fs_info->finalize_on_close = 1;
13521375
close_ctree(root);
13531376
close(fd);

0 commit comments

Comments
 (0)