Skip to contentSkip to conversation

Btrfs: add parent_transid parameter to veirfy_level_key

PATCH Superseded Liu Bo 4 participants 8 messages May 15, 2018 – May 25, 2018 Btrfs file system

lore
Share & tools
lore

Liu Bo

author
#0 lore raw

PATCH 1/1 Btrfs: add parent_transid parameter to veirfy_level_key

@parent_transid could tell whether the eb's generation has been verified by the caller.

---
 fs/btrfs/disk-io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +4 -4
index 60caa68c3618..b5d55b0ec19b 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;
@@ -454,10 +454,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu) parent_transid %llu",
 			  eb->start, first_key->objectid, first_key->type,
 			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+			  found_key.type, found_key.offset, parent_transid);
 	}
 #endif
 	return ret;
@@ -493,7 +493,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 2 lines · Liu Bo

@parent_transid could tell whether the eb's generation has been verified by the caller.

Can you please write why you add this change? Like is it an enhancement or debugging help or someting like that.

#2 lore raw
In reply to Liu Bo
Quoted 4 lines · Liu Bo

@parent_transid could tell whether the eb's generation has been verified by the caller.

Looks pretty useful to debug the btrfs/124 bug you just fixed.

But a small nitpick inlined below:

Quoted 18 lines
---
 fs/btrfs/disk-io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +1 -1
index 60caa68c3618..b5d55b0ec19b 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;

fs/btrfs/disk-io.c static int verify_level_key(struct btrfs_fs_info *fs_info, · line 457

Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
@@ -454,10 +454,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu) parent_transid %llu",

It would look better if parent transid can be before key output.

Despite that, everything looks good.

Thanks,
Qu

Quoted 17 lines
fs/btrfs/disk-io.c +2 -2
 			  eb->start, first_key->objectid, first_key->type,
 			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+			  found_key.type, found_key.offset, parent_transid);
 	}
 #endif
 	return ret;
@@ -493,7 +493,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;
author
#3 lore raw

PATCH v2 1/1 Btrfs: add parent_transid parameter to veirfy_level_key

In reply to Liu Bo

As verify_level_key() is checked after verify_parent_transid(), i.e.

if (verify_parent_transid())
ret = -EIO;
else if (verify_level_key())
ret = -EUCLEAN;

if parent_transid is 0, verify_parent_transid() skips verifying parent_transid and considers eb as valid, and if verify_level_key() reports something wrong, we're not going to know if it's caused by corrupted metadata or non-checkecd eb (e.g. stale eb).

@parent_transid is able to tell whether the eb's generation has been verified by the caller.

---
v2: - more explicit commit log.
- adjust the position shown in error msg.

 fs/btrfs/disk-io.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +7 -6
index 60caa68c3618..ad865176a3ca 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;
@@ -454,10 +454,11 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
-			  eb->start, first_key->objectid, first_key->type,
-			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+			  eb->start, parent_transid, first_key->objectid,
+			  first_key->type, first_key->offset,
+			  found_key.objectid, found_key.type,
+			  found_key.offset);
 	}
 #endif
 	return ret;
@@ -493,7 +494,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;
Signature · 1 line
1.8.3.1
#4 lore raw
Quoted 11 lines · Liu Bo

As verify_level_key() is checked after verify_parent_transid(), i.e.

if (verify_parent_transid())
ret = -EIO;
else if (verify_level_key())
ret = -EUCLEAN;

if parent_transid is 0, verify_parent_transid() skips verifying parent_transid and considers eb as valid, and if verify_level_key() reports something wrong, we're not going to know if it's caused by corrupted metadata or non-checkecd eb (e.g. stale eb).

It's really unclear (from the changelog) how the stale eb ties with parent_transid. You should have explained the relationship between checking parenttransid and stale/non-stale ebs

Quoted 3 lines

@parent_transid is able to tell whether the eb's generation has been verified by the caller.

It's really unclear why parent_transid is able to tell whether the generation is verified by the caller.

Quoted 48 lines

---
v2: - more explicit commit log.
- adjust the position shown in error msg.

 fs/btrfs/disk-io.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +7 -6
index 60caa68c3618..ad865176a3ca 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;
@@ -454,10 +454,11 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
-			  eb->start, first_key->objectid, first_key->type,
-			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+			  eb->start, parent_transid, first_key->objectid,
+			  first_key->type, first_key->offset,
+			  found_key.objectid, found_key.type,
+			  found_key.offset);
 	}
 #endif
 	return ret;
@@ -493,7 +494,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;
Reviewed-by on v2 1/1
#7 lore raw
In reply to Liu Bo
Quoted 12 lines · Liu Bo

As verify_level_key() is checked after verify_parent_transid(), i.e.

if (verify_parent_transid())
ret = -EIO;
else if (verify_level_key())
ret = -EUCLEAN;

