Skip to content

Commit 1c7b11c

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: remove btrfs_fs_info::leaf_data_size
[BUG] There is a bug report that legacy code of "btrfs rescue chunk-recover" is triggering false alerts from tree-checker, and refuse to work: # btrfs rescue chunk-recover /dev/nvme1n1p1 Scanning: DONE in dev0 corrupt leaf: root=1 block=13924671995904 slot=0, unexpected item end, have 16283 expect 0 <<< Note the "expect 0" leaf 13924671995904 items 11 free space 12709 generation 1589644 owner ROOT_TREE leaf 13924671995904 flags 0x1(WRITTEN) backref revision 1 [...] Couldn't read tree root open with broken chunk error [CAUSE] The item end checks is from __btrfs_check_leaf() from tree-checker, and for the first slot of a leaf, the expected end should be BTRFS_LEAF_DATA_SIZE(), which is fetched from fs_info->leaf_data_size. However for the fs_info opened by chunk recover, it's not going through the regular open_ctree(), but open_ctree_with_broken_chunk(), which doesn't populate that member and resulting BTRFS_LEAF_DATA_SIZE() to return 0. [FIX] There is no need to cache leaf_data_size, as it can be easily calculated using nodesize. And kernel is already doing that, so follow the kernel to remove btrfs_fs_info::leaf_data_size, and use a simple inline function to do the calculation instead. Pull-request: #1039 Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Link: https://lore.kernel.org/linux-btrfs/CABXGCsOug_bxVZ5CN1EM0sd9U4JAz=Jf5EB2TQe8gs9=KZvWEA@mail.gmail.com/ Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 9ca465c commit 1c7b11c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

kernel-shared/ctree.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
6969
#define BTRFS_MIN_BLOCKSIZE (SZ_4K)
7070
#endif
7171

72-
#define BTRFS_LEAF_DATA_SIZE(fs_info) (fs_info->leaf_data_size)
73-
7472
#define BTRFS_SUPER_INFO_OFFSET (65536)
7573
#define BTRFS_SUPER_INFO_SIZE (4096)
7674

@@ -401,7 +399,6 @@ struct btrfs_fs_info {
401399
u32 nodesize;
402400
u32 sectorsize;
403401
u32 stripesize;
404-
u32 leaf_data_size;
405402

406403
/*
407404
* For open_ctree_fs_info() to hold the initial fd until close.
@@ -426,6 +423,11 @@ struct btrfs_fs_info {
426423
struct super_block *sb;
427424
};
428425

426+
static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *fs_info)
427+
{
428+
return __BTRFS_LEAF_DATA_SIZE(fs_info->nodesize);
429+
}
430+
429431
static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info)
430432
{
431433
return fs_info->zoned != 0;

kernel-shared/disk-io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,6 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_args *oca
16041604
fs_info->stripesize = btrfs_super_stripesize(disk_super);
16051605
fs_info->csum_type = btrfs_super_csum_type(disk_super);
16061606
fs_info->csum_size = btrfs_super_csum_size(disk_super);
1607-
fs_info->leaf_data_size = __BTRFS_LEAF_DATA_SIZE(fs_info->nodesize);
16081607

16091608
ret = btrfs_check_fs_compatibility(fs_info->super_copy, flags);
16101609
if (ret)

0 commit comments

Comments
 (0)