Chris Mason | 6cbd557 | 2007-06-12 09:07:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Oracle. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public |
| 6 | * License v2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public |
| 14 | * License along with this program; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 021110-1307, USA. |
| 17 | */ |
| 18 | |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 19 | #include "ctree.h" |
| 20 | #include "disk-io.h" |
Chris Mason | 35b7e47 | 2007-05-02 15:53:43 -0400 | [diff] [blame] | 21 | #include "print-tree.h" |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 22 | |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 23 | static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk) |
| 24 | { |
| 25 | int num_stripes = btrfs_chunk_num_stripes(eb, chunk); |
| 26 | int i; |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 27 | pr_info("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 28 | btrfs_chunk_length(eb, chunk), btrfs_chunk_owner(eb, chunk), |
| 29 | btrfs_chunk_type(eb, chunk), num_stripes); |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 30 | for (i = 0 ; i < num_stripes ; i++) { |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 31 | pr_info("\t\t\tstripe %d devid %llu offset %llu\n", i, |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 32 | btrfs_stripe_devid_nr(eb, chunk, i), |
| 33 | btrfs_stripe_offset_nr(eb, chunk, i)); |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | static void print_dev_item(struct extent_buffer *eb, |
| 37 | struct btrfs_dev_item *dev_item) |
| 38 | { |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 39 | pr_info("\t\tdev item devid %llu total_bytes %llu bytes used %llu\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 40 | btrfs_device_id(eb, dev_item), |
| 41 | btrfs_device_total_bytes(eb, dev_item), |
| 42 | btrfs_device_bytes_used(eb, dev_item)); |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 43 | } |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 44 | static void print_extent_data_ref(struct extent_buffer *eb, |
| 45 | struct btrfs_extent_data_ref *ref) |
| 46 | { |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 47 | pr_info("\t\textent data backref root %llu objectid %llu offset %llu count %u\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 48 | btrfs_extent_data_ref_root(eb, ref), |
| 49 | btrfs_extent_data_ref_objectid(eb, ref), |
| 50 | btrfs_extent_data_ref_offset(eb, ref), |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 51 | btrfs_extent_data_ref_count(eb, ref)); |
| 52 | } |
| 53 | |
Josef Bacik | be2c765 | 2014-07-02 10:20:48 -0700 | [diff] [blame] | 54 | static void print_extent_item(struct extent_buffer *eb, int slot, int type) |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 55 | { |
| 56 | struct btrfs_extent_item *ei; |
| 57 | struct btrfs_extent_inline_ref *iref; |
| 58 | struct btrfs_extent_data_ref *dref; |
| 59 | struct btrfs_shared_data_ref *sref; |
| 60 | struct btrfs_disk_key key; |
| 61 | unsigned long end; |
| 62 | unsigned long ptr; |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 63 | u32 item_size = btrfs_item_size_nr(eb, slot); |
| 64 | u64 flags; |
| 65 | u64 offset; |
| 66 | |
| 67 | if (item_size < sizeof(*ei)) { |
| 68 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 |
| 69 | struct btrfs_extent_item_v0 *ei0; |
| 70 | BUG_ON(item_size != sizeof(*ei0)); |
| 71 | ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 72 | pr_info("\t\textent refs %u\n", |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 73 | btrfs_extent_refs_v0(eb, ei0)); |
| 74 | return; |
| 75 | #else |
| 76 | BUG(); |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item); |
| 81 | flags = btrfs_extent_flags(eb, ei); |
| 82 | |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 83 | pr_info("\t\textent refs %llu gen %llu flags %llu\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 84 | btrfs_extent_refs(eb, ei), btrfs_extent_generation(eb, ei), |
| 85 | flags); |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 86 | |
Josef Bacik | be2c765 | 2014-07-02 10:20:48 -0700 | [diff] [blame] | 87 | if ((type == BTRFS_EXTENT_ITEM_KEY) && |
| 88 | flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 89 | struct btrfs_tree_block_info *info; |
| 90 | info = (struct btrfs_tree_block_info *)(ei + 1); |
| 91 | btrfs_tree_block_key(eb, info, &key); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 92 | pr_info("\t\ttree block key (%llu %u %llu) level %d\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 93 | btrfs_disk_key_objectid(&key), key.type, |
| 94 | btrfs_disk_key_offset(&key), |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 95 | btrfs_tree_block_level(eb, info)); |
| 96 | iref = (struct btrfs_extent_inline_ref *)(info + 1); |
| 97 | } else { |
| 98 | iref = (struct btrfs_extent_inline_ref *)(ei + 1); |
| 99 | } |
| 100 | |
| 101 | ptr = (unsigned long)iref; |
| 102 | end = (unsigned long)ei + item_size; |
| 103 | while (ptr < end) { |
| 104 | iref = (struct btrfs_extent_inline_ref *)ptr; |
| 105 | type = btrfs_extent_inline_ref_type(eb, iref); |
| 106 | offset = btrfs_extent_inline_ref_offset(eb, iref); |
| 107 | switch (type) { |
| 108 | case BTRFS_TREE_BLOCK_REF_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 109 | pr_info("\t\ttree block backref root %llu\n", offset); |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 110 | break; |
| 111 | case BTRFS_SHARED_BLOCK_REF_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 112 | pr_info("\t\tshared block backref parent %llu\n", offset); |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 113 | break; |
| 114 | case BTRFS_EXTENT_DATA_REF_KEY: |
| 115 | dref = (struct btrfs_extent_data_ref *)(&iref->offset); |
| 116 | print_extent_data_ref(eb, dref); |
| 117 | break; |
| 118 | case BTRFS_SHARED_DATA_REF_KEY: |
| 119 | sref = (struct btrfs_shared_data_ref *)(iref + 1); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 120 | pr_info("\t\tshared data backref parent %llu count %u\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 121 | offset, btrfs_shared_data_ref_count(eb, sref)); |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 122 | break; |
| 123 | default: |
| 124 | BUG(); |
| 125 | } |
| 126 | ptr += btrfs_extent_inline_ref_size(type); |
| 127 | } |
| 128 | WARN_ON(ptr > end); |
| 129 | } |
| 130 | |
| 131 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 |
| 132 | static void print_extent_ref_v0(struct extent_buffer *eb, int slot) |
| 133 | { |
| 134 | struct btrfs_extent_ref_v0 *ref0; |
| 135 | |
| 136 | ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0); |
Jeff Mahoney | 5d163e0 | 2016-09-20 10:05:00 -0400 | [diff] [blame] | 137 | printk("\t\textent back ref root %llu gen %llu owner %llu num_refs %lu\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 138 | btrfs_ref_root_v0(eb, ref0), |
| 139 | btrfs_ref_generation_v0(eb, ref0), |
| 140 | btrfs_ref_objectid_v0(eb, ref0), |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 141 | (unsigned long)btrfs_ref_count_v0(eb, ref0)); |
| 142 | } |
| 143 | #endif |
| 144 | |
Stefan Behrens | 8f8ae8e | 2013-08-15 17:11:18 +0200 | [diff] [blame] | 145 | static void print_uuid_item(struct extent_buffer *l, unsigned long offset, |
| 146 | u32 item_size) |
| 147 | { |
| 148 | if (!IS_ALIGNED(item_size, sizeof(u64))) { |
Frank Holton | efe120a | 2013-12-20 11:37:06 -0500 | [diff] [blame] | 149 | pr_warn("BTRFS: uuid item with illegal size %lu!\n", |
Stefan Behrens | 8f8ae8e | 2013-08-15 17:11:18 +0200 | [diff] [blame] | 150 | (unsigned long)item_size); |
| 151 | return; |
| 152 | } |
| 153 | while (item_size) { |
| 154 | __le64 subvol_id; |
| 155 | |
| 156 | read_extent_buffer(l, &subvol_id, offset, sizeof(subvol_id)); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 157 | pr_info("\t\tsubvol_id %llu\n", |
Stefan Behrens | 8f8ae8e | 2013-08-15 17:11:18 +0200 | [diff] [blame] | 158 | (unsigned long long)le64_to_cpu(subvol_id)); |
| 159 | item_size -= sizeof(u64); |
| 160 | offset += sizeof(u64); |
| 161 | } |
| 162 | } |
| 163 | |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 164 | void btrfs_print_leaf(struct btrfs_fs_info *fs_info, struct extent_buffer *l) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 165 | { |
| 166 | int i; |
Daniel J Blueman | 068132b | 2011-06-23 23:01:01 +0800 | [diff] [blame] | 167 | u32 type, nr; |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 168 | struct btrfs_item *item; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 169 | struct btrfs_root_item *ri; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 170 | struct btrfs_dir_item *di; |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 171 | struct btrfs_inode_item *ii; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 172 | struct btrfs_block_group_item *bi; |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame] | 173 | struct btrfs_file_extent_item *fi; |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 174 | struct btrfs_extent_data_ref *dref; |
| 175 | struct btrfs_shared_data_ref *sref; |
| 176 | struct btrfs_dev_extent *dev_extent; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 177 | struct btrfs_key key; |
| 178 | struct btrfs_key found_key; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 179 | |
Daniel J Blueman | 068132b | 2011-06-23 23:01:01 +0800 | [diff] [blame] | 180 | if (!l) |
| 181 | return; |
| 182 | |
| 183 | nr = btrfs_header_nritems(l); |
| 184 | |
Jeff Mahoney | 0b246af | 2016-06-22 18:54:23 -0400 | [diff] [blame] | 185 | btrfs_info(fs_info, "leaf %llu total ptrs %d free space %d", |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 186 | btrfs_header_bytenr(l), nr, |
| 187 | btrfs_leaf_free_space(fs_info, l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 188 | for (i = 0 ; i < nr ; i++) { |
Ross Kirk | dd3cc16 | 2013-09-16 15:58:09 +0100 | [diff] [blame] | 189 | item = btrfs_item_nr(i); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 190 | btrfs_item_key_to_cpu(l, &key, i); |
David Sterba | 962a298 | 2014-06-04 18:41:45 +0200 | [diff] [blame] | 191 | type = key.type; |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 192 | pr_info("\titem %d key (%llu %u %llu) itemoff %d itemsize %d\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 193 | i, key.objectid, type, key.offset, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 194 | btrfs_item_offset(l, item), btrfs_item_size(l, item)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 195 | switch (type) { |
| 196 | case BTRFS_INODE_ITEM_KEY: |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 197 | ii = btrfs_item_ptr(l, i, struct btrfs_inode_item); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 198 | pr_info("\t\tinode generation %llu size %llu mode %o\n", |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 199 | btrfs_inode_generation(l, ii), |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 200 | btrfs_inode_size(l, ii), |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 201 | btrfs_inode_mode(l, ii)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 202 | break; |
| 203 | case BTRFS_DIR_ITEM_KEY: |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 204 | di = btrfs_item_ptr(l, i, struct btrfs_dir_item); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 205 | btrfs_dir_item_key_to_cpu(l, di, &found_key); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 206 | pr_info("\t\tdir oid %llu type %u\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 207 | found_key.objectid, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 208 | btrfs_dir_type(l, di)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 209 | break; |
| 210 | case BTRFS_ROOT_ITEM_KEY: |
| 211 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 212 | pr_info("\t\troot data bytenr %llu refs %u\n", |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 213 | btrfs_disk_root_bytenr(l, ri), |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 214 | btrfs_disk_root_refs(l, ri)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 215 | break; |
| 216 | case BTRFS_EXTENT_ITEM_KEY: |
Josef Bacik | be2c765 | 2014-07-02 10:20:48 -0700 | [diff] [blame] | 217 | case BTRFS_METADATA_ITEM_KEY: |
| 218 | print_extent_item(l, i, type); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 219 | break; |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 220 | case BTRFS_TREE_BLOCK_REF_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 221 | pr_info("\t\ttree block backref\n"); |
Chris Mason | 7bb8631 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 222 | break; |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 223 | case BTRFS_SHARED_BLOCK_REF_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 224 | pr_info("\t\tshared block backref\n"); |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 225 | break; |
| 226 | case BTRFS_EXTENT_DATA_REF_KEY: |
| 227 | dref = btrfs_item_ptr(l, i, |
| 228 | struct btrfs_extent_data_ref); |
| 229 | print_extent_data_ref(l, dref); |
| 230 | break; |
| 231 | case BTRFS_SHARED_DATA_REF_KEY: |
| 232 | sref = btrfs_item_ptr(l, i, |
| 233 | struct btrfs_shared_data_ref); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 234 | pr_info("\t\tshared data backref count %u\n", |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 235 | btrfs_shared_data_ref_count(l, sref)); |
| 236 | break; |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame] | 237 | case BTRFS_EXTENT_DATA_KEY: |
| 238 | fi = btrfs_item_ptr(l, i, |
| 239 | struct btrfs_file_extent_item); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 240 | if (btrfs_file_extent_type(l, fi) == |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame] | 241 | BTRFS_FILE_EXTENT_INLINE) { |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 242 | pr_info("\t\tinline extent data size %u\n", |
Chris Mason | 514ac8a | 2014-01-03 21:07:00 -0800 | [diff] [blame] | 243 | btrfs_file_extent_inline_len(l, i, fi)); |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame] | 244 | break; |
| 245 | } |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 246 | pr_info("\t\textent data disk bytenr %llu nr %llu\n", |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 247 | btrfs_file_extent_disk_bytenr(l, fi), |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 248 | btrfs_file_extent_disk_num_bytes(l, fi)); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 249 | pr_info("\t\textent data offset %llu nr %llu ram %llu\n", |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 250 | btrfs_file_extent_offset(l, fi), |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 251 | btrfs_file_extent_num_bytes(l, fi), |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 252 | btrfs_file_extent_ram_bytes(l, fi)); |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame] | 253 | break; |
Yan Zheng | 5d4f98a | 2009-06-10 10:45:14 -0400 | [diff] [blame] | 254 | case BTRFS_EXTENT_REF_V0_KEY: |
| 255 | #ifdef BTRFS_COMPAT_EXTENT_TREE_V0 |
| 256 | print_extent_ref_v0(l, i); |
| 257 | #else |
| 258 | BUG(); |
| 259 | #endif |
liubo | 333e810 | 2011-01-26 06:22:33 +0000 | [diff] [blame] | 260 | break; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 261 | case BTRFS_BLOCK_GROUP_ITEM_KEY: |
| 262 | bi = btrfs_item_ptr(l, i, |
| 263 | struct btrfs_block_group_item); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 264 | pr_info("\t\tblock group used %llu\n", |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 265 | btrfs_disk_block_group_used(l, bi)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 266 | break; |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 267 | case BTRFS_CHUNK_ITEM_KEY: |
Chris Mason | d397712 | 2009-01-05 21:25:51 -0500 | [diff] [blame] | 268 | print_chunk(l, btrfs_item_ptr(l, i, |
| 269 | struct btrfs_chunk)); |
Chris Mason | 0b86a83 | 2008-03-24 15:01:56 -0400 | [diff] [blame] | 270 | break; |
| 271 | case BTRFS_DEV_ITEM_KEY: |
| 272 | print_dev_item(l, btrfs_item_ptr(l, i, |
| 273 | struct btrfs_dev_item)); |
| 274 | break; |
| 275 | case BTRFS_DEV_EXTENT_KEY: |
| 276 | dev_extent = btrfs_item_ptr(l, i, |
| 277 | struct btrfs_dev_extent); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 278 | pr_info("\t\tdev extent chunk_tree %llu\n\t\tchunk objectid %llu chunk offset %llu length %llu\n", |
Chris Mason | e17cade | 2008-04-15 15:41:47 -0400 | [diff] [blame] | 279 | btrfs_dev_extent_chunk_tree(l, dev_extent), |
Chris Mason | e17cade | 2008-04-15 15:41:47 -0400 | [diff] [blame] | 280 | btrfs_dev_extent_chunk_objectid(l, dev_extent), |
Chris Mason | e17cade | 2008-04-15 15:41:47 -0400 | [diff] [blame] | 281 | btrfs_dev_extent_chunk_offset(l, dev_extent), |
Chris Mason | e17cade | 2008-04-15 15:41:47 -0400 | [diff] [blame] | 282 | btrfs_dev_extent_length(l, dev_extent)); |
Eric Sandeen | 0e63602 | 2013-01-31 00:54:57 +0000 | [diff] [blame] | 283 | break; |
David Sterba | 585a3d0 | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 284 | case BTRFS_PERSISTENT_ITEM_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 285 | pr_info("\t\tpersistent item objectid %llu offset %llu\n", |
David Sterba | 585a3d0 | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 286 | key.objectid, key.offset); |
| 287 | switch (key.objectid) { |
| 288 | case BTRFS_DEV_STATS_OBJECTID: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 289 | pr_info("\t\tdevice stats\n"); |
David Sterba | 585a3d0 | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 290 | break; |
| 291 | default: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 292 | pr_info("\t\tunknown persistent item\n"); |
David Sterba | 585a3d0 | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 293 | } |
Stefan Behrens | 733f4fb | 2012-05-25 16:06:10 +0200 | [diff] [blame] | 294 | break; |
David Sterba | 9f07e1d | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 295 | case BTRFS_TEMPORARY_ITEM_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 296 | pr_info("\t\ttemporary item objectid %llu offset %llu\n", |
David Sterba | 9f07e1d | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 297 | key.objectid, key.offset); |
| 298 | switch (key.objectid) { |
| 299 | case BTRFS_BALANCE_OBJECTID: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 300 | pr_info("\t\tbalance status\n"); |
David Sterba | 9f07e1d | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 301 | break; |
| 302 | default: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 303 | pr_info("\t\tunknown temporary item\n"); |
David Sterba | 9f07e1d | 2016-01-25 18:44:13 +0100 | [diff] [blame] | 304 | } |
| 305 | break; |
Stefan Behrens | a2bff64 | 2012-11-05 17:32:20 +0100 | [diff] [blame] | 306 | case BTRFS_DEV_REPLACE_KEY: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 307 | pr_info("\t\tdev replace\n"); |
Stefan Behrens | a2bff64 | 2012-11-05 17:32:20 +0100 | [diff] [blame] | 308 | break; |
Stefan Behrens | 8f8ae8e | 2013-08-15 17:11:18 +0200 | [diff] [blame] | 309 | case BTRFS_UUID_KEY_SUBVOL: |
| 310 | case BTRFS_UUID_KEY_RECEIVED_SUBVOL: |
| 311 | print_uuid_item(l, btrfs_item_ptr_offset(l, i), |
| 312 | btrfs_item_size_nr(l, i)); |
| 313 | break; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 314 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 317 | |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 318 | void btrfs_print_tree(struct btrfs_fs_info *fs_info, struct extent_buffer *c) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 319 | { |
Chris Mason | e17cade | 2008-04-15 15:41:47 -0400 | [diff] [blame] | 320 | int i; u32 nr; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 321 | struct btrfs_key key; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 322 | int level; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 323 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 324 | if (!c) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 325 | return; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 326 | nr = btrfs_header_nritems(c); |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 327 | level = btrfs_header_level(c); |
| 328 | if (level == 0) { |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 329 | btrfs_print_leaf(fs_info, c); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 330 | return; |
| 331 | } |
Jeff Mahoney | 0b246af | 2016-06-22 18:54:23 -0400 | [diff] [blame] | 332 | btrfs_info(fs_info, |
Jeff Mahoney | 5d163e0 | 2016-09-20 10:05:00 -0400 | [diff] [blame] | 333 | "node %llu level %d total ptrs %d free spc %u", |
| 334 | btrfs_header_bytenr(c), level, nr, |
Jeff Mahoney | 0b246af | 2016-06-22 18:54:23 -0400 | [diff] [blame] | 335 | (u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 336 | for (i = 0; i < nr; i++) { |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 337 | btrfs_node_key_to_cpu(c, &key, i); |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 338 | pr_info("\tkey %d (%llu %u %llu) block %llu\n", |
Geert Uytterhoeven | c1c9ff7 | 2013-08-20 13:20:07 +0200 | [diff] [blame] | 339 | i, key.objectid, key.type, key.offset, |
| 340 | btrfs_node_blockptr(c, i)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 341 | } |
| 342 | for (i = 0; i < nr; i++) { |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 343 | struct extent_buffer *next = read_tree_block(fs_info, |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 344 | btrfs_node_blockptr(c, i), |
Chris Mason | ca7a79a | 2008-05-12 12:59:19 -0400 | [diff] [blame] | 345 | btrfs_node_ptr_generation(c, i)); |
Liu Bo | a42cbec | 2016-09-14 17:23:39 -0700 | [diff] [blame] | 346 | if (IS_ERR(next)) { |
| 347 | continue; |
| 348 | } else if (!extent_buffer_uptodate(next)) { |
| 349 | free_extent_buffer(next); |
| 350 | continue; |
| 351 | } |
| 352 | |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 353 | if (btrfs_is_leaf(next) && |
Daniel Cadete | c271b49 | 2009-07-22 16:52:13 -0400 | [diff] [blame] | 354 | level != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 355 | BUG(); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 356 | if (btrfs_header_level(next) != |
Daniel Cadete | c271b49 | 2009-07-22 16:52:13 -0400 | [diff] [blame] | 357 | level - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 358 | BUG(); |
Jeff Mahoney | 2ff7e61 | 2016-06-22 18:54:24 -0400 | [diff] [blame] | 359 | btrfs_print_tree(fs_info, next); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 360 | free_extent_buffer(next); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 361 | } |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 362 | } |