Merge branch 'vendor/BINUTILS225'
[dragonfly.git] / sbin / hammer / cmd_blockmap.c
1 /*
2  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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
16  *    distribution.
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.
20  *
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
32  * SUCH DAMAGE.
33  *
34  * $DragonFly: src/sbin/hammer/cmd_blockmap.c,v 1.4 2008/07/19 18:48:14 dillon Exp $
35  */
36
37 #include "hammer.h"
38
39 /*
40  * Each collect covers 1<<(19+23) bytes address space of layer 1.
41  * (plus a copy of 1<<23 bytes that holds layer2 entries in layer 1).
42  */
43 typedef struct collect {
44         RB_ENTRY(collect) entry;
45         hammer_off_t    phys_offset;  /* layer2 address pointed by layer1 */
46         hammer_off_t    *offsets;  /* big-block offset for layer2[i] */
47         struct hammer_blockmap_layer2 *track2;  /* track of layer2 entries */
48         struct hammer_blockmap_layer2 *layer2;  /* 1<<19 x 16 bytes entries */
49         int error;  /* # of inconsistencies */
50 } *collect_t;
51
52 static int
53 collect_compare(struct collect *c1, struct collect *c2)
54 {
55         if (c1->phys_offset < c2->phys_offset)
56                 return(-1);
57         if (c1->phys_offset > c2->phys_offset)
58                 return(1);
59         return(0);
60 }
61
62 RB_HEAD(collect_rb_tree, collect) CollectTree = RB_INITIALIZER(&CollectTree);
63 RB_PROTOTYPE2(collect_rb_tree, collect, entry, collect_compare, hammer_off_t);
64 RB_GENERATE2(collect_rb_tree, collect, entry, collect_compare, hammer_off_t,
65         phys_offset);
66
67 static void dump_blockmap(const char *label, int zone);
68 static void check_freemap(hammer_blockmap_t freemap);
69 static void check_btree_node(hammer_off_t node_offset, int depth);
70 static void check_undo(hammer_blockmap_t undomap);
71 static __inline void collect_btree_root(hammer_off_t node_offset);
72 static __inline void collect_btree_internal(hammer_btree_elm_t elm);
73 static __inline void collect_btree_leaf(hammer_btree_elm_t elm);
74 static __inline void collect_freemap_layer1(hammer_blockmap_t freemap);
75 static __inline void collect_freemap_layer2(struct hammer_blockmap_layer1 *layer1);
76 static __inline void collect_undo(hammer_off_t scan_offset,
77         hammer_fifo_head_t head);
78 static void collect_blockmap(hammer_off_t offset, int32_t length, int zone);
79 static struct hammer_blockmap_layer2 *collect_get_track(
80         collect_t collect, hammer_off_t offset, int zone,
81         struct hammer_blockmap_layer2 *layer2);
82 static collect_t collect_get(hammer_off_t phys_offset);
83 static void dump_collect_table(void);
84 static void dump_collect(collect_t collect, struct zone_stat *stats);
85
86 static int num_bad_layer1 = 0;
87 static int num_bad_layer2 = 0;
88 static int num_bad_node = 0;
89
90 void
91 hammer_cmd_blockmap(void)
92 {
93         dump_blockmap("freemap", HAMMER_ZONE_FREEMAP_INDEX);
94 }
95
96 static
97 void
98 dump_blockmap(const char *label, int zone)
99 {
100         struct volume_info *root_volume;
101         hammer_blockmap_t rootmap;
102         hammer_blockmap_t blockmap;
103         struct hammer_blockmap_layer1 *layer1;
104         struct hammer_blockmap_layer2 *layer2;
105         struct buffer_info *buffer1 = NULL;
106         struct buffer_info *buffer2 = NULL;
107         hammer_off_t layer1_offset;
108         hammer_off_t layer2_offset;
109         hammer_off_t scan1;
110         hammer_off_t scan2;
111         struct zone_stat *stats = NULL;
112         int xerr;
113         int i;
114
115         assert(RootVolNo >= 0);
116         root_volume = get_volume(RootVolNo);
117         rootmap = &root_volume->ondisk->vol0_blockmap[zone];
118         assert(rootmap->phys_offset != 0);
119
120         printf("                   "
121                "phys             first            next             alloc\n");
122         for (i = 0; i < HAMMER_MAX_ZONES; i++) {
123                 blockmap = &root_volume->ondisk->vol0_blockmap[i];
124                 if (VerboseOpt || i == zone) {
125                         printf("zone %-2d %-10s %016jx %016jx %016jx %016jx\n",
126                                 i, (i == zone ? label : ""),
127                                 (uintmax_t)blockmap->phys_offset,
128                                 (uintmax_t)blockmap->first_offset,
129                                 (uintmax_t)blockmap->next_offset,
130                                 (uintmax_t)blockmap->alloc_offset);
131                 }
132         }
133
134         if (VerboseOpt)
135                 stats = hammer_init_zone_stat();
136
137         for (scan1 = HAMMER_ZONE_ENCODE(zone, 0);
138              scan1 < HAMMER_ZONE_ENCODE(zone, HAMMER_OFF_LONG_MASK);
139              scan1 += HAMMER_BLOCKMAP_LAYER2) {
140                 /*
141                  * Dive layer 1.
142                  */
143                 layer1_offset = rootmap->phys_offset +
144                                 HAMMER_BLOCKMAP_LAYER1_OFFSET(scan1);
145                 layer1 = get_buffer_data(layer1_offset, &buffer1, 0);
146
147                 xerr = ' ';  /* good */
148                 if (layer1->layer1_crc !=
149                     crc32(layer1, HAMMER_LAYER1_CRCSIZE)) {
150                         xerr = 'B';
151                         ++num_bad_layer1;
152                 }
153                 if (xerr == ' ' &&
154                     layer1->phys_offset == HAMMER_BLOCKMAP_UNAVAIL) {
155                         continue;
156                 }
157                 printf("%c layer1 %016jx @%016jx blocks-free %jd\n",
158                         xerr,
159                         (uintmax_t)scan1,
160                         (uintmax_t)layer1->phys_offset,
161                         (intmax_t)layer1->blocks_free);
162
163                 for (scan2 = scan1;
164                      scan2 < scan1 + HAMMER_BLOCKMAP_LAYER2;
165                      scan2 += HAMMER_BIGBLOCK_SIZE) {
166                         /*
167                          * Dive layer 2, each entry represents a big-block.
168                          */
169                         layer2_offset = layer1->phys_offset +
170                                         HAMMER_BLOCKMAP_LAYER2_OFFSET(scan2);
171                         layer2 = get_buffer_data(layer2_offset, &buffer2, 0);
172
173                         xerr = ' ';  /* good */
174                         if (layer2->entry_crc !=
175                             crc32(layer2, HAMMER_LAYER2_CRCSIZE)) {
176                                 xerr = 'B';
177                                 ++num_bad_layer2;
178                         }
179                         printf("%c       %016jx zone=%-2d ",
180                                 xerr,
181                                 (uintmax_t)scan2,
182                                 layer2->zone);
183                         if (VerboseOpt > 1)
184                                 printf("vol=%-3d L1=%-7lu L2=%-7lu ",
185                                         HAMMER_VOL_DECODE(scan2),
186                                         HAMMER_BLOCKMAP_LAYER1_OFFSET(scan2),
187                                         HAMMER_BLOCKMAP_LAYER2_OFFSET(scan2));
188                         else if (VerboseOpt > 0)
189                                 printf("vol=%-3d L1=%-6d L2=%-6d ",
190                                         HAMMER_VOL_DECODE(scan2),
191                                         HAMMER_BLOCKMAP_LAYER1_INDEX(scan2),
192                                         HAMMER_BLOCKMAP_LAYER2_INDEX(scan2));
193                         printf("app=%-7d free=%-7d",
194                                 layer2->append_off,
195                                 layer2->bytes_free);
196                         if (VerboseOpt) {
197                                 double bytes_used;
198                                 if (layer2->zone != HAMMER_ZONE_UNAVAIL_INDEX) {
199                                         bytes_used = HAMMER_BIGBLOCK_SIZE -
200                                                 layer2->bytes_free;
201                                 } else {
202                                         /* UNAVAIL zone has 0 for bytes_free */
203                                         bytes_used = 0;
204                                 }
205                                 printf(" fill=%-5.1lf crc=%08x-%08x\n",
206                                         bytes_used * 100 / HAMMER_BIGBLOCK_SIZE,
207                                         layer1->layer1_crc,
208                                         layer2->entry_crc);
209                         } else {
210                                 printf("\n");
211                         }
212
213                         if (VerboseOpt)
214                                 hammer_add_zone_stat_layer2(stats, layer2);
215                 }
216         }
217         rel_buffer(buffer1);
218         rel_buffer(buffer2);
219         rel_volume(root_volume);
220
221         if (VerboseOpt) {
222                 hammer_print_zone_stat(stats);
223                 hammer_cleanup_zone_stat(stats);
224         }
225
226         if (num_bad_layer1 || VerboseOpt) {
227                 printf("%d bad layer1\n", num_bad_layer1);
228         }
229         if (num_bad_layer2 || VerboseOpt) {
230                 printf("%d bad layer2\n", num_bad_layer1);
231         }
232 }
233
234 void
235 hammer_cmd_checkmap(void)
236 {
237         struct volume_info *volume;
238         hammer_blockmap_t freemap;
239         hammer_blockmap_t undomap;
240         hammer_off_t node_offset;
241
242         volume = get_volume(RootVolNo);
243         node_offset = volume->ondisk->vol0_btree_root;
244         freemap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_FREEMAP_INDEX];
245         undomap = &volume->ondisk->vol0_blockmap[HAMMER_ZONE_UNDO_INDEX];
246
247         if (QuietOpt < 3) {
248                 printf("Volume header\trecords=%jd next_tid=%016jx\n",
249                        (intmax_t)volume->ondisk->vol0_stat_records,
250                        (uintmax_t)volume->ondisk->vol0_next_tid);
251                 printf("\t\tbufoffset=%016jx\n",
252                        (uintmax_t)volume->ondisk->vol_buf_beg);
253                 printf("\t\tundosize=%jdMB\n",
254                        (intmax_t)((undomap->alloc_offset & HAMMER_OFF_LONG_MASK)
255                         / (1024 * 1024)));
256         }
257         rel_volume(volume);
258
259         AssertOnFailure = (DebugOpt != 0);
260
261         printf("Collecting allocation info from freemap: ");
262         fflush(stdout);
263         check_freemap(freemap);
264         printf("done\n");
265
266         printf("Collecting allocation info from B-Tree: ");
267         fflush(stdout);
268         check_btree_node(node_offset, 0);
269         printf("done\n");
270
271         printf("Collecting allocation info from UNDO: ");
272         fflush(stdout);
273         check_undo(undomap);
274         printf("done\n");
275
276         dump_collect_table();
277         AssertOnFailure = 1;
278 }
279
280 static void
281 check_freemap(hammer_blockmap_t freemap)
282 {
283         hammer_off_t offset;
284         struct buffer_info *buffer1 = NULL;
285         struct hammer_blockmap_layer1 *layer1;
286         int i;
287
288         collect_freemap_layer1(freemap);
289
290         for (i = 0; i < HAMMER_BLOCKMAP_RADIX1; ++i) {
291                 offset = freemap->phys_offset + i * sizeof(*layer1);
292                 layer1 = get_buffer_data(offset, &buffer1, 0);
293                 if (layer1->phys_offset != HAMMER_BLOCKMAP_UNAVAIL)
294                         collect_freemap_layer2(layer1);
295         }
296         rel_buffer(buffer1);
297 }
298
299 static void
300 check_btree_node(hammer_off_t node_offset, int depth)
301 {
302         struct buffer_info *buffer = NULL;
303         hammer_node_ondisk_t node;
304         hammer_btree_elm_t elm;
305         int i;
306         char badc = ' ';  /* good */
307         char badm = ' ';  /* good */
308
309         if (depth == 0)
310                 collect_btree_root(node_offset);
311         node = get_node(node_offset, &buffer);
312
313         if (node == NULL) {
314                 badc = 'B';
315                 badm = 'I';
316         } else if (crc32(&node->crc + 1, HAMMER_BTREE_CRCSIZE) != node->crc) {
317                 badc = 'B';
318         }
319
320         if (badm != ' ' || badc != ' ') {  /* not good */
321                 ++num_bad_node;
322                 printf("%c%c   NODE %016jx ",
323                         badc, badm, (uintmax_t)node_offset);
324                 if (node == NULL) {
325                         printf("(IO ERROR)\n");
326                         rel_buffer(buffer);
327                         return;
328                 } else {
329                         printf("cnt=%02d p=%016jx type=%c depth=%d mirror=%016jx\n",
330                                node->count,
331                                (uintmax_t)node->parent,
332                                (node->type ? node->type : '?'),
333                                depth,
334                                (uintmax_t)node->mirror_tid);
335                 }
336         }
337
338         for (i = 0; i < node->count; ++i) {
339                 elm = &node->elms[i];
340
341                 switch(node->type) {
342                 case HAMMER_BTREE_TYPE_INTERNAL:
343                         if (elm->internal.subtree_offset) {
344                                 collect_btree_internal(elm);
345                                 check_btree_node(elm->internal.subtree_offset,
346                                                  depth + 1);
347                         }
348                         break;
349                 case HAMMER_BTREE_TYPE_LEAF:
350                         if (elm->leaf.data_offset)
351                                 collect_btree_leaf(elm);
352                         break;
353                 default:
354                         if (AssertOnFailure)
355                                 assert(0);
356                         break;
357                 }
358         }
359         rel_buffer(buffer);
360 }
361
362 static void
363 check_undo(hammer_blockmap_t undomap)
364 {
365         struct buffer_info *buffer = NULL;
366         hammer_off_t scan_offset;
367         hammer_fifo_head_t head;
368
369         scan_offset = HAMMER_ZONE_ENCODE(HAMMER_ZONE_UNDO_INDEX, 0);
370         while (scan_offset < undomap->alloc_offset) {
371                 head = get_buffer_data(scan_offset, &buffer, 0);
372                 switch (head->hdr_type) {
373                 case HAMMER_HEAD_TYPE_PAD:
374                 case HAMMER_HEAD_TYPE_DUMMY:
375                 case HAMMER_HEAD_TYPE_UNDO:
376                 case HAMMER_HEAD_TYPE_REDO:
377                         collect_undo(scan_offset, head);
378                         break;
379                 default:
380                         if (AssertOnFailure)
381                                 assert(0);
382                         break;
383                 }
384                 if ((head->hdr_size & HAMMER_HEAD_ALIGN_MASK) ||
385                      head->hdr_size == 0 ||
386                      head->hdr_size > HAMMER_UNDO_ALIGN -
387                         ((u_int)scan_offset & HAMMER_UNDO_MASK)) {
388                         printf("Illegal size, skipping to next boundary\n");
389                         scan_offset = (scan_offset + HAMMER_UNDO_MASK) &
390                                         ~HAMMER_UNDO_MASK64;
391                 } else {
392                         scan_offset += head->hdr_size;
393                 }
394         }
395         rel_buffer(buffer);
396 }
397
398 static __inline
399 void
400 collect_freemap_layer1(hammer_blockmap_t freemap)
401 {
402         /*
403          * This translation is necessary to do checkmap properly
404          * as zone4 is really just zone2 address space.
405          */
406         hammer_off_t zone4_offset = hammer_xlate_to_zoneX(
407                 HAMMER_ZONE_FREEMAP_INDEX, freemap->phys_offset);
408         collect_blockmap(zone4_offset, HAMMER_BIGBLOCK_SIZE,
409                 HAMMER_ZONE_FREEMAP_INDEX);
410 }
411
412 static __inline
413 void
414 collect_freemap_layer2(struct hammer_blockmap_layer1 *layer1)
415 {
416         /*
417          * This translation is necessary to do checkmap properly
418          * as zone4 is really just zone2 address space.
419          */
420         hammer_off_t zone4_offset = hammer_xlate_to_zoneX(
421                 HAMMER_ZONE_FREEMAP_INDEX, layer1->phys_offset);
422         collect_blockmap(zone4_offset, HAMMER_BIGBLOCK_SIZE,
423                 HAMMER_ZONE_FREEMAP_INDEX);
424 }
425
426 static __inline
427 void
428 collect_btree_root(hammer_off_t node_offset)
429 {
430         collect_blockmap(node_offset,
431                 sizeof(struct hammer_node_ondisk),  /* 4KB */
432                 HAMMER_ZONE_BTREE_INDEX);
433 }
434
435 static __inline
436 void
437 collect_btree_internal(hammer_btree_elm_t elm)
438 {
439         collect_blockmap(elm->internal.subtree_offset,
440                 sizeof(struct hammer_node_ondisk),  /* 4KB */
441                 HAMMER_ZONE_BTREE_INDEX);
442 }
443
444 static __inline
445 void
446 collect_btree_leaf(hammer_btree_elm_t elm)
447 {
448         int zone;
449
450         switch (elm->base.rec_type) {
451         case HAMMER_RECTYPE_INODE:
452         case HAMMER_RECTYPE_DIRENTRY:
453         case HAMMER_RECTYPE_EXT:
454         case HAMMER_RECTYPE_FIX:
455         case HAMMER_RECTYPE_PFS:
456         case HAMMER_RECTYPE_SNAPSHOT:
457         case HAMMER_RECTYPE_CONFIG:
458                 zone = HAMMER_ZONE_META_INDEX;
459                 break;
460         case HAMMER_RECTYPE_DATA:
461         case HAMMER_RECTYPE_DB:
462                 zone = hammer_data_zone_index(elm->leaf.data_len);
463                 break;
464         default:
465                 zone = HAMMER_ZONE_UNAVAIL_INDEX;
466                 break;
467         }
468         collect_blockmap(elm->leaf.data_offset,
469                 (elm->leaf.data_len + 15) & ~15, zone);
470 }
471
472 static __inline
473 void
474 collect_undo(hammer_off_t scan_offset, hammer_fifo_head_t head)
475 {
476         collect_blockmap(scan_offset, head->hdr_size,
477                 HAMMER_ZONE_UNDO_INDEX);
478 }
479
480 static
481 void
482 collect_blockmap(hammer_off_t offset, int32_t length, int zone)
483 {
484         struct hammer_blockmap_layer1 layer1;
485         struct hammer_blockmap_layer2 layer2;
486         struct hammer_blockmap_layer2 *track2;
487         hammer_off_t result_offset;
488         collect_t collect;
489         int error;
490
491         result_offset = blockmap_lookup(offset, &layer1, &layer2, &error);
492         if (AssertOnFailure) {
493                 assert(HAMMER_ZONE_DECODE(offset) == zone);
494                 assert(HAMMER_ZONE_DECODE(result_offset) ==
495                         HAMMER_ZONE_RAW_BUFFER_INDEX);
496                 assert(error == 0);
497         }
498         collect = collect_get(layer1.phys_offset); /* layer2 address */
499         track2 = collect_get_track(collect, result_offset, zone, &layer2);
500         track2->bytes_free -= length;
501 }
502
503 static
504 collect_t
505 collect_get(hammer_off_t phys_offset)
506 {
507         collect_t collect;
508
509         collect = RB_LOOKUP(collect_rb_tree, &CollectTree, phys_offset);
510         if (collect)
511                 return(collect);
512
513         collect = calloc(sizeof(*collect), 1);
514         collect->track2 = malloc(HAMMER_BIGBLOCK_SIZE);  /* 1<<23 bytes */
515         collect->layer2 = malloc(HAMMER_BIGBLOCK_SIZE);  /* 1<<23 bytes */
516         collect->offsets = malloc(sizeof(hammer_off_t) * HAMMER_BLOCKMAP_RADIX2);
517         collect->phys_offset = phys_offset;
518         RB_INSERT(collect_rb_tree, &CollectTree, collect);
519         bzero(collect->track2, HAMMER_BIGBLOCK_SIZE);
520         bzero(collect->layer2, HAMMER_BIGBLOCK_SIZE);
521
522         return (collect);
523 }
524
525 static
526 void
527 collect_rel(collect_t collect)
528 {
529         free(collect->offsets);
530         free(collect->layer2);
531         free(collect->track2);
532         free(collect);
533 }
534
535 static
536 struct hammer_blockmap_layer2 *
537 collect_get_track(collect_t collect, hammer_off_t offset, int zone,
538                   struct hammer_blockmap_layer2 *layer2)
539 {
540         struct hammer_blockmap_layer2 *track2;
541         size_t i;
542
543         i = HAMMER_BLOCKMAP_LAYER2_INDEX(offset);
544         track2 = &collect->track2[i];
545         if (track2->entry_crc == 0) {
546                 collect->layer2[i] = *layer2;
547                 collect->offsets[i] = offset & ~HAMMER_BIGBLOCK_MASK64;
548                 track2->zone = zone;
549                 track2->bytes_free = HAMMER_BIGBLOCK_SIZE;
550                 track2->entry_crc = 1;  /* steal field to tag track load */
551         }
552         return (track2);
553 }
554
555 static
556 void
557 dump_collect_table(void)
558 {
559         collect_t collect;
560         int error = 0;
561         struct zone_stat *stats = NULL;
562
563         if (VerboseOpt)
564                 stats = hammer_init_zone_stat();
565
566         RB_FOREACH(collect, collect_rb_tree, &CollectTree) {
567                 dump_collect(collect, stats);
568                 error += collect->error;
569         }
570
571         while ((collect = RB_ROOT(&CollectTree)) != NULL) {
572                 RB_REMOVE(collect_rb_tree, &CollectTree, collect);
573                 collect_rel(collect);
574         }
575         assert(RB_EMPTY(&CollectTree));
576
577         if (VerboseOpt) {
578                 hammer_print_zone_stat(stats);
579                 hammer_cleanup_zone_stat(stats);
580         }
581
582         if (num_bad_node || VerboseOpt) {
583                 printf("%d bad nodes\n", num_bad_node);
584         }
585         if (error || VerboseOpt) {
586                 printf("%d errors\n", error);
587         }
588 }
589
590 static
591 void
592 dump_collect(collect_t collect, struct zone_stat *stats)
593 {
594         struct hammer_blockmap_layer2 *track2;
595         struct hammer_blockmap_layer2 *layer2;
596         hammer_off_t offset;
597         int i, zone;
598
599         for (i = 0; i < HAMMER_BLOCKMAP_RADIX2; ++i) {
600                 track2 = &collect->track2[i];
601                 layer2 = &collect->layer2[i];
602                 offset = collect->offsets[i];
603
604                 /*
605                  * Check big-blocks referenced by freemap, data,
606                  * B-Tree nodes and UNDO fifo.
607                  */
608                 if (track2->entry_crc == 0)
609                         continue;
610
611                 zone = layer2->zone;
612                 if (AssertOnFailure) {
613                         assert((zone == HAMMER_ZONE_UNDO_INDEX) ||
614                                 (zone == HAMMER_ZONE_FREEMAP_INDEX) ||
615                                 hammer_is_zone2_mapped_index(zone));
616                 }
617                 if (VerboseOpt)
618                         hammer_add_zone_stat_layer2(stats, layer2);
619
620                 if (track2->zone != layer2->zone) {
621                         printf("BZ\tblock=%016jx calc zone=%-2d, got zone=%-2d\n",
622                                 (intmax_t)offset,
623                                 track2->zone,
624                                 layer2->zone);
625                         collect->error++;
626                 } else if (track2->bytes_free != layer2->bytes_free) {
627                         printf("BM\tblock=%016jx zone=%-2d calc %d free, got %d\n",
628                                 (intmax_t)offset,
629                                 layer2->zone,
630                                 track2->bytes_free,
631                                 layer2->bytes_free);
632                         collect->error++;
633                 } else if (VerboseOpt) {
634                         printf("\tblock=%016jx zone=%-2d %d free (correct)\n",
635                                 (intmax_t)offset,
636                                 layer2->zone,
637                                 track2->bytes_free);
638                 }
639         }
640 }