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_save(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
;
631 data_offset
= elm
->leaf
.data_offset
;
632 data_len
= elm
->leaf
.data_len
;
634 if (data_offset
== 0 || data_len
== 0)
635 return("ZO"); /* zero offset or length */
638 switch (elm
->leaf
.base
.rec_type
) {
639 case HAMMER_RECTYPE_INODE
:
640 if (data_len
!= sizeof(struct hammer_inode_data
))
641 return("BI"); /* bad inode size */
642 ptr
= get_buffer_data(data_offset
, &data_buffer
, 0);
643 crc
= hammer_crc_get_leaf(ptr
, &elm
->leaf
);
644 rel_buffer(data_buffer
);
647 crc
= get_buf_crc(data_offset
, data_len
);
652 return("Bx"); /* bad crc */
653 if (crc
!= elm
->leaf
.data_crc
)
654 return("BX"); /* bad crc */
655 return(NULL
); /* success */
660 get_buf_crc(hammer_off_t buf_offset
, int32_t buf_len
)
662 struct buffer_info
*data_buffer
= NULL
;
668 ptr
= get_buffer_data(buf_offset
, &data_buffer
, 0);
669 len
= HAMMER_BUFSIZE
- ((int)buf_offset
& HAMMER_BUFMASK
);
672 assert(len
<= HAMMER_BUFSIZE
);
673 crc
= crc32_ext(ptr
, len
, crc
);
677 rel_buffer(data_buffer
);
684 print_config(char *cfgtxt
)
688 printf("\n%s%17s", INDENT
, "");
689 printf("config text=\"\n");
690 if (cfgtxt
!= NULL
) {
691 while((token
= strsep(&cfgtxt
, "\r\n")) != NULL
)
693 printf("%s%17s %s\n",
696 printf("%s%17s \"", INDENT
, "");
701 print_record(hammer_btree_elm_t elm
)
703 struct buffer_info
*data_buffer
;
704 hammer_off_t data_offset
;
706 hammer_data_ondisk_t data
;
711 data_offset
= elm
->leaf
.data_offset
;
712 data_len
= elm
->leaf
.data_len
;
713 assert(data_offset
!= 0);
714 assert(data_len
!= 0);
717 data
= get_buffer_data(data_offset
, &data_buffer
, 0);
718 assert(data
!= NULL
);
720 switch(elm
->leaf
.base
.rec_type
) {
721 case HAMMER_RECTYPE_UNKNOWN
:
722 printf("\n%s%17s", INDENT
, "");
725 case HAMMER_RECTYPE_INODE
:
726 printf("\n%s%17s", INDENT
, "");
727 printf("inode size=%jd nlinks=%jd",
728 (intmax_t)data
->inode
.size
,
729 (intmax_t)data
->inode
.nlinks
);
730 printf(" mode=%05o uflags=%08x caps=%02x",
733 data
->inode
.cap_flags
);
734 printf(" pobjid=%016jx ot=%02x\n",
735 (uintmax_t)data
->inode
.parent_obj_id
,
736 data
->inode
.obj_type
);
737 printf("%s%17s", INDENT
, "");
738 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
739 (uintmax_t)data
->inode
.ctime
,
740 (uintmax_t)data
->inode
.mtime
,
741 (uintmax_t)data
->inode
.atime
);
742 if (data
->inode
.ext
.symlink
[0])
743 printf(" symlink=\"%s\"",
744 data
->inode
.ext
.symlink
);
746 case HAMMER_RECTYPE_DIRENTRY
:
747 data_len
-= HAMMER_ENTRY_NAME_OFF
;
748 printf("\n%s%17s", INDENT
, "");
749 printf("dir-entry objid=%016jx lo=%08x",
750 (uintmax_t)data
->entry
.obj_id
,
751 data
->entry
.localization
);
753 printf(" name=\"%*.*s\"",
754 data_len
, data_len
, data
->entry
.name
);
756 case HAMMER_RECTYPE_FIX
:
757 switch(elm
->leaf
.base
.key
) {
758 case HAMMER_FIXKEY_SYMLINK
:
759 data_len
-= HAMMER_SYMLINK_NAME_OFF
;
760 printf("\n%s%17s", INDENT
, "");
761 printf("fix-symlink name=\"%*.*s\"",
762 data_len
, data_len
, data
->symlink
.name
);
766 case HAMMER_RECTYPE_PFS
:
767 printf("\n%s%17s", INDENT
, "");
768 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
769 (intmax_t)data
->pfsd
.sync_beg_tid
,
770 (intmax_t)data
->pfsd
.sync_end_tid
);
771 uuid_to_string(&data
->pfsd
.shared_uuid
, &str1
, &status
);
772 uuid_to_string(&data
->pfsd
.unique_uuid
, &str2
, &status
);
774 printf(" shared_uuid=%s\n", str1
);
776 printf(" unique_uuid=%s\n", str2
);
778 printf(" mirror_flags=%08x label=\"%s\"",
779 data
->pfsd
.mirror_flags
, data
->pfsd
.label
);
780 if (data
->pfsd
.snapshots
[0])
781 printf(" snapshots=\"%s\"", data
->pfsd
.snapshots
);
785 case HAMMER_RECTYPE_SNAPSHOT
:
786 printf("\n%s%17s", INDENT
, "");
787 printf("snapshot tid=%016jx label=\"%s\"",
788 (intmax_t)data
->snap
.tid
, data
->snap
.label
);
790 case HAMMER_RECTYPE_CONFIG
:
791 if (VerboseOpt
> 2) {
792 char *p
= strdup(data
->config
.text
);
797 case HAMMER_RECTYPE_DATA
:
798 if (VerboseOpt
> 3) {
800 hexdump_record(data
, data_len
, "\t\t ");
803 case HAMMER_RECTYPE_EXT
:
804 case HAMMER_RECTYPE_DB
:
805 if (VerboseOpt
> 2) {
807 hexdump_record(data
, data_len
, "\t\t ");
814 rel_buffer(data_buffer
);
818 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
819 * which is 16KB. Passing record data length larger than 16KB to
820 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
823 hexdump_record(const void *ptr
, int length
, const char *hdr
)
825 int data_len
= length
;
827 if (data_len
> HAMMER_BUFSIZE
) /* XXX */
828 data_len
= HAMMER_BUFSIZE
;
829 hexdump(ptr
, data_len
, hdr
, 0);
831 if (length
> data_len
)
832 printf("%s....\n", hdr
);
835 static __inline __always_inline
837 _strtoul(const char *p
, int base
)
839 unsigned long retval
;
841 errno
= 0; /* clear */
842 retval
= strtoul(p
, NULL
, base
);
843 if (errno
== ERANGE
&& retval
== ULONG_MAX
)
848 static __inline __always_inline
850 _strtoull(const char *p
, int base
)
852 unsigned long long retval
;
854 errno
= 0; /* clear */
855 retval
= strtoull(p
, NULL
, base
);
856 if (errno
== ERANGE
&& retval
== ULLONG_MAX
)
862 init_btree_search(const char *arg
)
867 bzero(&opt
.base
, sizeof(opt
.base
));
872 if (strcmp(arg
, "none") == 0)
879 while ((p
= s
) != NULL
) {
880 if ((s
= strchr(s
, ':')) != NULL
)
883 opt
.base
.localization
= _strtoul(p
, 16);
885 opt
.base
.obj_id
= _strtoull(p
, 16);
887 opt
.base
.rec_type
= _strtoul(p
, 16);
889 opt
.base
.key
= _strtoull(p
, 16);
891 opt
.base
.create_tid
= _strtoull(p
, 16);
902 test_btree_search(hammer_btree_elm_t elm
)
904 hammer_base_elm_t base1
= &elm
->base
;
905 hammer_base_elm_t base2
= &opt
.base
;
906 int limit
= opt
.limit
;
908 if (base1
->localization
< base2
->localization
)
910 if (base1
->localization
> base2
->localization
)
913 return(0); /* ignore below */
915 if (base1
->obj_id
< base2
->obj_id
)
917 if (base1
->obj_id
> base2
->obj_id
)
920 return(0); /* ignore below */
922 if (base1
->rec_type
< base2
->rec_type
)
924 if (base1
->rec_type
> base2
->rec_type
)
927 return(0); /* ignore below */
929 if (base1
->key
< base2
->key
)
931 if (base1
->key
> base2
->key
)
934 return(0); /* ignore below */
936 if (base1
->create_tid
== 0) {
937 if (base2
->create_tid
== 0)
941 if (base2
->create_tid
== 0)
943 if (base1
->create_tid
< base2
->create_tid
)
945 if (base1
->create_tid
> base2
->create_tid
)
952 test_btree_match(hammer_btree_elm_t elm
)
954 if (test_btree_search(elm
) == 0)
961 test_btree_out_of_range(hammer_btree_elm_t elm
)
963 if (test_btree_search(elm
) > 0)
964 return(1); /* conditions < this elm */
966 if (opt
.limit
>= 5) {
967 if (test_btree_search(elm
+ 1) <= 0)
968 return(1); /* next elm <= conditions */
970 if (test_btree_search(elm
+ 1) < 0)
971 return(1); /* next elm < conditions */
980 hammer_cmd_show_undo(void)
982 struct volume_info
*volume
;
983 hammer_blockmap_t rootmap
;
984 hammer_off_t scan_offset
;
985 hammer_fifo_any_t head
;
986 hammer_fifo_head_t hdr
;
987 struct buffer_info
*data_buffer
= NULL
;
988 struct zone_stat
*stats
= NULL
;
990 volume
= get_root_volume();
991 rootmap
= &volume
->ondisk
->vol0_blockmap
[HAMMER_ZONE_UNDO_INDEX
];
993 print_blockmap(volume
);
996 stats
= hammer_init_zone_stat_bits();
998 scan_offset
= HAMMER_ENCODE_UNDO(0);
999 while (scan_offset
< rootmap
->alloc_offset
) {
1000 head
= get_buffer_data(scan_offset
, &data_buffer
, 0);
1002 printf("%016jx ", scan_offset
);
1004 switch(hdr
->hdr_type
) {
1005 case HAMMER_HEAD_TYPE_PAD
:
1006 printf("PAD(%d)", hdr
->hdr_size
);
1008 case HAMMER_HEAD_TYPE_DUMMY
:
1009 printf("DUMMY(%d)\tseq=%08x",
1010 hdr
->hdr_size
, hdr
->hdr_seq
);
1012 case HAMMER_HEAD_TYPE_UNDO
:
1013 printf("UNDO(%d)\tseq=%08x offset=%016jx bytes=%d",
1014 hdr
->hdr_size
, hdr
->hdr_seq
,
1015 (intmax_t)head
->undo
.undo_offset
,
1016 head
->undo
.undo_data_bytes
);
1018 case HAMMER_HEAD_TYPE_REDO
:
1019 printf("REDO(%d)\tseq=%08x offset=%016jx bytes=%d "
1020 "objid=%016jx flags=%08x lo=%08x",
1021 hdr
->hdr_size
, hdr
->hdr_seq
,
1022 (intmax_t)head
->redo
.redo_offset
,
1023 head
->redo
.redo_data_bytes
,
1024 (intmax_t)head
->redo
.redo_objid
,
1025 head
->redo
.redo_flags
,
1026 head
->redo
.redo_localization
);
1029 printf("%04x(%d)\tseq=%08x",
1030 hdr
->hdr_type
, hdr
->hdr_size
, hdr
->hdr_seq
);
1034 if (scan_offset
== rootmap
->first_offset
)
1036 if (scan_offset
== rootmap
->next_offset
)
1041 hammer_add_zone_stat(stats
, scan_offset
, hdr
->hdr_size
);
1043 if ((hdr
->hdr_size
& HAMMER_HEAD_ALIGN_MASK
) ||
1044 hdr
->hdr_size
== 0 ||
1045 hdr
->hdr_size
> HAMMER_UNDO_ALIGN
-
1046 ((u_int
)scan_offset
& HAMMER_UNDO_MASK
)) {
1047 printf("Illegal size field, skipping to "
1049 scan_offset
= HAMMER_UNDO_DOALIGN(scan_offset
);
1051 scan_offset
+= hdr
->hdr_size
;
1054 rel_buffer(data_buffer
);
1057 hammer_print_zone_stat(stats
);
1058 hammer_cleanup_zone_stat(stats
);