Blame view

fs/btrfs/print-tree.c 11.5 KB
c1d7c514f   David Sterba   btrfs: replace GP...
1
  // SPDX-License-Identifier: GPL-2.0
6cbd55707   Chris Mason   Btrfs: add GPLv2
2
3
  /*
   * Copyright (C) 2007 Oracle.  All rights reserved.
6cbd55707   Chris Mason   Btrfs: add GPLv2
4
   */
5de08d7d5   Chris Mason   Btrfs: Break up c...
5
6
  #include "ctree.h"
  #include "disk-io.h"
35b7e4761   Chris Mason   Btrfs: fix page c...
7
  #include "print-tree.h"
5de08d7d5   Chris Mason   Btrfs: Break up c...
8

0b86a832a   Chris Mason   Btrfs: Add suppor...
9
10
11
12
  static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
  {
  	int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
  	int i;
62e855771   Jeff Mahoney   btrfs: convert pr...
13
14
  	pr_info("\t\tchunk length %llu owner %llu type %llu num_stripes %d
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
15
16
  	       btrfs_chunk_length(eb, chunk), btrfs_chunk_owner(eb, chunk),
  	       btrfs_chunk_type(eb, chunk), num_stripes);
0b86a832a   Chris Mason   Btrfs: Add suppor...
17
  	for (i = 0 ; i < num_stripes ; i++) {
62e855771   Jeff Mahoney   btrfs: convert pr...
18
19
  		pr_info("\t\t\tstripe %d devid %llu offset %llu
  ", i,
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
20
21
  		      btrfs_stripe_devid_nr(eb, chunk, i),
  		      btrfs_stripe_offset_nr(eb, chunk, i));
0b86a832a   Chris Mason   Btrfs: Add suppor...
22
23
24
25
26
  	}
  }
  static void print_dev_item(struct extent_buffer *eb,
  			   struct btrfs_dev_item *dev_item)
  {
62e855771   Jeff Mahoney   btrfs: convert pr...
27
28
  	pr_info("\t\tdev item devid %llu total_bytes %llu bytes used %llu
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
29
30
31
  	       btrfs_device_id(eb, dev_item),
  	       btrfs_device_total_bytes(eb, dev_item),
  	       btrfs_device_bytes_used(eb, dev_item));
0b86a832a   Chris Mason   Btrfs: Add suppor...
32
  }
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
33
34
35
  static void print_extent_data_ref(struct extent_buffer *eb,
  				  struct btrfs_extent_data_ref *ref)
  {
64ecdb647   Liu Bo   Btrfs: add one mo...
36
37
  	pr_cont("extent data backref root %llu objectid %llu offset %llu count %u
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
38
39
40
  	       btrfs_extent_data_ref_root(eb, ref),
  	       btrfs_extent_data_ref_objectid(eb, ref),
  	       btrfs_extent_data_ref_offset(eb, ref),
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
41
42
  	       btrfs_extent_data_ref_count(eb, ref));
  }
