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_node(node_offset, &buffer);
204 if (crc32(&node->crc + 1, HAMMER_BTREE_CRCSIZE) != node->crc)
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_node(node->parent, &buffer);
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 == 0 &&
322 elm->base.obj_id == (int64_t)-0x8000000000000000LL &&
323 elm->base.key == (int64_t)-0x8000000000000000LL &&
324 elm->base.create_tid == 1 &&
325 elm->base.delete_tid == 1 &&
326 elm->base.rec_type == 0 &&
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 == 0xFFFFFFFFU &&
338 elm->base.obj_id == 0x7FFFFFFFFFFFFFFFLL &&
339 elm->base.key == 0x7FFFFFFFFFFFFFFFLL &&
340 elm->base.create_tid == 0xFFFFFFFFFFFFFFFFULL &&
341 elm->base.delete_tid == 0 &&
342 elm->base.rec_type == 0xFFFFU &&
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_node(child_offset, &buffer);
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;
542 test_lr(hammer_btree_elm_t elm,
543 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
545 if (left_bound == NULL || right_bound == NULL)
547 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
548 return(FLAG_TOOFARLEFT);
549 if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
550 return(FLAG_TOOFARRIGHT);
556 test_rbn_lr(hammer_btree_elm_t rbn,
557 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
559 if (left_bound == NULL || right_bound == NULL)
561 if (hammer_btree_cmp(&rbn->base, left_bound) < 0)
562 return(FLAG_TOOFARLEFT);
563 if (hammer_btree_cmp(&rbn->base, right_bound) > 0)
564 return(FLAG_TOOFARRIGHT);
570 print_bigblock_fill(hammer_off_t offset)
572 struct hammer_blockmap_layer1 layer1;
573 struct hammer_blockmap_layer2 layer2;
577 blockmap_lookup(offset, &layer1, &layer2, &error);
578 printf("z%d:v%d:%d:%d:%lu=",
579 HAMMER_ZONE_DECODE(offset),
580 HAMMER_VOL_DECODE(offset),
581 HAMMER_BLOCKMAP_LAYER1_INDEX(offset),
582 HAMMER_BLOCKMAP_LAYER2_INDEX(offset),
583 offset & HAMMER_BIGBLOCK_MASK64);
586 printf("B%d", error);
588 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
589 printf("%d%%", 100 - fill);
594 * Check the generic crc on a data element. Inodes record types are
595 * special in that some of their fields are not CRCed.
597 * Also check that the zone is valid.
601 check_data_crc(hammer_btree_elm_t elm)
603 struct buffer_info *data_buffer;
604 hammer_off_t data_offset;
605 hammer_off_t buf_offset;
612 data_offset = elm->leaf.data_offset;
613 data_len = elm->leaf.data_len;
615 if (data_offset == 0 || data_len == 0)
616 return("ZO"); /* zero offset or length */
619 buf_offset = blockmap_lookup(data_offset, NULL, NULL, &error);
621 bzero(bo, sizeof(bo));
622 snprintf(bo, sizeof(bo), "BO%d", -error);
627 switch (elm->leaf.base.rec_type) {
628 case HAMMER_RECTYPE_INODE:
629 if (data_len != sizeof(struct hammer_inode_data))
630 return("BI"); /* bad inode size */
631 ptr = get_buffer_data(buf_offset, &data_buffer, 0);
632 crc = crc32(ptr, HAMMER_INODE_CRCSIZE);
633 rel_buffer(data_buffer);
636 crc = get_buf_crc(buf_offset, data_len);
641 return("Bx"); /* bad crc */
642 if (crc != elm->leaf.data_crc)
643 return("BX"); /* bad crc */
644 return(NULL); /* success */
649 get_buf_crc(hammer_off_t buf_offset, int32_t buf_len)
651 struct buffer_info *data_buffer = NULL;
657 ptr = get_buffer_data(buf_offset, &data_buffer, 0);
658 len = HAMMER_BUFSIZE - ((int)buf_offset & HAMMER_BUFMASK);
661 assert(len <= HAMMER_BUFSIZE);
662 crc = crc32_ext(ptr, len, crc);
666 rel_buffer(data_buffer);
673 print_config(char *cfgtxt)
677 printf("\n%s%17s", INDENT, "");
678 printf("config text=\"\n");
679 if (cfgtxt != NULL) {
680 while((token = strsep(&cfgtxt, "\r\n")) != NULL)
682 printf("%s%17s %s\n",
685 printf("%s%17s \"", INDENT, "");
690 print_record(hammer_btree_elm_t elm)
692 struct buffer_info *data_buffer;
693 hammer_off_t data_offset;
695 hammer_data_ondisk_t data;
700 data_offset = elm->leaf.data_offset;
701 data_len = elm->leaf.data_len;
702 assert(data_offset != 0);
703 assert(data_len != 0);
706 data = get_buffer_data(data_offset, &data_buffer, 0);
707 assert(data != NULL);
709 switch(elm->leaf.base.rec_type) {
710 case HAMMER_RECTYPE_UNKNOWN:
711 printf("\n%s%17s", INDENT, "");
714 case HAMMER_RECTYPE_INODE:
715 printf("\n%s%17s", INDENT, "");
716 printf("inode size=%jd nlinks=%jd",
717 (intmax_t)data->inode.size,
718 (intmax_t)data->inode.nlinks);
719 printf(" mode=%05o uflags=%08x caps=%02x",
722 data->inode.cap_flags);
723 printf(" pobjid=%016jx ot=%02x\n",
724 (uintmax_t)data->inode.parent_obj_id,
725 data->inode.obj_type);
726 printf("%s%17s", INDENT, "");
727 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
728 (uintmax_t)data->inode.ctime,
729 (uintmax_t)data->inode.mtime,
730 (uintmax_t)data->inode.atime);
731 if (data->inode.ext.symlink[0])
732 printf(" symlink=\"%s\"",
733 data->inode.ext.symlink);
735 case HAMMER_RECTYPE_DIRENTRY:
736 data_len -= HAMMER_ENTRY_NAME_OFF;
737 printf("\n%s%17s", INDENT, "");
738 printf("dir-entry objid=%016jx lo=%08x",
739 (uintmax_t)data->entry.obj_id,
740 data->entry.localization);
742 printf(" name=\"%*.*s\"",
743 data_len, data_len, data->entry.name);
745 case HAMMER_RECTYPE_FIX:
746 switch(elm->leaf.base.key) {
747 case HAMMER_FIXKEY_SYMLINK:
748 data_len -= HAMMER_SYMLINK_NAME_OFF;
749 printf("\n%s%17s", INDENT, "");
750 printf("fix-symlink name=\"%*.*s\"",
751 data_len, data_len, data->symlink.name);
755 case HAMMER_RECTYPE_PFS:
756 printf("\n%s%17s", INDENT, "");
757 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
758 (intmax_t)data->pfsd.sync_beg_tid,
759 (intmax_t)data->pfsd.sync_end_tid);
760 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
761 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
763 printf(" shared_uuid=%s\n", str1);
765 printf(" unique_uuid=%s\n", str2);
767 printf(" mirror_flags=%08x label=\"%s\"",
768 data->pfsd.mirror_flags, data->pfsd.label);
769 if (data->pfsd.snapshots[0])
770 printf(" snapshots=\"%s\"", data->pfsd.snapshots);
774 case HAMMER_RECTYPE_SNAPSHOT:
775 printf("\n%s%17s", INDENT, "");
776 printf("snapshot tid=%016jx label=\"%s\"",
777 (intmax_t)data->snap.tid, data->snap.label);
779 case HAMMER_RECTYPE_CONFIG:
780 if (VerboseOpt > 2) {
781 char *p = strdup(data->config.text);
786 case HAMMER_RECTYPE_DATA:
787 if (VerboseOpt > 3) {
789 hexdump_record(data, data_len, "\t\t ");
792 case HAMMER_RECTYPE_EXT:
793 case HAMMER_RECTYPE_DB:
794 if (VerboseOpt > 2) {
796 hexdump_record(data, data_len, "\t\t ");
803 rel_buffer(data_buffer);
807 * HAMMER userspace only supports buffer size upto HAMMER_BUFSIZE
808 * which is 16KB. Passing record data length larger than 16KB to
809 * hexdump(3) is invalid even if the leaf node elm says >16KB data.
812 hexdump_record(const void *ptr, int length, const char *hdr)
814 int data_len = length;
816 if (data_len > HAMMER_BUFSIZE) /* XXX */
817 data_len = HAMMER_BUFSIZE;
818 hexdump(ptr, data_len, hdr, 0);
820 if (length > data_len)
821 printf("%s....\n", hdr);
826 _strtoul(const char *p, int base)
828 unsigned long retval;
830 errno = 0; /* clear */
831 retval = strtoul(p, NULL, base);
832 if (errno == ERANGE && retval == ULONG_MAX)
839 _strtoull(const char *p, int base)
841 unsigned long long retval;
843 errno = 0; /* clear */
844 retval = strtoull(p, NULL, base);
845 if (errno == ERANGE && retval == ULLONG_MAX)
851 init_btree_search(const char *arg)
856 bzero(&opt.base, sizeof(opt.base));
861 if (strcmp(arg, "none") == 0)
868 while ((p = s) != NULL) {
869 if ((s = strchr(s, ':')) != NULL)
872 opt.base.localization = _strtoul(p, 16);
874 opt.base.obj_id = _strtoull(p, 16);
876 opt.base.rec_type = _strtoul(p, 16);
878 opt.base.key = _strtoull(p, 16);
880 opt.base.create_tid = _strtoull(p, 16);
891 test_btree_search(hammer_btree_elm_t elm)
893 hammer_base_elm_t base1 = &elm->base;
894 hammer_base_elm_t base2 = &opt.base;
895 int limit = opt.limit;
897 if (base1->localization < base2->localization)
899 if (base1->localization > base2->localization)
902 return(0); /* ignore below */
904 if (base1->obj_id < base2->obj_id)
906 if (base1->obj_id > base2->obj_id)
909 return(0); /* ignore below */
911 if (base1->rec_type < base2->rec_type)
913 if (base1->rec_type > base2->rec_type)
916 return(0); /* ignore below */
918 if (base1->key < base2->key)
920 if (base1->key > base2->key)
923 return(0); /* ignore below */
925 if (base1->create_tid == 0) {
926 if (base2->create_tid == 0)
930 if (base2->create_tid == 0)
932 if (base1->create_tid < base2->create_tid)
934 if (base1->create_tid > base2->create_tid)
941 test_btree_match(hammer_btree_elm_t elm)
943 if (test_btree_search(elm) == 0)
950 test_btree_out_of_range(hammer_btree_elm_t elm)
952 if (test_btree_search(elm) > 0)
953 return(1); /* conditions < this elm */
955 if (opt.limit >= 5) {
956 if (test_btree_search(elm + 1) <= 0)
957 return(1); /* next elm <= conditions */
959 if (test_btree_search(elm + 1) < 0)
960 return(1); /* next elm < conditions */
969 hammer_cmd_show_undo(void)
971 struct volume_info *volume;
972 hammer_blockmap_t rootmap;
973 hammer_off_t scan_offset;
974 hammer_fifo_any_t head;
975 struct buffer_info *data_buffer = NULL;
977 volume = get_root_volume();
978 rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
980 print_blockmap(volume);
982 scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
983 while (scan_offset < rootmap->alloc_offset) {
984 head = get_buffer_data(scan_offset, &data_buffer, 0);
985 printf("%016jx ", scan_offset);
987 switch(head->head.hdr_type) {
988 case HAMMER_HEAD_TYPE_PAD:
989 printf("PAD(%04x)", head->head.hdr_size);
991 case HAMMER_HEAD_TYPE_DUMMY:
992 printf("DUMMY(%04x) seq=%08x",
993 head->head.hdr_size, head->head.hdr_seq);
995 case HAMMER_HEAD_TYPE_UNDO:
996 printf("UNDO(%04x) seq=%08x "
997 "dataoff=%016jx bytes=%d",
998 head->head.hdr_size, head->head.hdr_seq,
999 (intmax_t)head->undo.undo_offset,
1000 head->undo.undo_data_bytes);
1002 case HAMMER_HEAD_TYPE_REDO:
1003 printf("REDO(%04x) seq=%08x flags=%08x "
1004 "objid=%016jx logoff=%016jx bytes=%d",
1005 head->head.hdr_size, head->head.hdr_seq,
1006 head->redo.redo_flags,
1007 (intmax_t)head->redo.redo_objid,
1008 (intmax_t)head->redo.redo_offset,
1009 head->redo.redo_data_bytes);
1012 printf("UNKNOWN(%04x,%04x) seq=%08x",
1013 head->head.hdr_type,
1014 head->head.hdr_size,
1015 head->head.hdr_seq);
1019 if (scan_offset == rootmap->first_offset)
1021 if (scan_offset == rootmap->next_offset)
1025 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
1026 head->head.hdr_size == 0 ||
1027 head->head.hdr_size > HAMMER_UNDO_ALIGN -
1028 ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
1029 printf("Illegal size field, skipping to "
1031 scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
1032 ~HAMMER_UNDO_MASK64;
1034 scan_offset += head->head.hdr_size;
1037 rel_buffer(data_buffer);