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 hammer_volume_ondisk_t ondisk;
119 struct zone_stat *stats = NULL;
122 stats = hammer_init_zone_stat_bits();
124 volume = get_root_volume();
125 ondisk = volume->ondisk;
127 print_blockmap(volume);
129 bzero(&opt, sizeof(opt));
131 opt.obfuscate = obfuscate;
135 if (init_btree_search(arg) > 0) {
136 printf("arg=\"%s\"", arg);
138 printf(" lo=%08x", opt.base.localization);
140 printf(" objid=%016jx", (uintmax_t)opt.base.obj_id);
142 printf(" rt=%02x", opt.base.rec_type);
144 printf(" key=%016jx", (uintmax_t)opt.base.key);
146 printf(" tid=%016jx", (uintmax_t)opt.base.create_tid);
149 print_btree(ondisk->vol0_btree_root);
152 hammer_print_zone_stat(stats);
153 hammer_cleanup_zone_stat(stats);
156 if (num_bad_node || VerboseOpt) {
157 printf("%d bad nodes\n", num_bad_node);
159 if (num_bad_elm || VerboseOpt) {
160 printf("%d bad elms\n", num_bad_elm);
162 if (num_bad_rec || VerboseOpt) {
163 printf("%d bad records\n", num_bad_rec);
169 print_btree(hammer_off_t node_offset)
172 print_btree_node(node_offset, HAMMER_MAX_TID, NULL, NULL);
178 print_subtree(hammer_btree_elm_t elm)
180 print_btree_node(elm->internal.subtree_offset,
181 elm->internal.mirror_tid, &elm[0].base, &elm[1].base);
185 print_btree_node(hammer_off_t node_offset,
186 hammer_tid_t mirror_tid,
187 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
189 struct buffer_info *buffer = NULL;
190 hammer_node_ondisk_t node;
191 hammer_btree_elm_t elm;
193 char badc = ' '; /* good */
194 char badm = ' '; /* good */
198 node = get_buffer_data(node_offset, &buffer, 0);
204 if (!hammer_crc_test_btree(node))
206 if (node->mirror_tid > mirror_tid) {
210 if (test_node_count(node, &badm) == -1) {
216 if (badm != ' ' || badc != ' ') /* not good */
219 printf("%s%c%c NODE %016jx ",
220 INDENT, badc, badm, (uintmax_t)node_offset);
221 printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx",
223 (uintmax_t)node->parent,
224 (node->type ? node->type : '?'),
226 (uintmax_t)node->mirror_tid);
228 print_bigblock_fill(node_offset);
232 hammer_add_zone_stat(opt.stats, node_offset, sizeof(*node));
234 for (i = 0; i < node->count; ++i) {
235 elm = &node->elms[i];
238 switch (node->type) {
239 case HAMMER_BTREE_TYPE_INTERNAL:
240 if (!test_btree_out_of_range(elm))
243 case HAMMER_BTREE_TYPE_LEAF:
244 if (test_btree_match(elm))
249 print_btree_elm(node, node_offset,
250 elm, left_bound, right_bound, ext);
252 if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
253 assert(i == node->count); /* boundary */
254 elm = &node->elms[i];
255 print_btree_elm(node, node_offset,
256 elm, left_bound, right_bound, NULL);
258 printf("%s }\n", INDENT);
260 if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
261 for (i = 0; i < node->count; ++i) {
262 elm = &node->elms[i];
263 if (opt.limit && opt.filter) {
264 if (test_btree_out_of_range(elm))
267 if (elm->internal.subtree_offset) {
270 * Cause show to do normal iteration after
271 * seeking to the lo:objid:rt:key:tid
274 if (opt.limit && opt.filter == -1) /* default */
284 test_node_count(hammer_node_ondisk_t node, char *badmp)
286 hammer_node_ondisk_t parent_node;
287 struct buffer_info *buffer = NULL;
290 maxcount = hammer_node_max_elements(node->type);
292 if (maxcount == -1) {
295 } else if (node->count > maxcount) {
298 } else if (node->count == 0) {
299 parent_node = get_buffer_data(node->parent, &buffer, 0);
300 if (parent_node->count != 1) {
313 is_root_btree_beg(uint8_t type, int i, hammer_btree_elm_t elm)
316 * elm->base.btype depends on what the original node had
317 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
319 return (type == HAMMER_BTREE_TYPE_INTERNAL &&
321 elm->base.localization == HAMMER_MIN_ONDISK_LOCALIZATION &&
322 elm->base.obj_id == (int64_t)HAMMER_MIN_OBJID &&
323 elm->base.key == (int64_t)HAMMER_MIN_KEY &&
324 elm->base.create_tid == 1 &&
325 elm->base.delete_tid == 1 &&
326 elm->base.rec_type == HAMMER_MIN_RECTYPE &&
327 elm->base.obj_type == 0 &&
328 elm->base.btype != HAMMER_BTREE_TYPE_NONE);
333 is_root_btree_end(uint8_t type, int i, hammer_btree_elm_t elm)
335 return (type == HAMMER_BTREE_TYPE_INTERNAL &&
337 elm->base.localization == HAMMER_MAX_ONDISK_LOCALIZATION &&
338 elm->base.obj_id == HAMMER_MAX_OBJID &&
339 elm->base.key == HAMMER_MAX_KEY &&
340 elm->base.create_tid == HAMMER_MAX_TID &&
341 elm->base.delete_tid == 0 &&
342 elm->base.rec_type == HAMMER_MAX_RECTYPE &&
343 elm->base.obj_type == 0 &&
344 elm->base.btype == HAMMER_BTREE_TYPE_NONE);
349 print_btree_elm(hammer_node_ondisk_t node, hammer_off_t node_offset,
350 hammer_btree_elm_t elm,
351 hammer_base_elm_t left_bound,
352 hammer_base_elm_t right_bound,
355 char flagstr[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
361 int i = ((char*)elm - (char*)node) / (int)sizeof(*elm) - 1;
363 flags = get_elm_flags(node, node_offset, elm, left_bound, right_bound);
364 flagstr[0] = flags ? 'B' : 'G';
365 if (flags & FLAG_TOOFARLEFT)
367 if (flags & FLAG_TOOFARRIGHT)
369 if (flags & FLAG_BADTYPE)
371 if (flags & FLAG_BADCHILDPARENT)
373 if (flags & FLAG_BADMIRRORTID)
375 if (flagstr[0] == 'B')
379 * Check if elm is derived from root split
381 if (is_root_btree_beg(node->type, i, elm))
383 else if (is_root_btree_end(node->type, i, elm))
388 if (elm->base.delete_tid)
393 if (node->type == HAMMER_BTREE_TYPE_INTERNAL && node->count == i)
398 printf("%s%s %s %2d %c ",
399 INDENT, flagstr, label, i, hammer_elm_btype(elm));
400 printf("lo=%08x objid=%016jx rt=%02x key=%016jx tid=%016jx\n",
401 elm->base.localization,
402 (uintmax_t)elm->base.obj_id,
404 (uintmax_t)elm->base.key,
405 (uintmax_t)elm->base.create_tid);
406 printf("%s %c del=%016jx ot=%02x",
408 (rootelm == ' ' ? deleted : rootelm),
409 (uintmax_t)elm->base.delete_tid,
413 case HAMMER_BTREE_TYPE_INTERNAL:
414 printf(" suboff=%016jx mirror=%016jx",
415 (uintmax_t)elm->internal.subtree_offset,
416 (uintmax_t)elm->internal.mirror_tid);
420 case HAMMER_BTREE_TYPE_LEAF:
421 switch(elm->base.btype) {
422 case HAMMER_BTREE_TYPE_RECORD:
423 printf(" dataoff=%016jx/%d",
424 (uintmax_t)elm->leaf.data_offset,
426 p = check_data_crc(elm);
427 printf(" crc=%08x", elm->leaf.data_crc);
429 printf(" error=%s", p);
433 print_bigblock_fill(elm->leaf.data_offset);
437 hammer_add_zone_stat(opt.stats,
438 elm->leaf.data_offset,
442 printf(" badtype=%d", elm->base.btype);
454 get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
455 hammer_btree_elm_t elm,
456 hammer_base_elm_t left_bound,
457 hammer_base_elm_t right_bound)
459 hammer_off_t child_offset;
461 int i = ((char*)elm - (char*)node) / (int)sizeof(*elm) - 1;
464 case HAMMER_BTREE_TYPE_INTERNAL:
465 child_offset = elm->internal.subtree_offset;
466 if (elm->internal.mirror_tid > node->mirror_tid)
467 flags |= FLAG_BADMIRRORTID;
469 if (i == node->count) {
470 if (child_offset != 0)
471 flags |= FLAG_BADCHILDPARENT;
472 switch(elm->base.btype) {
473 case HAMMER_BTREE_TYPE_NONE:
474 flags |= test_rbn_lr(elm, left_bound, right_bound);
477 flags |= FLAG_BADTYPE;
481 if (child_offset == 0) {
482 flags |= FLAG_BADCHILDPARENT;
484 struct buffer_info *buffer = NULL;
485 hammer_node_ondisk_t subnode;
486 subnode = get_buffer_data(child_offset, &buffer, 0);
488 flags |= FLAG_BADCHILDPARENT;
489 else if (subnode->parent != node_offset)
490 flags |= FLAG_BADCHILDPARENT;
493 switch(elm->base.btype) {
494 case HAMMER_BTREE_TYPE_INTERNAL:
495 case HAMMER_BTREE_TYPE_LEAF:
496 flags |= test_lr(elm, left_bound, right_bound);
499 flags |= FLAG_BADTYPE;
504 case HAMMER_BTREE_TYPE_LEAF:
505 if (elm->leaf.data_offset == 0) {
506 flags |= FLAG_BADCHILDPARENT;
508 if (elm->leaf.data_len == 0) {
509 flags |= FLAG_BADCHILDPARENT;
512 if (node->mirror_tid == 0 &&
513 !(node->parent == 0 && node->count == 2)) {
514 flags |= FLAG_BADMIRRORTID;
516 if (elm->base.create_tid && node->mirror_tid &&
517 elm->base.create_tid > node->mirror_tid) {
518 flags |= FLAG_BADMIRRORTID;
520 if (elm->base.delete_tid && node->mirror_tid &&
521 elm->base.delete_tid > node->mirror_tid) {
522 flags |= FLAG_BADMIRRORTID;
524 switch(elm->base.btype) {
525 case HAMMER_BTREE_TYPE_RECORD:
526 flags |= test_lr(elm, left_bound, right_bound);
529 flags |= FLAG_BADTYPE;
534 flags |= FLAG_BADTYPE;
541 * Taken from /usr/src/sys/vfs/hammer/hammer_btree.c.
545 hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2)
547 if (key1->localization < key2->localization)
549 if (key1->localization > key2->localization)
552 if (key1->obj_id < key2->obj_id)
554 if (key1->obj_id > key2->obj_id)
557 if (key1->rec_type < key2->rec_type)
559 if (key1->rec_type > key2->rec_type)
562 if (key1->key < key2->key)
564 if (key1->key > key2->key)
567 if (key1->create_tid == 0) {
568 if (key2->create_tid == 0)
572 if (key2->create_tid == 0)
574 if (key1->create_tid < key2->create_tid)
576 if (key1->create_tid > key2->create_tid)
583 test_lr(hammer_btree_elm_t elm,
584 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
586 if (left_bound == NULL || right_bound == NULL)
588 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
589 return(FLAG_TOOFARLEFT);
590 if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
591 return(FLAG_TOOFARRIGHT);
597 test_rbn_lr(hammer_btree_elm_t rbn,
598 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
600 if (left_bound == NULL || right_bound == NULL)
602 if (hammer_btree_cmp(&rbn->base, left_bound) < 0)
603 return(FLAG_TOOFARLEFT);
604 if (hammer_btree_cmp(&rbn->base, right_bound) > 0)
605 return(FLAG_TOOFARRIGHT);
611 print_bigblock_fill(hammer_off_t offset)
613 struct hammer_blockmap_layer1 layer1;
614 struct hammer_blockmap_layer2 layer2;
618 blockmap_lookup(offset, &layer1, &layer2, &error);
619 printf("z%d:v%d:%d:%d:%lu=",
620 HAMMER_ZONE_DECODE(offset),
621 HAMMER_VOL_DECODE(offset),
622 HAMMER_BLOCKMAP_LAYER1_INDEX(offset),
623 HAMMER_BLOCKMAP_LAYER2_INDEX(offset),
624 offset & HAMMER_BIGBLOCK_MASK64);
627 printf("B%d", error);
629 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
630 printf("%d%%", 100 - fill);
635 * Check the generic crc on a data element. Inodes record types are
636 * special in that some of their fields are not CRCed.
638 * Also check that the zone is valid.
642 check_data_crc(hammer_btree_elm_t elm)
644 struct buffer_info *data_buffer;
645 hammer_off_t data_offset;
646 hammer_off_t buf_offset;
653 data_offset = elm->leaf.data_offset;
654 data_len = elm->leaf.data_len;
656 if (data_offset == 0 || data_len == 0)
657 return("ZO"); /* zero offset or length */
660 buf_offset = blockmap_lookup(data_offset, NULL, NULL, &error);
662 bzero(bo, sizeof(bo));
663 snprintf(bo, sizeof(bo), "BO%d", -error);
668 switch (elm->leaf.base.rec_type) {
669 case HAMMER_RECTYPE_INODE:
670 if (data_len != sizeof(struct hammer_inode_data))
671 return("BI"); /* bad inode size */
672 ptr = get_buffer_data(buf_offset, &data_buffer, 0);
673 crc = hammer_crc_get_leaf(ptr, &elm->leaf);
674 rel_buffer(data_buffer);
677 crc = get_buf_crc(buf_offset, data_len);
682 return("Bx"); /* bad crc */
683 if (crc != elm->leaf.data_crc)
684 return("BX"); /* bad crc */
685 return(NULL); /* success */
690 get_buf_crc(hammer_off_t buf_offset, int32_t buf_len)
692 struct buffer_info *data_buffer = NULL;
698 ptr = get_buffer_data(buf_offset, &data_buffer, 0);
699 len = HAMMER_BUFSIZE - ((int)buf_offset & HAMMER_BUFMASK);
702 assert(len <= HAMMER_BUFSIZE);
703 crc = crc32_ext(ptr, len, crc);
707 rel_buffer(data_buffer);
714 print_config(char *cfgtxt)
718 printf("\n%s%17s", INDENT, "");
719 printf("config text=\"\n");
720 if (cfgtxt != NULL) {
721 while((token = strsep(&cfgtxt, "\r\n")) != NULL)
723 printf("%s%17s %s\n",
726 printf("%s%17s \"", INDENT, "");
731 print_record(hammer_btree_elm_t elm)
733 struct buffer_info *data_buffer;
734 hammer_off_t data_offset;
736 hammer_data_ondisk_t data;
741 data_offset = elm->leaf.data_offset;
742 data_len = elm->leaf.data_len;
743 assert(data_offset != 0);
744 assert(data_len != 0);
747 data = get_buffer_data(data_offset, &data_buffer, 0);
748 assert(data != NULL);
750 switch(elm->leaf.base.rec_type) {
751 case HAMMER_RECTYPE_UNKNOWN:
752 printf("\n%s%17s", INDENT, "");
755 case HAMMER_RECTYPE_INODE:
756 printf("\n%s%17s", INDENT, "");
757 printf("inode size=%jd nlinks=%jd",
758 (intmax_t)data->inode.size,
759 (intmax_t)data->inode.nlinks);
760 printf(" mode=%05o uflags=%08x caps=%02x",
763 data->inode.cap_flags);
764 printf(" pobjid=%016jx ot=%02x\n",
765 (uintmax_t)data->inode.parent_obj_id,
766 data->inode.obj_type);
767 printf("%s%17s", INDENT, "");
768 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
769 (uintmax_t)data->inode.ctime,
770 (uintmax_t)data->inode.mtime,
771 (uintmax_t)data->inode.atime);
772 if (data->inode.ext.symlink[0])
773 printf(" symlink=\"%s\"",
774 data->inode.ext.symlink);
776 case HAMMER_RECTYPE_DIRENTRY:
777 data_len -= HAMMER_ENTRY_NAME_OFF;
778 printf("\n%s%17s", INDENT, "");
779 printf("dir-entry objid=%016jx lo=%08x",
780 (uintmax_t)data->entry.obj_id,
781 data->entry.localization);
783 printf(" name=\"%*.*s\"",
784 data_len, data_len, data->entry.name);
786 case HAMMER_RECTYPE_FIX:
787 switch(elm->leaf.base.key) {
788 case HAMMER_FIXKEY_SYMLINK:
789 data_len -= HAMMER_SYMLINK_NAME_OFF;
790 printf("\n%s%17s", INDENT, "");
791 printf("fix-symlink name=\"%*.*s\"",
792 data_len, data_len, data->symlink.name);
796 case HAMMER_RECTYPE_PFS:
797 printf("\n%s%17s", INDENT, "");
798 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
799 (intmax_t)data->pfsd.sync_beg_tid,
800 (intmax_t)data->pfsd.sync_end_tid);
801 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
802 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
804 printf(" shared_uuid=%s\n", str1);
806 printf(" unique_uuid=%s\n", str2);
808 printf(" mirror_flags=%08x label=\"%s\"",
809 data->pfsd.mirror_flags, data->pfsd.label);
810 if (data->pfsd.snapshots[0])
811 printf(" snapshots=\"%s\"", data->pfsd.snapshots);
815 case HAMMER_RECTYPE_SNAPSHOT:
816 printf("\n%s%17s", INDENT, "");
817 printf("snapshot tid=%016jx label=\"%s\"",
818 (intmax_t)data->snap.tid, data->snap.label);
820 case HAMMER_RECTYPE_CONFIG:
821 if (VerboseOpt > 2) {
822 char *p = strdup(data->config.text);
827 case HAMMER_RECTYPE_DATA:
828 if (VerboseOpt > 3) {
830 hexdump_record(data, data_len, "\t\t ");
833 case HAMMER_RECTYPE_EXT:
834 case HAMMER_RECTYPE_DB:
835 if (VerboseOpt > 2) {
837 hexdump_record(data, data_len, "\t\t ");
844 rel_buffer(data_buffer);
848 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
849 * which is 16KB. Passing record data length larger than 16KB to
850 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
853 hexdump_record(const void *ptr, int length, const char *hdr)
855 int data_len = length;
857 if (data_len > HAMMER_BUFSIZE) /* XXX */
858 data_len = HAMMER_BUFSIZE;
859 hexdump(ptr, data_len, hdr, 0);
861 if (length > data_len)
862 printf("%s....\n", hdr);
867 _strtoul(const char *p, int base)
869 unsigned long retval;
871 errno = 0; /* clear */
872 retval = strtoul(p, NULL, base);
873 if (errno == ERANGE && retval == ULONG_MAX)
880 _strtoull(const char *p, int base)
882 unsigned long long retval;
884 errno = 0; /* clear */
885 retval = strtoull(p, NULL, base);
886 if (errno == ERANGE && retval == ULLONG_MAX)
892 init_btree_search(const char *arg)
897 bzero(&opt.base, sizeof(opt.base));
902 if (strcmp(arg, "none") == 0)
909 while ((p = s) != NULL) {
910 if ((s = strchr(s, ':')) != NULL)
913 opt.base.localization = _strtoul(p, 16);
915 opt.base.obj_id = _strtoull(p, 16);
917 opt.base.rec_type = _strtoul(p, 16);
919 opt.base.key = _strtoull(p, 16);
921 opt.base.create_tid = _strtoull(p, 16);
932 test_btree_search(hammer_btree_elm_t elm)
934 hammer_base_elm_t base1 = &elm->base;
935 hammer_base_elm_t base2 = &opt.base;
936 int limit = opt.limit;
938 if (base1->localization < base2->localization)
940 if (base1->localization > base2->localization)
943 return(0); /* ignore below */
945 if (base1->obj_id < base2->obj_id)
947 if (base1->obj_id > base2->obj_id)
950 return(0); /* ignore below */
952 if (base1->rec_type < base2->rec_type)
954 if (base1->rec_type > base2->rec_type)
957 return(0); /* ignore below */
959 if (base1->key < base2->key)
961 if (base1->key > base2->key)
964 return(0); /* ignore below */
966 if (base1->create_tid == 0) {
967 if (base2->create_tid == 0)
971 if (base2->create_tid == 0)
973 if (base1->create_tid < base2->create_tid)
975 if (base1->create_tid > base2->create_tid)
982 test_btree_match(hammer_btree_elm_t elm)
984 if (test_btree_search(elm) == 0)
991 test_btree_out_of_range(hammer_btree_elm_t elm)
993 if (test_btree_search(elm) > 0)
994 return(1); /* conditions < this elm */
996 if (opt.limit >= 5) {
997 if (test_btree_search(elm + 1) <= 0)
998 return(1); /* next elm <= conditions */
1000 if (test_btree_search(elm + 1) < 0)
1001 return(1); /* next elm < conditions */
1007 * Dump the UNDO FIFO
1010 hammer_cmd_show_undo(void)
1012 struct volume_info *volume;
1013 hammer_blockmap_t rootmap;
1014 hammer_off_t scan_offset;
1015 hammer_fifo_any_t head;
1016 struct buffer_info *data_buffer = NULL;
1018 volume = get_root_volume();
1019 rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
1021 print_blockmap(volume);
1023 scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
1024 while (scan_offset < rootmap->alloc_offset) {
1025 head = get_buffer_data(scan_offset, &data_buffer, 0);
1026 printf("%016jx ", scan_offset);
1028 switch(head->head.hdr_type) {
1029 case HAMMER_HEAD_TYPE_PAD:
1030 printf("PAD(%04x)", head->head.hdr_size);
1032 case HAMMER_HEAD_TYPE_DUMMY:
1033 printf("DUMMY(%04x) seq=%08x",
1034 head->head.hdr_size, head->head.hdr_seq);
1036 case HAMMER_HEAD_TYPE_UNDO:
1037 printf("UNDO(%04x) seq=%08x "
1038 "dataoff=%016jx bytes=%d",
1039 head->head.hdr_size, head->head.hdr_seq,
1040 (intmax_t)head->undo.undo_offset,
1041 head->undo.undo_data_bytes);
1043 case HAMMER_HEAD_TYPE_REDO:
1044 printf("REDO(%04x) seq=%08x flags=%08x "
1045 "objid=%016jx logoff=%016jx bytes=%d",
1046 head->head.hdr_size, head->head.hdr_seq,
1047 head->redo.redo_flags,
1048 (intmax_t)head->redo.redo_objid,
1049 (intmax_t)head->redo.redo_offset,
1050 head->redo.redo_data_bytes);
1053 printf("UNKNOWN(%04x,%04x) seq=%08x",
1054 head->head.hdr_type,
1055 head->head.hdr_size,
1056 head->head.hdr_seq);
1060 if (scan_offset == rootmap->first_offset)
1062 if (scan_offset == rootmap->next_offset)
1066 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
1067 head->head.hdr_size == 0 ||
1068 head->head.hdr_size > HAMMER_UNDO_ALIGN -
1069 ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
1070 printf("Illegal size field, skipping to "
1072 scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
1073 ~HAMMER_UNDO_MASK64;
1075 scan_offset += head->head.hdr_size;
1078 rel_buffer(data_buffer);