be2c765df   Josef Bacik   Btrfs: fix btrfs_...
43
  static void print_extent_item(struct extent_buffer *eb, int slot, int type)
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
44
45
46
47
48
49
50
51
  {
  	struct btrfs_extent_item *ei;
  	struct btrfs_extent_inline_ref *iref;
  	struct btrfs_extent_data_ref *dref;
  	struct btrfs_shared_data_ref *sref;
  	struct btrfs_disk_key key;
  	unsigned long end;
  	unsigned long ptr;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
52
53
54
  	u32 item_size = btrfs_item_size_nr(eb, slot);
  	u64 flags;
  	u64 offset;
64ecdb647   Liu Bo   Btrfs: add one mo...
55
  	int ref_index = 0;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
56

6d8ff4e45   David Sterba   btrfs: annotate u...
57
  	if (unlikely(item_size < sizeof(*ei))) {
ba3c2b196   Nikolay Borisov   btrfs: Add gracef...
58
59
60
  		btrfs_print_v0_err(eb->fs_info);
  		btrfs_handle_fs_error(eb->fs_info, -EINVAL, NULL);
  	}
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
61
62
63
  
  	ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
  	flags = btrfs_extent_flags(eb, ei);
62e855771   Jeff Mahoney   btrfs: convert pr...
64
65
  	pr_info("\t\textent refs %llu gen %llu flags %llu
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
66
67
  	       btrfs_extent_refs(eb, ei), btrfs_extent_generation(eb, ei),
  	       flags);
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
68

be2c765df   Josef Bacik   Btrfs: fix btrfs_...
69
70
  	if ((type == BTRFS_EXTENT_ITEM_KEY) &&
  	    flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
71
72
73
  		struct btrfs_tree_block_info *info;
  		info = (struct btrfs_tree_block_info *)(ei + 1);
  		btrfs_tree_block_key(eb, info, &key);
62e855771   Jeff Mahoney   btrfs: convert pr...
74
75
  		pr_info("\t\ttree block key (%llu %u %llu) level %d
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
76
77
  		       btrfs_disk_key_objectid(&key), key.type,
  		       btrfs_disk_key_offset(&key),
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
78
79
80
81
82
83
84
85
86
87
88
89
  		       btrfs_tree_block_level(eb, info));
  		iref = (struct btrfs_extent_inline_ref *)(info + 1);
  	} else {
  		iref = (struct btrfs_extent_inline_ref *)(ei + 1);
  	}
  
  	ptr = (unsigned long)iref;
  	end = (unsigned long)ei + item_size;
  	while (ptr < end) {
  		iref = (struct btrfs_extent_inline_ref *)ptr;
  		type = btrfs_extent_inline_ref_type(eb, iref);
  		offset = btrfs_extent_inline_ref_offset(eb, iref);
64ecdb647   Liu Bo   Btrfs: add one mo...
90
  		pr_info("\t\tref#%d: ", ref_index++);
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
91
92
  		switch (type) {
  		case BTRFS_TREE_BLOCK_REF_KEY:
64ecdb647   Liu Bo   Btrfs: add one mo...
93
94
  			pr_cont("tree block backref root %llu
  ", offset);
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
95
96
  			break;
  		case BTRFS_SHARED_BLOCK_REF_KEY:
64ecdb647   Liu Bo   Btrfs: add one mo...
97
98
99
100
101
102
103
104
105
106
  			pr_cont("shared block backref parent %llu
  ", offset);
  			/*
  			 * offset is supposed to be a tree block which
  			 * must be aligned to nodesize.
  			 */
  			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
  				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)
  ",
  					offset, (unsigned long long)eb->fs_info->nodesize);
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
107
108
109
110
111
112
113
  			break;
  		case BTRFS_EXTENT_DATA_REF_KEY:
  			dref = (struct btrfs_extent_data_ref *)(&iref->offset);
  			print_extent_data_ref(eb, dref);
  			break;
  		case BTRFS_SHARED_DATA_REF_KEY:
  			sref = (struct btrfs_shared_data_ref *)(iref + 1);
64ecdb647   Liu Bo   Btrfs: add one mo...
114
115
  			pr_cont("shared data backref parent %llu count %u
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
116
  			       offset, btrfs_shared_data_ref_count(eb, sref));
64ecdb647   Liu Bo   Btrfs: add one mo...
117
118
119
120
121
122
123
124
  			/*
  			 * offset is supposed to be a tree block which
  			 * must be aligned to nodesize.
  			 */
  			if (!IS_ALIGNED(offset, eb->fs_info->nodesize))
  				pr_info("\t\t\t(parent %llu is NOT ALIGNED to nodesize %llu)
  ",
  				     offset, (unsigned long long)eb->fs_info->nodesize);
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
125
126
  			break;
  		default:
64ecdb647   Liu Bo   Btrfs: add one mo...
127
128
  			pr_cont("(extent %llu has INVALID ref type %d)
  ",
07638ea59   Liu Bo   Btrfs: remove BUG...
129
130
  				  eb->start, type);
  			return;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
131
132
133
134
135
  		}
  		ptr += btrfs_extent_inline_ref_size(type);
  	}
  	WARN_ON(ptr > end);
  }
