forked from mirrors/linux
		
	btrfs: pretty print leaked root name
I'm a actual human being so am incapable of converting u64 to s64 in my head, so add a helper to get the pretty name of a root objectid and use that helper to spit out the name for any special roots for leaked roots, so I don't have to scratch my head and figure out which root I messed up the refs for. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
		
							parent
							
								
									66a2823c54
								
							
						
					
					
						commit
						457f1864b5
					
				
					 3 changed files with 46 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1503,10 +1503,12 @@ void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info)
 | 
			
		|||
	struct btrfs_root *root;
 | 
			
		||||
 | 
			
		||||
	while (!list_empty(&fs_info->allocated_roots)) {
 | 
			
		||||
		char buf[BTRFS_ROOT_NAME_BUF_LEN];
 | 
			
		||||
 | 
			
		||||
		root = list_first_entry(&fs_info->allocated_roots,
 | 
			
		||||
					struct btrfs_root, leak_list);
 | 
			
		||||
		btrfs_err(fs_info, "leaked root %llu-%llu refcount %d",
 | 
			
		||||
			  root->root_key.objectid, root->root_key.offset,
 | 
			
		||||
		btrfs_err(fs_info, "leaked root %s refcount %d",
 | 
			
		||||
			  btrfs_root_name(root->root_key.objectid, buf),
 | 
			
		||||
			  refcount_read(&root->refs));
 | 
			
		||||
		while (refcount_read(&root->refs) > 1)
 | 
			
		||||
			btrfs_put_root(root);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,44 @@
 | 
			
		|||
#include "disk-io.h"
 | 
			
		||||
#include "print-tree.h"
 | 
			
		||||
 | 
			
		||||
struct root_name_map {
 | 
			
		||||
	u64 id;
 | 
			
		||||
	char name[16];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const struct root_name_map root_map[] = {
 | 
			
		||||
	{ BTRFS_ROOT_TREE_OBJECTID,		"ROOT_TREE"		},
 | 
			
		||||
	{ BTRFS_EXTENT_TREE_OBJECTID,		"EXTENT_TREE"		},
 | 
			
		||||
	{ BTRFS_CHUNK_TREE_OBJECTID,		"CHUNK_TREE"		},
 | 
			
		||||
	{ BTRFS_DEV_TREE_OBJECTID,		"DEV_TREE"		},
 | 
			
		||||
	{ BTRFS_FS_TREE_OBJECTID,		"FS_TREE"		},
 | 
			
		||||
	{ BTRFS_CSUM_TREE_OBJECTID,		"CSUM_TREE"		},
 | 
			
		||||
	{ BTRFS_TREE_LOG_OBJECTID,		"TREE_LOG"		},
 | 
			
		||||
	{ BTRFS_QUOTA_TREE_OBJECTID,		"QUOTA_TREE"		},
 | 
			
		||||
	{ BTRFS_UUID_TREE_OBJECTID,		"UUID_TREE"		},
 | 
			
		||||
	{ BTRFS_FREE_SPACE_TREE_OBJECTID,	"FREE_SPACE_TREE"	},
 | 
			
		||||
	{ BTRFS_DATA_RELOC_TREE_OBJECTID,	"DATA_RELOC_TREE"	},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const char *btrfs_root_name(u64 objectid, char *buf)
 | 
			
		||||
{
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	if (objectid == BTRFS_TREE_RELOC_OBJECTID) {
 | 
			
		||||
		snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN,
 | 
			
		||||
			 "TREE_RELOC offset=%llu", objectid);
 | 
			
		||||
		return buf;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < ARRAY_SIZE(root_map); i++) {
 | 
			
		||||
		if (root_map[i].id == objectid)
 | 
			
		||||
			return root_map[i].name;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", objectid);
 | 
			
		||||
	return buf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
 | 
			
		||||
{
 | 
			
		||||
	int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,11 @@
 | 
			
		|||
#ifndef BTRFS_PRINT_TREE_H
 | 
			
		||||
#define BTRFS_PRINT_TREE_H
 | 
			
		||||
 | 
			
		||||
/* Buffer size to contain tree name and possibly additional data (offset) */
 | 
			
		||||
#define BTRFS_ROOT_NAME_BUF_LEN				48
 | 
			
		||||
 | 
			
		||||
void btrfs_print_leaf(struct extent_buffer *l);
 | 
			
		||||
void btrfs_print_tree(struct extent_buffer *c, bool follow);
 | 
			
		||||
const char *btrfs_root_name(u64 objectid, char *buf);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue