]> git.karo-electronics.de Git - karo-tx-linux.git/blob - fs/btrfs/print-tree.c
Subject: Rework btrfs_file_write to only allocate while page locks are held
[karo-tx-linux.git] / fs / btrfs / print-tree.c
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
19 #include <linux/module.h>
20 #include "ctree.h"
21 #include "disk-io.h"
22 #include "print-tree.h"
23
24 void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
25 {
26         int i;
27         u32 nr = btrfs_header_nritems(&l->header);
28         struct btrfs_item *item;
29         struct btrfs_extent_item *ei;
30         struct btrfs_root_item *ri;
31         struct btrfs_dir_item *di;
32         struct btrfs_inode_item *ii;
33         struct btrfs_block_group_item *bi;
34         struct btrfs_file_extent_item *fi;
35         u32 type;
36
37         printk("leaf %llu total ptrs %d free space %d\n",
38                 (unsigned long long)btrfs_header_blocknr(&l->header), nr,
39                 btrfs_leaf_free_space(root, l));
40         for (i = 0 ; i < nr ; i++) {
41                 item = l->items + i;
42                 type = btrfs_disk_key_type(&item->key);
43                 printk("\titem %d key (%llu %x %llu) itemoff %d itemsize %d\n",
44                         i,
45                         (unsigned long long)btrfs_disk_key_objectid(&item->key),
46                         btrfs_disk_key_flags(&item->key),
47                         (unsigned long long)btrfs_disk_key_offset(&item->key),
48                         btrfs_item_offset(item),
49                         btrfs_item_size(item));
50                 switch (type) {
51                 case BTRFS_INODE_ITEM_KEY:
52                         ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
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),
56                                btrfs_inode_mode(ii));
57                         break;
58                 case BTRFS_DIR_ITEM_KEY:
59                         di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
60                         printk("\t\tdir oid %llu flags %u type %u\n",
61                                 (unsigned long long)btrfs_disk_key_objectid(
62                                                             &di->location),
63                                 btrfs_dir_flags(di),
64                                 btrfs_dir_type(di));
65                         printk("\t\tname %.*s\n",
66                                btrfs_dir_name_len(di),(char *)(di + 1));
67                         break;
68                 case BTRFS_ROOT_ITEM_KEY:
69                         ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
70                         printk("\t\troot data blocknr %llu refs %u\n",
71                                 (unsigned long long)btrfs_root_blocknr(ri),
72                                 btrfs_root_refs(ri));
73                         break;
74                 case BTRFS_EXTENT_ITEM_KEY:
75                         ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
76                         printk("\t\textent data refs %u\n",
77                                 btrfs_extent_refs(ei));
78                         break;
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;
96                 case BTRFS_BLOCK_GROUP_ITEM_KEY:
97                         bi = btrfs_item_ptr(l, i,
98                                             struct btrfs_block_group_item);
99                         printk("\t\tblock group used %llu\n",
100                                (unsigned long long)btrfs_block_group_used(bi));
101                         break;
102                 case BTRFS_STRING_ITEM_KEY:
103                         printk("\t\titem data %.*s\n", btrfs_item_size(item),
104                                 btrfs_leaf_data(l) + btrfs_item_offset(item));
105                         break;
106                 };
107         }
108 }
109
110 void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t)
111 {
112         int i;
113         u32 nr;
114         struct btrfs_node *c;
115
116         if (!t)
117                 return;
118         c = btrfs_buffer_node(t);
119         nr = btrfs_header_nritems(&c->header);
120         if (btrfs_is_leaf(c)) {
121                 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
122                 return;
123         }
124         printk("node %llu level %d total ptrs %d free spc %u\n",
125                (unsigned long long)btrfs_header_blocknr(&c->header),
126                btrfs_header_level(&c->header), nr,
127                (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
128         for (i = 0; i < nr; i++) {
129                 printk("\tkey %d (%llu %u %llu) block %llu\n",
130                        i,
131                        (unsigned long long)c->ptrs[i].key.objectid,
132                        c->ptrs[i].key.flags,
133                        (unsigned long long)c->ptrs[i].key.offset,
134                        (unsigned long long)btrfs_node_blockptr(c, i));
135         }
136         for (i = 0; i < nr; i++) {
137                 struct buffer_head *next_buf = read_tree_block(root,
138                                                 btrfs_node_blockptr(c, i));
139                 struct btrfs_node *next = btrfs_buffer_node(next_buf);
140                 if (btrfs_is_leaf(next) &&
141                     btrfs_header_level(&c->header) != 1)
142                         BUG();
143                 if (btrfs_header_level(&next->header) !=
144                         btrfs_header_level(&c->header) - 1)
145                         BUG();
146                 btrfs_print_tree(root, next_buf);
147                 btrfs_block_release(root, next_buf);
148         }
149 }
150