Temporarly comment out message based bridge control; there are copyout deep
[dragonfly.git] / sbin / hammer / cmd_show.c
blobaef93d8edff27dd3eed9e8cd5a29fc8a2643f525
1 /*
2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sbin/hammer/cmd_show.c,v 1.12 2008/05/18 01:49:41 dillon Exp $
37 #include "hammer.h"
39 #define FLAG_TOOFARLEFT 0x0001
40 #define FLAG_TOOFARRIGHT 0x0002
41 #define FLAG_BADTYPE 0x0004
42 #define FLAG_BADCHILDPARENT 0x0008
44 static void print_btree_node(hammer_off_t node_offset, int depth, int spike,
45 hammer_base_elm_t left_bound,
46 hammer_base_elm_t right_bound);
47 static void print_record(hammer_btree_elm_t elm);
48 static void print_btree_elm(hammer_btree_elm_t elm, int i, u_int8_t type,
49 int flags, const char *label);
50 static int print_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
51 hammer_btree_elm_t elm, u_int8_t btype,
52 hammer_base_elm_t left_bound,
53 hammer_base_elm_t right_bound);
54 static void print_bigblock_fill(hammer_off_t offset);
56 void
57 hammer_cmd_show(hammer_off_t node_offset, int depth,
58 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
60 struct volume_info *volume;
62 if (node_offset == (hammer_off_t)-1) {
63 volume = get_volume(RootVolNo);
64 node_offset = volume->ondisk->vol0_btree_root;
65 if (VerboseOpt) {
66 printf("\trecords=%lld\n",
67 volume->ondisk->vol0_stat_records);
69 rel_volume(volume);
71 printf("show %016llx depth %d\n", node_offset, depth);
72 print_btree_node(node_offset, depth, 0, left_bound, right_bound);
73 print_btree_node(node_offset, depth, 1, left_bound, right_bound);
76 static void
77 print_btree_node(hammer_off_t node_offset, int depth, int spike,
78 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
80 struct buffer_info *buffer = NULL;
81 hammer_node_ondisk_t node;
82 hammer_btree_elm_t elm;
83 int i;
84 int flags;
85 int maxcount;
86 char badc;
88 node = get_node(node_offset, &buffer);
90 if (crc32(&node->crc + 1, HAMMER_BTREE_CRCSIZE) == node->crc)
91 badc = ' ';
92 else
93 badc = 'B';
95 if (spike == 0) {
96 printf("%c NODE %016llx count=%d parent=%016llx "
97 "type=%c depth=%d fill=",
98 badc,
99 node_offset, node->count, node->parent,
100 (node->type ? node->type : '?'), depth);
101 if (VerboseOpt)
102 print_bigblock_fill(node_offset);
103 printf(" {\n");
105 maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ?
106 HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS;
108 for (i = 0; i < node->count && i < maxcount; ++i) {
109 elm = &node->elms[i];
110 flags = print_elm_flags(node, node_offset,
111 elm, elm->base.btype,
112 left_bound, right_bound);
113 print_btree_elm(elm, i, node->type, flags, "ELM");
115 if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
116 elm = &node->elms[i];
117 flags = print_elm_flags(node, node_offset,
118 elm, 'I',
119 left_bound, right_bound);
120 print_btree_elm(elm, i, node->type, flags, "RBN");
122 printf(" }\n");
125 for (i = 0; i < node->count; ++i) {
126 elm = &node->elms[i];
128 switch(node->type) {
129 case HAMMER_BTREE_TYPE_INTERNAL:
130 if (elm->internal.subtree_offset) {
131 print_btree_node(elm->internal.subtree_offset,
132 depth + 1, spike,
133 &elm[0].base, &elm[1].base);
135 break;
136 default:
137 break;
140 rel_buffer(buffer);
143 static
144 void
145 print_btree_elm(hammer_btree_elm_t elm, int i, u_int8_t type,
146 int flags, const char *label)
148 char flagstr[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
150 flagstr[0] = flags ? 'B' : 'G';
151 if (flags & FLAG_TOOFARLEFT)
152 flagstr[2] = 'L';
153 if (flags & FLAG_TOOFARRIGHT)
154 flagstr[3] = 'R';
155 if (flags & FLAG_BADTYPE)
156 flagstr[4] = 'T';
157 if (flags & FLAG_BADCHILDPARENT)
158 flagstr[4] = 'C';
160 printf("%s\t%s %2d %c ",
161 flagstr, label, i,
162 (elm->base.btype ? elm->base.btype : '?'));
163 printf("obj=%016llx key=%016llx lo=%08x rt=%02x ot=%02x\n",
164 elm->base.obj_id,
165 elm->base.key,
166 elm->base.localization,
167 elm->base.rec_type,
168 elm->base.obj_type);
169 printf("\t %c tids %016llx:%016llx ",
170 (elm->base.delete_tid ? 'd' : ' '),
171 elm->base.create_tid,
172 elm->base.delete_tid);
174 switch(type) {
175 case HAMMER_BTREE_TYPE_INTERNAL:
176 printf("suboff=%016llx", elm->internal.subtree_offset);
177 break;
178 case HAMMER_BTREE_TYPE_LEAF:
179 switch(elm->base.btype) {
180 case HAMMER_BTREE_TYPE_RECORD:
181 printf("\n\t ");
182 printf(" dataoff=%016llx/%d",
183 elm->leaf.data_offset, elm->leaf.data_len);
184 if (VerboseOpt) {
185 printf("\n\t fills=");
186 print_bigblock_fill(elm->leaf.data_offset);
188 if (VerboseOpt > 1)
189 print_record(elm);
190 break;
192 break;
193 default:
194 break;
196 printf("\n");
199 static
201 print_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
202 hammer_btree_elm_t elm, u_int8_t btype,
203 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
205 int flags = 0;
207 switch(node->type) {
208 case HAMMER_BTREE_TYPE_INTERNAL:
209 if (elm->internal.subtree_offset) {
210 struct buffer_info *buffer = NULL;
211 hammer_node_ondisk_t subnode;
213 subnode = get_node(elm->internal.subtree_offset,
214 &buffer);
215 if (subnode->parent != node_offset)
216 flags |= FLAG_BADCHILDPARENT;
217 rel_buffer(buffer);
220 switch(btype) {
221 case HAMMER_BTREE_TYPE_INTERNAL:
222 if (left_bound == NULL || right_bound == NULL)
223 break;
224 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
225 flags |= FLAG_TOOFARLEFT;
226 if (hammer_btree_cmp(&elm->base, right_bound) > 0)
227 flags |= FLAG_TOOFARRIGHT;
228 break;
229 case HAMMER_BTREE_TYPE_LEAF:
230 if (left_bound == NULL || right_bound == NULL)
231 break;
232 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
233 flags |= FLAG_TOOFARLEFT;
234 if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
235 flags |= FLAG_TOOFARRIGHT;
236 break;
237 default:
238 flags |= FLAG_BADTYPE;
239 break;
241 break;
242 case HAMMER_BTREE_TYPE_LEAF:
243 switch(btype) {
244 case HAMMER_BTREE_TYPE_RECORD:
245 if (left_bound == NULL || right_bound == NULL)
246 break;
247 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
248 flags |= FLAG_TOOFARLEFT;
249 if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
250 flags |= FLAG_TOOFARRIGHT;
251 break;
252 default:
253 flags |= FLAG_BADTYPE;
254 break;
256 break;
257 default:
258 flags |= FLAG_BADTYPE;
259 break;
261 return(flags);
264 static
265 void
266 print_bigblock_fill(hammer_off_t offset)
268 struct hammer_blockmap_layer1 layer1;
269 struct hammer_blockmap_layer2 layer2;
270 int fill;
272 blockmap_lookup(offset, &layer1, &layer2);
273 fill = layer2.bytes_free * 100 / HAMMER_LARGEBLOCK_SIZE;
274 fill = 100 - fill;
276 printf("z%d:%lld=%d%%",
277 HAMMER_ZONE_DECODE(offset),
278 (offset & ~HAMMER_OFF_ZONE_MASK) / HAMMER_LARGEBLOCK_SIZE,
279 fill
283 static
284 void
285 print_record(hammer_btree_elm_t elm)
287 struct buffer_info *data_buffer;
288 hammer_off_t data_offset;
289 int32_t data_len;
290 hammer_data_ondisk_t data;
292 data_offset = elm->leaf.data_offset;
293 data_len = elm->leaf.data_len;
294 data_buffer = NULL;
296 if (data_offset)
297 data = get_buffer_data(data_offset, &data_buffer, 0);
298 else
299 data = NULL;
301 switch(elm->leaf.base.rec_type) {
302 case HAMMER_RECTYPE_INODE:
303 printf("\n%17s", "");
304 printf("size=%lld nlinks=%lld",
305 data->inode.size, data->inode.nlinks);
306 if (VerboseOpt > 2) {
307 printf(" mode=%05o uflags=%08x\n",
308 data->inode.mode,
309 data->inode.uflags);
310 printf("%17s", "");
311 printf("ctime=%016llx pobjid=%016llx obj_type=%d\n",
312 data->inode.ctime, data->inode.parent_obj_id,
313 data->inode.obj_type);
314 printf("%17s", "");
315 printf("mtime=%016llx", data->inode.mtime);
317 break;
318 case HAMMER_RECTYPE_DIRENTRY:
319 printf("\n%17s", "");
320 data_len -= HAMMER_ENTRY_NAME_OFF;
321 printf("dir-entry ino=%016llx name=\"%*.*s\"",
322 data->entry.obj_id,
323 data_len, data_len, data->entry.name);
324 break;
325 case HAMMER_RECTYPE_FIX:
326 switch(elm->leaf.base.key) {
327 case HAMMER_FIXKEY_SYMLINK:
328 data_len -= HAMMER_SYMLINK_NAME_OFF;
329 printf("\n%17s", "");
330 printf("symlink=\"%*.*s\"", data_len, data_len,
331 data->symlink.name);
332 break;
333 default:
334 break;
336 break;
337 default:
338 break;
340 if (data_buffer)
341 rel_buffer(data_buffer);