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 */
51 struct zone_stat
*stats
;
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_leaf_crc(uint32_t vol_version
, void *data
,
68 hammer_btree_leaf_elm_t leaf
, const char **whichp
);
69 static uint32_t get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
,
70 uint32_t leaf_crc
, const char **whichp
);
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 struct volume_info
*volume
;
110 hammer_volume_ondisk_t ondisk
;
111 struct zone_stat
*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
);
174 print_btree_node(hammer_off_t node_offset
, hammer_tid_t mirror_tid
,
175 hammer_btree_elm_t lbe
)
177 struct buffer_info
*buffer
= NULL
;
178 hammer_node_ondisk_t node
;
179 hammer_btree_elm_t elm
;
181 char badc
= ' '; /* good */
182 char badm
= ' '; /* good */
186 node
= get_buffer_data(node_offset
, &buffer
, 0);
192 if (!hammer_crc_test_btree(HammerVersion
, node
))
194 if (node
->mirror_tid
> mirror_tid
) {
198 if (test_node_count(node
, &badm
) == -1) {
204 if (badm
!= ' ' || badc
!= ' ') /* not good */
207 printf("%s%c%c NODE %016jx ",
208 INDENT
, badc
, badm
, (uintmax_t)node_offset
);
209 printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx",
211 (uintmax_t)node
->parent
,
212 (node
->type
? node
->type
: '?'),
214 (uintmax_t)node
->mirror_tid
);
216 print_bigblock_fill(node_offset
);
220 hammer_add_zone_stat(opt
.stats
, node_offset
, sizeof(*node
));
222 for (i
= 0; i
< node
->count
; ++i
) {
223 elm
= &node
->elms
[i
];
226 switch (node
->type
) {
227 case HAMMER_BTREE_TYPE_INTERNAL
:
228 if (!test_btree_out_of_range(elm
))
231 case HAMMER_BTREE_TYPE_LEAF
:
232 if (test_btree_match(elm
))
236 print_btree_elm(node
, node_offset
, elm
, lbe
, ext
);
238 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
239 assert(i
== node
->count
); /* boundary */
240 elm
= &node
->elms
[i
];
241 print_btree_elm(node
, node_offset
, elm
, lbe
, NULL
);
243 printf("%s }\n", INDENT
);
245 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
)
246 for (i
= 0; i
< node
->count
; ++i
) {
247 elm
= &node
->elms
[i
];
248 if (opt
.limit
&& opt
.filter
)
249 if (test_btree_out_of_range(elm
))
251 if (elm
->internal
.subtree_offset
) {
254 * Cause show to do normal iteration after
255 * seeking to the lo:objid:rt:key:tid
258 if (opt
.limit
&& opt
.filter
== -1) /* default */
267 test_node_count(hammer_node_ondisk_t node
, char *badmp
)
269 hammer_node_ondisk_t parent_node
;
270 struct buffer_info
*buffer
= NULL
;
273 maxcount
= hammer_node_max_elements(node
->type
);
275 if (maxcount
== -1) {
278 } else if (node
->count
> maxcount
) {
281 } else if (node
->count
== 0) {
282 parent_node
= get_buffer_data(node
->parent
, &buffer
, 0);
283 if (parent_node
->count
!= 1) {
296 is_root_btree_beg(uint8_t type
, int i
, hammer_btree_elm_t elm
)
299 * elm->base.btype depends on what the original node had
300 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
302 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
304 elm
->base
.localization
== HAMMER_MIN_ONDISK_LOCALIZATION
&&
305 elm
->base
.obj_id
== (int64_t)HAMMER_MIN_OBJID
&&
306 elm
->base
.key
== (int64_t)HAMMER_MIN_KEY
&&
307 elm
->base
.create_tid
== 1 &&
308 elm
->base
.delete_tid
== 1 &&
309 elm
->base
.rec_type
== HAMMER_MIN_RECTYPE
&&
310 elm
->base
.obj_type
== 0 &&
311 elm
->base
.btype
!= HAMMER_BTREE_TYPE_NONE
);
316 is_root_btree_end(uint8_t type
, int i
, hammer_btree_elm_t elm
)
318 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
320 elm
->base
.localization
== HAMMER_MAX_ONDISK_LOCALIZATION
&&
321 elm
->base
.obj_id
== HAMMER_MAX_OBJID
&&
322 elm
->base
.key
== HAMMER_MAX_KEY
&&
323 elm
->base
.create_tid
== HAMMER_MAX_TID
&&
324 elm
->base
.delete_tid
== 0 &&
325 elm
->base
.rec_type
== HAMMER_MAX_RECTYPE
&&
326 elm
->base
.obj_type
== 0 &&
327 elm
->base
.btype
== HAMMER_BTREE_TYPE_NONE
);
332 print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
333 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
, const char *ext
)
335 char flagstr
[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
342 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
344 flags
= get_elm_flags(node
, node_offset
, elm
, lbe
);
345 flagstr
[0] = flags
? 'B' : 'G';
346 if (flags
& FLAG_TOOFARLEFT
)
348 if (flags
& FLAG_TOOFARRIGHT
)
350 if (flags
& FLAG_BADTYPE
)
352 if (flags
& FLAG_BADCHILDPARENT
)
354 if (flags
& FLAG_BADMIRRORTID
)
356 if (flagstr
[0] == 'B')
360 * Check if elm is derived from root split
362 if (is_root_btree_beg(node
->type
, i
, elm
))
364 else if (is_root_btree_end(node
->type
, i
, elm
))
369 if (elm
->base
.delete_tid
)
374 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
&& node
->count
== i
)
379 printf("%s%s %s %2d %c ",
380 INDENT
, flagstr
, label
, i
, hammer_elm_btype(elm
));
381 printf("lo=%08x objid=%016jx rt=%02x key=%016jx tid=%016jx\n",
382 elm
->base
.localization
,
383 (uintmax_t)elm
->base
.obj_id
,
385 (uintmax_t)elm
->base
.key
,
386 (uintmax_t)elm
->base
.create_tid
);
387 printf("%s %c del=%016jx ot=%02x",
389 (rootelm
== ' ' ? deleted
: rootelm
),
390 (uintmax_t)elm
->base
.delete_tid
,
394 case HAMMER_BTREE_TYPE_INTERNAL
:
395 printf(" suboff=%016jx mirror=%016jx",
396 (uintmax_t)elm
->internal
.subtree_offset
,
397 (uintmax_t)elm
->internal
.mirror_tid
);
401 case HAMMER_BTREE_TYPE_LEAF
:
402 switch(elm
->base
.btype
) {
403 case HAMMER_BTREE_TYPE_RECORD
:
404 printf(" dataoff=%016jx/%d",
405 (uintmax_t)elm
->leaf
.data_offset
,
407 p
= check_data_crc(elm
, &which
);
408 printf(" %scrc=%08x", which
, elm
->leaf
.data_crc
);
410 printf(" error=%s", p
);
414 print_bigblock_fill(elm
->leaf
.data_offset
);
418 hammer_add_zone_stat(opt
.stats
,
419 elm
->leaf
.data_offset
,
423 printf(" badtype=%d", elm
->base
.btype
);
435 get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
436 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
438 hammer_off_t child_offset
;
440 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
443 case HAMMER_BTREE_TYPE_INTERNAL
:
444 child_offset
= elm
->internal
.subtree_offset
;
445 if (elm
->internal
.mirror_tid
> node
->mirror_tid
)
446 flags
|= FLAG_BADMIRRORTID
;
448 if (i
== node
->count
) {
449 if (child_offset
!= 0)
450 flags
|= FLAG_BADCHILDPARENT
;
451 switch(elm
->base
.btype
) {
452 case HAMMER_BTREE_TYPE_NONE
:
453 flags
|= test_rbn_lr(elm
, lbe
);
456 flags
|= FLAG_BADTYPE
;
460 if (child_offset
== 0) {
461 flags
|= FLAG_BADCHILDPARENT
;
463 struct buffer_info
*buffer
= NULL
;
464 hammer_node_ondisk_t subnode
;
465 subnode
= get_buffer_data(child_offset
, &buffer
, 0);
467 flags
|= FLAG_BADCHILDPARENT
;
468 else if (subnode
->parent
!= node_offset
)
469 flags
|= FLAG_BADCHILDPARENT
;
472 switch(elm
->base
.btype
) {
473 case HAMMER_BTREE_TYPE_INTERNAL
:
474 case HAMMER_BTREE_TYPE_LEAF
:
475 flags
|= test_lr(elm
, lbe
);
478 flags
|= FLAG_BADTYPE
;
483 case HAMMER_BTREE_TYPE_LEAF
:
484 if (elm
->leaf
.data_offset
== 0)
485 flags
|= FLAG_BADCHILDPARENT
;
486 if (elm
->leaf
.data_len
== 0)
487 flags
|= FLAG_BADCHILDPARENT
;
489 if (node
->mirror_tid
== 0 &&
490 !(node
->parent
== 0 && node
->count
== 2))
491 flags
|= FLAG_BADMIRRORTID
;
492 if (elm
->base
.create_tid
&& node
->mirror_tid
&&
493 elm
->base
.create_tid
> node
->mirror_tid
)
494 flags
|= FLAG_BADMIRRORTID
;
495 if (elm
->base
.delete_tid
&& node
->mirror_tid
&&
496 elm
->base
.delete_tid
> node
->mirror_tid
)
497 flags
|= FLAG_BADMIRRORTID
;
498 switch(elm
->base
.btype
) {
499 case HAMMER_BTREE_TYPE_RECORD
:
500 flags
|= test_lr(elm
, lbe
);
503 flags
|= FLAG_BADTYPE
;
508 flags
|= FLAG_BADTYPE
;
515 * Taken from /usr/src/sys/vfs/hammer/hammer_btree.c.
519 hammer_btree_cmp(hammer_base_elm_t key1
, hammer_base_elm_t key2
)
521 if (key1
->localization
< key2
->localization
)
523 if (key1
->localization
> key2
->localization
)
526 if (key1
->obj_id
< key2
->obj_id
)
528 if (key1
->obj_id
> key2
->obj_id
)
531 if (key1
->rec_type
< key2
->rec_type
)
533 if (key1
->rec_type
> key2
->rec_type
)
536 if (key1
->key
< key2
->key
)
538 if (key1
->key
> key2
->key
)
541 if (key1
->create_tid
== 0) {
542 if (key2
->create_tid
== 0)
546 if (key2
->create_tid
== 0)
548 if (key1
->create_tid
< key2
->create_tid
)
550 if (key1
->create_tid
> key2
->create_tid
)
557 test_lr(hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
560 hammer_btree_elm_t rbe
= lbe
+ 1;
561 if (hammer_btree_cmp(&elm
->base
, &lbe
->base
) < 0)
562 return(FLAG_TOOFARLEFT
);
563 if (hammer_btree_cmp(&elm
->base
, &rbe
->base
) >= 0)
564 return(FLAG_TOOFARRIGHT
);
571 test_rbn_lr(hammer_btree_elm_t rbn
, hammer_btree_elm_t lbe
)
574 hammer_btree_elm_t rbe
= lbe
+ 1;
575 if (hammer_btree_cmp(&rbn
->base
, &lbe
->base
) < 0)
576 return(FLAG_TOOFARLEFT
);
577 if (hammer_btree_cmp(&rbn
->base
, &rbe
->base
) > 0)
578 return(FLAG_TOOFARRIGHT
);
585 print_bigblock_fill(hammer_off_t offset
)
587 struct hammer_blockmap_layer1 layer1
;
588 struct hammer_blockmap_layer2 layer2
;
592 blockmap_lookup_save(offset
, &layer1
, &layer2
, &error
);
593 printf("z%d:v%d:%d:%d:%lu=",
594 HAMMER_ZONE_DECODE(offset
),
595 HAMMER_VOL_DECODE(offset
),
596 HAMMER_BLOCKMAP_LAYER1_INDEX(offset
),
597 HAMMER_BLOCKMAP_LAYER2_INDEX(offset
),
598 offset
& HAMMER_BIGBLOCK_MASK64
);
601 printf("B%d", error
);
603 fill
= layer2
.bytes_free
* 100 / HAMMER_BIGBLOCK_SIZE
;
604 printf("%d%%", 100 - fill
);
609 * Check the generic crc on a data element. Inodes record types are
610 * special in that some of their fields are not CRCed.
612 * Also check that the zone is valid.
616 check_data_crc(hammer_btree_elm_t elm
, const char **whichp
)
618 struct buffer_info
*data_buffer
;
619 hammer_off_t data_offset
;
625 data_offset
= elm
->leaf
.data_offset
;
626 data_len
= elm
->leaf
.data_len
;
628 if (data_offset
== 0 || data_len
== 0)
629 return("ZO"); /* zero offset or length */
632 switch (elm
->leaf
.base
.rec_type
) {
633 case HAMMER_RECTYPE_INODE
:
634 if (data_len
!= sizeof(struct hammer_inode_data
))
635 return("BI"); /* bad inode size */
636 ptr
= get_buffer_data(data_offset
, &data_buffer
, 0);
637 crc
= get_leaf_crc(HammerVersion
, ptr
, &elm
->leaf
, whichp
);
638 rel_buffer(data_buffer
);
641 crc
= get_buf_crc(data_offset
, data_len
, elm
->leaf
.data_crc
,
647 return("Bx"); /* bad crc */
648 if (crc
!= elm
->leaf
.data_crc
)
649 return("BX"); /* bad crc */
650 return(NULL
); /* success */
655 get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
, uint32_t leaf_crc
,
658 struct buffer_info
*data_buffer
= NULL
;
665 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
666 len
= HAMMER_BUFSIZE
- ((int)buf_offset
& HAMMER_BUFMASK
);
669 assert(len
<= HAMMER_BUFSIZE
);
670 crc
= crc32_ext(ptr
, len
, crc
);
671 ncrc
= iscsi_crc32_ext(ptr
, len
, ncrc
);
675 rel_buffer(data_buffer
);
677 if (leaf_crc
== crc
) {
686 get_leaf_crc(uint32_t vol_version
, void *data
, hammer_btree_leaf_elm_t leaf
,
692 if (leaf
->data_len
== 0)
695 switch(leaf
->base
.rec_type
) {
696 case HAMMER_RECTYPE_INODE
:
697 if (leaf
->data_len
!= sizeof(struct hammer_inode_data
))
698 return(0); /* This shouldn't happen */
699 if (vol_version
>= HAMMER_VOL_VERSION_SEVEN
) {
700 crc
= iscsi_crc32(data
, HAMMER_INODE_CRCSIZE
);
701 if (crc
== leaf
->data_crc
) {
706 crc
= crc32(data
, HAMMER_INODE_CRCSIZE
);
707 if (crc
== leaf
->data_crc
)
711 if (vol_version
>= HAMMER_VOL_VERSION_SEVEN
) {
712 crc
= iscsi_crc32(data
, leaf
->data_len
);
713 if (crc
== leaf
->data_crc
) {
718 crc
= crc32(data
, leaf
->data_len
);
719 if (crc
== leaf
->data_crc
)
728 print_config(char *cfgtxt
)
732 printf("\n%s%17s", INDENT
, "");
733 printf("config text=\"\n");
735 while((token
= strsep(&cfgtxt
, "\r\n")) != NULL
)
737 printf("%s%17s %s\n",
739 printf("%s%17s \"", INDENT
, "");
744 print_record(hammer_btree_elm_t elm
)
746 struct buffer_info
*data_buffer
;
747 hammer_off_t data_offset
;
749 hammer_data_ondisk_t data
;
754 data_offset
= elm
->leaf
.data_offset
;
755 data_len
= elm
->leaf
.data_len
;
756 assert(data_offset
!= 0);
757 assert(data_len
!= 0);
760 data
= get_buffer_data(data_offset
, &data_buffer
, 0);
761 assert(data
!= NULL
);
763 switch(elm
->leaf
.base
.rec_type
) {
764 case HAMMER_RECTYPE_UNKNOWN
:
765 printf("\n%s%17s", INDENT
, "");
768 case HAMMER_RECTYPE_INODE
:
769 printf("\n%s%17s", INDENT
, "");
770 printf("inode size=%jd nlinks=%jd",
771 (intmax_t)data
->inode
.size
,
772 (intmax_t)data
->inode
.nlinks
);
773 printf(" mode=%05o uflags=%08x caps=%02x",
776 data
->inode
.cap_flags
);
777 printf(" pobjid=%016jx ot=%02x\n",
778 (uintmax_t)data
->inode
.parent_obj_id
,
779 data
->inode
.obj_type
);
780 printf("%s%17s", INDENT
, "");
781 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
782 (uintmax_t)data
->inode
.ctime
,
783 (uintmax_t)data
->inode
.mtime
,
784 (uintmax_t)data
->inode
.atime
);
785 if (data
->inode
.ext
.symlink
[0])
786 printf(" symlink=\"%s\"",
787 data
->inode
.ext
.symlink
);
789 case HAMMER_RECTYPE_DIRENTRY
:
790 data_len
-= HAMMER_ENTRY_NAME_OFF
;
791 printf("\n%s%17s", INDENT
, "");
792 printf("dir-entry objid=%016jx lo=%08x",
793 (uintmax_t)data
->entry
.obj_id
,
794 data
->entry
.localization
);
796 printf(" name=\"%*.*s\"",
797 data_len
, data_len
, data
->entry
.name
);
799 case HAMMER_RECTYPE_FIX
:
800 switch(elm
->leaf
.base
.key
) {
801 case HAMMER_FIXKEY_SYMLINK
:
802 data_len
-= HAMMER_SYMLINK_NAME_OFF
;
803 printf("\n%s%17s", INDENT
, "");
804 printf("fix-symlink name=\"%*.*s\"",
805 data_len
, data_len
, data
->symlink
.name
);
809 case HAMMER_RECTYPE_PFS
:
810 printf("\n%s%17s", INDENT
, "");
811 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
812 (intmax_t)data
->pfsd
.sync_beg_tid
,
813 (intmax_t)data
->pfsd
.sync_end_tid
);
814 uuid_to_string(&data
->pfsd
.shared_uuid
, &str1
, &status
);
815 uuid_to_string(&data
->pfsd
.unique_uuid
, &str2
, &status
);
817 printf(" shared_uuid=%s\n", str1
);
819 printf(" unique_uuid=%s\n", str2
);
821 printf(" mirror_flags=%08x label=\"%s\"",
822 data
->pfsd
.mirror_flags
, data
->pfsd
.label
);
823 if (data
->pfsd
.snapshots
[0])
824 printf(" snapshots=\"%s\"", data
->pfsd
.snapshots
);
828 case HAMMER_RECTYPE_SNAPSHOT
:
829 printf("\n%s%17s", INDENT
, "");
830 printf("snapshot tid=%016jx label=\"%s\"",
831 (intmax_t)data
->snap
.tid
, data
->snap
.label
);
833 case HAMMER_RECTYPE_CONFIG
:
834 if (VerboseOpt
> 2) {
835 char *p
= strdup(data
->config
.text
);
840 case HAMMER_RECTYPE_DATA
:
841 if (VerboseOpt
> 3) {
843 hexdump_record(data
, data_len
, "\t\t ");
846 case HAMMER_RECTYPE_EXT
:
847 case HAMMER_RECTYPE_DB
:
848 if (VerboseOpt
> 2) {
850 hexdump_record(data
, data_len
, "\t\t ");
857 rel_buffer(data_buffer
);
861 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
862 * which is 16KB. Passing record data length larger than 16KB to
863 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
866 hexdump_record(const void *ptr
, int length
, const char *hdr
)
868 int data_len
= length
;
870 if (data_len
> HAMMER_BUFSIZE
) /* XXX */
871 data_len
= HAMMER_BUFSIZE
;
872 hexdump(ptr
, data_len
, hdr
, 0);
874 if (length
> data_len
)
875 printf("%s....\n", hdr
);
878 static __inline __always_inline
880 _strtoul(const char *p
, int base
)
882 unsigned long retval
;
884 errno
= 0; /* clear */
885 retval
= strtoul(p
, NULL
, base
);
886 if (errno
== ERANGE
&& retval
== ULONG_MAX
)
891 static __inline __always_inline
893 _strtoull(const char *p
, int base
)
895 unsigned long long retval
;
897 errno
= 0; /* clear */
898 retval
= strtoull(p
, NULL
, base
);
899 if (errno
== ERANGE
&& retval
== ULLONG_MAX
)
905 init_btree_search(const char *arg
)
910 bzero(&opt
.base
, sizeof(opt
.base
));
915 if (strcmp(arg
, "none") == 0)
922 while ((p
= s
) != NULL
) {
923 if ((s
= strchr(s
, ':')) != NULL
)
926 opt
.base
.localization
= _strtoul(p
, 16);
928 opt
.base
.obj_id
= _strtoull(p
, 16);
930 opt
.base
.rec_type
= _strtoul(p
, 16);
932 opt
.base
.key
= _strtoull(p
, 16);
934 opt
.base
.create_tid
= _strtoull(p
, 16);
945 test_btree_search(hammer_btree_elm_t elm
)
947 hammer_base_elm_t base1
= &elm
->base
;
948 hammer_base_elm_t base2
= &opt
.base
;
949 int limit
= opt
.limit
;
951 if (base1
->localization
< base2
->localization
)
953 if (base1
->localization
> base2
->localization
)
956 return(0); /* ignore below */
958 if (base1
->obj_id
< base2
->obj_id
)
960 if (base1
->obj_id
> base2
->obj_id
)
963 return(0); /* ignore below */
965 if (base1
->rec_type
< base2
->rec_type
)
967 if (base1
->rec_type
> base2
->rec_type
)
970 return(0); /* ignore below */
972 if (base1
->key
< base2
->key
)
974 if (base1
->key
> base2
->key
)
977 return(0); /* ignore below */
979 if (base1
->create_tid
== 0) {
980 if (base2
->create_tid
== 0)
984 if (base2
->create_tid
== 0)
986 if (base1
->create_tid
< base2
->create_tid
)
988 if (base1
->create_tid
> base2
->create_tid
)
995 test_btree_match(hammer_btree_elm_t elm
)
997 if (test_btree_search(elm
) == 0)
1004 test_btree_out_of_range(hammer_btree_elm_t elm
)
1006 if (test_btree_search(elm
) > 0)
1007 return(1); /* conditions < this elm */
1009 if (opt
.limit
>= 5) {
1010 if (test_btree_search(elm
+ 1) <= 0)
1011 return(1); /* next elm <= conditions */
1013 if (test_btree_search(elm
+ 1) < 0)
1014 return(1); /* next elm < conditions */
1020 * Dump the UNDO FIFO
1023 hammer_cmd_show_undo(void)
1025 struct volume_info
*volume
;
1026 hammer_blockmap_t rootmap
;
1027 hammer_off_t scan_offset
;
1028 hammer_fifo_any_t head
;
1029 hammer_fifo_head_t hdr
;
1030 struct buffer_info
*data_buffer
= NULL
;
1031 struct zone_stat
*stats
= NULL
;
1033 volume
= get_root_volume();
1034 rootmap
= &volume
->ondisk
->vol0_blockmap
[HAMMER_ZONE_UNDO_INDEX
];
1036 print_blockmap(volume
);
1039 stats
= hammer_init_zone_stat_bits();
1041 scan_offset
= HAMMER_ENCODE_UNDO(0);
1042 while (scan_offset
< rootmap
->alloc_offset
) {
1043 head
= get_buffer_data(scan_offset
, &data_buffer
, 0);
1045 printf("%016jx ", scan_offset
);
1047 switch(hdr
->hdr_type
) {
1048 case HAMMER_HEAD_TYPE_PAD
:
1049 printf("PAD(%d)", hdr
->hdr_size
);
1051 case HAMMER_HEAD_TYPE_DUMMY
:
1052 printf("DUMMY(%d)\tseq=%08x",
1053 hdr
->hdr_size
, hdr
->hdr_seq
);
1055 case HAMMER_HEAD_TYPE_UNDO
:
1056 printf("UNDO(%d)\tseq=%08x offset=%016jx bytes=%d",
1057 hdr
->hdr_size
, hdr
->hdr_seq
,
1058 (intmax_t)head
->undo
.undo_offset
,
1059 head
->undo
.undo_data_bytes
);
1061 case HAMMER_HEAD_TYPE_REDO
:
1062 printf("REDO(%d)\tseq=%08x offset=%016jx bytes=%d "
1063 "objid=%016jx flags=%08x lo=%08x",
1064 hdr
->hdr_size
, hdr
->hdr_seq
,
1065 (intmax_t)head
->redo
.redo_offset
,
1066 head
->redo
.redo_data_bytes
,
1067 (intmax_t)head
->redo
.redo_objid
,
1068 head
->redo
.redo_flags
,
1069 head
->redo
.redo_localization
);
1072 printf("%04x(%d)\tseq=%08x",
1073 hdr
->hdr_type
, hdr
->hdr_size
, hdr
->hdr_seq
);
1077 if (scan_offset
== rootmap
->first_offset
)
1079 if (scan_offset
== rootmap
->next_offset
)
1084 hammer_add_zone_stat(stats
, scan_offset
, hdr
->hdr_size
);
1086 if ((hdr
->hdr_size
& HAMMER_HEAD_ALIGN_MASK
) ||
1087 hdr
->hdr_size
== 0 ||
1088 hdr
->hdr_size
> HAMMER_UNDO_ALIGN
-
1089 ((u_int
)scan_offset
& HAMMER_UNDO_MASK
)) {
1090 printf("Illegal size field, skipping to "
1092 scan_offset
= HAMMER_UNDO_DOALIGN(scan_offset
);
1094 scan_offset
+= hdr
->hdr_size
;
1097 rel_buffer(data_buffer
);
1100 hammer_print_zone_stat(stats
);
1101 hammer_cleanup_zone_stat(stats
);