Skip to contentSkip to conversation

btrfs-progs: check: add inode invalid transid detect and repair support

PATCH In review Qu Wenruo 3 participants 8 messages Aug 26, 2020 – Aug 31, 2020 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

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
author
#1 lore raw

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
index 837bacf920ac..2b689b2abf63 100644
@@ -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
Reviewed-by on v1 1/3
#2 lore raw

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.

Thanks,

Josef

author
#3 lore raw

PATCH 2/3 btrfs-progs: check/original: add inode transid detect and repair support

In reply to Qu Wenruo

The 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
index 9a2ee2a00f9a..e7996b7c8c0e 100644
@@ -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
author
#5 lore raw

PATCH 3/3 btrfs-progs: tests/fsck: add test image for inode transid repair

In reply to 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 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
new file mode 100644
index 0000000000000000000000000000000000000000..91ee6947fd71b52d5426b7adeb20cb1f6fd2866b
GIT binary patch
Signature · 1 line
2.28.0
Reviewed-by on v1 3/3
#6 lore raw

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 0

Thanks,

Josef

#7 lore raw
In reply to Qu Wenruo
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

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.