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
45 typedef struct btree_search {
46 struct hammer_base_elm base;
47 int limit; /* # of fields to test */
48 int filter; /* filter type (default -1) */
51 static void print_btree_node(hammer_off_t node_offset, btree_search_t search,
52 int depth, hammer_tid_t mirror_tid,
53 hammer_base_elm_t left_bound,
54 hammer_base_elm_t right_bound,
55 struct zone_stat *stats);
56 static const char *check_data_crc(hammer_btree_elm_t elm);
57 static void print_record(hammer_btree_elm_t elm);
58 static void print_btree_elm(hammer_node_ondisk_t node, hammer_off_t node_offset,
59 hammer_btree_elm_t elm,
60 hammer_base_elm_t left_bound,
61 hammer_base_elm_t right_bound,
62 const char *ext, struct zone_stat *stats);
63 static int get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
64 hammer_btree_elm_t elm,
65 hammer_base_elm_t left_bound,
66 hammer_base_elm_t right_bound);
67 static int test_lr(hammer_btree_elm_t elm,
68 hammer_base_elm_t left_bound,
69 hammer_base_elm_t right_bound);
70 static int test_rbn_lr(hammer_btree_elm_t elm,
71 hammer_base_elm_t left_bound,
72 hammer_base_elm_t right_bound);
73 static void print_bigblock_fill(hammer_off_t offset);
74 static int init_btree_search(const char *arg, int filter,
75 btree_search_t search);
76 static int test_btree_search(hammer_btree_elm_t elm, btree_search_t search);
77 static int test_btree_match(hammer_btree_elm_t elm, btree_search_t search);
78 static int test_btree_out_of_range(hammer_btree_elm_t elm, btree_search_t search);
80 static int num_bad_node = 0;
81 static int num_bad_elm = 0;
82 static int num_bad_rec = 0;
83 static int do_obfuscate = 0;
86 hammer_cmd_show(hammer_off_t node_offset, const char *arg,
87 int filter, int obfuscate, int depth,
88 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
90 struct volume_info *volume;
91 struct btree_search search;
92 struct zone_stat *stats = NULL;
95 AssertOnFailure = (DebugOpt != 0);
98 stats = hammer_init_zone_stat_bits();
100 if (node_offset == HAMMER_OFF_BAD) {
101 volume = get_volume(RootVolNo);
102 node_offset = volume->ondisk->vol0_btree_root;
104 printf("Volume header\trecords=%jd next_tid=%016jx\n",
105 (intmax_t)volume->ondisk->vol0_stat_records,
106 (uintmax_t)volume->ondisk->vol0_next_tid);
107 printf("\t\tbufoffset=%016jx\n",
108 (uintmax_t)volume->ondisk->vol_buf_beg);
109 for (zone = 0; zone < HAMMER_MAX_ZONES; ++zone) {
110 printf("\t\tzone %d\tnext_offset=%016jx\n",
112 (uintmax_t)volume->ondisk->vol0_blockmap[zone].next_offset
119 printf("show %016jx", (uintmax_t)node_offset);
121 do_obfuscate = obfuscate;
122 init_btree_search(arg, filter, &search);
124 if (search.limit >= 1)
125 printf(" lo %08x", search.base.localization);
126 if (search.limit >= 2)
127 printf(" obj_id %016jx", (uintmax_t)search.base.obj_id);
128 if (search.limit >= 3)
129 printf(" rec_type %02x", search.base.rec_type);
130 if (search.limit >= 4)
131 printf(" key %016jx", (uintmax_t)search.base.key);
132 if (search.limit == 5)
133 printf(" create_tid %016jx\n",
134 (uintmax_t)search.base.create_tid);
136 printf(" depth %d\n", depth);
137 print_btree_node(node_offset, &search, depth, HAMMER_MAX_TID,
138 left_bound, right_bound, stats);
143 hammer_print_zone_stat(stats);
144 hammer_cleanup_zone_stat(stats);
147 if (num_bad_node || VerboseOpt) {
148 printf("%d bad nodes\n", num_bad_node);
150 if (num_bad_elm || VerboseOpt) {
151 printf("%d bad elms\n", num_bad_elm);
153 if (num_bad_rec || VerboseOpt) {
154 printf("%d bad records\n", num_bad_rec);
159 print_btree_node(hammer_off_t node_offset, btree_search_t search,
160 int depth, hammer_tid_t mirror_tid,
161 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound,
162 struct zone_stat *stats)
164 struct buffer_info *buffer = NULL;
165 hammer_node_ondisk_t node;
166 hammer_btree_elm_t elm;
169 char badc = ' '; /* good */
170 char badm = ' '; /* good */
173 node = get_node(node_offset, &buffer);
179 if (crc32(&node->crc + 1, HAMMER_BTREE_CRCSIZE) != node->crc)
181 if (node->mirror_tid > mirror_tid) {
185 maxcount = hammer_node_max_elements(node->type);
186 if (maxcount == -1) {
189 } else if (node->count == 0 || node->count > maxcount) {
195 if (badm != ' ' || badc != ' ') /* not good */
198 printf("%c%c NODE %016jx ", badc, badm, (uintmax_t)node_offset);
200 printf("(IO ERROR)\n");
205 printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx",
207 (uintmax_t)node->parent,
208 (node->type ? node->type : '?'),
210 (uintmax_t)node->mirror_tid);
213 print_bigblock_fill(node_offset);
218 hammer_add_zone_stat(stats, node_offset, sizeof(*node));
220 for (i = 0; i < node->count; ++i) {
221 elm = &node->elms[i];
225 switch (node->type) {
226 case HAMMER_BTREE_TYPE_INTERNAL:
227 if (!test_btree_out_of_range(elm, search))
230 case HAMMER_BTREE_TYPE_LEAF:
231 if (test_btree_match(elm, search))
236 print_btree_elm(node, node_offset,
237 elm, left_bound, right_bound,
240 if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
241 assert(i == node->count); /* boundary */
242 elm = &node->elms[i];
243 print_btree_elm(node, node_offset,
244 elm, left_bound, right_bound,
249 if (node->type == HAMMER_BTREE_TYPE_INTERNAL) {
250 for (i = 0; i < node->count; ++i) {
251 elm = &node->elms[i];
252 if (search->limit && search->filter) {
253 if (test_btree_out_of_range(elm, search))
256 if (elm->internal.subtree_offset) {
257 print_btree_node(elm->internal.subtree_offset,
259 elm->internal.mirror_tid,
260 &elm[0].base, &elm[1].base,
263 * Cause show to do normal iteration after
264 * seeking to the lo:objid:rectype:key:tid
267 if (search->limit && search->filter == -1) /* default */
277 is_root_btree_beg(uint8_t type, int i, hammer_btree_elm_t elm)
280 * elm->base.btype depends on what the original node had
281 * so it could be anything but HAMMER_BTREE_TYPE_NONE.
283 return (type == HAMMER_BTREE_TYPE_INTERNAL &&
285 elm->base.localization == 0 &&
286 elm->base.obj_id == (int64_t)-0x8000000000000000LL &&
287 elm->base.key == (int64_t)-0x8000000000000000LL &&
288 elm->base.create_tid == 1 &&
289 elm->base.delete_tid == 1 &&
290 elm->base.rec_type == 0 &&
291 elm->base.obj_type == 0 &&
292 elm->base.btype != HAMMER_BTREE_TYPE_NONE);
297 is_root_btree_end(uint8_t type, int i, hammer_btree_elm_t elm)
299 return (type == HAMMER_BTREE_TYPE_INTERNAL &&
301 elm->base.localization == 0xFFFFFFFFU &&
302 elm->base.obj_id == 0x7FFFFFFFFFFFFFFFLL &&
303 elm->base.key == 0x7FFFFFFFFFFFFFFFLL &&
304 elm->base.create_tid == 0xFFFFFFFFFFFFFFFFULL &&
305 elm->base.delete_tid == 0 &&
306 elm->base.rec_type == 0xFFFFU &&
307 elm->base.obj_type == 0 &&
308 elm->base.btype == HAMMER_BTREE_TYPE_NONE);
313 print_btree_elm(hammer_node_ondisk_t node, hammer_off_t node_offset,
314 hammer_btree_elm_t elm,
315 hammer_base_elm_t left_bound,
316 hammer_base_elm_t right_bound,
317 const char *ext, struct zone_stat *stats)
319 char flagstr[8] = { 0, '-', '-', '-', '-', '-', '-', 0 };
324 int i = ((char*)elm - (char*)node) / (int)sizeof(*elm) - 1;
326 flags = get_elm_flags(node, node_offset, elm, left_bound, right_bound);
327 flagstr[0] = flags ? 'B' : 'G';
328 if (flags & FLAG_TOOFARLEFT)
330 if (flags & FLAG_TOOFARRIGHT)
332 if (flags & FLAG_BADTYPE)
334 if (flags & FLAG_BADCHILDPARENT)
336 if (flags & FLAG_BADMIRRORTID)
338 if (flagstr[0] == 'B')
342 * Check if elm is derived from root split
344 if (is_root_btree_beg(node->type, i, elm))
346 else if (is_root_btree_end(node->type, i, elm))
351 if (elm->base.delete_tid)
356 if (node->type == HAMMER_BTREE_TYPE_INTERNAL && node->count == i)
361 printf("%s\t%s %2d %c ", flagstr, label, i, hammer_elm_btype(elm));
362 printf("lo=%08x obj=%016jx rt=%02x key=%016jx tid=%016jx\n",
363 elm->base.localization,
364 (uintmax_t)elm->base.obj_id,
366 (uintmax_t)elm->base.key,
367 (uintmax_t)elm->base.create_tid);
368 printf("\t %c del=%016jx ot=%02x",
369 (rootelm == ' ' ? deleted : rootelm),
370 (uintmax_t)elm->base.delete_tid,
374 case HAMMER_BTREE_TYPE_INTERNAL:
375 printf(" suboff=%016jx",
376 (uintmax_t)elm->internal.subtree_offset);
378 printf(" mirror=%016jx",
379 (uintmax_t)elm->internal.mirror_tid);
384 case HAMMER_BTREE_TYPE_LEAF:
385 switch(elm->base.btype) {
386 case HAMMER_BTREE_TYPE_RECORD:
387 printf(" dataoff=%016jx/%d",
388 (uintmax_t)elm->leaf.data_offset,
391 const char *p = check_data_crc(elm);
392 printf(" crc=%08x", elm->leaf.data_crc);
394 printf(" error=%s", p);
398 print_bigblock_fill(elm->leaf.data_offset);
403 hammer_add_zone_stat(stats,
404 elm->leaf.data_offset,
409 printf("badtype=%d", elm->base.btype);
421 get_elm_flags(hammer_node_ondisk_t node, hammer_off_t node_offset,
422 hammer_btree_elm_t elm,
423 hammer_base_elm_t left_bound,
424 hammer_base_elm_t right_bound)
426 hammer_off_t child_offset;
428 int i = ((char*)elm - (char*)node) / (int)sizeof(*elm) - 1;
431 case HAMMER_BTREE_TYPE_INTERNAL:
432 child_offset = elm->internal.subtree_offset;
433 if (elm->internal.mirror_tid > node->mirror_tid)
434 flags |= FLAG_BADMIRRORTID;
436 if (i == node->count) {
437 if (child_offset != 0)
438 flags |= FLAG_BADCHILDPARENT;
439 switch(elm->base.btype) {
440 case HAMMER_BTREE_TYPE_NONE:
441 flags |= test_rbn_lr(elm, left_bound, right_bound);
444 flags |= FLAG_BADTYPE;
448 if (child_offset == 0) {
449 flags |= FLAG_BADCHILDPARENT;
451 struct buffer_info *buffer = NULL;
452 hammer_node_ondisk_t subnode;
453 subnode = get_node(child_offset, &buffer);
455 flags |= FLAG_BADCHILDPARENT;
456 else if (subnode->parent != node_offset)
457 flags |= FLAG_BADCHILDPARENT;
460 switch(elm->base.btype) {
461 case HAMMER_BTREE_TYPE_INTERNAL:
462 case HAMMER_BTREE_TYPE_LEAF:
463 flags |= test_lr(elm, left_bound, right_bound);
466 flags |= FLAG_BADTYPE;
471 case HAMMER_BTREE_TYPE_LEAF:
472 if (elm->leaf.data_offset == 0) {
473 flags |= FLAG_BADCHILDPARENT;
475 if (elm->leaf.data_len == 0) {
476 flags |= FLAG_BADCHILDPARENT;
479 if (node->mirror_tid == 0 &&
480 !(node->parent == 0 && node->count == 2)) {
481 flags |= FLAG_BADMIRRORTID;
483 if (elm->base.create_tid && node->mirror_tid &&
484 elm->base.create_tid > node->mirror_tid) {
485 flags |= FLAG_BADMIRRORTID;
487 if (elm->base.delete_tid && node->mirror_tid &&
488 elm->base.delete_tid > node->mirror_tid) {
489 flags |= FLAG_BADMIRRORTID;
491 switch(elm->base.btype) {
492 case HAMMER_BTREE_TYPE_RECORD:
493 flags |= test_lr(elm, left_bound, right_bound);
496 flags |= FLAG_BADTYPE;
501 flags |= FLAG_BADTYPE;
509 test_lr(hammer_btree_elm_t elm,
510 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
512 if (left_bound == NULL || right_bound == NULL)
514 if (hammer_btree_cmp(&elm->base, left_bound) < 0)
515 return(FLAG_TOOFARLEFT);
516 if (hammer_btree_cmp(&elm->base, right_bound) >= 0)
517 return(FLAG_TOOFARRIGHT);
523 test_rbn_lr(hammer_btree_elm_t rbn,
524 hammer_base_elm_t left_bound, hammer_base_elm_t right_bound)
526 if (left_bound == NULL || right_bound == NULL)
528 if (hammer_btree_cmp(&rbn->base, left_bound) < 0)
529 return(FLAG_TOOFARLEFT);
530 if (hammer_btree_cmp(&rbn->base, right_bound) > 0)
531 return(FLAG_TOOFARRIGHT);
537 print_bigblock_fill(hammer_off_t offset)
539 struct hammer_blockmap_layer1 layer1;
540 struct hammer_blockmap_layer2 layer2;
544 blockmap_lookup(offset, &layer1, &layer2, &error);
545 printf("z%d:v%d:%d:%d:%lu=",
546 HAMMER_ZONE_DECODE(offset),
547 HAMMER_VOL_DECODE(offset),
548 HAMMER_BLOCKMAP_LAYER1_INDEX(offset),
549 HAMMER_BLOCKMAP_LAYER2_INDEX(offset),
550 offset & HAMMER_BIGBLOCK_MASK64);
553 printf("B%d", error);
555 fill = layer2.bytes_free * 100 / HAMMER_BIGBLOCK_SIZE;
557 printf("%d%%", fill);
562 * Check the generic crc on a data element. Inodes record types are
563 * special in that some of their fields are not CRCed.
565 * Also check that the zone is valid.
569 check_data_crc(hammer_btree_elm_t elm)
571 struct buffer_info *data_buffer;
572 hammer_off_t data_offset;
580 data_offset = elm->leaf.data_offset;
581 data_len = elm->leaf.data_len;
583 if (data_offset == 0 || data_len == 0)
584 return("ZO"); /* zero offset or length */
589 blockmap_lookup(data_offset, NULL, NULL, &error);
592 ptr = get_buffer_data(data_offset, &data_buffer, 0);
593 len = HAMMER_BUFSIZE - ((int)data_offset & HAMMER_BUFMASK);
596 if (elm->leaf.base.rec_type == HAMMER_RECTYPE_INODE &&
597 data_len == sizeof(struct hammer_inode_data)) {
598 crc = crc32_ext(ptr, HAMMER_INODE_CRCSIZE, crc);
600 crc = crc32_ext(ptr, len, crc);
606 rel_buffer(data_buffer);
607 if (error) { /* bad offset on blockmap lookup */
609 bzero(bo, sizeof(bo));
610 snprintf(bo, sizeof(bo), "BO%d", -error);
613 if (crc != elm->leaf.data_crc)
614 return("BX"); /* bad crc */
615 return(NULL); /* success */
620 print_config(char *cfgtxt)
624 printf("\n%17s", "");
625 printf("config text=\"\n");
626 if (cfgtxt != NULL) {
627 while((token = strsep(&cfgtxt, "\r\n")) != NULL)
629 printf("%17s %s\n", "", token);
631 printf("%17s \"", "");
636 print_record(hammer_btree_elm_t elm)
638 struct buffer_info *data_buffer;
639 hammer_off_t data_offset;
641 hammer_data_ondisk_t data;
646 data_offset = elm->leaf.data_offset;
647 data_len = elm->leaf.data_len;
648 assert(data_offset != 0);
649 assert(data_len != 0);
652 data = get_buffer_data(data_offset, &data_buffer, 0);
653 assert(data != NULL);
655 switch(elm->leaf.base.rec_type) {
656 case HAMMER_RECTYPE_UNKNOWN:
657 printf("\n%17s", "");
660 case HAMMER_RECTYPE_INODE:
661 printf("\n%17s", "");
662 printf("inode size=%jd nlinks=%jd",
663 (intmax_t)data->inode.size,
664 (intmax_t)data->inode.nlinks);
666 printf(" mode=%05o uflags=%08x caps=%02x",
669 data->inode.cap_flags);
670 printf(" pobjid=%016jx ot=%02x\n",
671 (uintmax_t)data->inode.parent_obj_id,
672 data->inode.obj_type);
674 printf(" ctime=%016jx mtime=%016jx atime=%016jx",
675 (uintmax_t)data->inode.ctime,
676 (uintmax_t)data->inode.mtime,
677 (uintmax_t)data->inode.atime);
678 if (data->inode.ext.symlink[0])
679 printf(" symlink=\"%s\"",
680 data->inode.ext.symlink);
683 case HAMMER_RECTYPE_DIRENTRY:
684 data_len -= HAMMER_ENTRY_NAME_OFF;
685 printf("\n%17s", "");
686 printf("dir-entry ino=%016jx lo=%08x",
687 (uintmax_t)data->entry.obj_id,
688 data->entry.localization);
690 printf(" name=\"%*.*s\"",
691 data_len, data_len, data->entry.name);
693 case HAMMER_RECTYPE_FIX:
694 switch(elm->leaf.base.key) {
695 case HAMMER_FIXKEY_SYMLINK:
696 data_len -= HAMMER_SYMLINK_NAME_OFF;
697 printf("\n%17s", "");
698 printf("fix-symlink name=\"%*.*s\"",
699 data_len, data_len, data->symlink.name);
703 case HAMMER_RECTYPE_PFS:
704 printf("\n%17s", "");
705 printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
706 (intmax_t)data->pfsd.sync_beg_tid,
707 (intmax_t)data->pfsd.sync_end_tid);
708 uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
709 uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
711 printf(" shared_uuid=%s\n", str1);
713 printf(" unique_uuid=%s\n", str2);
715 printf(" mirror_flags=%08x label=\"%s\"",
716 data->pfsd.mirror_flags, data->pfsd.label);
717 if (data->pfsd.snapshots[0])
718 printf(" snapshots=\"%s\"", data->pfsd.snapshots);
722 case HAMMER_RECTYPE_SNAPSHOT:
723 printf("\n%17s", "");
724 printf("snapshot tid=%016jx label=\"%s\"",
725 (intmax_t)data->snap.tid, data->snap.label);
727 case HAMMER_RECTYPE_CONFIG:
728 if (VerboseOpt > 2) {
729 char *p = strdup(data->config.text);
734 case HAMMER_RECTYPE_DATA:
735 if (VerboseOpt > 3) {
737 hexdump(data, data_len, "\t\t ", 0);
740 case HAMMER_RECTYPE_EXT:
741 case HAMMER_RECTYPE_DB:
742 if (VerboseOpt > 2) {
744 hexdump(data, data_len, "\t\t ", 0);
751 rel_buffer(data_buffer);
756 _strtoul(const char *p, int base)
758 unsigned long retval;
760 errno = 0; /* clear */
761 retval = strtoul(p, NULL, base);
762 if (errno == ERANGE && retval == ULONG_MAX)
769 _strtoull(const char *p, int base)
771 unsigned long long retval;
773 errno = 0; /* clear */
774 retval = strtoull(p, NULL, base);
775 if (errno == ERANGE && retval == ULLONG_MAX)
781 init_btree_search(const char *arg, int filter, btree_search_t search)
786 bzero(&search->base, sizeof(search->base));
788 search->filter = filter;
792 if (strcmp(arg, "none") == 0)
799 while ((p = s) != NULL) {
800 if ((s = strchr(s, ':')) != NULL)
803 search->base.localization = _strtoul(p, 16);
805 search->base.obj_id = _strtoull(p, 16);
807 search->base.rec_type = _strtoul(p, 16);
809 search->base.key = _strtoull(p, 16);
811 search->base.create_tid = _strtoull(p, 16);
822 test_btree_search(hammer_btree_elm_t elm, btree_search_t search)
824 hammer_base_elm_t base1 = &elm->base;
825 hammer_base_elm_t base2 = &search->base;
828 if (base1->localization < base2->localization)
830 if (base1->localization > base2->localization)
832 if (search->limit == 1)
833 return(0); /* ignore below */
835 if (base1->obj_id < base2->obj_id)
837 if (base1->obj_id > base2->obj_id)
839 if (search->limit == 2)
840 return(0); /* ignore below */
842 if (base1->rec_type < base2->rec_type)
844 if (base1->rec_type > base2->rec_type)
846 if (search->limit == 3)
847 return(0); /* ignore below */
849 if (base1->key < base2->key)
851 if (base1->key > base2->key)
853 if (search->limit == 4)
854 return(0); /* ignore below */
856 if (base1->create_tid == 0) {
857 if (base2->create_tid == 0)
861 if (base2->create_tid == 0)
863 if (base1->create_tid < base2->create_tid)
865 if (base1->create_tid > base2->create_tid)
872 test_btree_match(hammer_btree_elm_t elm, btree_search_t search)
874 if (test_btree_search(elm, search) == 0)
881 test_btree_out_of_range(hammer_btree_elm_t elm, btree_search_t search)
883 if (test_btree_search(elm, search) > 0)
884 return(1); /* search < this elm */
886 if (search->limit >= 5) {
887 if (test_btree_search(elm + 1, search) <= 0)
888 return(1); /* next elm <= search */
890 if (test_btree_search(elm + 1, search) < 0)
891 return(1); /* next elm < search */
900 hammer_cmd_show_undo(void)
902 struct volume_info *volume;
903 hammer_blockmap_t rootmap;
904 hammer_off_t scan_offset;
905 hammer_fifo_any_t head;
906 struct buffer_info *data_buffer = NULL;
909 volume = get_volume(RootVolNo);
910 rootmap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
911 if (rootmap->first_offset <= rootmap->next_offset)
912 bytes = rootmap->next_offset - rootmap->first_offset;
914 bytes = rootmap->alloc_offset - rootmap->first_offset +
915 (rootmap->next_offset & HAMMER_OFF_LONG_MASK);
917 printf("Volume header UNDO %016jx-%016jx/%016jx\n",
918 (intmax_t)rootmap->first_offset,
919 (intmax_t)rootmap->next_offset,
920 (intmax_t)rootmap->alloc_offset);
921 printf("UNDO map is %jdMB\n",
922 (intmax_t)((rootmap->alloc_offset & HAMMER_OFF_LONG_MASK) /
924 printf("UNDO being used is %jdB\n", (intmax_t)bytes);
926 scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
927 while (scan_offset < rootmap->alloc_offset) {
928 head = get_buffer_data(scan_offset, &data_buffer, 0);
929 printf("%016jx ", scan_offset);
931 switch(head->head.hdr_type) {
932 case HAMMER_HEAD_TYPE_PAD:
933 printf("PAD(%04x)", head->head.hdr_size);
935 case HAMMER_HEAD_TYPE_DUMMY:
936 printf("DUMMY(%04x) seq=%08x",
937 head->head.hdr_size, head->head.hdr_seq);
939 case HAMMER_HEAD_TYPE_UNDO:
940 printf("UNDO(%04x) seq=%08x "
941 "dataoff=%016jx bytes=%d",
942 head->head.hdr_size, head->head.hdr_seq,
943 (intmax_t)head->undo.undo_offset,
944 head->undo.undo_data_bytes);
946 case HAMMER_HEAD_TYPE_REDO:
947 printf("REDO(%04x) seq=%08x flags=%08x "
948 "objid=%016jx logoff=%016jx bytes=%d",
949 head->head.hdr_size, head->head.hdr_seq,
950 head->redo.redo_flags,
951 (intmax_t)head->redo.redo_objid,
952 (intmax_t)head->redo.redo_offset,
953 head->redo.redo_data_bytes);
956 printf("UNKNOWN(%04x,%04x) seq=%08x",
963 if (scan_offset == rootmap->first_offset)
965 if (scan_offset == rootmap->next_offset)
969 if ((head->head.hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
970 head->head.hdr_size == 0 ||
971 head->head.hdr_size > HAMMER_UNDO_ALIGN -
972 ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
973 printf("Illegal size field, skipping to "
975 scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
978 scan_offset += head->head.hdr_size;
981 rel_buffer(data_buffer);