if parent_transid is 0, verify_parent_transid() skips verifying parent_transid and considers eb as valid, and if verify_level_key() reports something wrong, we're not going to know if it's caused by corrupted metadata or non-checkecd eb (e.g. stale eb).

Quoted 4 lines

@parent_transid is able to tell whether the eb's generation has been verified by the caller.

Thanks,
Qu

Quoted 46 lines

---
v2: - more explicit commit log.
- adjust the position shown in error msg.

 fs/btrfs/disk-io.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +7 -6
index 60caa68c3618..ad865176a3ca 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;
@@ -454,10 +454,11 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
-			  eb->start, first_key->objectid, first_key->type,
-			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+			  eb->start, parent_transid, first_key->objectid,
+			  first_key->type, first_key->offset,
+			  found_key.objectid, found_key.type,
+			  found_key.offset);
 	}
 #endif
 	return ret;
@@ -493,7 +494,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;
#5 lore raw
In reply to Nikolay Borisov
Quoted 10 lines · Nikolay Borisov
Quoted 7 lines · Liu Bo

As verify_level_key() is checked after verify_parent_transid(), i.e.

if (verify_parent_transid())
ret = -EIO;
else if (verify_level_key())
ret = -EUCLEAN;

Quoted 8 lines
Quoted 4 lines

if parent_transid is 0, verify_parent_transid() skips verifying parent_transid and considers eb as valid, and if verify_level_key() reports something wrong, we're not going to know if it's caused by corrupted metadata or non-checkecd eb (e.g. stale eb).

It's really unclear (from the changelog) how the stale eb ties with parent_transid. You should have explained the relationship between checking parenttransid and stale/non-stale ebs

It's in fact related to the fixing patch:
Btrfs: fix the corruption by reading stale btree blocks

But whatever, extra mention won't hurt.

Quoted 7 lines
Quoted 4 lines

@parent_transid is able to tell whether the eb's generation has been verified by the caller.

It's really unclear why parent_transid is able to tell whether the generation is verified by the caller.

At least this looks pretty straightforward to me. @parent_transid = 0 means no generation check, and @parent_transid != 0 means already checked.

So at least for this part I didn't get any confusion.

Thanks,
Qu

Quoted 54 lines
Quoted 41 lines

---
v2: - more explicit commit log.
- adjust the position shown in error msg.

 fs/btrfs/disk-io.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
fs/btrfs/disk-io.c +6 -5
index 60caa68c3618..ad865176a3ca 100644
@@ -416,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 
 static int verify_level_key(struct btrfs_fs_info *fs_info,
 			    struct extent_buffer *eb, int level,
-			    struct btrfs_key *first_key)
+			    struct btrfs_key *first_key, u64 parent_transid)
 {
 	int found_level;
 	struct btrfs_key found_key;
@@ -454,10 +454,11 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,
 	if (ret) {
 		WARN_ON(1);
 		btrfs_err(fs_info,
-"tree first key mismatch detected, bytenr=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
-			  eb->start, first_key->objectid, first_key->type,
-			  first_key->offset, found_key.objectid,
-			  found_key.type, found_key.offset);
+"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu, %u, %llu) has=(%llu, %u, %llu)",
+			  eb->start, parent_transid, first_key->objectid,
+			  first_key->type, first_key->offset,
+			  found_key.objectid, found_key.type,
+			  found_key.offset);
 	}
 #endif
 	return ret;

fs/btrfs/disk-io.c static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info, · line 500

Quoted 8 lines
fs/btrfs/disk-io.c +1 -1
@@ -493,7 +494,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_fs_info *fs_info,
 						   parent_transid, 0))
 				ret = -EIO;
 			else if (verify_level_key(fs_info, eb, level,
-						  first_key))
+						  first_key, parent_transid))
 				ret = -EUCLEAN;
 			else
 				break;

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 18 lines · Qu Wenruo
Quoted 15 lines · Nikolay Borisov
Quoted 11 lines · Liu Bo

As verify_level_key() is checked after verify_parent_transid(), i.e.

if (verify_parent_transid())
ret = -EIO;
else if (verify_level_key())
ret = -EUCLEAN;

if parent_transid is 0, verify_parent_transid() skips verifying parent_transid and considers eb as valid, and if verify_level_key() reports something wrong, we're not going to know if it's caused by corrupted metadata or non-checkecd eb (e.g. stale eb).

Quoted 8 lines
Quoted 3 lines

It's really unclear (from the changelog) how the stale eb ties with parent_transid. You should have explained the relationship between checking parenttransid and stale/non-stale ebs

It's in fact related to the fixing patch:
Btrfs: fix the corruption by reading stale btree blocks

But whatever, extra mention won't hurt.

I've added reference to the patch as it has more details so we don't have to repeat it in the changelog.

Patch added to misc-next, thanks.