2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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
39 #define FLAG_TOOFARLEFT 0x0001
40 #define FLAG_TOOFARRIGHT 0x0002
41 #define FLAG_BADTYPE 0x0004
42 #define FLAG_BADCHILDPARENT 0x0008
43 #define FLAG_BADMIRRORTID 0x0010
46 struct hammer_base_elm base
;
47 int limit
; /* # of fields to test */
48 int filter
; /* filter type (default -1) */
49 int obfuscate
; /* obfuscate direntry name */
50 int indent
; /* use depth indentation */
54 static __inline
void print_btree(hammer_off_t node_offset
);
55 static __inline
void print_subtree(hammer_btree_elm_t elm
);
56 static void print_btree_node(hammer_off_t node_offset
, hammer_tid_t mirror_tid
,
57 hammer_btree_elm_t lbe
);
58 static int test_node_count(hammer_node_ondisk_t node
, char *badmp
);
59 static void print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
60 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
, const char *ext
);
61 static int get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
62 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
);
63 static int test_lr(hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
);
64 static int test_rbn_lr(hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
);
65 static void print_bigblock_fill(hammer_off_t offset
);
66 static const char *check_data_crc(hammer_btree_elm_t elm
, const char **whichp
);
67 static hammer_crc_t
get_inode_crc(hammer_btree_leaf_elm_t leaf
,
69 static hammer_crc_t
get_buf_crc(hammer_btree_leaf_elm_t leaf
,
71 static void print_record(hammer_btree_elm_t elm
);
72 static int init_btree_search(const char *arg
);
73 static int test_btree_search(hammer_btree_elm_t elm
);
74 static int test_btree_match(hammer_btree_elm_t elm
);
75 static int test_btree_out_of_range(hammer_btree_elm_t elm
);
76 static void hexdump_record(const void *ptr
, int length
, const char *hdr
);
78 static int num_bad_node
= 0;
79 static int num_bad_elm
= 0;
80 static int num_bad_rec
= 0;
84 static const char* _indents
[] = {
93 _X _X _X _X _X _X _X _X
,
94 _X _X _X _X _X _X _X _X _X
,
95 _X _X _X _X _X _X _X _X _X _X
,
96 _X _X _X _X _X _X _X _X _X _X _X
,
97 _X _X _X _X _X _X _X _X _X _X _X _X
,
98 _X _X _X _X _X _X _X _X _X _X _X _X _X
,
99 _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
100 _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
101 _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
104 #define INDENT _indents[opt.indent ? depth : 0]
107 hammer_cmd_show(const char *arg
, int filter
, int obfuscate
, int indent
)
109 volume_info_t volume
;
110 hammer_volume_ondisk_t ondisk
;
111 zone_stat_t stats
= NULL
;
113 volume
= get_root_volume();
114 ondisk
= volume
->ondisk
;
116 print_blockmap(volume
);
119 stats
= hammer_init_zone_stat_bits();
121 bzero(&opt
, sizeof(opt
));
123 opt
.obfuscate
= obfuscate
;
127 if (init_btree_search(arg
) > 0) {
128 printf("arg=\"%s\"", arg
);
130 printf(" lo=%08x", opt
.base
.localization
);
132 printf(" objid=%016jx", (uintmax_t)opt
.base
.obj_id
);
134 printf(" rt=%02x", opt
.base
.rec_type
);
136 printf(" key=%016jx", (uintmax_t)opt
.base
.key
);
138 printf(" tid=%016jx", (uintmax_t)opt
.base
.create_tid
);
141 print_btree(ondisk
->vol0_btree_root
);
144 hammer_print_zone_stat(stats
);
145 hammer_cleanup_zone_stat(stats
);
148 if (num_bad_node
|| VerboseOpt
)
149 printf("%d bad nodes\n", num_bad_node
);
150 if (num_bad_elm
|| VerboseOpt
)
151 printf("%d bad elms\n", num_bad_elm
);
152 if (num_bad_rec
|| VerboseOpt
)
153 printf("%d bad records\n", num_bad_rec
);
158 print_btree(hammer_off_t node_offset
)
161 print_btree_node(node_offset
, HAMMER_MAX_TID
, NULL
);
167 print_subtree(hammer_btree_elm_t elm
)
169 hammer_btree_internal_elm_t i
= &elm
->internal
;
170 print_btree_node(i
->subtree_offset
, i
->mirror_tid
, elm
);
175 print_btree_node(hammer_off_t node_offset
, hammer_tid_t mirror_tid
,
176 hammer_btree_elm_t lbe
)
178 buffer_info_t buffer
= NULL
;
179 hammer_node_ondisk_t node
;
180 hammer_btree_elm_t elm
;
182 char badc
= ' '; /* good */
183 char badm
= ' '; /* good */
187 node
= get_buffer_data(node_offset
, &buffer
, 0);
193 if (!hammer_crc_test_btree(HammerVersion
, node
))
195 if (node
->mirror_tid
> mirror_tid
) {
199 if (test_node_count(node
, &badm
) == -1) {
205 if (badm
!= ' ' || badc
!= ' ') /* not good */
208 printf("%s%c%c NODE %016jx ",
209 INDENT
, badc
, badm
, (uintmax_t)node_offset
);
210 printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx",
212 (uintmax_t)node
->parent
,
213 (node
->type
? node
->type
: '?'),
215 (uintmax_t)node
->mirror_tid
);
217 print_bigblock_fill(node_offset
);
221 hammer_add_zone_stat(opt
.stats
, node_offset
, sizeof(*node
));
223 for (i
= 0; i
< node
->count
; ++i
) {
224 elm
= &node
->elms
[i
];
227 switch (node
->type
) {
228 case HAMMER_BTREE_TYPE_INTERNAL
:
229 if (!test_btree_out_of_range(elm
))
232 case HAMMER_BTREE_TYPE_LEAF
:
233 if (test_btree_match(elm
))
238 print_btree_elm(node
, node_offset
, elm
, lbe
, ext
);
240 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
241 assert(i
== node
->count
); /* boundary */
242 elm
= &node
->elms
[i
];
243 print_btree_elm(node
, node_offset
, elm
, lbe
, NULL
);
245 printf("%s }\n", INDENT
);
247 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
248 for (i
= 0; i
< node
->count
; ++i
) {
249 elm
= &node
->elms
[i
];
250 if (opt
.limit
&& opt
.filter
) {
251 if (test_btree_out_of_range(elm
))
254 if (elm
->internal
.subtree_offset
) {
257 * Cause show to do normal iteration after
258 * seeking to the lo:objid:rt:key:tid
261 if (opt
.limit
&& opt
.filter
== -1) /* default */
272 test_node_count(hammer_node_ondisk_t node
, char *badmp
)
274 hammer_node_ondisk_t parent_node
;
275 buffer_info_t buffer
= NULL
;
278 maxcount
= hammer_node_max_elements(node
->type
);
280 if (maxcount
== -1) {
283 } else if (node
->count
> maxcount
) {
286 } else if (node
->count
== 0) {
287 parent_node
= get_buffer_data(node
->parent
, &buffer
, 0);
288 if (parent_node
->count
!= 1) {
301 is_root_btree_beg(uint8_t type
, int i
, hammer_btree_elm_t elm
)
304 * elm->base.btype depends on what the original node had
305 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
307 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
309 elm
->base
.localization
== HAMMER_MIN_ONDISK_LOCALIZATION
&&
310 elm
->base
.obj_id
== (int64_t)HAMMER_MIN_OBJID
&&
311 elm
->base
.key
== (int64_t)HAMMER_MIN_KEY
&&
312 elm
->base
.create_tid
== 1 &&
313 elm
->base
.delete_tid
== 1 &&
314 elm
->base
.rec_type
== HAMMER_MIN_RECTYPE
&&
315 elm
->base
.obj_type
== 0 &&
316 elm
->base
.btype
!= HAMMER_BTREE_TYPE_NONE
);
321 is_root_btree_end(uint8_t type
, int i
, hammer_btree_elm_t elm
)
323 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
325 elm
->base
.localization
== HAMMER_MAX_ONDISK_LOCALIZATION
&&
326 elm
->base
.obj_id
== HAMMER_MAX_OBJID
&&
327 elm
->base
.key
== HAMMER_MAX_KEY
&&
328 elm
->base
.create_tid
== HAMMER_MAX_TID
&&
329 elm
->base
.delete_tid
== 0 &&
330 elm
->base
.rec_type
== HAMMER_MAX_RECTYPE
&&
331 elm
->base
.obj_type
== 0 &&
332 elm
->base
.btype
== HAMMER_BTREE_TYPE_NONE
);
337 print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
338 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
, const char *ext
)
340 char flagstr
[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
347 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
349 flags
= get_elm_flags(node
, node_offset
, elm
, lbe
);
350 flagstr
[0] = flags
? 'B' : 'G';
351 if (flags
& FLAG_TOOFARLEFT
)
353 if (flags
& FLAG_TOOFARRIGHT
)
355 if (flags
& FLAG_BADTYPE
)
357 if (flags
& FLAG_BADCHILDPARENT
)
359 if (flags
& FLAG_BADMIRRORTID
)
361 if (flagstr
[0] == 'B')
365 * Check if elm is derived from root split
367 if (is_root_btree_beg(node
->type
, i
, elm
))
369 else if (is_root_btree_end(node
->type
, i
, elm
))
374 if (elm
->base
.delete_tid
)
379 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
&& node
->count
== i
)
384 printf("%s%s %s %2d %c ",
385 INDENT
, flagstr
, label
, i
, hammer_elm_btype(elm
));
386 printf("lo=%08x objid=%016jx rt=%02x key=%016jx tid=%016jx\n",
387 elm
->base
.localization
,
388 (uintmax_t)elm
->base
.obj_id
,
390 (uintmax_t)elm
->base
.key
,
391 (uintmax_t)elm
->base
.create_tid
);
392 printf("%s %c del=%016jx ot=%02x",
394 (rootelm
== ' ' ? deleted
: rootelm
),
395 (uintmax_t)elm
->base
.delete_tid
,
399 case HAMMER_BTREE_TYPE_INTERNAL
:
400 printf(" suboff=%016jx mirror=%016jx",
401 (uintmax_t)elm
->internal
.subtree_offset
,
402 (uintmax_t)elm
->internal
.mirror_tid
);
406 case HAMMER_BTREE_TYPE_LEAF
:
407 switch(elm
->base
.btype
) {
408 case HAMMER_BTREE_TYPE_RECORD
:
409 printf(" dataoff=%016jx/%d",
410 (uintmax_t)elm
->leaf
.data_offset
,
412 p
= check_data_crc(elm
, &which
);
413 printf(" %scrc=%08x", which
, elm
->leaf
.data_crc
);
415 printf(" error=%s", p
);
419 print_bigblock_fill(elm
->leaf
.data_offset
);
423 hammer_add_zone_stat(opt
.stats
,
424 elm
->leaf
.data_offset
,
429 printf(" badtype=%d", elm
->base
.btype
);
441 get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
442 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
444 hammer_off_t child_offset
;
446 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
449 case HAMMER_BTREE_TYPE_INTERNAL
:
450 child_offset
= elm
->internal
.subtree_offset
;
451 if (elm
->internal
.mirror_tid
> node
->mirror_tid
)
452 flags
|= FLAG_BADMIRRORTID
;
454 if (i
== node
->count
) {
455 if (child_offset
!= 0)
456 flags
|= FLAG_BADCHILDPARENT
;
457 switch(elm
->base
.btype
) {
458 case HAMMER_BTREE_TYPE_NONE
:
459 flags
|= test_rbn_lr(elm
, lbe
);
462 flags
|= FLAG_BADTYPE
;
466 if (child_offset
== 0) {
467 flags
|= FLAG_BADCHILDPARENT
;
469 buffer_info_t buffer
= NULL
;
470 hammer_node_ondisk_t subnode
;
471 subnode
= get_buffer_data(child_offset
, &buffer
, 0);
473 flags
|= FLAG_BADCHILDPARENT
;
474 else if (subnode
->parent
!= node_offset
)
475 flags
|= FLAG_BADCHILDPARENT
;
478 switch(elm
->base
.btype
) {
479 case HAMMER_BTREE_TYPE_INTERNAL
:
480 case HAMMER_BTREE_TYPE_LEAF
:
481 flags
|= test_lr(elm
, lbe
);
484 flags
|= FLAG_BADTYPE
;
489 case HAMMER_BTREE_TYPE_LEAF
:
490 if (elm
->leaf
.data_offset
== 0)
491 flags
|= FLAG_BADCHILDPARENT
;
492 if (elm
->leaf
.data_len
== 0)
493 flags
|= FLAG_BADCHILDPARENT
;
495 if (node
->mirror_tid
== 0 &&
496 !(node
->parent
== 0 && node
->count
== 2)) {
497 flags
|= FLAG_BADMIRRORTID
;
499 if (elm
->base
.create_tid
&& node
->mirror_tid
&&
500 elm
->base
.create_tid
> node
->mirror_tid
) {
501 flags
|= FLAG_BADMIRRORTID
;
503 if (elm
->base
.delete_tid
&& node
->mirror_tid
&&
504 elm
->base
.delete_tid
> node
->mirror_tid
) {
505 flags
|= FLAG_BADMIRRORTID
;
507 switch(elm
->base
.btype
) {
508 case HAMMER_BTREE_TYPE_RECORD
:
509 flags
|= test_lr(elm
, lbe
);
512 flags
|= FLAG_BADTYPE
;
517 flags
|= FLAG_BADTYPE
;
524 * Taken from /usr/src/sys/vfs/hammer/hammer_btree.c.
528 hammer_btree_cmp(hammer_base_elm_t key1
, hammer_base_elm_t key2
)
530 if (key1
->localization
< key2
->localization
)
532 if (key1
->localization
> key2
->localization
)
535 if (key1
->obj_id
< key2
->obj_id
)
537 if (key1
->obj_id
> key2
->obj_id
)
540 if (key1
->rec_type
< key2
->rec_type
)
542 if (key1
->rec_type
> key2
->rec_type
)
545 if (key1
->key
< key2
->key
)
547 if (key1
->key
> key2
->key
)
550 if (key1
->create_tid
== 0) {
551 if (key2
->create_tid
== 0)
555 if (key2
->create_tid
== 0)
557 if (key1
->create_tid
< key2
->create_tid
)
559 if (key1
->create_tid
> key2
->create_tid
)
566 test_lr(hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
569 hammer_btree_elm_t rbe
= lbe
+ 1;
570 if (hammer_btree_cmp(&elm
->base
, &lbe
->base
) < 0)
571 return(FLAG_TOOFARLEFT
);
572 if (hammer_btree_cmp(&elm
->base
, &rbe
->base
) >= 0)
573 return(FLAG_TOOFARRIGHT
);
580 test_rbn_lr(hammer_btree_elm_t rbn
, hammer_btree_elm_t lbe
)
583 hammer_btree_elm_t rbe
= lbe
+ 1;
584 if (hammer_btree_cmp(&rbn
->base
, &lbe
->base
) < 0)
585 return(FLAG_TOOFARLEFT
);
586 if (hammer_btree_cmp(&rbn
->base
, &rbe
->base
) > 0)
587 return(FLAG_TOOFARRIGHT
);
594 print_bigblock_fill(hammer_off_t offset
)
596 struct hammer_blockmap_layer1 layer1
;
597 struct hammer_blockmap_layer2 layer2
;
601 blockmap_lookup_save(offset
, &layer1
, &layer2
, &error
);
602 printf("z%d:v%d:%d:%d:%lu=",
603 HAMMER_ZONE_DECODE(offset
),
604 HAMMER_VOL_DECODE(offset
),
605 HAMMER_BLOCKMAP_LAYER1_INDEX(offset
),
606 HAMMER_BLOCKMAP_LAYER2_INDEX(offset
),
607 offset
& HAMMER_BIGBLOCK_MASK64
);
610 printf("B%d", error
);
612 fill
= layer2
.bytes_free
* 100 / HAMMER_BIGBLOCK_SIZE
;
613 printf("%d%%", 100 - fill
);
618 * Check the generic crc on a data element. Inodes record types are
619 * special in that some of their fields are not CRCed.
621 * Also check that the zone is valid.
625 check_data_crc(hammer_btree_elm_t elm
, const char **whichp
)
630 if (elm
->leaf
.data_offset
== 0 || elm
->leaf
.data_len
== 0)
631 return("ZO"); /* zero offset or length */
633 switch (elm
->leaf
.base
.rec_type
) {
634 case HAMMER_RECTYPE_INODE
:
635 if (elm
->leaf
.data_len
!= sizeof(struct hammer_inode_data
))
636 return("BI"); /* bad inode size */
637 crc
= get_inode_crc(&elm
->leaf
, whichp
);
640 crc
= get_buf_crc(&elm
->leaf
, whichp
);
645 return("Bx"); /* bad crc */
646 if (crc
!= elm
->leaf
.data_crc
)
647 return("BX"); /* bad crc */
648 return(NULL
); /* success */
653 get_inode_crc(hammer_btree_leaf_elm_t leaf
, const char **whichp
)
655 buffer_info_t data_buffer
= NULL
;
659 ptr
= get_buffer_data(leaf
->data_offset
, &data_buffer
, 0);
661 if (HammerVersion
>= HAMMER_VOL_VERSION_SEVEN
) {
662 crc
= iscsi_crc32(ptr
, HAMMER_INODE_CRCSIZE
);
663 if (crc
== leaf
->data_crc
) {
669 crc
= crc32(ptr
, HAMMER_INODE_CRCSIZE
);
670 if (crc
== leaf
->data_crc
) {
677 rel_buffer(data_buffer
);
681 typedef uint32_t (*crc32_ext_fn
)(const void *, size_t, uint32_t);
685 __get_buf_crc(hammer_btree_leaf_elm_t leaf
, crc32_ext_fn f
)
687 buffer_info_t data_buffer
= NULL
;
688 hammer_off_t buf_offset
;
689 hammer_crc_t crc
= 0;
690 int32_t buf_len
, len
;
693 buf_offset
= leaf
->data_offset
;
694 buf_len
= leaf
->data_len
;
697 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
698 len
= HAMMER_BUFSIZE
- ((int)buf_offset
& HAMMER_BUFMASK
);
701 assert(len
<= HAMMER_BUFSIZE
);
702 crc
= f(ptr
, len
, crc
);
706 rel_buffer(data_buffer
);
713 get_buf_crc(hammer_btree_leaf_elm_t leaf
, const char **whichp
)
717 if (HammerVersion
>= HAMMER_VOL_VERSION_SEVEN
) {
718 crc
= __get_buf_crc(leaf
, iscsi_crc32_ext
);
719 if (crc
== leaf
->data_crc
) {
725 crc
= __get_buf_crc(leaf
, crc32_ext
);
726 if (crc
== leaf
->data_crc
) {
738 print_config(char *cfgtxt
)
742 printf("\n%s%17s", INDENT
, "");
743 printf("config text=\"\n");
744 if (cfgtxt
!= NULL
) {
745 while((token
= strsep(&cfgtxt
, "\r\n")) != NULL
) {
747 printf("%s%17s %s\n",
752 printf("%s%17s \"", INDENT
, "");
757 print_record(hammer_btree_elm_t elm
)
759 buffer_info_t data_buffer
;
760 hammer_off_t data_offset
;
762 hammer_data_ondisk_t data
;
767 data_offset
= elm
->leaf
.data_offset
;
768 data_len
= elm
->leaf
.data_len
;
769 assert(data_offset
!= 0);
770 assert(data_len
!= 0);
773 data
= get_buffer_data(data_offset
, &data_buffer
, 0);
774 assert(data
!= NULL
);
776 switch(elm
->leaf
.base
.rec_type
) {
777 case HAMMER_RECTYPE_UNKNOWN
:
778 printf("\n%s%17s", INDENT
, "");
781 case HAMMER_RECTYPE_INODE
:
782 printf("\n%s%17s", INDENT
, "");
783 printf("inode size=%jd nlinks=%jd",
784 (intmax_t)data
->inode
.size
,
785 (intmax_t)data
->inode
.nlinks
);
786 printf(" mode=%05o uflags=%08x caps=%02x",
789 data
->inode
.cap_flags
);
790 printf(" pobjid=%016jx ot=%02x\n",
791 (uintmax_t)data
->inode
.parent_obj_id
,
792 data
->inode
.obj_type
);
793 printf("%s%17s", INDENT
, "");
794 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
795 (uintmax_t)data
->inode
.ctime
,
796 (uintmax_t)data
->inode
.mtime
,
797 (uintmax_t)data
->inode
.atime
);
798 if (data
->inode
.ext
.symlink
[0]) {
799 printf(" symlink=\"%s\"",
800 data
->inode
.ext
.symlink
);
803 case HAMMER_RECTYPE_DIRENTRY
:
804 data_len
-= HAMMER_ENTRY_NAME_OFF
;
805 printf("\n%s%17s", INDENT
, "");
806 printf("dir-entry objid=%016jx lo=%08x",
807 (uintmax_t)data
->entry
.obj_id
,
808 data
->entry
.localization
);
809 if (!opt
.obfuscate
) {
810 printf(" name=\"%*.*s\"",
811 data_len
, data_len
, data
->entry
.name
);
814 case HAMMER_RECTYPE_FIX
:
815 switch(elm
->leaf
.base
.key
) {
816 case HAMMER_FIXKEY_SYMLINK
:
817 data_len
-= HAMMER_SYMLINK_NAME_OFF
;
818 printf("\n%s%17s", INDENT
, "");
819 printf("fix-symlink name=\"%*.*s\"",
820 data_len
, data_len
, data
->symlink
.name
);
824 case HAMMER_RECTYPE_PFS
:
825 printf("\n%s%17s", INDENT
, "");
826 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
827 (intmax_t)data
->pfsd
.sync_beg_tid
,
828 (intmax_t)data
->pfsd
.sync_end_tid
);
829 uuid_to_string(&data
->pfsd
.shared_uuid
, &str1
, &status
);
830 uuid_to_string(&data
->pfsd
.unique_uuid
, &str2
, &status
);
832 printf(" shared_uuid=%s\n", str1
);
834 printf(" unique_uuid=%s\n", str2
);
836 printf(" mirror_flags=%08x label=\"%s\"",
837 data
->pfsd
.mirror_flags
, data
->pfsd
.label
);
838 if (data
->pfsd
.snapshots
[0])
839 printf(" snapshots=\"%s\"", data
->pfsd
.snapshots
);
843 case HAMMER_RECTYPE_SNAPSHOT
:
844 printf("\n%s%17s", INDENT
, "");
845 printf("snapshot tid=%016jx label=\"%s\"",
846 (intmax_t)data
->snap
.tid
, data
->snap
.label
);
848 case HAMMER_RECTYPE_CONFIG
:
849 if (VerboseOpt
> 2) {
850 char *p
= strdup(data
->config
.text
);
855 case HAMMER_RECTYPE_DATA
:
856 if (VerboseOpt
> 3) {
858 hexdump_record(data
, data_len
, "\t\t ");
861 case HAMMER_RECTYPE_EXT
:
862 case HAMMER_RECTYPE_DB
:
863 if (VerboseOpt
> 2) {
865 hexdump_record(data
, data_len
, "\t\t ");
872 rel_buffer(data_buffer
);
876 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
877 * which is 16KB. Passing record data length larger than 16KB to
878 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
882 hexdump_record(const void *ptr
, int length
, const char *hdr
)
884 int data_len
= length
;
886 if (data_len
> HAMMER_BUFSIZE
) /* XXX */
887 data_len
= HAMMER_BUFSIZE
;
888 hexdump(ptr
, data_len
, hdr
, 0);
890 if (length
> data_len
)
891 printf("%s....\n", hdr
);
894 static __inline __always_inline
896 _strtoul(const char *p
, int base
)
898 unsigned long retval
;
900 errno
= 0; /* clear */
901 retval
= strtoul(p
, NULL
, base
);
902 if (errno
== ERANGE
&& retval
== ULONG_MAX
) {
909 static __inline __always_inline
911 _strtoull(const char *p
, int base
)
913 unsigned long long retval
;
915 errno
= 0; /* clear */
916 retval
= strtoull(p
, NULL
, base
);
917 if (errno
== ERANGE
&& retval
== ULLONG_MAX
) {
926 init_btree_search(const char *arg
)
931 bzero(&opt
.base
, sizeof(opt
.base
));
936 if (strcmp(arg
, "none") == 0)
943 while ((p
= s
) != NULL
) {
944 if ((s
= strchr(s
, ':')) != NULL
)
947 opt
.base
.localization
= _strtoul(p
, 16);
949 opt
.base
.obj_id
= _strtoull(p
, 16);
951 opt
.base
.rec_type
= _strtoul(p
, 16);
953 opt
.base
.key
= _strtoull(p
, 16);
955 opt
.base
.create_tid
= _strtoull(p
, 16);
967 test_btree_search(hammer_btree_elm_t elm
)
969 hammer_base_elm_t base1
= &elm
->base
;
970 hammer_base_elm_t base2
= &opt
.base
;
971 int limit
= opt
.limit
;
973 if (base1
->localization
< base2
->localization
)
975 if (base1
->localization
> base2
->localization
)
978 return(0); /* ignore below */
980 if (base1
->obj_id
< base2
->obj_id
)
982 if (base1
->obj_id
> base2
->obj_id
)
985 return(0); /* ignore below */
987 if (base1
->rec_type
< base2
->rec_type
)
989 if (base1
->rec_type
> base2
->rec_type
)
992 return(0); /* ignore below */
994 if (base1
->key
< base2
->key
)
996 if (base1
->key
> base2
->key
)
999 return(0); /* ignore below */
1001 if (base1
->create_tid
== 0) {
1002 if (base2
->create_tid
== 0)
1006 if (base2
->create_tid
== 0)
1008 if (base1
->create_tid
< base2
->create_tid
)
1010 if (base1
->create_tid
> base2
->create_tid
)
1017 test_btree_match(hammer_btree_elm_t elm
)
1019 if (test_btree_search(elm
) == 0)
1026 test_btree_out_of_range(hammer_btree_elm_t elm
)
1028 if (test_btree_search(elm
) > 0)
1029 return(1); /* conditions < this elm */
1031 if (opt
.limit
>= 5) {
1032 if (test_btree_search(elm
+ 1) <= 0)
1033 return(1); /* next elm <= conditions */
1035 if (test_btree_search(elm
+ 1) < 0)
1036 return(1); /* next elm < conditions */
1042 * Dump the UNDO FIFO
1045 hammer_cmd_show_undo(void)
1047 volume_info_t volume
;
1048 hammer_blockmap_t rootmap
;
1049 hammer_off_t scan_offset
;
1050 hammer_fifo_any_t head
;
1051 hammer_fifo_head_t hdr
;
1052 buffer_info_t data_buffer
= NULL
;
1053 zone_stat_t stats
= NULL
;
1055 volume
= get_root_volume();
1056 rootmap
= &volume
->ondisk
->vol0_blockmap
[HAMMER_ZONE_UNDO_INDEX
];
1058 print_blockmap(volume
);
1061 stats
= hammer_init_zone_stat_bits();
1063 scan_offset
= HAMMER_ENCODE_UNDO(0);
1064 while (scan_offset
< rootmap
->alloc_offset
) {
1065 head
= get_buffer_data(scan_offset
, &data_buffer
, 0);
1067 printf("%016jx ", scan_offset
);
1069 switch(hdr
->hdr_type
) {
1070 case HAMMER_HEAD_TYPE_PAD
:
1071 printf("PAD(%d)", hdr
->hdr_size
);
1073 case HAMMER_HEAD_TYPE_DUMMY
:
1074 printf("DUMMY(%d)\tseq=%08x",
1075 hdr
->hdr_size
, hdr
->hdr_seq
);
1077 case HAMMER_HEAD_TYPE_UNDO
:
1078 printf("UNDO(%d)\tseq=%08x offset=%016jx bytes=%d",
1079 hdr
->hdr_size
, hdr
->hdr_seq
,
1080 (intmax_t)head
->undo
.undo_offset
,
1081 head
->undo
.undo_data_bytes
);
1083 case HAMMER_HEAD_TYPE_REDO
:
1084 printf("REDO(%d)\tseq=%08x offset=%016jx bytes=%d "
1085 "objid=%016jx flags=%08x lo=%08x",
1086 hdr
->hdr_size
, hdr
->hdr_seq
,
1087 (intmax_t)head
->redo
.redo_offset
,
1088 head
->redo
.redo_data_bytes
,
1089 (intmax_t)head
->redo
.redo_objid
,
1090 head
->redo
.redo_flags
,
1091 head
->redo
.redo_localization
);
1094 printf("%04x(%d)\tseq=%08x",
1095 hdr
->hdr_type
, hdr
->hdr_size
, hdr
->hdr_seq
);
1099 if (scan_offset
== rootmap
->first_offset
)
1101 if (scan_offset
== rootmap
->next_offset
)
1106 hammer_add_zone_stat(stats
, scan_offset
, hdr
->hdr_size
);
1108 if ((hdr
->hdr_size
& HAMMER_HEAD_ALIGN_MASK
) ||
1109 hdr
->hdr_size
== 0 ||
1110 hdr
->hdr_size
> HAMMER_UNDO_ALIGN
-
1111 ((u_int
)scan_offset
& HAMMER_UNDO_MASK
)) {
1112 printf("Illegal size field, skipping to "
1114 scan_offset
= HAMMER_UNDO_DOALIGN(scan_offset
);
1116 scan_offset
+= hdr
->hdr_size
;
1119 rel_buffer(data_buffer
);
1122 hammer_print_zone_stat(stats
);
1123 hammer_cleanup_zone_stat(stats
);