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
);
67 static uint32_t get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
);
68 static void print_record(hammer_btree_elm_t elm
);
69 static int init_btree_search(const char *arg
);
70 static int test_btree_search(hammer_btree_elm_t elm
);
71 static int test_btree_match(hammer_btree_elm_t elm
);
72 static int test_btree_out_of_range(hammer_btree_elm_t elm
);
73 static void hexdump_record(const void *ptr
, int length
, const char *hdr
);
75 static int num_bad_node
= 0;
76 static int num_bad_elm
= 0;
77 static int num_bad_rec
= 0;
81 static const char* _indents
[] = {
90 _X _X _X _X _X _X _X _X
,
91 _X _X _X _X _X _X _X _X _X
,
92 _X _X _X _X _X _X _X _X _X _X
,
93 _X _X _X _X _X _X _X _X _X _X _X
,
94 _X _X _X _X _X _X _X _X _X _X _X _X
,
95 _X _X _X _X _X _X _X _X _X _X _X _X _X
,
96 _X _X _X _X _X _X _X _X _X _X _X _X _X _X
,
97 _X _X _X _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 _X _X _X
,
101 #define INDENT _indents[opt.indent ? depth : 0]
104 hammer_cmd_show(const char *arg
, int filter
, int obfuscate
, int indent
)
106 struct volume_info
*volume
;
107 hammer_volume_ondisk_t ondisk
;
108 struct zone_stat
*stats
= NULL
;
110 volume
= get_root_volume();
111 ondisk
= volume
->ondisk
;
113 print_blockmap(volume
);
116 stats
= hammer_init_zone_stat_bits();
118 bzero(&opt
, sizeof(opt
));
120 opt
.obfuscate
= obfuscate
;
124 if (init_btree_search(arg
) > 0) {
125 printf("arg=\"%s\"", arg
);
127 printf(" lo=%08x", opt
.base
.localization
);
129 printf(" objid=%016jx", (uintmax_t)opt
.base
.obj_id
);
131 printf(" rt=%02x", opt
.base
.rec_type
);
133 printf(" key=%016jx", (uintmax_t)opt
.base
.key
);
135 printf(" tid=%016jx", (uintmax_t)opt
.base
.create_tid
);
138 print_btree(ondisk
->vol0_btree_root
);
141 hammer_print_zone_stat(stats
);
142 hammer_cleanup_zone_stat(stats
);
145 if (num_bad_node
|| VerboseOpt
) {
146 printf("%d bad nodes\n", num_bad_node
);
148 if (num_bad_elm
|| VerboseOpt
) {
149 printf("%d bad elms\n", num_bad_elm
);
151 if (num_bad_rec
|| VerboseOpt
) {
152 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(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
))
237 print_btree_elm(node
, node_offset
, elm
, lbe
, ext
);
239 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
240 assert(i
== node
->count
); /* boundary */
241 elm
= &node
->elms
[i
];
242 print_btree_elm(node
, node_offset
, elm
, lbe
, NULL
);
244 printf("%s }\n", INDENT
);
246 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
) {
247 for (i
= 0; i
< node
->count
; ++i
) {
248 elm
= &node
->elms
[i
];
249 if (opt
.limit
&& opt
.filter
) {
250 if (test_btree_out_of_range(elm
))
253 if (elm
->internal
.subtree_offset
) {
256 * Cause show to do normal iteration after
257 * seeking to the lo:objid:rt:key:tid
260 if (opt
.limit
&& opt
.filter
== -1) /* default */
270 test_node_count(hammer_node_ondisk_t node
, char *badmp
)
272 hammer_node_ondisk_t parent_node
;
273 struct buffer_info
*buffer
= NULL
;
276 maxcount
= hammer_node_max_elements(node
->type
);
278 if (maxcount
== -1) {
281 } else if (node
->count
> maxcount
) {
284 } else if (node
->count
== 0) {
285 parent_node
= get_buffer_data(node
->parent
, &buffer
, 0);
286 if (parent_node
->count
!= 1) {
299 is_root_btree_beg(uint8_t type
, int i
, hammer_btree_elm_t elm
)
302 * elm->base.btype depends on what the original node had
303 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
305 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
307 elm
->base
.localization
== HAMMER_MIN_ONDISK_LOCALIZATION
&&
308 elm
->base
.obj_id
== (int64_t)HAMMER_MIN_OBJID
&&
309 elm
->base
.key
== (int64_t)HAMMER_MIN_KEY
&&
310 elm
->base
.create_tid
== 1 &&
311 elm
->base
.delete_tid
== 1 &&
312 elm
->base
.rec_type
== HAMMER_MIN_RECTYPE
&&
313 elm
->base
.obj_type
== 0 &&
314 elm
->base
.btype
!= HAMMER_BTREE_TYPE_NONE
);
319 is_root_btree_end(uint8_t type
, int i
, hammer_btree_elm_t elm
)
321 return (type
== HAMMER_BTREE_TYPE_INTERNAL
&&
323 elm
->base
.localization
== HAMMER_MAX_ONDISK_LOCALIZATION
&&
324 elm
->base
.obj_id
== HAMMER_MAX_OBJID
&&
325 elm
->base
.key
== HAMMER_MAX_KEY
&&
326 elm
->base
.create_tid
== HAMMER_MAX_TID
&&
327 elm
->base
.delete_tid
== 0 &&
328 elm
->base
.rec_type
== HAMMER_MAX_RECTYPE
&&
329 elm
->base
.obj_type
== 0 &&
330 elm
->base
.btype
== HAMMER_BTREE_TYPE_NONE
);
335 print_btree_elm(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
336 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
, const char *ext
)
338 char flagstr
[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
344 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
346 flags
= get_elm_flags(node
, node_offset
, elm
, lbe
);
347 flagstr
[0] = flags
? 'B' : 'G';
348 if (flags
& FLAG_TOOFARLEFT
)
350 if (flags
& FLAG_TOOFARRIGHT
)
352 if (flags
& FLAG_BADTYPE
)
354 if (flags
& FLAG_BADCHILDPARENT
)
356 if (flags
& FLAG_BADMIRRORTID
)
358 if (flagstr
[0] == 'B')
362 * Check if elm is derived from root split
364 if (is_root_btree_beg(node
->type
, i
, elm
))
366 else if (is_root_btree_end(node
->type
, i
, elm
))
371 if (elm
->base
.delete_tid
)
376 if (node
->type
== HAMMER_BTREE_TYPE_INTERNAL
&& node
->count
== i
)
381 printf("%s%s %s %2d %c ",
382 INDENT
, flagstr
, label
, i
, hammer_elm_btype(elm
));
383 printf("lo=%08x objid=%016jx rt=%02x key=%016jx tid=%016jx\n",
384 elm
->base
.localization
,
385 (uintmax_t)elm
->base
.obj_id
,
387 (uintmax_t)elm
->base
.key
,
388 (uintmax_t)elm
->base
.create_tid
);
389 printf("%s %c del=%016jx ot=%02x",
391 (rootelm
== ' ' ? deleted
: rootelm
),
392 (uintmax_t)elm
->base
.delete_tid
,
396 case HAMMER_BTREE_TYPE_INTERNAL
:
397 printf(" suboff=%016jx mirror=%016jx",
398 (uintmax_t)elm
->internal
.subtree_offset
,
399 (uintmax_t)elm
->internal
.mirror_tid
);
403 case HAMMER_BTREE_TYPE_LEAF
:
404 switch(elm
->base
.btype
) {
405 case HAMMER_BTREE_TYPE_RECORD
:
406 printf(" dataoff=%016jx/%d",
407 (uintmax_t)elm
->leaf
.data_offset
,
409 p
= check_data_crc(elm
);
410 printf(" crc=%08x", elm
->leaf
.data_crc
);
412 printf(" error=%s", p
);
416 print_bigblock_fill(elm
->leaf
.data_offset
);
420 hammer_add_zone_stat(opt
.stats
,
421 elm
->leaf
.data_offset
,
425 printf(" badtype=%d", elm
->base
.btype
);
437 get_elm_flags(hammer_node_ondisk_t node
, hammer_off_t node_offset
,
438 hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
440 hammer_off_t child_offset
;
442 int i
= ((char*)elm
- (char*)node
) / (int)sizeof(*elm
) - 1;
445 case HAMMER_BTREE_TYPE_INTERNAL
:
446 child_offset
= elm
->internal
.subtree_offset
;
447 if (elm
->internal
.mirror_tid
> node
->mirror_tid
)
448 flags
|= FLAG_BADMIRRORTID
;
450 if (i
== node
->count
) {
451 if (child_offset
!= 0)
452 flags
|= FLAG_BADCHILDPARENT
;
453 switch(elm
->base
.btype
) {
454 case HAMMER_BTREE_TYPE_NONE
:
455 flags
|= test_rbn_lr(elm
, lbe
);
458 flags
|= FLAG_BADTYPE
;
462 if (child_offset
== 0) {
463 flags
|= FLAG_BADCHILDPARENT
;
465 struct buffer_info
*buffer
= NULL
;
466 hammer_node_ondisk_t subnode
;
467 subnode
= get_buffer_data(child_offset
, &buffer
, 0);
469 flags
|= FLAG_BADCHILDPARENT
;
470 else if (subnode
->parent
!= node_offset
)
471 flags
|= FLAG_BADCHILDPARENT
;
474 switch(elm
->base
.btype
) {
475 case HAMMER_BTREE_TYPE_INTERNAL
:
476 case HAMMER_BTREE_TYPE_LEAF
:
477 flags
|= test_lr(elm
, lbe
);
480 flags
|= FLAG_BADTYPE
;
485 case HAMMER_BTREE_TYPE_LEAF
:
486 if (elm
->leaf
.data_offset
== 0) {
487 flags
|= FLAG_BADCHILDPARENT
;
489 if (elm
->leaf
.data_len
== 0) {
490 flags
|= FLAG_BADCHILDPARENT
;
493 if (node
->mirror_tid
== 0 &&
494 !(node
->parent
== 0 && node
->count
== 2)) {
495 flags
|= FLAG_BADMIRRORTID
;
497 if (elm
->base
.create_tid
&& node
->mirror_tid
&&
498 elm
->base
.create_tid
> node
->mirror_tid
) {
499 flags
|= FLAG_BADMIRRORTID
;
501 if (elm
->base
.delete_tid
&& node
->mirror_tid
&&
502 elm
->base
.delete_tid
> node
->mirror_tid
) {
503 flags
|= FLAG_BADMIRRORTID
;
505 switch(elm
->base
.btype
) {
506 case HAMMER_BTREE_TYPE_RECORD
:
507 flags
|= test_lr(elm
, lbe
);
510 flags
|= FLAG_BADTYPE
;
515 flags
|= FLAG_BADTYPE
;
522 * Taken from /usr/src/sys/vfs/hammer/hammer_btree.c.
526 hammer_btree_cmp(hammer_base_elm_t key1
, hammer_base_elm_t key2
)
528 if (key1
->localization
< key2
->localization
)
530 if (key1
->localization
> key2
->localization
)
533 if (key1
->obj_id
< key2
->obj_id
)
535 if (key1
->obj_id
> key2
->obj_id
)
538 if (key1
->rec_type
< key2
->rec_type
)
540 if (key1
->rec_type
> key2
->rec_type
)
543 if (key1
->key
< key2
->key
)
545 if (key1
->key
> key2
->key
)
548 if (key1
->create_tid
== 0) {
549 if (key2
->create_tid
== 0)
553 if (key2
->create_tid
== 0)
555 if (key1
->create_tid
< key2
->create_tid
)
557 if (key1
->create_tid
> key2
->create_tid
)
564 test_lr(hammer_btree_elm_t elm
, hammer_btree_elm_t lbe
)
567 hammer_btree_elm_t rbe
= lbe
+ 1;
568 if (hammer_btree_cmp(&elm
->base
, &lbe
->base
) < 0)
569 return(FLAG_TOOFARLEFT
);
570 if (hammer_btree_cmp(&elm
->base
, &rbe
->base
) >= 0)
571 return(FLAG_TOOFARRIGHT
);
578 test_rbn_lr(hammer_btree_elm_t rbn
, hammer_btree_elm_t lbe
)
581 hammer_btree_elm_t rbe
= lbe
+ 1;
582 if (hammer_btree_cmp(&rbn
->base
, &lbe
->base
) < 0)
583 return(FLAG_TOOFARLEFT
);
584 if (hammer_btree_cmp(&rbn
->base
, &rbe
->base
) > 0)
585 return(FLAG_TOOFARRIGHT
);
592 print_bigblock_fill(hammer_off_t offset
)
594 struct hammer_blockmap_layer1 layer1
;
595 struct hammer_blockmap_layer2 layer2
;
599 blockmap_lookup(offset
, &layer1
, &layer2
, &error
);
600 printf("z%d:v%d:%d:%d:%lu=",
601 HAMMER_ZONE_DECODE(offset
),
602 HAMMER_VOL_DECODE(offset
),
603 HAMMER_BLOCKMAP_LAYER1_INDEX(offset
),
604 HAMMER_BLOCKMAP_LAYER2_INDEX(offset
),
605 offset
& HAMMER_BIGBLOCK_MASK64
);
608 printf("B%d", error
);
610 fill
= layer2
.bytes_free
* 100 / HAMMER_BIGBLOCK_SIZE
;
611 printf("%d%%", 100 - fill
);
616 * Check the generic crc on a data element. Inodes record types are
617 * special in that some of their fields are not CRCed.
619 * Also check that the zone is valid.
623 check_data_crc(hammer_btree_elm_t elm
)
625 struct buffer_info
*data_buffer
;
626 hammer_off_t data_offset
;
627 hammer_off_t buf_offset
;
634 data_offset
= elm
->leaf
.data_offset
;
635 data_len
= elm
->leaf
.data_len
;
637 if (data_offset
== 0 || data_len
== 0)
638 return("ZO"); /* zero offset or length */
641 buf_offset
= blockmap_lookup(data_offset
, NULL
, NULL
, &error
);
643 bzero(bo
, sizeof(bo
));
644 snprintf(bo
, sizeof(bo
), "BO%d", -error
);
649 switch (elm
->leaf
.base
.rec_type
) {
650 case HAMMER_RECTYPE_INODE
:
651 if (data_len
!= sizeof(struct hammer_inode_data
))
652 return("BI"); /* bad inode size */
653 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
654 crc
= hammer_crc_get_leaf(ptr
, &elm
->leaf
);
655 rel_buffer(data_buffer
);
658 crc
= get_buf_crc(buf_offset
, data_len
);
663 return("Bx"); /* bad crc */
664 if (crc
!= elm
->leaf
.data_crc
)
665 return("BX"); /* bad crc */
666 return(NULL
); /* success */
671 get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
)
673 struct buffer_info
*data_buffer
= NULL
;
679 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
680 len
= HAMMER_BUFSIZE
- ((int)buf_offset
& HAMMER_BUFMASK
);
683 assert(len
<= HAMMER_BUFSIZE
);
684 crc
= crc32_ext(ptr
, len
, crc
);
688 rel_buffer(data_buffer
);
695 print_config(char *cfgtxt
)
699 printf("\n%s%17s", INDENT
, "");
700 printf("config text=\"\n");
701 if (cfgtxt
!= NULL
) {
702 while((token
= strsep(&cfgtxt
, "\r\n")) != NULL
)
704 printf("%s%17s %s\n",
707 printf("%s%17s \"", INDENT
, "");
712 print_record(hammer_btree_elm_t elm
)
714 struct buffer_info
*data_buffer
;
715 hammer_off_t data_offset
;
717 hammer_data_ondisk_t data
;
722 data_offset
= elm
->leaf
.data_offset
;
723 data_len
= elm
->leaf
.data_len
;
724 assert(data_offset
!= 0);
725 assert(data_len
!= 0);
728 data
= get_buffer_data(data_offset
, &data_buffer
, 0);
729 assert(data
!= NULL
);
731 switch(elm
->leaf
.base
.rec_type
) {
732 case HAMMER_RECTYPE_UNKNOWN
:
733 printf("\n%s%17s", INDENT
, "");
736 case HAMMER_RECTYPE_INODE
:
737 printf("\n%s%17s", INDENT
, "");
738 printf("inode size=%jd nlinks=%jd",
739 (intmax_t)data
->inode
.size
,
740 (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
);
757 case HAMMER_RECTYPE_DIRENTRY
:
758 data_len
-= HAMMER_ENTRY_NAME_OFF
;
759 printf("\n%s%17s", INDENT
, "");
760 printf("dir-entry objid=%016jx lo=%08x",
761 (uintmax_t)data
->entry
.obj_id
,
762 data
->entry
.localization
);
764 printf(" name=\"%*.*s\"",
765 data_len
, data_len
, data
->entry
.name
);
767 case HAMMER_RECTYPE_FIX
:
768 switch(elm
->leaf
.base
.key
) {
769 case HAMMER_FIXKEY_SYMLINK
:
770 data_len
-= HAMMER_SYMLINK_NAME_OFF
;
771 printf("\n%s%17s", INDENT
, "");
772 printf("fix-symlink name=\"%*.*s\"",
773 data_len
, data_len
, data
->symlink
.name
);
777 case HAMMER_RECTYPE_PFS
:
778 printf("\n%s%17s", INDENT
, "");
779 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
780 (intmax_t)data
->pfsd
.sync_beg_tid
,
781 (intmax_t)data
->pfsd
.sync_end_tid
);
782 uuid_to_string(&data
->pfsd
.shared_uuid
, &str1
, &status
);
783 uuid_to_string(&data
->pfsd
.unique_uuid
, &str2
, &status
);
785 printf(" shared_uuid=%s\n", str1
);
787 printf(" unique_uuid=%s\n", str2
);
789 printf(" mirror_flags=%08x label=\"%s\"",
790 data
->pfsd
.mirror_flags
, data
->pfsd
.label
);
791 if (data
->pfsd
.snapshots
[0])
792 printf(" snapshots=\"%s\"", data
->pfsd
.snapshots
);
796 case HAMMER_RECTYPE_SNAPSHOT
:
797 printf("\n%s%17s", INDENT
, "");
798 printf("snapshot tid=%016jx label=\"%s\"",
799 (intmax_t)data
->snap
.tid
, data
->snap
.label
);
801 case HAMMER_RECTYPE_CONFIG
:
802 if (VerboseOpt
> 2) {
803 char *p
= strdup(data
->config
.text
);
808 case HAMMER_RECTYPE_DATA
:
809 if (VerboseOpt
> 3) {
811 hexdump_record(data
, data_len
, "\t\t ");
814 case HAMMER_RECTYPE_EXT
:
815 case HAMMER_RECTYPE_DB
:
816 if (VerboseOpt
> 2) {
818 hexdump_record(data
, data_len
, "\t\t ");
825 rel_buffer(data_buffer
);
829 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
830 * which is 16KB. Passing record data length larger than 16KB to
831 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
834 hexdump_record(const void *ptr
, int length
, const char *hdr
)
836 int data_len
= length
;
838 if (data_len
> HAMMER_BUFSIZE
) /* XXX */
839 data_len
= HAMMER_BUFSIZE
;
840 hexdump(ptr
, data_len
, hdr
, 0);
842 if (length
> data_len
)
843 printf("%s....\n", hdr
);
846 static __inline __always_inline
848 _strtoul(const char *p
, int base
)
850 unsigned long retval
;
852 errno
= 0; /* clear */
853 retval
= strtoul(p
, NULL
, base
);
854 if (errno
== ERANGE
&& retval
== ULONG_MAX
)
859 static __inline __always_inline
861 _strtoull(const char *p
, int base
)
863 unsigned long long retval
;
865 errno
= 0; /* clear */
866 retval
= strtoull(p
, NULL
, base
);
867 if (errno
== ERANGE
&& retval
== ULLONG_MAX
)
873 init_btree_search(const char *arg
)
878 bzero(&opt
.base
, sizeof(opt
.base
));
883 if (strcmp(arg
, "none") == 0)
890 while ((p
= s
) != NULL
) {
891 if ((s
= strchr(s
, ':')) != NULL
)
894 opt
.base
.localization
= _strtoul(p
, 16);
896 opt
.base
.obj_id
= _strtoull(p
, 16);
898 opt
.base
.rec_type
= _strtoul(p
, 16);
900 opt
.base
.key
= _strtoull(p
, 16);
902 opt
.base
.create_tid
= _strtoull(p
, 16);
913 test_btree_search(hammer_btree_elm_t elm
)
915 hammer_base_elm_t base1
= &elm
->base
;
916 hammer_base_elm_t base2
= &opt
.base
;
917 int limit
= opt
.limit
;
919 if (base1
->localization
< base2
->localization
)
921 if (base1
->localization
> base2
->localization
)
924 return(0); /* ignore below */
926 if (base1
->obj_id
< base2
->obj_id
)
928 if (base1
->obj_id
> base2
->obj_id
)
931 return(0); /* ignore below */
933 if (base1
->rec_type
< base2
->rec_type
)
935 if (base1
->rec_type
> base2
->rec_type
)
938 return(0); /* ignore below */
940 if (base1
->key
< base2
->key
)
942 if (base1
->key
> base2
->key
)
945 return(0); /* ignore below */
947 if (base1
->create_tid
== 0) {
948 if (base2
->create_tid
== 0)
952 if (base2
->create_tid
== 0)
954 if (base1
->create_tid
< base2
->create_tid
)
956 if (base1
->create_tid
> base2
->create_tid
)
963 test_btree_match(hammer_btree_elm_t elm
)
965 if (test_btree_search(elm
) == 0)
972 test_btree_out_of_range(hammer_btree_elm_t elm
)
974 if (test_btree_search(elm
) > 0)
975 return(1); /* conditions < this elm */
977 if (opt
.limit
>= 5) {
978 if (test_btree_search(elm
+ 1) <= 0)
979 return(1); /* next elm <= conditions */
981 if (test_btree_search(elm
+ 1) < 0)
982 return(1); /* next elm < conditions */
991 hammer_cmd_show_undo(void)
993 struct volume_info
*volume
;
994 hammer_blockmap_t rootmap
;
995 hammer_off_t scan_offset
;
996 hammer_fifo_any_t head
;
997 hammer_fifo_head_t hdr
;
998 struct buffer_info
*data_buffer
= NULL
;
999 struct zone_stat
*stats
= NULL
;
1001 volume
= get_root_volume();
1002 rootmap
= &volume
->ondisk
->vol0_blockmap
[HAMMER_ZONE_UNDO_INDEX
];
1004 print_blockmap(volume
);
1007 stats
= hammer_init_zone_stat_bits();
1009 scan_offset
= HAMMER_ENCODE_UNDO(0);
1010 while (scan_offset
< rootmap
->alloc_offset
) {
1011 head
= get_buffer_data(scan_offset
, &data_buffer
, 0);
1013 printf("%016jx ", scan_offset
);
1015 switch(hdr
->hdr_type
) {
1016 case HAMMER_HEAD_TYPE_PAD
:
1017 printf("PAD(%d)", hdr
->hdr_size
);
1019 case HAMMER_HEAD_TYPE_DUMMY
:
1020 printf("DUMMY(%d)\tseq=%08x",
1021 hdr
->hdr_size
, hdr
->hdr_seq
);
1023 case HAMMER_HEAD_TYPE_UNDO
:
1024 printf("UNDO(%d)\tseq=%08x offset=%016jx bytes=%d",
1025 hdr
->hdr_size
, hdr
->hdr_seq
,
1026 (intmax_t)head
->undo
.undo_offset
,
1027 head
->undo
.undo_data_bytes
);
1029 case HAMMER_HEAD_TYPE_REDO
:
1030 printf("REDO(%d)\tseq=%08x offset=%016jx bytes=%d "
1031 "objid=%016jx flags=%08x lo=%08x",
1032 hdr
->hdr_size
, hdr
->hdr_seq
,
1033 (intmax_t)head
->redo
.redo_offset
,
1034 head
->redo
.redo_data_bytes
,
1035 (intmax_t)head
->redo
.redo_objid
,
1036 head
->redo
.redo_flags
,
1037 head
->redo
.redo_localization
);
1040 printf("%04x(%d)\tseq=%08x",
1041 hdr
->hdr_type
, hdr
->hdr_size
, hdr
->hdr_seq
);
1045 if (scan_offset
== rootmap
->first_offset
)
1047 if (scan_offset
== rootmap
->next_offset
)
1052 hammer_add_zone_stat(stats
, scan_offset
, hdr
->hdr_size
);
1054 if ((hdr
->hdr_size
& HAMMER_HEAD_ALIGN_MASK
) ||
1055 hdr
->hdr_size
== 0 ||
1056 hdr
->hdr_size
> HAMMER_UNDO_ALIGN
-
1057 ((u_int
)scan_offset
& HAMMER_UNDO_MASK
)) {
1058 printf("Illegal size field, skipping to "
1060 scan_offset
= HAMMER_UNDO_DOALIGN(scan_offset
);
1062 scan_offset
+= hdr
->hdr_size
;
1065 rel_buffer(data_buffer
);
1068 hammer_print_zone_stat(stats
);
1069 hammer_cleanup_zone_stat(stats
);