8f8ae8e21   Stefan Behrens   Btrfs: support pr...
136
137
138
139
  static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
  			    u32 item_size)
  {
  	if (!IS_ALIGNED(item_size, sizeof(u64))) {
efe120a06   Frank Holton   Btrfs: convert pr...
140
141
  		pr_warn("BTRFS: uuid item with illegal size %lu!
  ",
8f8ae8e21   Stefan Behrens   Btrfs: support pr...
142
143
144
145
146
147
148
  			(unsigned long)item_size);
  		return;
  	}
  	while (item_size) {
  		__le64 subvol_id;
  
  		read_extent_buffer(l, &subvol_id, offset, sizeof(subvol_id));
62e855771   Jeff Mahoney   btrfs: convert pr...
149
150
  		pr_info("\t\tsubvol_id %llu
  ",
8f8ae8e21   Stefan Behrens   Btrfs: support pr...
151
152
153
154
155
  		       (unsigned long long)le64_to_cpu(subvol_id));
  		item_size -= sizeof(u64);
  		offset += sizeof(u64);
  	}
  }
b54599369   Qu Wenruo   btrfs: print-tree...
156
157
158
159
160
161
162
163
164
  /*
   * Helper to output refs and locking status of extent buffer.  Useful to debug
   * race condition related problems.
   */
  static void print_eb_refs_lock(struct extent_buffer *eb)
  {
  #ifdef CONFIG_BTRFS_DEBUG
  	btrfs_info(eb->fs_info,
  "refs %u lock (w:%d r:%d bw:%d br:%d sw:%d sr:%d) lock_owner %u current %u",
00801ae4b   David Sterba   btrfs: switch ext...
165
  		   atomic_read(&eb->refs), eb->write_locks,
b54599369   Qu Wenruo   btrfs: print-tree...
166
  		   atomic_read(&eb->read_locks),
06297d8ce   David Sterba   btrfs: switch ext...
167
  		   eb->blocking_writers,
b54599369   Qu Wenruo   btrfs: print-tree...
168
  		   atomic_read(&eb->blocking_readers),
f3dc24c52   David Sterba   btrfs: switch ext...
169
  		   eb->spinning_writers,
b54599369   Qu Wenruo   btrfs: print-tree...
170
171
172
173
  		   atomic_read(&eb->spinning_readers),
  		   eb->lock_owner, current->pid);
  #endif
  }
a4f78750e   David Sterba   btrfs: get fs_inf...
174
  void btrfs_print_leaf(struct extent_buffer *l)
