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
,
57 hammer_tid_t mirror_tid
,
58 hammer_base_elm_t left_bound
,
59 hammer_base_elm_t right_bound
);
60 static int test_node_count(hammer_node_ondisk_t node
, char *badmp
);
61 static void print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
62 hammer_btree_elm_t elm
,
63 hammer_base_elm_t left_bound
,
64 hammer_base_elm_t right_bound
,
66 static int get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
67 hammer_btree_elm_t elm
,
68 hammer_base_elm_t left_bound
,
69 hammer_base_elm_t right_bound
);
70 static int test_lr(hammer_btree_elm_t elm
,
71 hammer_base_elm_t left_bound
,
72 hammer_base_elm_t right_bound
);
73 static int test_rbn_lr(hammer_btree_elm_t elm
,
74 hammer_base_elm_t left_bound
,
75 hammer_base_elm_t right_bound
);
76 static void print_bigblock_fill(hammer_off_t offset
);
77 static const char *check_data_crc(hammer_btree_elm_t elm
);
78 static uint32_t get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
);
79 static void print_record(hammer_btree_elm_t elm
);
80 static int init_btree_search(const char *arg
);
81 static int test_btree_search(hammer_btree_elm_t elm
);
82 static int test_btree_match(hammer_btree_elm_t elm
);
83 static int test_btree_out_of_range(hammer_btree_elm_t elm
);
84 static void hexdump_record(const void *ptr
, int length
, const char *hdr
);
86 static int num_bad_node
= 0;
87 static int num_bad_elm
= 0;
88 static int num_bad_rec
= 0;
92 static const char* _indents
[] = {
100 _X _X _X _X _X _X _X
,
101 _X _X _X _X _X _X _X _X
,
102 _X _X _X _X _X _X _X _X _X
,
103 _X _X _X _X _X _X _X _X _X _X
,
104 _X _X _X _X _X _X _X _X _X _X _X
,
105 _X _X _X _X _X _X _X _X _X _X _X _X
,
106 _X _X _X _X _X _X _X _X _X _X _X _X _X
,
107 _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
108 _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
109 _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
112 #define INDENT _indents[opt.indent ? depth : 0]
115 hammer_cmd_show(const char *arg
, int filter
, int obfuscate
, int indent
)
117 struct volume_info
*volume
;
118 struct hammer_volume_ondisk
*ondisk
;
119 struct hammer_blockmap
*blockmap
;
120 struct zone_stat
*stats
= NULL
;
123 AssertOnFailure
= (DebugOpt
!= 0);
126 stats
= hammer_init_zone_stat_bits();
128 volume
= get_root_volume();
129 ondisk
= volume
->ondisk
;
131 printf("Volume header\tnext_tid=%016jx\n",
132 (uintmax_t)ondisk
->vol0_next_tid
);
133 printf("\t\tbufoffset=%016jx\n",
134 (uintmax_t)ondisk
->vol_buf_beg
);
135 for (zone
= 0; zone
< HAMMER_MAX_ZONES
; ++zone
) {
136 blockmap
= ondisk
->vol0_blockmap
+ zone
;
137 printf("\t\tzone %d\tnext_offset=%016jx\n",
138 zone
, blockmap
->next_offset
);
142 bzero(&opt
, sizeof(opt
));
144 opt
.obfuscate
= obfuscate
;
148 if (init_btree_search(arg
) > 0) {
149 printf("arg=\"%s\"", arg
);
151 printf(" lo=%08x", opt
.base
.localization
);
153 printf(" obj=%016jx", (uintmax_t)opt
.base
.obj_id
);
155 printf(" rt=%02x", opt
.base
.rec_type
);
157 printf(" key=%016jx", (uintmax_t)opt
.base
.key
);
159 printf(" tid=%016jx", (uintmax_t)opt
.base
.create_tid
);
162 print_btree(ondisk
->vol0_btree_root
);
165 hammer_print_zone_stat(stats
);
166 hammer_cleanup_zone_stat(stats
);
169 if (num_bad_node
|| VerboseOpt
) {
170 printf("%d bad nodes\n", num_bad_node
);
172 if (num_bad_elm
|| VerboseOpt
) {
173 printf("%d bad elms\n", num_bad_elm
);
175 if (num_bad_rec
|| VerboseOpt
) {
176 printf("%d bad records\n", num_bad_rec
);
182 print_btree(hammer_off_t node_offset
)
185 print_btree_node(node_offset
, HAMMER_MAX_TID
, NULL
, NULL
);
191 print_subtree(hammer_btree_elm_t elm
)
193 print_btree_node(elm
->internal
.subtree_offset
,
194 elm
->internal
.mirror_tid
, &elm
[0].base
, &elm
[1].base
);
198 print_btree_node(hammer_off_t node_offset
,
199 hammer_tid_t mirror_tid
,
200 hammer_base_elm_t left_bound
, hammer_base_elm_t right_bound
)
202 struct buffer_info
*buffer
= NULL
;
203 hammer_node_ondisk_t node
;
204 hammer_btree_elm_t elm
;
206 char badc
= ' '; /* good */
207 char badm
= ' '; /* good */
211 node
= get_node(node_offset
, &buffer
);
217 if (crc32(&node
->crc
+ 1, HAMMER_BTREE_CRCSIZE
) != node
->crc
)
219 if (node
->mirror_tid
> mirror_tid
) {
223 if (test_node_count(node
, &badm
) == -1) {
229 if (badm
!= ' ' || badc
!= ' ') /* not good */
232 printf("%s%c%c NODE %016jx ",
233 INDENT
, badc
, badm
, (uintmax_t)node_offset
);
234 printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx",
236 (uintmax_t)node
->parent
,
237 (node
->type
? node
->type
: '?'),
239 (uintmax_t)node
->mirror_tid
);
242 print_bigblock_fill(node_offset
);
247 hammer_add_zone_stat(opt
.stats
, node_offset
, sizeof(*node
));
249 for (i
= 0; i
< node
->count
; ++i
) {
250 elm
= &node
->elms
[i
];
253 switch (node
->type
) {
254 case HAMMER_BTREE_TYPE_INTERNAL
:
255 if (!test_btree_out_of_range(elm
))
258 case HAMMER_BTREE_TYPE_LEAF
:
259 if (test_btree_match(elm
))
264 print_btree_elm(node
, node_offset
,
265 elm
, left_bound
, right_bound
, ext
);
267 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
268 assert(i
== node
->count
); /* boundary */
269 elm
= &node
->elms
[i
];
270 print_btree_elm(node
, node_offset
,
271 elm
, left_bound
, right_bound
, NULL
);
273 printf("%s }\n", INDENT
);
275 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
276 for (i
= 0; i
< node
->count
; ++i
) {
277 elm
= &node
->elms
[i
];
278 if (opt
.limit
&& opt
.filter
) {
279 if (test_btree_out_of_range(elm
))
282 if (elm
->internal
.subtree_offset
) {
285 * Cause show to do normal iteration after
286 * seeking to the lo:objid:rectype:key:tid
289 if (opt
.limit
&& opt
.filter
== -1) /* default */
299 test_node_count(hammer_node_ondisk_t node
, char *badmp
)
301 hammer_node_ondisk_t parent_node
;
302 struct buffer_info
*buffer
= NULL
;
305 maxcount
= hammer_node_max_elements(node
->type
);
307 if (maxcount
== -1) {
310 } else if (node
->count
> maxcount
) {
313 } else if (node
->count
== 0) {
314 parent_node
= get_node(node
->parent
, &buffer
);
315 if (parent_node
->count
!= 1) {
328 is_root_btree_beg(uint8_t type
, int i
, hammer_btree_elm_t elm
)
331 * elm->base.btype depends on what the original node had
332 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
334 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
336 elm
->base
.localization
== 0 &&
337 elm
->base
.obj_id
== (int64_t)-0x8000000000000000LL
&&
338 elm
->base
.key
== (int64_t)-0x8000000000000000LL
&&
339 elm
->base
.create_tid
== 1 &&
340 elm
->base
.delete_tid
== 1 &&
341 elm
->base
.rec_type
== 0 &&
342 elm
->base
.obj_type
== 0 &&
343 elm
->base
.btype
!= HAMMER_BTREE_TYPE_NONE
);
348 is_root_btree_end(uint8_t type
, int i
, hammer_btree_elm_t elm
)
350 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
352 elm
->base
.localization
== 0xFFFFFFFFU
&&
353 elm
->base
.obj_id
== 0x7FFFFFFFFFFFFFFFLL
&&
354 elm
->base
.key
== 0x7FFFFFFFFFFFFFFFLL
&&
355 elm
->base
.create_tid
== 0xFFFFFFFFFFFFFFFFULL
&&
356 elm
->base
.delete_tid
== 0 &&
357 elm
->base
.rec_type
== 0xFFFFU
&&
358 elm
->base
.obj_type
== 0 &&
359 elm
->base
.btype
== HAMMER_BTREE_TYPE_NONE
);
364 print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
365 hammer_btree_elm_t elm
,
366 hammer_base_elm_t left_bound
,
367 hammer_base_elm_t right_bound
,
370 char flagstr
[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
375 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
377 flags
= get_elm_flags(node
, node_offset
, elm
, left_bound
, right_bound
);
378 flagstr
[0] = flags
? 'B' : 'G';
379 if (flags
& FLAG_TOOFARLEFT
)
381 if (flags
& FLAG_TOOFARRIGHT
)
383 if (flags
& FLAG_BADTYPE
)
385 if (flags
& FLAG_BADCHILDPARENT
)
387 if (flags
& FLAG_BADMIRRORTID
)
389 if (flagstr
[0] == 'B')
393 * Check if elm is derived from root split
395 if (is_root_btree_beg(node
->type
, i
, elm
))
397 else if (is_root_btree_end(node
->type
, i
, elm
))
402 if (elm
->base
.delete_tid
)
407 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
&& node
->count
== i
)
412 printf("%s%s %s %2d %c ",
413 INDENT
, flagstr
, label
, i
, hammer_elm_btype(elm
));
414 printf("lo=%08x obj=%016jx rt=%02x key=%016jx tid=%016jx\n",
415 elm
->base
.localization
,
416 (uintmax_t)elm
->base
.obj_id
,
418 (uintmax_t)elm
->base
.key
,
419 (uintmax_t)elm
->base
.create_tid
);
420 printf("%s %c del=%016jx ot=%02x",
422 (rootelm
== ' ' ? deleted
: rootelm
),
423 (uintmax_t)elm
->base
.delete_tid
,
427 case HAMMER_BTREE_TYPE_INTERNAL
:
428 printf(" suboff=%016jx",
429 (uintmax_t)elm
->internal
.subtree_offset
);
431 printf(" mirror=%016jx",
432 (uintmax_t)elm
->internal
.mirror_tid
);
437 case HAMMER_BTREE_TYPE_LEAF
:
438 switch(elm
->base
.btype
) {
439 case HAMMER_BTREE_TYPE_RECORD
:
440 printf(" dataoff=%016jx/%d",
441 (uintmax_t)elm
->leaf
.data_offset
,
444 const char *p
= check_data_crc(elm
);
445 printf(" crc=%08x", elm
->leaf
.data_crc
);
447 printf(" error=%s", p
);
451 print_bigblock_fill(elm
->leaf
.data_offset
);
456 hammer_add_zone_stat(opt
.stats
,
457 elm
->leaf
.data_offset
,
461 printf(" badtype=%d", elm
->base
.btype
);
473 get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
474 hammer_btree_elm_t elm
,
475 hammer_base_elm_t left_bound
,
476 hammer_base_elm_t right_bound
)
478 hammer_off_t child_offset
;
480 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
483 case HAMMER_BTREE_TYPE_INTERNAL
:
484 child_offset
= elm
->internal
.subtree_offset
;
485 if (elm
->internal
.mirror_tid
> node
->mirror_tid
)
486 flags
|= FLAG_BADMIRRORTID
;
488 if (i
== node
->count
) {
489 if (child_offset
!= 0)
490 flags
|= FLAG_BADCHILDPARENT
;
491 switch(elm
->base
.btype
) {
492 case HAMMER_BTREE_TYPE_NONE
:
493 flags
|= test_rbn_lr(elm
, left_bound
, right_bound
);
496 flags
|= FLAG_BADTYPE
;
500 if (child_offset
== 0) {
501 flags
|= FLAG_BADCHILDPARENT
;
503 struct buffer_info
*buffer
= NULL
;
504 hammer_node_ondisk_t subnode
;
505 subnode
= get_node(child_offset
, &buffer
);
507 flags
|= FLAG_BADCHILDPARENT
;
508 else if (subnode
->parent
!= node_offset
)
509 flags
|= FLAG_BADCHILDPARENT
;
512 switch(elm
->base
.btype
) {
513 case HAMMER_BTREE_TYPE_INTERNAL
:
514 case HAMMER_BTREE_TYPE_LEAF
:
515 flags
|= test_lr(elm
, left_bound
, right_bound
);
518 flags
|= FLAG_BADTYPE
;
523 case HAMMER_BTREE_TYPE_LEAF
:
524 if (elm
->leaf
.data_offset
== 0) {
525 flags
|= FLAG_BADCHILDPARENT
;
527 if (elm
->leaf
.data_len
== 0) {
528 flags
|= FLAG_BADCHILDPARENT
;
531 if (node
->mirror_tid
== 0 &&
532 !(node
->parent
== 0 && node
->count
== 2)) {
533 flags
|= FLAG_BADMIRRORTID
;
535 if (elm
->base
.create_tid
&& node
->mirror_tid
&&
536 elm
->base
.create_tid
> node
->mirror_tid
) {
537 flags
|= FLAG_BADMIRRORTID
;
539 if (elm
->base
.delete_tid
&& node
->mirror_tid
&&
540 elm
->base
.delete_tid
> node
->mirror_tid
) {
541 flags
|= FLAG_BADMIRRORTID
;
543 switch(elm
->base
.btype
) {
544 case HAMMER_BTREE_TYPE_RECORD
:
545 flags
|= test_lr(elm
, left_bound
, right_bound
);
548 flags
|= FLAG_BADTYPE
;
553 flags
|= FLAG_BADTYPE
;
561 test_lr(hammer_btree_elm_t elm
,
562 hammer_base_elm_t left_bound
, hammer_base_elm_t right_bound
)
564 if (left_bound
== NULL
|| right_bound
== NULL
)
566 if (hammer_btree_cmp(&elm
->base
, left_bound
) < 0)
567 return(FLAG_TOOFARLEFT
);
568 if (hammer_btree_cmp(&elm
->base
, right_bound
) >= 0)
569 return(FLAG_TOOFARRIGHT
);
575 test_rbn_lr(hammer_btree_elm_t rbn
,
576 hammer_base_elm_t left_bound
, hammer_base_elm_t right_bound
)
578 if (left_bound
== NULL
|| right_bound
== NULL
)
580 if (hammer_btree_cmp(&rbn
->base
, left_bound
) < 0)
581 return(FLAG_TOOFARLEFT
);
582 if (hammer_btree_cmp(&rbn
->base
, right_bound
) > 0)
583 return(FLAG_TOOFARRIGHT
);
589 print_bigblock_fill(hammer_off_t offset
)
591 struct hammer_blockmap_layer1 layer1
;
592 struct hammer_blockmap_layer2 layer2
;
596 blockmap_lookup(offset
, &layer1
, &layer2
, &error
);
597 printf("z%d:v%d:%d:%d:%lu=",
598 HAMMER_ZONE_DECODE(offset
),
599 HAMMER_VOL_DECODE(offset
),
600 HAMMER_BLOCKMAP_LAYER1_INDEX(offset
),
601 HAMMER_BLOCKMAP_LAYER2_INDEX(offset
),
602 offset
& HAMMER_BIGBLOCK_MASK64
);
605 printf("B%d", error
);
607 fill
= layer2
.bytes_free
* 100 / HAMMER_BIGBLOCK_SIZE
;
609 printf("%d%%", fill
);
614 * Check the generic crc on a data element. Inodes record types are
615 * special in that some of their fields are not CRCed.
617 * Also check that the zone is valid.
621 check_data_crc(hammer_btree_elm_t elm
)
623 struct buffer_info
*data_buffer
;
624 hammer_off_t data_offset
;
625 hammer_off_t buf_offset
;
632 data_offset
= elm
->leaf
.data_offset
;
633 data_len
= elm
->leaf
.data_len
;
635 if (data_offset
== 0 || data_len
== 0)
636 return("ZO"); /* zero offset or length */
639 buf_offset
= blockmap_lookup(data_offset
, NULL
, NULL
, &error
);
641 bzero(bo
, sizeof(bo
));
642 snprintf(bo
, sizeof(bo
), "BO%d", -error
);
647 switch (elm
->leaf
.base
.rec_type
) {
648 case HAMMER_RECTYPE_INODE
:
649 /* this should always match */
650 if (data_len
== sizeof(struct hammer_inode_data
)) {
651 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
652 crc
= crc32(ptr
, HAMMER_INODE_CRCSIZE
);
653 rel_buffer(data_buffer
);
657 crc
= get_buf_crc(buf_offset
, data_len
);
662 return("Bx"); /* bad crc */
663 if (crc
!= elm
->leaf
.data_crc
)
664 return("BX"); /* bad crc */
665 return(NULL
); /* success */
670 get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
)
672 struct buffer_info
*data_buffer
= NULL
;
678 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
679 len
= HAMMER_BUFSIZE
- ((int)buf_offset
& HAMMER_BUFMASK
);
682 assert(len
<= HAMMER_BUFSIZE
);
683 crc
= crc32_ext(ptr
, len
, crc
);
687 rel_buffer(data_buffer
);
694 print_config(char *cfgtxt
)
698 printf("\n%s%17s", INDENT
, "");
699 printf("config text=\"\n");
700 if (cfgtxt
!= NULL
) {
701 while((token
= strsep(&cfgtxt
, "\r\n")) != NULL
)
703 printf("%s%17s %s\n",
706 printf("%s%17s \"", INDENT
, "");
711 print_record(hammer_btree_elm_t elm
)
713 struct buffer_info
*data_buffer
;
714 hammer_off_t data_offset
;
716 hammer_data_ondisk_t data
;
721 data_offset
= elm
->leaf
.data_offset
;
722 data_len
= elm
->leaf
.data_len
;
723 assert(data_offset
!= 0);
724 assert(data_len
!= 0);
727 data
= get_buffer_data(data_offset
, &data_buffer
, 0);
728 assert(data
!= NULL
);
730 switch(elm
->leaf
.base
.rec_type
) {
731 case HAMMER_RECTYPE_UNKNOWN
:
732 printf("\n%s%17s", INDENT
, "");
735 case HAMMER_RECTYPE_INODE
:
736 printf("\n%s%17s", INDENT
, "");
737 printf("inode size=%jd nlinks=%jd",
738 (intmax_t)data
->inode
.size
,
739 (intmax_t)data
->inode
.nlinks
);
741 printf(" mode=%05o uflags=%08x caps=%02x",
744 data
->inode
.cap_flags
);
745 printf(" pobjid=%016jx ot=%02x\n",
746 (uintmax_t)data
->inode
.parent_obj_id
,
747 data
->inode
.obj_type
);
748 printf("%s%17s", INDENT
, "");
749 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
750 (uintmax_t)data
->inode
.ctime
,
751 (uintmax_t)data
->inode
.mtime
,
752 (uintmax_t)data
->inode
.atime
);
753 if (data
->inode
.ext
.symlink
[0])
754 printf(" symlink=\"%s\"",
755 data
->inode
.ext
.symlink
);
758 case HAMMER_RECTYPE_DIRENTRY
:
759 data_len
-= HAMMER_ENTRY_NAME_OFF
;
760 printf("\n%s%17s", INDENT
, "");
761 printf("dir-entry ino=%016jx lo=%08x",
762 (uintmax_t)data
->entry
.obj_id
,
763 data
->entry
.localization
);
765 printf(" name=\"%*.*s\"",
766 data_len
, data_len
, data
->entry
.name
);
768 case HAMMER_RECTYPE_FIX
:
769 switch(elm
->leaf
.base
.key
) {
770 case HAMMER_FIXKEY_SYMLINK
:
771 data_len
-= HAMMER_SYMLINK_NAME_OFF
;
772 printf("\n%s%17s", INDENT
, "");
773 printf("fix-symlink name=\"%*.*s\"",
774 data_len
, data_len
, data
->symlink
.name
);
778 case HAMMER_RECTYPE_PFS
:
779 printf("\n%s%17s", INDENT
, "");
780 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
781 (intmax_t)data
->pfsd
.sync_beg_tid
,
782 (intmax_t)data
->pfsd
.sync_end_tid
);
783 uuid_to_string(&data
->pfsd
.shared_uuid
, &str1
, &status
);
784 uuid_to_string(&data
->pfsd
.unique_uuid
, &str2
, &status
);
786 printf(" shared_uuid=%s\n", str1
);
788 printf(" unique_uuid=%s\n", str2
);
790 printf(" mirror_flags=%08x label=\"%s\"",
791 data
->pfsd
.mirror_flags
, data
->pfsd
.label
);
792 if (data
->pfsd
.snapshots
[0])
793 printf(" snapshots=\"%s\"", data
->pfsd
.snapshots
);
797 case HAMMER_RECTYPE_SNAPSHOT
:
798 printf("\n%s%17s", INDENT
, "");
799 printf("snapshot tid=%016jx label=\"%s\"",
800 (intmax_t)data
->snap
.tid
, data
->snap
.label
);
802 case HAMMER_RECTYPE_CONFIG
:
803 if (VerboseOpt
> 2) {
804 char *p
= strdup(data
->config
.text
);
809 case HAMMER_RECTYPE_DATA
:
810 if (VerboseOpt
> 3) {
812 hexdump_record(data
, data_len
, "\t\t ");
815 case HAMMER_RECTYPE_EXT
:
816 case HAMMER_RECTYPE_DB
:
817 if (VerboseOpt
> 2) {
819 hexdump_record(data
, data_len
, "\t\t ");
826 rel_buffer(data_buffer
);
830 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
831 * which is 16KB. Passing record data length larger than 16KB to
832 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
835 hexdump_record(const void *ptr
, int length
, const char *hdr
)
837 int data_len
= length
;
839 if (data_len
> HAMMER_BUFSIZE
) /* XXX */
840 data_len
= HAMMER_BUFSIZE
;
841 hexdump(ptr
, data_len
, hdr
, 0);
843 if (length
> data_len
)
844 printf("%s....\n", hdr
);
849 _strtoul(const char *p
, int base
)
851 unsigned long retval
;
853 errno
= 0; /* clear */
854 retval
= strtoul(p
, NULL
, base
);
855 if (errno
== ERANGE
&& retval
== ULONG_MAX
)
862 _strtoull(const char *p
, int base
)
864 unsigned long long retval
;
866 errno
= 0; /* clear */
867 retval
= strtoull(p
, NULL
, base
);
868 if (errno
== ERANGE
&& retval
== ULLONG_MAX
)
874 init_btree_search(const char *arg
)
879 bzero(&opt
.base
, sizeof(opt
.base
));
884 if (strcmp(arg
, "none") == 0)
891 while ((p
= s
) != NULL
) {
892 if ((s
= strchr(s
, ':')) != NULL
)
895 opt
.base
.localization
= _strtoul(p
, 16);
897 opt
.base
.obj_id
= _strtoull(p
, 16);
899 opt
.base
.rec_type
= _strtoul(p
, 16);
901 opt
.base
.key
= _strtoull(p
, 16);
903 opt
.base
.create_tid
= _strtoull(p
, 16);
914 test_btree_search(hammer_btree_elm_t elm
)
916 hammer_base_elm_t base1
= &elm
->base
;
917 hammer_base_elm_t base2
= &opt
.base
;
918 int limit
= opt
.limit
;
920 if (base1
->localization
< base2
->localization
)
922 if (base1
->localization
> base2
->localization
)
925 return(0); /* ignore below */
927 if (base1
->obj_id
< base2
->obj_id
)
929 if (base1
->obj_id
> base2
->obj_id
)
932 return(0); /* ignore below */
934 if (base1
->rec_type
< base2
->rec_type
)
936 if (base1
->rec_type
> base2
->rec_type
)
939 return(0); /* ignore below */
941 if (base1
->key
< base2
->key
)
943 if (base1
->key
> base2
->key
)
946 return(0); /* ignore below */
948 if (base1
->create_tid
== 0) {
949 if (base2
->create_tid
== 0)
953 if (base2
->create_tid
== 0)
955 if (base1
->create_tid
< base2
->create_tid
)
957 if (base1
->create_tid
> base2
->create_tid
)
964 test_btree_match(hammer_btree_elm_t elm
)
966 if (test_btree_search(elm
) == 0)
973 test_btree_out_of_range(hammer_btree_elm_t elm
)
975 if (test_btree_search(elm
) > 0)
976 return(1); /* conditions < this elm */
978 if (opt
.limit
>= 5) {
979 if (test_btree_search(elm
+ 1) <= 0)
980 return(1); /* next elm <= conditions */
982 if (test_btree_search(elm
+ 1) < 0)
983 return(1); /* next elm < conditions */
992 hammer_cmd_show_undo(void)
994 struct volume_info
*volume
;
995 hammer_blockmap_t rootmap
;
996 hammer_off_t scan_offset
;
997 hammer_fifo_any_t head
;
998 struct buffer_info
*data_buffer
= NULL
;
1001 volume
= get_root_volume();
1002 rootmap
= &volume
->ondisk
->vol0_blockmap
[HAMMER_ZONE_UNDO_INDEX
];
1003 if (rootmap
->first_offset
<= rootmap
->next_offset
)
1004 bytes
= rootmap
->next_offset
- rootmap
->first_offset
;
1006 bytes
= rootmap
->alloc_offset
- rootmap
->first_offset
+
1007 (rootmap
->next_offset
& HAMMER_OFF_LONG_MASK
);
1009 printf("Volume header UNDO %016jx-%016jx/%016jx\n",
1010 (intmax_t)rootmap
->first_offset
,
1011 (intmax_t)rootmap
->next_offset
,
1012 (intmax_t)rootmap
->alloc_offset
);
1013 printf("UNDO map is %jdMB\n",
1014 (intmax_t)((rootmap
->alloc_offset
& HAMMER_OFF_LONG_MASK
) /
1016 printf("UNDO being used is %jdB\n", (intmax_t)bytes
);
1018 scan_offset
= HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX
, 0);
1019 while (scan_offset
< rootmap
->alloc_offset
) {
1020 head
= get_buffer_data(scan_offset
, &data_buffer
, 0);
1021 printf("%016jx ", scan_offset
);
1023 switch(head
->head
.hdr_type
) {
1024 case HAMMER_HEAD_TYPE_PAD
:
1025 printf("PAD(%04x)", head
->head
.hdr_size
);
1027 case HAMMER_HEAD_TYPE_DUMMY
:
1028 printf("DUMMY(%04x) seq=%08x",
1029 head
->head
.hdr_size
, head
->head
.hdr_seq
);
1031 case HAMMER_HEAD_TYPE_UNDO
:
1032 printf("UNDO(%04x) seq=%08x "
1033 "dataoff=%016jx bytes=%d",
1034 head
->head
.hdr_size
, head
->head
.hdr_seq
,
1035 (intmax_t)head
->undo
.undo_offset
,
1036 head
->undo
.undo_data_bytes
);
1038 case HAMMER_HEAD_TYPE_REDO
:
1039 printf("REDO(%04x) seq=%08x flags=%08x "
1040 "objid=%016jx logoff=%016jx bytes=%d",
1041 head
->head
.hdr_size
, head
->head
.hdr_seq
,
1042 head
->redo
.redo_flags
,
1043 (intmax_t)head
->redo
.redo_objid
,
1044 (intmax_t)head
->redo
.redo_offset
,
1045 head
->redo
.redo_data_bytes
);
1048 printf("UNKNOWN(%04x,%04x) seq=%08x",
1049 head
->head
.hdr_type
,
1050 head
->head
.hdr_size
,
1051 head
->head
.hdr_seq
);
1055 if (scan_offset
== rootmap
->first_offset
)
1057 if (scan_offset
== rootmap
->next_offset
)
1061 if ((head
->head
.hdr_size
& HAMMER_HEAD_ALIGN_MASK
) ||
1062 head
->head
.hdr_size
== 0 ||
1063 head
->head
.hdr_size
> HAMMER_UNDO_ALIGN
-
1064 ((u_int
)scan_offset
& HAMMER_UNDO_MASK
)) {
1065 printf("Illegal size field, skipping to "
1067 scan_offset
= (scan_offset
+ HAMMER_UNDO_MASK
) &
1068 ~HAMMER_UNDO_MASK64
;
1070 scan_offset
+= head
->head
.hdr_size
;
1073 rel_buffer(data_buffer
);