btrfs-progs: check: report deprecated inode cache as errors
cover btrfs-progs: check: report deprecated inode cache as errors
There are two reports that inode cache is causing kernel to reject those data backrefs.
It turns out the long to be deprecated inode cache is biting us unexpectedly.
(And the design of those special inodes has no intention to properly fill its members like mode and transid correctly).
However the original mode btrfs check is not updated to detect them, in fact there are special hacks to not report them as errors. Meanwhile the lowmem mode immediately picks them as errors from day one.
The first patch fixes the original mode to report inode cache as error, and add extra messages on how to properly fix the problem using 'btrfs rescue clear-ino-cache'.
The second patch is a new test case for both modes of btrfs check.
Qu Wenruo (2):
btrfs-progs: check: detect deprecated inode cache
btrfs-progs: fsck-tests: add a test case with deprecated inode cache
check/main.c | 12 +++++++++--- check/mode-lowmem.c | 9 +++++++++ check/mode-original.h | 1 + .../4k_nodesize.img.xz | Bin 0 -> 17320 bytes .../064-deprecated-inode-cache/test.sh | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/fsck-tests/064-deprecated-inode-cache/4k_nodesize.img.xz create mode 100755 tests/fsck-tests/064-deprecated-inode-cache/test.sh
--
2.46.0
PATCH 1/2 btrfs-progs: check: detect deprecated inode cache
[BUG]
There are reports about deprecated inode cache causing newer kernels to rejecting them.
Such inode cache is rarely utilized and already fully deprecated since v5.11, and newer kernel will reject data extents of inode cache since v6.11.
But original mode btrfs check won't detect nor report them as error. Meanwhile lowmem mode can properly detect and report them:
ERROR: root 5 INODE[18446744073709551604] nlink(1) not equal to inode_refs(0)
ERROR: invalid imode mode bits: 00
ERROR: invalid inode generation 18446744073709551604 or transid 1 for ino 18446744073709551605, expect [0, 72)
ERROR: root 5 INODE[18446744073709551605] is orphan item
Since those inode cache paid no attention to properly maintain all the numbers, they are easy targets for more recent lowmem mode.
[CAUSE]
For original mode, it has extra hardcoded hacks to avoid nlink checks for inode cache inode.
Furthermore original mode doesn't check the mode bits nor its generation.
[FIX]
For original mode, remove the hack for inode cache so that the deprecated inode cache can be reported as an error.
For both modes, add extra global message to direct the affected users to use 'btrfs rescue clear-ino-cache' to clear the deprecated cache.
--- check/main.c | 12 +++++++++--- check/mode-lowmem.c | 9 +++++++++ check/mode-original.h | 1 + 3 files changed, 19 insertions(+), 3 deletions(-)
check/main.c +9 -3
@@ -86,6 +86,7 @@ bool no_holes = false;bool is_free_space_tree = false;bool init_extent_tree = false;bool check_data_csum = false; +static bool found_free_ino_cache = false;struct cache_tree *roots_info_cache =NULL ;enum btrfs_check_mode {
@@ -606,6 +607,8 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)fprintf (stderr,"root %llu inode %llu errors %x" , root_objectid, rec->ino, rec->errors); +if (errors &I_ERR_DEPRECATED_FREE_INO ) +fprintf (stderr,", deprecated free inode cache" );if (errors &I_ERR_NO_INODE_ITEM )fprintf (stderr,", no inode item" );if (errors &I_ERR_NO_ORPHAN_ITEM )
@@ -773,9 +776,6 @@ static struct inode_record *get_inode_rec(struct cache_tree *inode_cache, node->cache.size =1 ; node->data = rec; -if (ino ==BTRFS_FREE_INO_OBJECTID ) - rec->found_link =1 ; - ret =insert_cache_extent (inode_cache, &node->cache);if (ret) {free (rec);
@@ -3224,6 +3224,10 @@ static int check_inode_recs(struct btrfs_root *root, } } +if (rec->ino ==BTRFS_FREE_INO_OBJECTID ) { + rec->errors |=I_ERR_DEPRECATED_FREE_INO ; + found_free_ino_cache = true; + }if (!rec->found_inode_item) rec->errors |=I_ERR_NO_INODE_ITEM ;if (rec->found_link != rec->nlink)
@@ -10834,6 +10838,8 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) ret =do_check_fs_roots (&root_cache);task_stop (g_task_ctx.info); +if (found_free_ino_cache) +printf ("deprecated inode cache can be removed by 'btrfs rescue clear-ino-cache'\n" ); err |= !!ret;if (ret) {error ("errors found in fs roots" );
check/mode-lowmem.c +9 -0
@@ -44,6 +44,7 @@static u64 last_allocated_chunk;static u64 total_used =0 ; +static bool found_free_ino_cache = false;static int calc_extent_flag (struct btrfs_root *root,struct extent_buffer *eb,u64 *flags_ret)
@@ -2629,6 +2630,12 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)return err; } +if (inode_id ==BTRFS_FREE_INO_OBJECTID ) { +error ("subvolume %lld has deprecated inode cache" , + root->root_key.objectid); + found_free_ino_cache = true; + } + is_orphan =has_orphan_item (root, inode_id); ii = btrfs_item_ptr(node, slot, struct btrfs_inode_item); isize =btrfs_inode_size (node, ii);
@@ -5616,6 +5623,8 @@ next: out:btrfs_release_path (&path); +if (found_free_ino_cache) +printf ("deprecated inode cache can be removed by 'btrfs rescue clear-ino-cache'\n" );return err; }
check/mode-original.h +1 -0
@@ -189,6 +189,7 @@ struct unaligned_extent_rec_t {#define I_ERR_INVALID_GEN (1U << 20)#define I_ERR_INVALID_NLINK (1U << 21)#define I_ERR_INVALID_XATTR (1U << 22) +#define I_ERR_DEPRECATED_FREE_INO (1U << 23)struct inode_record {struct list_head backrefs;
Signature · 1 line
2.46.0
PATCH 2/2 btrfs-progs: fsck-tests: add a test case with deprecated inode cache
In reply to Qu WenruoThe inode_cache and involved on-disk formats are deprecated and will have no effect since v5.11 kernel.
And in v6.11 kernel, new tree-checker will even reject data extents belonging to those deprecated inode cache.
Lowmem check can detect such deprecated inode cache from the beginning.
This images are generated by 5.10 LTS kernels with inode cache.
--- .../4k_nodesize.img.xz | Bin 0 -> 17320 bytes .../064-deprecated-inode-cache/test.sh | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/fsck-tests/064-deprecated-inode-cache/4k_nodesize.img.xz create mode 100755 tests/fsck-tests/064-deprecated-inode-cache/test.sh
tests/fsck-tests/064-deprecated-inode-cache/4k_nodesize.img.xz new file binary +0 -0
tests/fsck-tests/064-deprecated-inode-cache/test.sh new file +14 -0
@@ -0,0 +1,14 @@ +#!/bin/bash +# +# Verify that check can report deprecated inode cache as an error + +source "$TEST_TOP/common" || exit + +check_prereq btrfs + +check_image() { + run_mustfail "deprecated inode cache not reported as an error" \ + "$TOP/btrfs" check "$1" +} + +check_all_images
Signature · 1 line
2.46.0