5de08d7d5   Chris Mason   Btrfs: Break up c...
175
  {
a4f78750e   David Sterba   btrfs: get fs_inf...
176
  	struct btrfs_fs_info *fs_info;
5de08d7d5   Chris Mason   Btrfs: Break up c...
177
  	int i;
068132bad   Daniel J Blueman   btrfs: fix oops o...
178
  	u32 type, nr;
0783fcfc4   Chris Mason   Btrfs: struct ite...
179
  	struct btrfs_item *item;
3768f3689   Chris Mason   Btrfs: Change the...
180
  	struct btrfs_root_item *ri;
1d4f6404d   Chris Mason   Btrfs: directory ...
181
  	struct btrfs_dir_item *di;
293ffd5fd   Chris Mason   Btrfs: change dir...
182
  	struct btrfs_inode_item *ii;
9078a3e1e   Chris Mason   Btrfs: start of b...
183
  	struct btrfs_block_group_item *bi;
8c2383c3d   Chris Mason   Subject: Rework b...
184
  	struct btrfs_file_extent_item *fi;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
185
186
187
  	struct btrfs_extent_data_ref *dref;
  	struct btrfs_shared_data_ref *sref;
  	struct btrfs_dev_extent *dev_extent;
5f39d397d   Chris Mason   Btrfs: Create ext...
188
189
  	struct btrfs_key key;
  	struct btrfs_key found_key;
1d4f6404d   Chris Mason   Btrfs: directory ...
190

068132bad   Daniel J Blueman   btrfs: fix oops o...
191
192
  	if (!l)
  		return;
a4f78750e   David Sterba   btrfs: get fs_inf...
193
  	fs_info = l->fs_info;
068132bad   Daniel J Blueman   btrfs: fix oops o...
194
  	nr = btrfs_header_nritems(l);
c08723237   Qu Wenruo   btrfs: print-tree...
195
196
197
  	btrfs_info(fs_info,
  		   "leaf %llu gen %llu total ptrs %d free space %d owner %llu",
  		   btrfs_header_bytenr(l), btrfs_header_generation(l), nr,
e902baac6   David Sterba   btrfs: get fs_inf...
198
  		   btrfs_leaf_free_space(l), btrfs_header_owner(l));
b54599369   Qu Wenruo   btrfs: print-tree...
199
  	print_eb_refs_lock(l);
5de08d7d5   Chris Mason   Btrfs: Break up c...
200
  	for (i = 0 ; i < nr ; i++) {
dd3cc16b8   Ross Kirk   btrfs: drop unuse...
201
  		item = btrfs_item_nr(i);
5f39d397d   Chris Mason   Btrfs: Create ext...
202
  		btrfs_item_key_to_cpu(l, &key, i);
962a298f3   David Sterba   btrfs: kill the k...
203
  		type = key.type;
62e855771   Jeff Mahoney   btrfs: convert pr...
204
205
  		pr_info("\titem %d key (%llu %u %llu) itemoff %d itemsize %d
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
206
  			i, key.objectid, type, key.offset,
5f39d397d   Chris Mason   Btrfs: Create ext...
207
  			btrfs_item_offset(l, item), btrfs_item_size(l, item));
62e2749e0   Chris Mason   Btrfs: Use a chun...
208
209
  		switch (type) {
  		case BTRFS_INODE_ITEM_KEY:
293ffd5fd   Chris Mason   Btrfs: change dir...
210
  			ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
62e855771   Jeff Mahoney   btrfs: convert pr...
211
212
  			pr_info("\t\tinode generation %llu size %llu mode %o
  ",
d397712bc   Chris Mason   Btrfs: Fix checkp...
213
  			       btrfs_inode_generation(l, ii),
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
214
  			       btrfs_inode_size(l, ii),
5f39d397d   Chris Mason   Btrfs: Create ext...
215
  			       btrfs_inode_mode(l, ii));
62e2749e0   Chris Mason   Btrfs: Use a chun...
216
217
  			break;
  		case BTRFS_DIR_ITEM_KEY:
1d4f6404d   Chris Mason   Btrfs: directory ...
218
  			di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
5f39d397d   Chris Mason   Btrfs: Create ext...
219
  			btrfs_dir_item_key_to_cpu(l, di, &found_key);
62e855771   Jeff Mahoney   btrfs: convert pr...
220
221
  			pr_info("\t\tdir oid %llu type %u
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
222
  				found_key.objectid,
5f39d397d   Chris Mason   Btrfs: Create ext...
223
  				btrfs_dir_type(l, di));
62e2749e0   Chris Mason   Btrfs: Use a chun...
224
225
226
  			break;
  		case BTRFS_ROOT_ITEM_KEY:
  			ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
62e855771   Jeff Mahoney   btrfs: convert pr...
227
228
  			pr_info("\t\troot data bytenr %llu refs %u
  ",
d397712bc   Chris Mason   Btrfs: Fix checkp...
229
  				btrfs_disk_root_bytenr(l, ri),
5f39d397d   Chris Mason   Btrfs: Create ext...
230
  				btrfs_disk_root_refs(l, ri));
62e2749e0   Chris Mason   Btrfs: Use a chun...
231
232
  			break;
  		case BTRFS_EXTENT_ITEM_KEY:
be2c765df   Josef Bacik   Btrfs: fix btrfs_...
233
234
  		case BTRFS_METADATA_ITEM_KEY:
  			print_extent_item(l, i, type);
62e2749e0   Chris Mason   Btrfs: Use a chun...
235
  			break;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
236
  		case BTRFS_TREE_BLOCK_REF_KEY:
62e855771   Jeff Mahoney   btrfs: convert pr...
237
238
  			pr_info("\t\ttree block backref
  ");
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
239
240
  			break;
  		case BTRFS_SHARED_BLOCK_REF_KEY:
62e855771   Jeff Mahoney   btrfs: convert pr...
241
242
  			pr_info("\t\tshared block backref
  ");
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
243
244
245
246
247
248
249
250
251
  			break;
  		case BTRFS_EXTENT_DATA_REF_KEY:
  			dref = btrfs_item_ptr(l, i,
  					      struct btrfs_extent_data_ref);
  			print_extent_data_ref(l, dref);
  			break;
  		case BTRFS_SHARED_DATA_REF_KEY:
  			sref = btrfs_item_ptr(l, i,
  					      struct btrfs_shared_data_ref);
62e855771   Jeff Mahoney   btrfs: convert pr...
252
253
  			pr_info("\t\tshared data backref count %u
  ",
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
254
  			       btrfs_shared_data_ref_count(l, sref));
7bb86316c   Chris Mason   Btrfs: Add back p...
255
  			break;
8c2383c3d   Chris Mason   Subject: Rework b...
256
257
258
  		case BTRFS_EXTENT_DATA_KEY:
  			fi = btrfs_item_ptr(l, i,
  					    struct btrfs_file_extent_item);
5f39d397d   Chris Mason   Btrfs: Create ext...
259
  			if (btrfs_file_extent_type(l, fi) ==
8c2383c3d   Chris Mason   Subject: Rework b...
260
  			    BTRFS_FILE_EXTENT_INLINE) {
e41ca5897   Qu Wenruo   btrfs: Get rid of...
261
262
263
  				pr_info("\t\tinline extent data size %llu
  ",
  				       btrfs_file_extent_ram_bytes(l, fi));
8c2383c3d   Chris Mason   Subject: Rework b...
264
265
  				break;
  			}
62e855771   Jeff Mahoney   btrfs: convert pr...
266
267
  			pr_info("\t\textent data disk bytenr %llu nr %llu
  ",
d397712bc   Chris Mason   Btrfs: Fix checkp...
268
  			       btrfs_file_extent_disk_bytenr(l, fi),
d397712bc   Chris Mason   Btrfs: Fix checkp...
269
  			       btrfs_file_extent_disk_num_bytes(l, fi));
62e855771   Jeff Mahoney   btrfs: convert pr...
270
271
  			pr_info("\t\textent data offset %llu nr %llu ram %llu
  ",
d397712bc   Chris Mason   Btrfs: Fix checkp...
272
  			       btrfs_file_extent_offset(l, fi),
d397712bc   Chris Mason   Btrfs: Fix checkp...
273
  			       btrfs_file_extent_num_bytes(l, fi),
d397712bc   Chris Mason   Btrfs: Fix checkp...
274
  			       btrfs_file_extent_ram_bytes(l, fi));
8c2383c3d   Chris Mason   Subject: Rework b...
275
  			break;
5d4f98a28   Yan Zheng   Btrfs: Mixed back...
276
  		case BTRFS_EXTENT_REF_V0_KEY:
ba3c2b196   Nikolay Borisov   btrfs: Add gracef...
277
278
  			btrfs_print_v0_err(fs_info);
  			btrfs_handle_fs_error(fs_info, -EINVAL, NULL);
333e81054   liubo   btrfs: fix missin...
279
  			break;
9078a3e1e   Chris Mason   Btrfs: start of b...
280
281
282
  		case BTRFS_BLOCK_GROUP_ITEM_KEY:
  			bi = btrfs_item_ptr(l, i,
  					    struct btrfs_block_group_item);
555ba411a   Liu Bo   Btrfs: let btrfs_...
283
284
285
286
287
288
  			pr_info(
  		   "\t\tblock group used %llu chunk_objectid %llu flags %llu
  ",
  				btrfs_disk_block_group_used(l, bi),
  				btrfs_disk_block_group_chunk_objectid(l, bi),
  				btrfs_disk_block_group_flags(l, bi));
62e2749e0   Chris Mason   Btrfs: Use a chun...
289
  			break;
0b86a832a   Chris Mason   Btrfs: Add suppor...
290
  		case BTRFS_CHUNK_ITEM_KEY:
d397712bc   Chris Mason   Btrfs: Fix checkp...
291
292
  			print_chunk(l, btrfs_item_ptr(l, i,
  						      struct btrfs_chunk));
0b86a832a   Chris Mason   Btrfs: Add suppor...
293
294
295
296
297
298
299
300
  			break;
  		case BTRFS_DEV_ITEM_KEY:
  			print_dev_item(l, btrfs_item_ptr(l, i,
  					struct btrfs_dev_item));
  			break;
  		case BTRFS_DEV_EXTENT_KEY:
  			dev_extent = btrfs_item_ptr(l, i,
  						    struct btrfs_dev_extent);
62e855771   Jeff Mahoney   btrfs: convert pr...
301
302
303
  			pr_info("\t\tdev extent chunk_tree %llu
  \t\tchunk objectid %llu chunk offset %llu length %llu
  ",
e17cade25   Chris Mason   Btrfs: Add chunk ...
304
  			       btrfs_dev_extent_chunk_tree(l, dev_extent),
e17cade25   Chris Mason   Btrfs: Add chunk ...
305
  			       btrfs_dev_extent_chunk_objectid(l, dev_extent),
e17cade25   Chris Mason   Btrfs: Add chunk ...
306
  			       btrfs_dev_extent_chunk_offset(l, dev_extent),
e17cade25   Chris Mason   Btrfs: Add chunk ...
307
  			       btrfs_dev_extent_length(l, dev_extent));
0e6360274   Eric Sandeen   btrfs: add missin...
308
  			break;
585a3d0d2   David Sterba   btrfs: teach prin...
309
  		case BTRFS_PERSISTENT_ITEM_KEY:
62e855771   Jeff Mahoney   btrfs: convert pr...
310
311
  			pr_info("\t\tpersistent item objectid %llu offset %llu
  ",
585a3d0d2   David Sterba   btrfs: teach prin...
312
313
314
  					key.objectid, key.offset);
  			switch (key.objectid) {
  			case BTRFS_DEV_STATS_OBJECTID:
62e855771   Jeff Mahoney   btrfs: convert pr...
315
316
  				pr_info("\t\tdevice stats
  ");
585a3d0d2   David Sterba   btrfs: teach prin...
317
318
  				break;
  			default:
62e855771   Jeff Mahoney   btrfs: convert pr...
319
320
  				pr_info("\t\tunknown persistent item
  ");
585a3d0d2   David Sterba   btrfs: teach prin...
321
  			}
733f4fbbc   Stefan Behrens   Btrfs: read devic...
322
  			break;
9f07e1d76   David Sterba   btrfs: teach prin...
323
  		case BTRFS_TEMPORARY_ITEM_KEY:
62e855771   Jeff Mahoney   btrfs: convert pr...
324
325
  			pr_info("\t\ttemporary item objectid %llu offset %llu
  ",
9f07e1d76   David Sterba   btrfs: teach prin...
326
327
328
  					key.objectid, key.offset);
  			switch (key.objectid) {
  			case BTRFS_BALANCE_OBJECTID:
62e855771   Jeff Mahoney   btrfs: convert pr...
329
330
  				pr_info("\t\tbalance status
  ");
9f07e1d76   David Sterba   btrfs: teach prin...
331
332
  				break;
  			default:
62e855771   Jeff Mahoney   btrfs: convert pr...
333
334
  				pr_info("\t\tunknown temporary item
  ");
9f07e1d76   David Sterba   btrfs: teach prin...
335
336
  			}
  			break;
a2bff6402   Stefan Behrens   Btrfs: introduce ...
337
  		case BTRFS_DEV_REPLACE_KEY:
62e855771   Jeff Mahoney   btrfs: convert pr...
338
339
  			pr_info("\t\tdev replace
  ");
a2bff6402   Stefan Behrens   Btrfs: introduce ...
340
  			break;
8f8ae8e21   Stefan Behrens   Btrfs: support pr...
341
342
343
344
345
  		case BTRFS_UUID_KEY_SUBVOL:
  		case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
  			print_uuid_item(l, btrfs_item_ptr_offset(l, i),
  					btrfs_item_size_nr(l, i));
  			break;
62e2749e0   Chris Mason   Btrfs: Use a chun...
346
  		};
5de08d7d5   Chris Mason   Btrfs: Break up c...
347
348
  	}
  }
e20d96d64   Chris Mason   Mountable btrfs, ...
349

c08723237   Qu Wenruo   btrfs: print-tree...
350
  void btrfs_print_tree(struct extent_buffer *c, bool follow)
5de08d7d5   Chris Mason   Btrfs: Break up c...
351
  {
abe60ba45   David Sterba   btrfs: get fs_inf...
352
  	struct btrfs_fs_info *fs_info;
e17cade25   Chris Mason   Btrfs: Add chunk ...
353
  	int i; u32 nr;
5f39d397d   Chris Mason   Btrfs: Create ext...
354
  	struct btrfs_key key;
db94535db   Chris Mason   Btrfs: Allow tree...
355
  	int level;
5de08d7d5   Chris Mason   Btrfs: Break up c...
356

5f39d397d   Chris Mason   Btrfs: Create ext...
357
  	if (!c)
5de08d7d5   Chris Mason   Btrfs: Break up c...
358
  		return;
abe60ba45   David Sterba   btrfs: get fs_inf...
359
  	fs_info = c->fs_info;
5f39d397d   Chris Mason   Btrfs: Create ext...
360
  	nr = btrfs_header_nritems(c);
db94535db   Chris Mason   Btrfs: Allow tree...
361
362
  	level = btrfs_header_level(c);
  	if (level == 0) {
a4f78750e   David Sterba   btrfs: get fs_inf...
363
  		btrfs_print_leaf(c);
5de08d7d5   Chris Mason   Btrfs: Break up c...
364
365
  		return;
  	}
0b246afa6   Jeff Mahoney   btrfs: root->fs_i...
366
  	btrfs_info(fs_info,
c08723237   Qu Wenruo   btrfs: print-tree...
367
368
369
370
  		   "node %llu level %d gen %llu total ptrs %d free spc %u owner %llu",
  		   btrfs_header_bytenr(c), level, btrfs_header_generation(c),
  		   nr, (u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr,
  		   btrfs_header_owner(c));
b54599369   Qu Wenruo   btrfs: print-tree...
371
  	print_eb_refs_lock(c);
5de08d7d5   Chris Mason   Btrfs: Break up c...
372
  	for (i = 0; i < nr; i++) {
5f39d397d   Chris Mason   Btrfs: Create ext...
373
  		btrfs_node_key_to_cpu(c, &key, i);
c08723237   Qu Wenruo   btrfs: print-tree...
374
375
  		pr_info("\tkey %d (%llu %u %llu) block %llu gen %llu
  ",
c1c9ff7c9   Geert Uytterhoeven   Btrfs: Remove sup...
376
  		       i, key.objectid, key.type, key.offset,
c08723237   Qu Wenruo   btrfs: print-tree...
377
378
  		       btrfs_node_blockptr(c, i),
  		       btrfs_node_ptr_generation(c, i));
5de08d7d5   Chris Mason   Btrfs: Break up c...
379
  	}
c08723237   Qu Wenruo   btrfs: print-tree...
380
381
  	if (!follow)
  		return;
5de08d7d5   Chris Mason   Btrfs: Break up c...
382
  	for (i = 0; i < nr; i++) {
581c17604   Qu Wenruo   btrfs: Validate c...
383
384
385
386
387
388
389
  		struct btrfs_key first_key;
  		struct extent_buffer *next;
  
  		btrfs_node_key_to_cpu(c, &first_key, i);
  		next = read_tree_block(fs_info, btrfs_node_blockptr(c, i),
  				       btrfs_node_ptr_generation(c, i),
  				       level - 1, &first_key);
a42cbec9c   Liu Bo   Btrfs: add error ...
390
391
392
393
394
395
  		if (IS_ERR(next)) {
  			continue;
  		} else if (!extent_buffer_uptodate(next)) {
  			free_extent_buffer(next);
  			continue;
  		}
7518a238e   Chris Mason   Btrfs: get/set fo...
396
  		if (btrfs_is_leaf(next) &&
c271b4924   Daniel Cadete   Btrfs: remove of ...
397
  		   level != 1)
5de08d7d5   Chris Mason   Btrfs: Break up c...
398
  			BUG();
5f39d397d   Chris Mason   Btrfs: Create ext...
399
  		if (btrfs_header_level(next) !=
c271b4924   Daniel Cadete   Btrfs: remove of ...
400
  		       level - 1)
5de08d7d5   Chris Mason   Btrfs: Break up c...
401
  			BUG();
c08723237   Qu Wenruo   btrfs: print-tree...
402
  		btrfs_print_tree(next, follow);
5f39d397d   Chris Mason   Btrfs: Create ext...
403
  		free_extent_buffer(next);
5de08d7d5   Chris Mason   Btrfs: Break up c...
404
  	}
5de08d7d5   Chris Mason   Btrfs: Break up c...
405
  }