Btrfs: add parent_transid parameter to veirfy_level_key
authorLiu Bo <bo.liu@linux.alibaba.com>
Fri, 18 May 2018 02:59:35 +0000 (10:59 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 30 May 2018 14:46:43 +0000 (16:46 +0200)
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).

The stale eb can be from an outdated raid1 mirror after a degraded
mount, see eg "btrfs: fix reading stale metadata blocks after degraded
raid1 mounts" (02a3307aa9c20b4f66262) for more details.

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

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c

index d8d3b73680ef56d1ed0dfbfa0c9dfe2c47523dd6..205092dc939082d48cabc43d7d4a4340a1feffb4 100644 (file)
@@ -415,7 +415,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;
@@ -453,10 +453,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;
@@ -492,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;