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 | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 19 | #include <linux/module.h> |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 20 | #include "ctree.h" |
| 21 | #include "disk-io.h" |
Chris Mason | 35b7e47 | 2007-05-02 15:53:43 -0400 | [diff] [blame] | 22 | #include "print-tree.h" |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 23 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 24 | void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 25 | { |
| 26 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 27 | u32 nr = btrfs_header_nritems(&l->header); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 28 | struct btrfs_item *item; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 29 | struct btrfs_extent_item *ei; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 30 | struct btrfs_root_item *ri; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 31 | struct btrfs_dir_item *di; |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 32 | struct btrfs_inode_item *ii; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 33 | struct btrfs_block_group_item *bi; |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame^] | 34 | struct btrfs_file_extent_item *fi; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 35 | u32 type; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 36 | |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 37 | printk("leaf %llu total ptrs %d free space %d\n", |
| 38 | (unsigned long long)btrfs_header_blocknr(&l->header), nr, |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 39 | btrfs_leaf_free_space(root, l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 40 | for (i = 0 ; i < nr ; i++) { |
| 41 | item = l->items + i; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 42 | type = btrfs_disk_key_type(&item->key); |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 43 | printk("\titem %d key (%llu %x %llu) itemoff %d itemsize %d\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 44 | i, |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 45 | (unsigned long long)btrfs_disk_key_objectid(&item->key), |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 46 | btrfs_disk_key_flags(&item->key), |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 47 | (unsigned long long)btrfs_disk_key_offset(&item->key), |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 48 | btrfs_item_offset(item), |
| 49 | btrfs_item_size(item)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 50 | switch (type) { |
| 51 | case BTRFS_INODE_ITEM_KEY: |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 52 | ii = btrfs_item_ptr(l, i, struct btrfs_inode_item); |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 53 | printk("\t\tinode generation %llu size %llu mode %o\n", |
| 54 | (unsigned long long)btrfs_inode_generation(ii), |
| 55 | (unsigned long long)btrfs_inode_size(ii), |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 56 | btrfs_inode_mode(ii)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 57 | break; |
| 58 | case BTRFS_DIR_ITEM_KEY: |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 59 | di = btrfs_item_ptr(l, i, struct btrfs_dir_item); |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 60 | printk("\t\tdir oid %llu flags %u type %u\n", |
| 61 | (unsigned long long)btrfs_disk_key_objectid( |
| 62 | &di->location), |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 63 | btrfs_dir_flags(di), |
| 64 | btrfs_dir_type(di)); |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 65 | printk("\t\tname %.*s\n", |
Chris Mason | 9f5fae2 | 2007-03-20 14:38:32 -0400 | [diff] [blame] | 66 | btrfs_dir_name_len(di),(char *)(di + 1)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 67 | break; |
| 68 | case BTRFS_ROOT_ITEM_KEY: |
| 69 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 70 | printk("\t\troot data blocknr %llu refs %u\n", |
| 71 | (unsigned long long)btrfs_root_blocknr(ri), |
| 72 | btrfs_root_refs(ri)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 73 | break; |
| 74 | case BTRFS_EXTENT_ITEM_KEY: |
| 75 | ei = btrfs_item_ptr(l, i, struct btrfs_extent_item); |
Chris Mason | d0dbc62 | 2007-04-10 12:36:36 -0400 | [diff] [blame] | 76 | printk("\t\textent data refs %u\n", |
| 77 | btrfs_extent_refs(ei)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 78 | break; |
Chris Mason | 8c2383c | 2007-06-18 09:57:58 -0400 | [diff] [blame^] | 79 | |
| 80 | case BTRFS_EXTENT_DATA_KEY: |
| 81 | fi = btrfs_item_ptr(l, i, |
| 82 | struct btrfs_file_extent_item); |
| 83 | if (btrfs_file_extent_type(fi) == |
| 84 | BTRFS_FILE_EXTENT_INLINE) { |
| 85 | printk("\t\tinline extent data size %u\n", |
| 86 | btrfs_file_extent_inline_len(l->items + i)); |
| 87 | break; |
| 88 | } |
| 89 | printk("\t\textent data disk block %llu nr %llu\n", |
| 90 | (unsigned long long)btrfs_file_extent_disk_blocknr(fi), |
| 91 | (unsigned long long)btrfs_file_extent_disk_num_blocks(fi)); |
| 92 | printk("\t\textent data offset %llu nr %llu\n", |
| 93 | (unsigned long long)btrfs_file_extent_offset(fi), |
| 94 | (unsigned long long)btrfs_file_extent_num_blocks(fi)); |
| 95 | break; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 96 | case BTRFS_BLOCK_GROUP_ITEM_KEY: |
| 97 | bi = btrfs_item_ptr(l, i, |
| 98 | struct btrfs_block_group_item); |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 99 | printk("\t\tblock group used %llu\n", |
| 100 | (unsigned long long)btrfs_block_group_used(bi)); |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 101 | break; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 102 | case BTRFS_STRING_ITEM_KEY: |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 103 | printk("\t\titem data %.*s\n", btrfs_item_size(item), |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 104 | btrfs_leaf_data(l) + btrfs_item_offset(item)); |
| 105 | break; |
| 106 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 107 | } |
| 108 | } |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 109 | |
| 110 | void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 111 | { |
| 112 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 113 | u32 nr; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 114 | struct btrfs_node *c; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 115 | |
| 116 | if (!t) |
| 117 | return; |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 118 | c = btrfs_buffer_node(t); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 119 | nr = btrfs_header_nritems(&c->header); |
| 120 | if (btrfs_is_leaf(c)) { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 121 | btrfs_print_leaf(root, (struct btrfs_leaf *)c); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 122 | return; |
| 123 | } |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 124 | printk("node %llu level %d total ptrs %d free spc %u\n", |
| 125 | (unsigned long long)btrfs_header_blocknr(&c->header), |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 126 | btrfs_header_level(&c->header), nr, |
| 127 | (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 128 | for (i = 0; i < nr; i++) { |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 129 | printk("\tkey %d (%llu %u %llu) block %llu\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 130 | i, |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 131 | (unsigned long long)c->ptrs[i].key.objectid, |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 132 | c->ptrs[i].key.flags, |
Chris Mason | 5af3981 | 2007-06-12 07:50:13 -0400 | [diff] [blame] | 133 | (unsigned long long)c->ptrs[i].key.offset, |
| 134 | (unsigned long long)btrfs_node_blockptr(c, i)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 135 | } |
| 136 | for (i = 0; i < nr; i++) { |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 137 | struct buffer_head *next_buf = read_tree_block(root, |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 138 | btrfs_node_blockptr(c, i)); |
Chris Mason | e20d96d | 2007-03-22 12:13:20 -0400 | [diff] [blame] | 139 | struct btrfs_node *next = btrfs_buffer_node(next_buf); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 140 | if (btrfs_is_leaf(next) && |
| 141 | btrfs_header_level(&c->header) != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 142 | BUG(); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 143 | if (btrfs_header_level(&next->header) != |
| 144 | btrfs_header_level(&c->header) - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 145 | BUG(); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 146 | btrfs_print_tree(root, next_buf); |
| 147 | btrfs_block_release(root, next_buf); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 148 | } |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 149 | } |
| 150 | |