btrfs-progs: check: add inode invalid transid detect and repair support
cover btrfs-progs: check: add inode invalid transid detect and repair support
Really nothing interesting here for btrfs-progs, just reusing existing inode generation detect and repair code.
The interesting part is, how a wrongly copied error message delayed us so long to locate a bug.
Qu Wenruo (3):
btrfs-progs: check/lowmem: add inode transid detect and repair support
btrfs-progs: check/original: add inode transid detect and repair
support
btrfs-progs: tests/fsck: add test image for inode transid repair
check/main.c | 8 +++++--- check/mode-lowmem.c | 11 +++++++---- .../bad_inode_transid.img.xz | Bin 0 -> 1888 bytes 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 tests/fsck-tests/043-bad-inode-generation/bad_inode_transid.img.xz
Signature · 1 line
2.28.0
PATCH 1/3 btrfs-progs: check/lowmem: add inode transid detect and repair support
There are quite some reports on kernel rejecting invalid inode generation, but it turns out to be that, kernel is just rejecting inode transid. It's a bug in kernel error message.
To solve the problem and make the fs mountable again, add the detect and repair support for lowmem mode.
The implementation is pretty much the same, just re-use the existing inode generation detect and repair code.
--- check/mode-lowmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
check/mode-lowmem.c +7 -4
@@ -2554,6 +2554,7 @@ static int repair_inode_gen_lowmem(struct btrfs_root *root, ii =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_inode_item);btrfs_set_inode_generation (path->nodes[0 ], ii, trans->transid); +btrfs_set_inode_transid (path->nodes[0 ], ii, trans->transid);btrfs_mark_buffer_dirty (path->nodes[0 ]); ret =btrfs_commit_transaction (trans, root);if (ret <0 ) {
@@ -2561,7 +2562,7 @@ static int repair_inode_gen_lowmem(struct btrfs_root *root,error ("failed to commit transaction: %m" ); goto error; } -printf ("resetting inode generation to %llu for ino %llu\n" , +printf ("resetting inode generation/transid to %llu for ino %llu\n" , transid, key.objectid);return ret;
@@ -2597,6 +2598,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)u64 extent_end =0 ;u64 extent_size =0 ;u64 generation; +u64 transid;u64 gen_uplimit;unsigned int dir;unsigned int nodatasum;
@@ -2629,6 +2631,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path) dir =imode_to_type (mode) ==BTRFS_FT_DIR ; nlink =btrfs_inode_nlink (node, ii); generation =btrfs_inode_generation (node, ii); + transid =btrfs_inode_transid (node, ii); nodatasum =btrfs_inode_flags (node, ii) &BTRFS_INODE_NODATASUM ;if (!is_valid_imode (mode)) {
@@ -2648,10 +2651,10 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)else gen_uplimit =btrfs_super_generation (super); -if (generation > gen_uplimit) { +if (generation > gen_uplimit || transid > gen_uplimit) {error ( -"invalid inode generation for ino %llu, have %llu expect [0, %llu)" , - inode_id, generation, gen_uplimit); +"invalid inode generation or transid for ino %llu, have %llu,%llu expect [0, %llu)" , + inode_id, generation, transid, gen_uplimit);if (repair) { ret =repair_inode_gen_lowmem (root, path);if (ret <0 )
Signature · 1 line
2.28.0
Re: [PATCH 1/3] btrfs-progs: check/lowmem: add inode transid detect and repair support
Quoted 11 lines · Qu Wenruo
There are quite some reports on kernel rejecting invalid inode generation, but it turns out to be that, kernel is just rejecting inode transid. It's a bug in kernel error message.
To solve the problem and make the fs mountable again, add the detect and repair support for lowmem mode.
The implementation is pretty much the same, just re-use the existing inode generation detect and repair code.
Signed-off-by Qu Wenruo <[email protected]>
Thanks,
Josef
PATCH 2/3 btrfs-progs: check/original: add inode transid detect and repair support
In reply to Qu WenruoThe inode transid detect and repair is reusing the existing inode geneartion code.
--- check/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
check/main.c +5 -3
@@ -620,7 +620,7 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)fprintf (stderr,", invalid inode mode bit 0%o" , rec->imode & ~07777 );if (errors &I_ERR_INVALID_GEN ) -fprintf (stderr,", invalid inode generation" ); +fprintf (stderr,", invalid inode generation or transid" );fprintf (stderr,"\n" );/* Print the holes if needed */
@@ -912,7 +912,8 @@ static int process_inode_item(struct extent_buffer *eb,* inode generation uplimit, use super_generation + 1 anyway */ gen_uplimit =btrfs_super_generation (gfs_info->super_copy) +1 ; -if (btrfs_inode_generation (eb, item) > gen_uplimit) +if (btrfs_inode_generation (eb, item) > gen_uplimit || +btrfs_inode_transid (eb, item) > gen_uplimit) rec->errors |=I_ERR_INVALID_GEN ;maybe_free_inode_rec (&active_node->inode_cache, rec);return 0 ;
@@ -2835,9 +2836,10 @@ static int repair_inode_gen_original(struct btrfs_trans_handle *trans, ii =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], struct btrfs_inode_item);btrfs_set_inode_generation (path->nodes[0 ], ii, trans->transid); +btrfs_set_inode_transid (path->nodes[0 ], ii, trans->transid);btrfs_mark_buffer_dirty (path->nodes[0 ]);btrfs_release_path (path); -printf ("resetting inode generation to %llu for ino %llu\n" , +printf ("resetting inode generation/transid to %llu for ino %llu\n" , trans->transid, rec->ino); rec->errors &= ~I_ERR_INVALID_GEN ;return 0 ;
Signature · 1 line
2.28.0
Re: [PATCH 2/3] btrfs-progs: check/original: add inode transid detect and repair support
Quoted 4 lines · Qu Wenruo
The inode transid detect and repair is reusing the existing inode geneartion code.
Signed-off-by Qu Wenruo <[email protected]>
Thanks,
Josef
PATCH 3/3 btrfs-progs: tests/fsck: add test image for inode transid repair
In reply to Qu WenruoThe image would contain an inode with invalid transid:
item 4 key (257 INODE_ITEM 0) itemoff 15881 itemsize 160
generation 6 transid 134217734 size 131072 nbytes 131072
block group 0 mode 100600 links 1 uid 0 gid 0 rdev 0--- .../bad_inode_transid.img.xz | Bin 0 -> 1888 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/043-bad-inode-generation/bad_inode_transid.img.xz
tests/fsck-tests/043-bad-inode-generation/bad_inode_transid.img.xz new file binary +0 -0
Signature · 1 line
2.28.0
Re: [PATCH 3/3] btrfs-progs: tests/fsck: add test image for inode transid repair
Quoted 7 lines · Qu Wenruo
The image would contain an inode with invalid transid:
item 4 key (257 INODE_ITEM 0) itemoff 15881 itemsize 160 generation 6 transid 134217734 size 131072 nbytes 131072 block group 0 mode 100600 links 1 uid 0 gid 0 rdev 0Signed-off-by Qu Wenruo <[email protected]>
Thanks,
Josef
Quoted 6 lines · Qu Wenruo
Really nothing interesting here for btrfs-progs, just reusing existing inode generation detect and repair code.
The interesting part is, how a wrongly copied error message delayed us so long to locate a bug.
Quoted 7 lines
Reported-by Tyler Richmond <[email protected]>Qu Wenruo (3):
btrfs-progs: check/lowmem: add inode transid detect and repair support
btrfs-progs: check/original: add inode transid detect and repair
support
btrfs-progs: tests/fsck: add test image for inode transid repair
Added to devel, thanks.