mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	btrfs: move btrfs_verify_level_key into tree-checker.c
This is more a buffer validation helper, move it into the tree-checker files where it makes more sense. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
		
							parent
							
								
									c26fa931eb
								
							
						
					
					
						commit
						2cac5af165
					
				
					 4 changed files with 60 additions and 60 deletions
				
			
		| 
						 | 
					@ -180,64 +180,6 @@ int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
 | 
					 | 
				
			||||||
			   struct btrfs_key *first_key, u64 parent_transid)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct btrfs_fs_info *fs_info = eb->fs_info;
 | 
					 | 
				
			||||||
	int found_level;
 | 
					 | 
				
			||||||
	struct btrfs_key found_key;
 | 
					 | 
				
			||||||
	int ret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	found_level = btrfs_header_level(eb);
 | 
					 | 
				
			||||||
	if (found_level != level) {
 | 
					 | 
				
			||||||
		WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 | 
					 | 
				
			||||||
		     KERN_ERR "BTRFS: tree level check failed\n");
 | 
					 | 
				
			||||||
		btrfs_err(fs_info,
 | 
					 | 
				
			||||||
"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
 | 
					 | 
				
			||||||
			  eb->start, level, found_level);
 | 
					 | 
				
			||||||
		return -EIO;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!first_key)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
					 | 
				
			||||||
	 * For live tree block (new tree blocks in current transaction),
 | 
					 | 
				
			||||||
	 * we need proper lock context to avoid race, which is impossible here.
 | 
					 | 
				
			||||||
	 * So we only checks tree blocks which is read from disk, whose
 | 
					 | 
				
			||||||
	 * generation <= fs_info->last_trans_committed.
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* We have @first_key, so this @eb must have at least one item */
 | 
					 | 
				
			||||||
	if (btrfs_header_nritems(eb) == 0) {
 | 
					 | 
				
			||||||
		btrfs_err(fs_info,
 | 
					 | 
				
			||||||
		"invalid tree nritems, bytenr=%llu nritems=0 expect >0",
 | 
					 | 
				
			||||||
			  eb->start);
 | 
					 | 
				
			||||||
		WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
 | 
					 | 
				
			||||||
		return -EUCLEAN;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (found_level)
 | 
					 | 
				
			||||||
		btrfs_node_key_to_cpu(eb, &found_key, 0);
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		btrfs_item_key_to_cpu(eb, &found_key, 0);
 | 
					 | 
				
			||||||
	ret = btrfs_comp_cpu_keys(first_key, &found_key);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (ret) {
 | 
					 | 
				
			||||||
		WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 | 
					 | 
				
			||||||
		     KERN_ERR "BTRFS: tree first key check failed\n");
 | 
					 | 
				
			||||||
		btrfs_err(fs_info,
 | 
					 | 
				
			||||||
"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);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return ret;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
 | 
					static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
 | 
				
			||||||
				      int mirror_num)
 | 
									      int mirror_num)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,8 +31,6 @@ struct btrfs_tree_parent_check;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
 | 
					void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
 | 
				
			||||||
void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
 | 
					void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
 | 
				
			||||||
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
 | 
					 | 
				
			||||||
			   struct btrfs_key *first_key, u64 parent_transid);
 | 
					 | 
				
			||||||
struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
 | 
					struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
 | 
				
			||||||
				      struct btrfs_tree_parent_check *check);
 | 
									      struct btrfs_tree_parent_check *check);
 | 
				
			||||||
struct extent_buffer *btrfs_find_create_tree_block(
 | 
					struct extent_buffer *btrfs_find_create_tree_block(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1963,3 +1963,61 @@ int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int btrfs_verify_level_key(struct extent_buffer *eb, int level,
 | 
				
			||||||
 | 
								   struct btrfs_key *first_key, u64 parent_transid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct btrfs_fs_info *fs_info = eb->fs_info;
 | 
				
			||||||
 | 
						int found_level;
 | 
				
			||||||
 | 
						struct btrfs_key found_key;
 | 
				
			||||||
 | 
						int ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						found_level = btrfs_header_level(eb);
 | 
				
			||||||
 | 
						if (found_level != level) {
 | 
				
			||||||
 | 
							WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 | 
				
			||||||
 | 
							     KERN_ERR "BTRFS: tree level check failed\n");
 | 
				
			||||||
 | 
							btrfs_err(fs_info,
 | 
				
			||||||
 | 
					"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
 | 
				
			||||||
 | 
								  eb->start, level, found_level);
 | 
				
			||||||
 | 
							return -EIO;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!first_key)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
						 * For live tree block (new tree blocks in current transaction),
 | 
				
			||||||
 | 
						 * we need proper lock context to avoid race, which is impossible here.
 | 
				
			||||||
 | 
						 * So we only checks tree blocks which is read from disk, whose
 | 
				
			||||||
 | 
						 * generation <= fs_info->last_trans_committed.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* We have @first_key, so this @eb must have at least one item */
 | 
				
			||||||
 | 
						if (btrfs_header_nritems(eb) == 0) {
 | 
				
			||||||
 | 
							btrfs_err(fs_info,
 | 
				
			||||||
 | 
							"invalid tree nritems, bytenr=%llu nritems=0 expect >0",
 | 
				
			||||||
 | 
								  eb->start);
 | 
				
			||||||
 | 
							WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
 | 
				
			||||||
 | 
							return -EUCLEAN;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (found_level)
 | 
				
			||||||
 | 
							btrfs_node_key_to_cpu(eb, &found_key, 0);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							btrfs_item_key_to_cpu(eb, &found_key, 0);
 | 
				
			||||||
 | 
						ret = btrfs_comp_cpu_keys(first_key, &found_key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ret) {
 | 
				
			||||||
 | 
							WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
 | 
				
			||||||
 | 
							     KERN_ERR "BTRFS: tree first key check failed\n");
 | 
				
			||||||
 | 
							btrfs_err(fs_info,
 | 
				
			||||||
 | 
					"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);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ret;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,5 +66,7 @@ int btrfs_check_node(struct extent_buffer *node);
 | 
				
			||||||
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
 | 
					int btrfs_check_chunk_valid(struct extent_buffer *leaf,
 | 
				
			||||||
			    struct btrfs_chunk *chunk, u64 logical);
 | 
								    struct btrfs_chunk *chunk, u64 logical);
 | 
				
			||||||
int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
 | 
					int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
 | 
				
			||||||
 | 
					int btrfs_verify_level_key(struct extent_buffer *eb, int level,
 | 
				
			||||||
 | 
								   struct btrfs_key *first_key, u64 parent_transid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue