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.1 2008/02/23 20:55:21 dillon Exp $ 35 */ 36 37 #include "hammer.h" 38 39 static void dump_blockmap(const char *label, int zone); 40 41 void 42 hammer_cmd_blockmap(void) 43 { 44 dump_blockmap("btree", HAMMER_ZONE_BTREE_INDEX); 45 dump_blockmap("record", HAMMER_ZONE_RECORD_INDEX); 46 dump_blockmap("large-data", HAMMER_ZONE_LARGE_DATA_INDEX); 47 dump_blockmap("small-data", HAMMER_ZONE_SMALL_DATA_INDEX); 48 } 49 50 static 51 void 52 dump_blockmap(const char *label, int zone) 53 { 54 struct volume_info *root_volume; 55 hammer_blockmap_t rootmap; 56 struct hammer_blockmap_layer1 *layer1; 57 struct hammer_blockmap_layer2 *layer2; 58 struct buffer_info *buffer1 = NULL; 59 struct buffer_info *buffer2 = NULL; 60 hammer_off_t layer1_offset; 61 hammer_off_t layer2_offset; 62 hammer_off_t scan1; 63 hammer_off_t scan2; 64 65 assert(zone >= HAMMER_ZONE_BTREE_INDEX && zone < HAMMER_MAX_ZONES); 66 assert(RootVolNo >= 0); 67 root_volume = get_volume(RootVolNo); 68 rootmap = &root_volume->ondisk->vol0_blockmap[zone]; 69 assert(rootmap->phys_offset != 0); 70 71 printf("zone %-16s next %016llx alloc %016llx\n", 72 label, rootmap->next_offset, rootmap->alloc_offset); 73 74 for (scan1 = HAMMER_ZONE_ENCODE(zone, 0); 75 scan1 < rootmap->alloc_offset; 76 scan1 += HAMMER_BLOCKMAP_LAYER1) { 77 /* 78 * Dive layer 1. 79 */ 80 layer1_offset = rootmap->phys_offset + 81 HAMMER_BLOCKMAP_LAYER1_OFFSET(scan1); 82 layer1 = get_buffer_data(layer1_offset, &buffer1, 0); 83 printf(" layer1 %016llx @%016llx blocks-free %lld\n", 84 scan1, layer1->phys_offset, layer1->blocks_free); 85 if (layer1->phys_offset == HAMMER_BLOCKMAP_FREE) 86 continue; 87 for (scan2 = scan1; 88 scan2 < scan1 + HAMMER_BLOCKMAP_LAYER1 && 89 scan2 < rootmap->alloc_offset; 90 scan2 += HAMMER_LARGEBLOCK_SIZE 91 ) { 92 /* 93 * Dive layer 2, each entry represents a large-block. 94 */ 95 layer2_offset = layer1->phys_offset + 96 HAMMER_BLOCKMAP_LAYER2_OFFSET(scan2); 97 layer2 = get_buffer_data(layer2_offset, &buffer2, 0); 98 switch(layer2->u.phys_offset) { 99 case HAMMER_BLOCKMAP_FREE: 100 break; 101 case HAMMER_BLOCKMAP_UNAVAIL: 102 break; 103 default: 104 printf(" %016llx @%016llx " 105 "free %3d%% (%u)\n", 106 scan2, layer2->u.phys_offset, 107 layer2->bytes_free * 100 / 108 HAMMER_LARGEBLOCK_SIZE, 109 layer2->bytes_free); 110 break; 111 } 112 } 113 } 114 if (buffer1) 115 rel_buffer(buffer1); 116 if (buffer2) 117 rel_buffer(buffer2); 118 rel_volume(root_volume); 119 } 120 121