1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5*ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6*ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 22*ea8dc4b6Seschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #pragma ident "%Z%%M% %I% %E% SMI" 27fa9e4066Sahrens 28fa9e4066Sahrens #include <stdio.h> 29fa9e4066Sahrens #include <stdlib.h> 30fa9e4066Sahrens #include <sys/zfs_context.h> 31fa9e4066Sahrens #include <sys/spa.h> 32fa9e4066Sahrens #include <sys/spa_impl.h> 33fa9e4066Sahrens #include <sys/dmu.h> 34fa9e4066Sahrens #include <sys/zap.h> 35fa9e4066Sahrens #include <sys/fs/zfs.h> 36fa9e4066Sahrens #include <sys/zfs_znode.h> 37fa9e4066Sahrens #include <sys/vdev.h> 38fa9e4066Sahrens #include <sys/vdev_impl.h> 39fa9e4066Sahrens #include <sys/metaslab_impl.h> 40fa9e4066Sahrens #include <sys/dmu_objset.h> 41fa9e4066Sahrens #include <sys/dsl_dir.h> 42fa9e4066Sahrens #include <sys/dsl_dataset.h> 43fa9e4066Sahrens #include <sys/dsl_pool.h> 44fa9e4066Sahrens #include <sys/dbuf.h> 45fa9e4066Sahrens #include <sys/zil.h> 46fa9e4066Sahrens #include <sys/zil_impl.h> 47fa9e4066Sahrens #include <sys/stat.h> 48fa9e4066Sahrens #include <sys/resource.h> 49fa9e4066Sahrens #include <sys/dmu_traverse.h> 50fa9e4066Sahrens #include <sys/zio_checksum.h> 51fa9e4066Sahrens #include <sys/zio_compress.h> 52fa9e4066Sahrens 53fa9e4066Sahrens const char cmdname[] = "zdb"; 54fa9e4066Sahrens uint8_t dump_opt[256]; 55fa9e4066Sahrens 56fa9e4066Sahrens typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size); 57fa9e4066Sahrens 58fa9e4066Sahrens extern void dump_intent_log(zilog_t *); 59fa9e4066Sahrens uint64_t *zopt_object = NULL; 60fa9e4066Sahrens int zopt_objects = 0; 61fa9e4066Sahrens int zdb_advance = ADVANCE_PRE; 62fa9e4066Sahrens zbookmark_t zdb_noread = { 0, 0, ZB_NO_LEVEL, 0 }; 63fa9e4066Sahrens 64fa9e4066Sahrens /* 65fa9e4066Sahrens * These libumem hooks provide a reasonable set of defaults for the allocator's 66fa9e4066Sahrens * debugging facilities. 67fa9e4066Sahrens */ 68fa9e4066Sahrens const char * 69fa9e4066Sahrens _umem_debug_init() 70fa9e4066Sahrens { 71fa9e4066Sahrens return ("default,verbose"); /* $UMEM_DEBUG setting */ 72fa9e4066Sahrens } 73fa9e4066Sahrens 74fa9e4066Sahrens const char * 75fa9e4066Sahrens _umem_logging_init(void) 76fa9e4066Sahrens { 77fa9e4066Sahrens return ("fail,contents"); /* $UMEM_LOGGING setting */ 78fa9e4066Sahrens } 79fa9e4066Sahrens 80fa9e4066Sahrens static void 81fa9e4066Sahrens usage(void) 82fa9e4066Sahrens { 83fa9e4066Sahrens (void) fprintf(stderr, 84fa9e4066Sahrens "Usage: %s [-udibcsvLU] [-O order] [-B os:obj:level:blkid] " 85fa9e4066Sahrens "dataset [object...]\n" 86fa9e4066Sahrens " %s -C [pool]\n" 87fa9e4066Sahrens " %s -l dev\n", 88fa9e4066Sahrens cmdname, cmdname, cmdname); 89fa9e4066Sahrens 90fa9e4066Sahrens (void) fprintf(stderr, " -u uberblock\n"); 91fa9e4066Sahrens (void) fprintf(stderr, " -d datasets\n"); 92fa9e4066Sahrens (void) fprintf(stderr, " -C cached pool configuration\n"); 93fa9e4066Sahrens (void) fprintf(stderr, " -i intent logs\n"); 94fa9e4066Sahrens (void) fprintf(stderr, " -b block statistics\n"); 95fa9e4066Sahrens (void) fprintf(stderr, " -c checksum all data blocks\n"); 96fa9e4066Sahrens (void) fprintf(stderr, " -s report stats on zdb's I/O\n"); 97fa9e4066Sahrens (void) fprintf(stderr, " -v verbose (applies to all others)\n"); 98fa9e4066Sahrens (void) fprintf(stderr, " -l dump label contents\n"); 99fa9e4066Sahrens (void) fprintf(stderr, " -L live pool (allows some errors)\n"); 100fa9e4066Sahrens (void) fprintf(stderr, " -O [!]<pre|post|prune|data|holes> " 101fa9e4066Sahrens "visitation order\n"); 102fa9e4066Sahrens (void) fprintf(stderr, " -U use zpool.cache in /tmp\n"); 103fa9e4066Sahrens (void) fprintf(stderr, " -B objset:object:level:blkid -- " 104fa9e4066Sahrens "simulate bad block\n"); 105fa9e4066Sahrens (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) " 106fa9e4066Sahrens "to make only that option verbose\n"); 107fa9e4066Sahrens (void) fprintf(stderr, "Default is to dump everything non-verbosely\n"); 108fa9e4066Sahrens exit(1); 109fa9e4066Sahrens } 110fa9e4066Sahrens 111fa9e4066Sahrens static void 112fa9e4066Sahrens fatal(const char *fmt, ...) 113fa9e4066Sahrens { 114fa9e4066Sahrens va_list ap; 115fa9e4066Sahrens 116fa9e4066Sahrens va_start(ap, fmt); 117fa9e4066Sahrens (void) fprintf(stderr, "%s: ", cmdname); 118fa9e4066Sahrens (void) vfprintf(stderr, fmt, ap); 119fa9e4066Sahrens va_end(ap); 120fa9e4066Sahrens (void) fprintf(stderr, "\n"); 121fa9e4066Sahrens 122fa9e4066Sahrens exit(1); 123fa9e4066Sahrens } 124fa9e4066Sahrens 125fa9e4066Sahrens static void 126fa9e4066Sahrens dump_nvlist(nvlist_t *list, int indent) 127fa9e4066Sahrens { 128fa9e4066Sahrens nvpair_t *elem = NULL; 129fa9e4066Sahrens 130fa9e4066Sahrens while ((elem = nvlist_next_nvpair(list, elem)) != NULL) { 131fa9e4066Sahrens switch (nvpair_type(elem)) { 132fa9e4066Sahrens case DATA_TYPE_STRING: 133fa9e4066Sahrens { 134fa9e4066Sahrens char *value; 135fa9e4066Sahrens 136fa9e4066Sahrens VERIFY(nvpair_value_string(elem, &value) == 0); 137fa9e4066Sahrens (void) printf("%*s%s='%s'\n", indent, "", 138fa9e4066Sahrens nvpair_name(elem), value); 139fa9e4066Sahrens } 140fa9e4066Sahrens break; 141fa9e4066Sahrens 142fa9e4066Sahrens case DATA_TYPE_UINT64: 143fa9e4066Sahrens { 144fa9e4066Sahrens uint64_t value; 145fa9e4066Sahrens 146fa9e4066Sahrens VERIFY(nvpair_value_uint64(elem, &value) == 0); 147fa9e4066Sahrens (void) printf("%*s%s=%llu\n", indent, "", 148fa9e4066Sahrens nvpair_name(elem), (u_longlong_t)value); 149fa9e4066Sahrens } 150fa9e4066Sahrens break; 151fa9e4066Sahrens 152fa9e4066Sahrens case DATA_TYPE_NVLIST: 153fa9e4066Sahrens { 154fa9e4066Sahrens nvlist_t *value; 155fa9e4066Sahrens 156fa9e4066Sahrens VERIFY(nvpair_value_nvlist(elem, &value) == 0); 157fa9e4066Sahrens (void) printf("%*s%s\n", indent, "", 158fa9e4066Sahrens nvpair_name(elem)); 159fa9e4066Sahrens dump_nvlist(value, indent + 4); 160fa9e4066Sahrens } 161fa9e4066Sahrens break; 162fa9e4066Sahrens 163fa9e4066Sahrens case DATA_TYPE_NVLIST_ARRAY: 164fa9e4066Sahrens { 165fa9e4066Sahrens nvlist_t **value; 166fa9e4066Sahrens uint_t c, count; 167fa9e4066Sahrens 168fa9e4066Sahrens VERIFY(nvpair_value_nvlist_array(elem, &value, 169fa9e4066Sahrens &count) == 0); 170fa9e4066Sahrens 171fa9e4066Sahrens for (c = 0; c < count; c++) { 172fa9e4066Sahrens (void) printf("%*s%s[%u]\n", indent, "", 173fa9e4066Sahrens nvpair_name(elem), c); 174fa9e4066Sahrens dump_nvlist(value[c], indent + 8); 175fa9e4066Sahrens } 176fa9e4066Sahrens } 177fa9e4066Sahrens break; 178fa9e4066Sahrens 179fa9e4066Sahrens default: 180fa9e4066Sahrens 181fa9e4066Sahrens (void) printf("bad config type %d for %s\n", 182fa9e4066Sahrens nvpair_type(elem), nvpair_name(elem)); 183fa9e4066Sahrens } 184fa9e4066Sahrens } 185fa9e4066Sahrens } 186fa9e4066Sahrens 187fa9e4066Sahrens /* ARGSUSED */ 188fa9e4066Sahrens static void 189fa9e4066Sahrens dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size) 190fa9e4066Sahrens { 191fa9e4066Sahrens nvlist_t *nv; 192fa9e4066Sahrens size_t nvsize = *(uint64_t *)data; 193fa9e4066Sahrens char *packed = umem_alloc(nvsize, UMEM_NOFAIL); 194fa9e4066Sahrens 195*ea8dc4b6Seschrock VERIFY(0 == dmu_read(os, object, 0, nvsize, packed)); 196fa9e4066Sahrens 197fa9e4066Sahrens VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0); 198fa9e4066Sahrens 199fa9e4066Sahrens umem_free(packed, nvsize); 200fa9e4066Sahrens 201fa9e4066Sahrens dump_nvlist(nv, 8); 202fa9e4066Sahrens 203fa9e4066Sahrens nvlist_free(nv); 204fa9e4066Sahrens } 205fa9e4066Sahrens 206fa9e4066Sahrens const char dump_zap_stars[] = "****************************************"; 207fa9e4066Sahrens const int dump_zap_width = sizeof (dump_zap_stars) - 1; 208fa9e4066Sahrens 209fa9e4066Sahrens static void 210fa9e4066Sahrens dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE]) 211fa9e4066Sahrens { 212fa9e4066Sahrens int i; 213fa9e4066Sahrens int minidx = ZAP_HISTOGRAM_SIZE - 1; 214fa9e4066Sahrens int maxidx = 0; 215fa9e4066Sahrens uint64_t max = 0; 216fa9e4066Sahrens 217fa9e4066Sahrens for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) { 218fa9e4066Sahrens if (histo[i] > max) 219fa9e4066Sahrens max = histo[i]; 220fa9e4066Sahrens if (histo[i] > 0 && i > maxidx) 221fa9e4066Sahrens maxidx = i; 222fa9e4066Sahrens if (histo[i] > 0 && i < minidx) 223fa9e4066Sahrens minidx = i; 224fa9e4066Sahrens } 225fa9e4066Sahrens 226fa9e4066Sahrens if (max < dump_zap_width) 227fa9e4066Sahrens max = dump_zap_width; 228fa9e4066Sahrens 229fa9e4066Sahrens for (i = minidx; i <= maxidx; i++) 230fa9e4066Sahrens (void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i], 231fa9e4066Sahrens &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]); 232fa9e4066Sahrens } 233fa9e4066Sahrens 234fa9e4066Sahrens static void 235fa9e4066Sahrens dump_zap_stats(objset_t *os, uint64_t object) 236fa9e4066Sahrens { 237fa9e4066Sahrens int error; 238fa9e4066Sahrens zap_stats_t zs; 239fa9e4066Sahrens 240fa9e4066Sahrens error = zap_get_stats(os, object, &zs); 241fa9e4066Sahrens if (error) 242fa9e4066Sahrens return; 243fa9e4066Sahrens 244fa9e4066Sahrens if (zs.zs_ptrtbl_len == 0) { 245fa9e4066Sahrens ASSERT(zs.zs_num_blocks == 1); 246fa9e4066Sahrens (void) printf("\tmicrozap: %llu bytes, %llu entries\n", 247fa9e4066Sahrens (u_longlong_t)zs.zs_blocksize, 248fa9e4066Sahrens (u_longlong_t)zs.zs_num_entries); 249fa9e4066Sahrens return; 250fa9e4066Sahrens } 251fa9e4066Sahrens 252fa9e4066Sahrens (void) printf("\tFat ZAP stats:\n"); 253fa9e4066Sahrens (void) printf("\t\tPointer table: %llu elements\n", 254fa9e4066Sahrens (u_longlong_t)zs.zs_ptrtbl_len); 255fa9e4066Sahrens (void) printf("\t\tZAP entries: %llu\n", 256fa9e4066Sahrens (u_longlong_t)zs.zs_num_entries); 257fa9e4066Sahrens (void) printf("\t\tLeaf blocks: %llu\n", 258fa9e4066Sahrens (u_longlong_t)zs.zs_num_leafs); 259fa9e4066Sahrens (void) printf("\t\tTotal blocks: %llu\n", 260fa9e4066Sahrens (u_longlong_t)zs.zs_num_blocks); 261fa9e4066Sahrens (void) printf("\t\tOversize blocks: %llu\n", 262fa9e4066Sahrens (u_longlong_t)zs.zs_num_blocks_large); 263fa9e4066Sahrens 264fa9e4066Sahrens (void) printf("\t\tLeafs with 2^n pointers:\n"); 265fa9e4066Sahrens dump_zap_histogram(zs.zs_leafs_with_2n_pointers); 266fa9e4066Sahrens 267fa9e4066Sahrens (void) printf("\t\tLeafs with n chained:\n"); 268fa9e4066Sahrens dump_zap_histogram(zs.zs_leafs_with_n_chained); 269fa9e4066Sahrens 270fa9e4066Sahrens (void) printf("\t\tBlocks with n*5 entries:\n"); 271fa9e4066Sahrens dump_zap_histogram(zs.zs_blocks_with_n5_entries); 272fa9e4066Sahrens 273fa9e4066Sahrens (void) printf("\t\tBlocks n/10 full:\n"); 274fa9e4066Sahrens dump_zap_histogram(zs.zs_blocks_n_tenths_full); 275fa9e4066Sahrens 276fa9e4066Sahrens (void) printf("\t\tEntries with n chunks:\n"); 277fa9e4066Sahrens dump_zap_histogram(zs.zs_entries_using_n_chunks); 278fa9e4066Sahrens 279fa9e4066Sahrens (void) printf("\t\tBuckets with n entries:\n"); 280fa9e4066Sahrens dump_zap_histogram(zs.zs_buckets_with_n_entries); 281fa9e4066Sahrens } 282fa9e4066Sahrens 283fa9e4066Sahrens /*ARGSUSED*/ 284fa9e4066Sahrens static void 285fa9e4066Sahrens dump_none(objset_t *os, uint64_t object, void *data, size_t size) 286fa9e4066Sahrens { 287fa9e4066Sahrens } 288fa9e4066Sahrens 289fa9e4066Sahrens /*ARGSUSED*/ 290fa9e4066Sahrens void 291fa9e4066Sahrens dump_uint8(objset_t *os, uint64_t object, void *data, size_t size) 292fa9e4066Sahrens { 293fa9e4066Sahrens } 294fa9e4066Sahrens 295fa9e4066Sahrens /*ARGSUSED*/ 296fa9e4066Sahrens static void 297fa9e4066Sahrens dump_uint64(objset_t *os, uint64_t object, void *data, size_t size) 298fa9e4066Sahrens { 299fa9e4066Sahrens } 300fa9e4066Sahrens 301fa9e4066Sahrens /*ARGSUSED*/ 302fa9e4066Sahrens static void 303fa9e4066Sahrens dump_zap(objset_t *os, uint64_t object, void *data, size_t size) 304fa9e4066Sahrens { 305fa9e4066Sahrens zap_cursor_t zc; 306fa9e4066Sahrens zap_attribute_t attr; 307fa9e4066Sahrens void *prop; 308fa9e4066Sahrens int i; 309fa9e4066Sahrens 310fa9e4066Sahrens dump_zap_stats(os, object); 311fa9e4066Sahrens (void) printf("\n"); 312fa9e4066Sahrens 313fa9e4066Sahrens for (zap_cursor_init(&zc, os, object); 314fa9e4066Sahrens zap_cursor_retrieve(&zc, &attr) == 0; 315fa9e4066Sahrens zap_cursor_advance(&zc)) { 316fa9e4066Sahrens (void) printf("\t\t%s = ", attr.za_name); 317fa9e4066Sahrens if (attr.za_num_integers == 0) { 318fa9e4066Sahrens (void) printf("\n"); 319fa9e4066Sahrens continue; 320fa9e4066Sahrens } 321fa9e4066Sahrens prop = umem_zalloc(attr.za_num_integers * 322fa9e4066Sahrens attr.za_integer_length, UMEM_NOFAIL); 323fa9e4066Sahrens (void) zap_lookup(os, object, attr.za_name, 324fa9e4066Sahrens attr.za_integer_length, attr.za_num_integers, prop); 325fa9e4066Sahrens if (attr.za_integer_length == 1) { 326fa9e4066Sahrens (void) printf("%s", (char *)prop); 327fa9e4066Sahrens } else { 328fa9e4066Sahrens for (i = 0; i < attr.za_num_integers; i++) { 329fa9e4066Sahrens switch (attr.za_integer_length) { 330fa9e4066Sahrens case 2: 331fa9e4066Sahrens (void) printf("%u ", 332fa9e4066Sahrens ((uint16_t *)prop)[i]); 333fa9e4066Sahrens break; 334fa9e4066Sahrens case 4: 335fa9e4066Sahrens (void) printf("%u ", 336fa9e4066Sahrens ((uint32_t *)prop)[i]); 337fa9e4066Sahrens break; 338fa9e4066Sahrens case 8: 339fa9e4066Sahrens (void) printf("%lld ", 340fa9e4066Sahrens (u_longlong_t)((int64_t *)prop)[i]); 341fa9e4066Sahrens break; 342fa9e4066Sahrens } 343fa9e4066Sahrens } 344fa9e4066Sahrens } 345fa9e4066Sahrens (void) printf("\n"); 346fa9e4066Sahrens umem_free(prop, attr.za_num_integers * attr.za_integer_length); 347fa9e4066Sahrens } 34887e5029aSahrens zap_cursor_fini(&zc); 349fa9e4066Sahrens } 350fa9e4066Sahrens 351fa9e4066Sahrens static void 352fa9e4066Sahrens dump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm) 353fa9e4066Sahrens { 354fa9e4066Sahrens uint64_t alloc, offset, entry; 355fa9e4066Sahrens int mapshift = sm->sm_shift; 356fa9e4066Sahrens uint64_t mapstart = sm->sm_start; 357fa9e4066Sahrens char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID" }; 358fa9e4066Sahrens 359fa9e4066Sahrens if (smo->smo_object == 0) 360fa9e4066Sahrens return; 361fa9e4066Sahrens 362fa9e4066Sahrens /* 363fa9e4066Sahrens * Print out the freelist entries in both encoded and decoded form. 364fa9e4066Sahrens */ 365fa9e4066Sahrens alloc = 0; 366fa9e4066Sahrens for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) { 367*ea8dc4b6Seschrock VERIFY(0 == dmu_read(os, smo->smo_object, offset, 368*ea8dc4b6Seschrock sizeof (entry), &entry)); 369fa9e4066Sahrens if (SM_DEBUG_DECODE(entry)) { 370fa9e4066Sahrens (void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n", 371fa9e4066Sahrens (u_longlong_t)(offset / sizeof (entry)), 372fa9e4066Sahrens ddata[SM_DEBUG_ACTION_DECODE(entry)], 373fa9e4066Sahrens SM_DEBUG_TXG_DECODE(entry), 374fa9e4066Sahrens SM_DEBUG_SYNCPASS_DECODE(entry)); 375fa9e4066Sahrens } else { 376fa9e4066Sahrens (void) printf("\t\t[%4llu] %c range:" 377fa9e4066Sahrens " %08llx-%08llx size: %06llx\n", 378fa9e4066Sahrens (u_longlong_t)(offset / sizeof (entry)), 379fa9e4066Sahrens SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F', 380fa9e4066Sahrens (SM_OFFSET_DECODE(entry) << mapshift) + mapstart, 381fa9e4066Sahrens (SM_OFFSET_DECODE(entry) << mapshift) + mapstart + 382fa9e4066Sahrens (SM_RUN_DECODE(entry) << mapshift), 383fa9e4066Sahrens (SM_RUN_DECODE(entry) << mapshift)); 384fa9e4066Sahrens if (SM_TYPE_DECODE(entry) == SM_ALLOC) 385fa9e4066Sahrens alloc += SM_RUN_DECODE(entry) << mapshift; 386fa9e4066Sahrens else 387fa9e4066Sahrens alloc -= SM_RUN_DECODE(entry) << mapshift; 388fa9e4066Sahrens } 389fa9e4066Sahrens } 390fa9e4066Sahrens if (alloc != smo->smo_alloc) { 391fa9e4066Sahrens (void) printf("space_map_object alloc (%llu) INCONSISTENT " 392fa9e4066Sahrens "with space map summary (%llu)\n", 393fa9e4066Sahrens (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc); 394fa9e4066Sahrens } 395fa9e4066Sahrens } 396fa9e4066Sahrens 397fa9e4066Sahrens static void 398fa9e4066Sahrens dump_metaslab(metaslab_t *msp) 399fa9e4066Sahrens { 400fa9e4066Sahrens char freebuf[5]; 401fa9e4066Sahrens space_map_obj_t *smo = msp->ms_smo; 402fa9e4066Sahrens vdev_t *vd = msp->ms_group->mg_vd; 403fa9e4066Sahrens spa_t *spa = vd->vdev_spa; 404fa9e4066Sahrens 405fa9e4066Sahrens nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf); 406fa9e4066Sahrens 407fa9e4066Sahrens if (dump_opt['d'] <= 5) { 408fa9e4066Sahrens (void) printf("\t%10llx %10llu %5s\n", 409fa9e4066Sahrens (u_longlong_t)msp->ms_map.sm_start, 410fa9e4066Sahrens (u_longlong_t)smo->smo_object, 411fa9e4066Sahrens freebuf); 412fa9e4066Sahrens return; 413fa9e4066Sahrens } 414fa9e4066Sahrens 415fa9e4066Sahrens (void) printf( 416fa9e4066Sahrens "\tvdev %llu offset %08llx spacemap %4llu free %5s\n", 417fa9e4066Sahrens (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start, 418fa9e4066Sahrens (u_longlong_t)smo->smo_object, freebuf); 419fa9e4066Sahrens 420fa9e4066Sahrens ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift)); 421fa9e4066Sahrens 422fa9e4066Sahrens dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map); 423fa9e4066Sahrens } 424fa9e4066Sahrens 425fa9e4066Sahrens static void 426fa9e4066Sahrens dump_metaslabs(spa_t *spa) 427fa9e4066Sahrens { 428fa9e4066Sahrens vdev_t *rvd = spa->spa_root_vdev; 429fa9e4066Sahrens vdev_t *vd; 430fa9e4066Sahrens int c, m; 431fa9e4066Sahrens 432fa9e4066Sahrens (void) printf("\nMetaslabs:\n"); 433fa9e4066Sahrens 434fa9e4066Sahrens for (c = 0; c < rvd->vdev_children; c++) { 435fa9e4066Sahrens vd = rvd->vdev_child[c]; 436fa9e4066Sahrens 437*ea8dc4b6Seschrock spa_config_enter(spa, RW_READER, FTAG); 438fa9e4066Sahrens (void) printf("\n vdev %llu = %s\n\n", 439fa9e4066Sahrens (u_longlong_t)vd->vdev_id, vdev_description(vd)); 440*ea8dc4b6Seschrock spa_config_exit(spa, FTAG); 441fa9e4066Sahrens 442fa9e4066Sahrens if (dump_opt['d'] <= 5) { 443fa9e4066Sahrens (void) printf("\t%10s %10s %5s\n", 444fa9e4066Sahrens "offset", "spacemap", "free"); 445fa9e4066Sahrens (void) printf("\t%10s %10s %5s\n", 446fa9e4066Sahrens "------", "--------", "----"); 447fa9e4066Sahrens } 448fa9e4066Sahrens for (m = 0; m < vd->vdev_ms_count; m++) 449fa9e4066Sahrens dump_metaslab(vd->vdev_ms[m]); 450fa9e4066Sahrens (void) printf("\n"); 451fa9e4066Sahrens } 452fa9e4066Sahrens } 453fa9e4066Sahrens 454fa9e4066Sahrens static void 455fa9e4066Sahrens dump_dtl(vdev_t *vd, int indent) 456fa9e4066Sahrens { 457fa9e4066Sahrens avl_tree_t *t = &vd->vdev_dtl_map.sm_root; 458fa9e4066Sahrens spa_t *spa = vd->vdev_spa; 459fa9e4066Sahrens space_seg_t *ss; 460fa9e4066Sahrens vdev_t *pvd; 461fa9e4066Sahrens int c; 462fa9e4066Sahrens 463fa9e4066Sahrens if (indent == 0) 464fa9e4066Sahrens (void) printf("\nDirty time logs:\n\n"); 465fa9e4066Sahrens 466*ea8dc4b6Seschrock spa_config_enter(spa, RW_READER, FTAG); 467fa9e4066Sahrens (void) printf("\t%*s%s\n", indent, "", vdev_description(vd)); 468*ea8dc4b6Seschrock spa_config_exit(spa, FTAG); 469fa9e4066Sahrens 470fa9e4066Sahrens for (ss = avl_first(t); ss; ss = AVL_NEXT(t, ss)) { 471fa9e4066Sahrens /* 472fa9e4066Sahrens * Everything in this DTL must appear in all parent DTL unions. 473fa9e4066Sahrens */ 474fa9e4066Sahrens for (pvd = vd; pvd; pvd = pvd->vdev_parent) 475fa9e4066Sahrens ASSERT(vdev_dtl_contains(&pvd->vdev_dtl_map, 476fa9e4066Sahrens ss->ss_start, ss->ss_end - ss->ss_start)); 477fa9e4066Sahrens (void) printf("\t%*soutage [%llu,%llu] length %llu\n", 478fa9e4066Sahrens indent, "", 479fa9e4066Sahrens (u_longlong_t)ss->ss_start, 480fa9e4066Sahrens (u_longlong_t)ss->ss_end - 1, 481fa9e4066Sahrens (u_longlong_t)ss->ss_end - ss->ss_start); 482fa9e4066Sahrens } 483fa9e4066Sahrens 484fa9e4066Sahrens (void) printf("\n"); 485fa9e4066Sahrens 486fa9e4066Sahrens if (dump_opt['d'] > 5 && vd->vdev_children == 0) { 487fa9e4066Sahrens dump_spacemap(vd->vdev_spa->spa_meta_objset, &vd->vdev_dtl, 488fa9e4066Sahrens &vd->vdev_dtl_map); 489fa9e4066Sahrens (void) printf("\n"); 490fa9e4066Sahrens } 491fa9e4066Sahrens 492fa9e4066Sahrens for (c = 0; c < vd->vdev_children; c++) 493fa9e4066Sahrens dump_dtl(vd->vdev_child[c], indent + 4); 494fa9e4066Sahrens } 495fa9e4066Sahrens 496fa9e4066Sahrens /*ARGSUSED*/ 497fa9e4066Sahrens static void 498fa9e4066Sahrens dump_dnode(objset_t *os, uint64_t object, void *data, size_t size) 499fa9e4066Sahrens { 500fa9e4066Sahrens } 501fa9e4066Sahrens 502fa9e4066Sahrens static uint64_t 503fa9e4066Sahrens blkid2offset(dnode_phys_t *dnp, int level, uint64_t blkid) 504fa9e4066Sahrens { 505fa9e4066Sahrens if (level < 0) 506fa9e4066Sahrens return (blkid); 507fa9e4066Sahrens 508fa9e4066Sahrens return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) * 509fa9e4066Sahrens dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT); 510fa9e4066Sahrens } 511fa9e4066Sahrens 512fa9e4066Sahrens /* ARGSUSED */ 513fa9e4066Sahrens static int 514fa9e4066Sahrens zdb_indirect_cb(traverse_blk_cache_t *bc, spa_t *spa, void *a) 515fa9e4066Sahrens { 516fa9e4066Sahrens zbookmark_t *zb = &bc->bc_bookmark; 517fa9e4066Sahrens blkptr_t *bp = &bc->bc_blkptr; 518fa9e4066Sahrens dva_t *dva = &bp->blk_dva[0]; 519fa9e4066Sahrens void *data = bc->bc_data; 520fa9e4066Sahrens dnode_phys_t *dnp = bc->bc_dnode; 521fa9e4066Sahrens char buffer[300]; 522fa9e4066Sahrens int l; 523fa9e4066Sahrens 524fa9e4066Sahrens if (bc->bc_errno) { 525fa9e4066Sahrens (void) sprintf(buffer, 526*ea8dc4b6Seschrock "Error %d reading <%llu, %llu, %lld, %llu>: ", 527fa9e4066Sahrens bc->bc_errno, 528fa9e4066Sahrens (u_longlong_t)zb->zb_objset, 529fa9e4066Sahrens (u_longlong_t)zb->zb_object, 530*ea8dc4b6Seschrock (u_longlong_t)zb->zb_level, 531fa9e4066Sahrens (u_longlong_t)zb->zb_blkid); 532fa9e4066Sahrens goto out; 533fa9e4066Sahrens } 534fa9e4066Sahrens 535fa9e4066Sahrens if (zb->zb_level == -1) { 536fa9e4066Sahrens ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_OBJSET); 537fa9e4066Sahrens ASSERT3U(BP_GET_LEVEL(bp), ==, 0); 538fa9e4066Sahrens } else { 539fa9e4066Sahrens ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type); 540fa9e4066Sahrens ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level); 541fa9e4066Sahrens } 542fa9e4066Sahrens 543fa9e4066Sahrens if (zb->zb_level > 0) { 544fa9e4066Sahrens uint64_t fill = 0; 545fa9e4066Sahrens blkptr_t *bpx, *bpend; 546fa9e4066Sahrens 547fa9e4066Sahrens for (bpx = data, bpend = bpx + BP_GET_LSIZE(bp) / sizeof (*bpx); 548fa9e4066Sahrens bpx < bpend; bpx++) { 549fa9e4066Sahrens if (bpx->blk_birth != 0) { 550fa9e4066Sahrens fill += bpx->blk_fill; 551fa9e4066Sahrens } else { 552fa9e4066Sahrens ASSERT(bpx->blk_fill == 0); 553fa9e4066Sahrens } 554fa9e4066Sahrens } 555fa9e4066Sahrens ASSERT3U(fill, ==, bp->blk_fill); 556fa9e4066Sahrens } 557fa9e4066Sahrens 558fa9e4066Sahrens if (zb->zb_level == 0 && dnp->dn_type == DMU_OT_DNODE) { 559fa9e4066Sahrens uint64_t fill = 0; 560fa9e4066Sahrens dnode_phys_t *dnx, *dnend; 561fa9e4066Sahrens 562fa9e4066Sahrens for (dnx = data, dnend = dnx + (BP_GET_LSIZE(bp)>>DNODE_SHIFT); 563fa9e4066Sahrens dnx < dnend; dnx++) { 564fa9e4066Sahrens if (dnx->dn_type != DMU_OT_NONE) 565fa9e4066Sahrens fill++; 566fa9e4066Sahrens } 567fa9e4066Sahrens ASSERT3U(fill, ==, bp->blk_fill); 568fa9e4066Sahrens } 569fa9e4066Sahrens 570fa9e4066Sahrens (void) sprintf(buffer, "%16llx ", 571fa9e4066Sahrens (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid)); 572fa9e4066Sahrens 573fa9e4066Sahrens ASSERT(zb->zb_level >= 0); 574fa9e4066Sahrens 575fa9e4066Sahrens for (l = dnp->dn_nlevels - 1; l >= -1; l--) { 576fa9e4066Sahrens if (l == zb->zb_level) { 577*ea8dc4b6Seschrock (void) sprintf(buffer + strlen(buffer), "L%llx", 578*ea8dc4b6Seschrock (u_longlong_t)zb->zb_level); 579fa9e4066Sahrens } else { 580fa9e4066Sahrens (void) sprintf(buffer + strlen(buffer), " "); 581fa9e4066Sahrens } 582fa9e4066Sahrens } 583fa9e4066Sahrens 584fa9e4066Sahrens out: 585fa9e4066Sahrens if (bp->blk_birth == 0) { 586fa9e4066Sahrens (void) sprintf(buffer + strlen(buffer), "<hole>"); 587fa9e4066Sahrens (void) printf("%s\n", buffer); 588fa9e4066Sahrens } else { 589fa9e4066Sahrens // XXBP - Need to print number of active BPs here 590fa9e4066Sahrens (void) sprintf(buffer + strlen(buffer), 591fa9e4066Sahrens "vdev=%llu off=%llx %llxL/%llxP/%llxA F=%llu B=%llu", 592fa9e4066Sahrens (u_longlong_t)DVA_GET_VDEV(dva), 593fa9e4066Sahrens (u_longlong_t)DVA_GET_OFFSET(dva), 594fa9e4066Sahrens (u_longlong_t)BP_GET_LSIZE(bp), 595fa9e4066Sahrens (u_longlong_t)BP_GET_PSIZE(bp), 596fa9e4066Sahrens (u_longlong_t)DVA_GET_ASIZE(dva), 597fa9e4066Sahrens (u_longlong_t)bp->blk_fill, 598fa9e4066Sahrens (u_longlong_t)bp->blk_birth); 599fa9e4066Sahrens 600fa9e4066Sahrens (void) printf("%s\n", buffer); 601fa9e4066Sahrens } 602fa9e4066Sahrens 603fa9e4066Sahrens return (bc->bc_errno ? ERESTART : 0); 604fa9e4066Sahrens } 605fa9e4066Sahrens 606fa9e4066Sahrens /*ARGSUSED*/ 607fa9e4066Sahrens static void 608fa9e4066Sahrens dump_indirect(objset_t *os, uint64_t object, void *data, size_t size) 609fa9e4066Sahrens { 610fa9e4066Sahrens traverse_handle_t *th; 611fa9e4066Sahrens uint64_t objset = dmu_objset_id(os); 612fa9e4066Sahrens int advance = zdb_advance; 613fa9e4066Sahrens 614fa9e4066Sahrens (void) printf("Indirect blocks:\n"); 615fa9e4066Sahrens 616fa9e4066Sahrens if (object == 0) 617fa9e4066Sahrens advance |= ADVANCE_DATA; 618fa9e4066Sahrens 619fa9e4066Sahrens th = traverse_init(dmu_objset_spa(os), zdb_indirect_cb, NULL, advance, 620fa9e4066Sahrens ZIO_FLAG_CANFAIL); 621fa9e4066Sahrens th->th_noread = zdb_noread; 622fa9e4066Sahrens 623fa9e4066Sahrens traverse_add_dnode(th, 0, -1ULL, objset, object); 624fa9e4066Sahrens 625fa9e4066Sahrens while (traverse_more(th) == EAGAIN) 626fa9e4066Sahrens continue; 627fa9e4066Sahrens 628fa9e4066Sahrens (void) printf("\n"); 629fa9e4066Sahrens 630fa9e4066Sahrens traverse_fini(th); 631fa9e4066Sahrens } 632fa9e4066Sahrens 633fa9e4066Sahrens /*ARGSUSED*/ 634fa9e4066Sahrens static void 635fa9e4066Sahrens dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size) 636fa9e4066Sahrens { 637fa9e4066Sahrens dsl_dir_phys_t *dd = data; 638fa9e4066Sahrens time_t crtime; 639fa9e4066Sahrens char used[6], compressed[6], uncompressed[6], quota[6], resv[6]; 640fa9e4066Sahrens 641fa9e4066Sahrens if (dd == NULL) 642fa9e4066Sahrens return; 643fa9e4066Sahrens 644fa9e4066Sahrens ASSERT(size == sizeof (*dd)); 645fa9e4066Sahrens 646fa9e4066Sahrens crtime = dd->dd_creation_time; 647fa9e4066Sahrens nicenum(dd->dd_used_bytes, used); 648fa9e4066Sahrens nicenum(dd->dd_compressed_bytes, compressed); 649fa9e4066Sahrens nicenum(dd->dd_uncompressed_bytes, uncompressed); 650fa9e4066Sahrens nicenum(dd->dd_quota, quota); 651fa9e4066Sahrens nicenum(dd->dd_reserved, resv); 652fa9e4066Sahrens 653fa9e4066Sahrens (void) printf("\t\tcreation_time = %s", ctime(&crtime)); 654fa9e4066Sahrens (void) printf("\t\thead_dataset_obj = %llu\n", 655fa9e4066Sahrens (u_longlong_t)dd->dd_head_dataset_obj); 656fa9e4066Sahrens (void) printf("\t\tparent_dir_obj = %llu\n", 657fa9e4066Sahrens (u_longlong_t)dd->dd_parent_obj); 658fa9e4066Sahrens (void) printf("\t\tclone_parent_obj = %llu\n", 659fa9e4066Sahrens (u_longlong_t)dd->dd_clone_parent_obj); 660fa9e4066Sahrens (void) printf("\t\tchild_dir_zapobj = %llu\n", 661fa9e4066Sahrens (u_longlong_t)dd->dd_child_dir_zapobj); 662fa9e4066Sahrens (void) printf("\t\tused_bytes = %s\n", used); 663fa9e4066Sahrens (void) printf("\t\tcompressed_bytes = %s\n", compressed); 664fa9e4066Sahrens (void) printf("\t\tuncompressed_bytes = %s\n", uncompressed); 665fa9e4066Sahrens (void) printf("\t\tquota = %s\n", quota); 666fa9e4066Sahrens (void) printf("\t\treserved = %s\n", resv); 667fa9e4066Sahrens (void) printf("\t\tprops_zapobj = %llu\n", 668fa9e4066Sahrens (u_longlong_t)dd->dd_props_zapobj); 669fa9e4066Sahrens } 670fa9e4066Sahrens 671fa9e4066Sahrens /*ARGSUSED*/ 672fa9e4066Sahrens static void 673fa9e4066Sahrens dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size) 674fa9e4066Sahrens { 675fa9e4066Sahrens dsl_dataset_phys_t *ds = data; 676fa9e4066Sahrens time_t crtime; 677fbabab8fSmaybee char used[6], compressed[6], uncompressed[6], unique[6]; 678fbabab8fSmaybee char blkbuf[BP_SPRINTF_LEN]; 679fa9e4066Sahrens 680fa9e4066Sahrens if (ds == NULL) 681fa9e4066Sahrens return; 682fa9e4066Sahrens 683fa9e4066Sahrens ASSERT(size == sizeof (*ds)); 684fa9e4066Sahrens crtime = ds->ds_creation_time; 685fa9e4066Sahrens nicenum(ds->ds_used_bytes, used); 686fa9e4066Sahrens nicenum(ds->ds_compressed_bytes, compressed); 687fa9e4066Sahrens nicenum(ds->ds_uncompressed_bytes, uncompressed); 688fa9e4066Sahrens nicenum(ds->ds_unique_bytes, unique); 689fbabab8fSmaybee sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp); 690fa9e4066Sahrens 691fa9e4066Sahrens (void) printf("\t\tdataset_obj = %llu\n", 692fa9e4066Sahrens (u_longlong_t)ds->ds_dir_obj); 693fa9e4066Sahrens (void) printf("\t\tprev_snap_obj = %llu\n", 694fa9e4066Sahrens (u_longlong_t)ds->ds_prev_snap_obj); 695fa9e4066Sahrens (void) printf("\t\tprev_snap_txg = %llu\n", 696fa9e4066Sahrens (u_longlong_t)ds->ds_prev_snap_txg); 697fa9e4066Sahrens (void) printf("\t\tnext_snap_obj = %llu\n", 698fa9e4066Sahrens (u_longlong_t)ds->ds_next_snap_obj); 699fa9e4066Sahrens (void) printf("\t\tsnapnames_zapobj = %llu\n", 700fa9e4066Sahrens (u_longlong_t)ds->ds_snapnames_zapobj); 701fa9e4066Sahrens (void) printf("\t\tnum_children = %llu\n", 702fa9e4066Sahrens (u_longlong_t)ds->ds_num_children); 703fa9e4066Sahrens (void) printf("\t\tcreation_time = %s", ctime(&crtime)); 704fa9e4066Sahrens (void) printf("\t\tcreation_txg = %llu\n", 705fa9e4066Sahrens (u_longlong_t)ds->ds_creation_txg); 706fa9e4066Sahrens (void) printf("\t\tdeadlist_obj = %llu\n", 707fa9e4066Sahrens (u_longlong_t)ds->ds_deadlist_obj); 708fa9e4066Sahrens (void) printf("\t\tused_bytes = %s\n", used); 709fa9e4066Sahrens (void) printf("\t\tcompressed_bytes = %s\n", compressed); 710fa9e4066Sahrens (void) printf("\t\tuncompressed_bytes = %s\n", uncompressed); 711fa9e4066Sahrens (void) printf("\t\tunique = %s\n", unique); 712fa9e4066Sahrens (void) printf("\t\tfsid_guid = %llu\n", 713fa9e4066Sahrens (u_longlong_t)ds->ds_fsid_guid); 714fa9e4066Sahrens (void) printf("\t\tguid = %llu\n", 715fa9e4066Sahrens (u_longlong_t)ds->ds_guid); 716fa9e4066Sahrens (void) printf("\t\trestoring = %llu\n", 717fa9e4066Sahrens (u_longlong_t)ds->ds_restoring); 718fa9e4066Sahrens (void) printf("\t\tbp = %s\n", blkbuf); 719fa9e4066Sahrens } 720fa9e4066Sahrens 721fa9e4066Sahrens static void 722fa9e4066Sahrens dump_bplist(objset_t *mos, uint64_t object, char *name) 723fa9e4066Sahrens { 724fa9e4066Sahrens bplist_t bpl = { 0 }; 725fa9e4066Sahrens blkptr_t blk, *bp = &blk; 726fa9e4066Sahrens uint64_t itor = 0; 727fa9e4066Sahrens char numbuf[6]; 728fa9e4066Sahrens 729fa9e4066Sahrens if (dump_opt['d'] < 3) 730fa9e4066Sahrens return; 731fa9e4066Sahrens 732*ea8dc4b6Seschrock VERIFY(0 == bplist_open(&bpl, mos, object)); 733fa9e4066Sahrens if (bplist_empty(&bpl)) { 734fa9e4066Sahrens bplist_close(&bpl); 735fa9e4066Sahrens return; 736fa9e4066Sahrens } 737fa9e4066Sahrens 738fa9e4066Sahrens nicenum(bpl.bpl_phys->bpl_bytes, numbuf); 739fa9e4066Sahrens 740fa9e4066Sahrens (void) printf("\n %s: %llu entries, %s\n", 741fa9e4066Sahrens name, (u_longlong_t)bpl.bpl_phys->bpl_entries, numbuf); 742fa9e4066Sahrens 743fa9e4066Sahrens if (dump_opt['d'] < 5) { 744fa9e4066Sahrens bplist_close(&bpl); 745fa9e4066Sahrens return; 746fa9e4066Sahrens } 747fa9e4066Sahrens 748fa9e4066Sahrens (void) printf("\n"); 749fa9e4066Sahrens 750fa9e4066Sahrens while (bplist_iterate(&bpl, &itor, bp) == 0) { 751fa9e4066Sahrens ASSERT(bp->blk_birth != 0); 752fa9e4066Sahrens // XXBP - Do we want to see all DVAs, or just one? 753fa9e4066Sahrens (void) printf("\tItem %3llu: vdev=%llu off=%llx " 754fa9e4066Sahrens "%llxL/%llxP/%llxA F=%llu B=%llu\n", 755fa9e4066Sahrens (u_longlong_t)itor - 1, 756fa9e4066Sahrens (u_longlong_t)DVA_GET_VDEV(&bp->blk_dva[0]), 757fa9e4066Sahrens (u_longlong_t)DVA_GET_OFFSET(&bp->blk_dva[0]), 758fa9e4066Sahrens (u_longlong_t)BP_GET_LSIZE(bp), 759fa9e4066Sahrens (u_longlong_t)BP_GET_PSIZE(bp), 760fa9e4066Sahrens (u_longlong_t)DVA_GET_ASIZE(&bp->blk_dva[0]), 761fa9e4066Sahrens (u_longlong_t)bp->blk_fill, 762fa9e4066Sahrens (u_longlong_t)bp->blk_birth); 763fa9e4066Sahrens } 764fa9e4066Sahrens 765fa9e4066Sahrens bplist_close(&bpl); 766fa9e4066Sahrens } 767fa9e4066Sahrens 768fa9e4066Sahrens static char * 769fa9e4066Sahrens znode_path(objset_t *os, uint64_t object, char *pathbuf, size_t size) 770fa9e4066Sahrens { 771fa9e4066Sahrens dmu_buf_t *db; 772fa9e4066Sahrens dmu_object_info_t doi; 773fa9e4066Sahrens znode_phys_t *zp; 774fa9e4066Sahrens uint64_t parent = 0; 775fa9e4066Sahrens size_t complen; 776fa9e4066Sahrens char component[MAXNAMELEN + 1]; 777fa9e4066Sahrens char *path; 778*ea8dc4b6Seschrock int error; 779fa9e4066Sahrens 780fa9e4066Sahrens path = pathbuf + size; 781fa9e4066Sahrens *--path = '\0'; 782fa9e4066Sahrens 783fa9e4066Sahrens for (;;) { 784*ea8dc4b6Seschrock error = dmu_bonus_hold(os, object, FTAG, &db); 785*ea8dc4b6Seschrock if (error) 786fa9e4066Sahrens break; 787fa9e4066Sahrens 788fa9e4066Sahrens dmu_object_info_from_db(db, &doi); 789fa9e4066Sahrens zp = db->db_data; 790fa9e4066Sahrens parent = zp->zp_parent; 791*ea8dc4b6Seschrock dmu_buf_rele(db, FTAG); 792fa9e4066Sahrens 793fa9e4066Sahrens if (doi.doi_bonus_type != DMU_OT_ZNODE) 794fa9e4066Sahrens break; 795fa9e4066Sahrens 796fa9e4066Sahrens if (parent == object) { 797fa9e4066Sahrens if (path[0] != '/') 798fa9e4066Sahrens *--path = '/'; 799fa9e4066Sahrens return (path); 800fa9e4066Sahrens } 801fa9e4066Sahrens 802fa9e4066Sahrens if (zap_value_search(os, parent, object, component) != 0) 803fa9e4066Sahrens break; 804fa9e4066Sahrens 805fa9e4066Sahrens complen = strlen(component); 806fa9e4066Sahrens path -= complen; 807fa9e4066Sahrens bcopy(component, path, complen); 808fa9e4066Sahrens *--path = '/'; 809fa9e4066Sahrens 810fa9e4066Sahrens object = parent; 811fa9e4066Sahrens } 812fa9e4066Sahrens 813fa9e4066Sahrens (void) sprintf(component, "???<object#%llu>", (u_longlong_t)object); 814fa9e4066Sahrens 815fa9e4066Sahrens complen = strlen(component); 816fa9e4066Sahrens path -= complen; 817fa9e4066Sahrens bcopy(component, path, complen); 818fa9e4066Sahrens 819fa9e4066Sahrens return (path); 820fa9e4066Sahrens } 821fa9e4066Sahrens 822fa9e4066Sahrens /*ARGSUSED*/ 823fa9e4066Sahrens static void 824fa9e4066Sahrens dump_znode(objset_t *os, uint64_t object, void *data, size_t size) 825fa9e4066Sahrens { 826fa9e4066Sahrens znode_phys_t *zp = data; 827fa9e4066Sahrens time_t z_crtime, z_atime, z_mtime, z_ctime; 828fa9e4066Sahrens char path[MAXPATHLEN * 2]; /* allow for xattr and failure prefix */ 829fa9e4066Sahrens 830fa9e4066Sahrens ASSERT(size >= sizeof (znode_phys_t)); 831fa9e4066Sahrens 832fa9e4066Sahrens if (dump_opt['d'] < 3) { 833fa9e4066Sahrens (void) printf("\t%s\n", 834fa9e4066Sahrens znode_path(os, object, path, sizeof (path))); 835fa9e4066Sahrens return; 836fa9e4066Sahrens } 837fa9e4066Sahrens 838fa9e4066Sahrens z_crtime = (time_t)zp->zp_crtime[0]; 839fa9e4066Sahrens z_atime = (time_t)zp->zp_atime[0]; 840fa9e4066Sahrens z_mtime = (time_t)zp->zp_mtime[0]; 841fa9e4066Sahrens z_ctime = (time_t)zp->zp_ctime[0]; 842fa9e4066Sahrens 843fa9e4066Sahrens (void) printf("\tpath %s\n", 844fa9e4066Sahrens znode_path(os, object, path, sizeof (path))); 845fa9e4066Sahrens (void) printf("\tatime %s", ctime(&z_atime)); 846fa9e4066Sahrens (void) printf("\tmtime %s", ctime(&z_mtime)); 847fa9e4066Sahrens (void) printf("\tctime %s", ctime(&z_ctime)); 848fa9e4066Sahrens (void) printf("\tcrtime %s", ctime(&z_crtime)); 849fa9e4066Sahrens (void) printf("\tgen %llu\n", (u_longlong_t)zp->zp_gen); 850fa9e4066Sahrens (void) printf("\tmode %llo\n", (u_longlong_t)zp->zp_mode); 851fa9e4066Sahrens (void) printf("\tsize %llu\n", (u_longlong_t)zp->zp_size); 852fa9e4066Sahrens (void) printf("\tparent %llu\n", (u_longlong_t)zp->zp_parent); 853fa9e4066Sahrens (void) printf("\tlinks %llu\n", (u_longlong_t)zp->zp_links); 854fa9e4066Sahrens (void) printf("\txattr %llu\n", (u_longlong_t)zp->zp_xattr); 855fa9e4066Sahrens (void) printf("\trdev 0x%016llx\n", (u_longlong_t)zp->zp_rdev); 856fa9e4066Sahrens } 857fa9e4066Sahrens 858fa9e4066Sahrens /*ARGSUSED*/ 859fa9e4066Sahrens static void 860fa9e4066Sahrens dump_acl(objset_t *os, uint64_t object, void *data, size_t size) 861fa9e4066Sahrens { 862fa9e4066Sahrens } 863fa9e4066Sahrens 864fa9e4066Sahrens /*ARGSUSED*/ 865fa9e4066Sahrens static void 866fa9e4066Sahrens dump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size) 867fa9e4066Sahrens { 868fa9e4066Sahrens } 869fa9e4066Sahrens 870fa9e4066Sahrens static object_viewer_t *object_viewer[DMU_OT_NUMTYPES] = { 871fa9e4066Sahrens dump_none, /* unallocated */ 872fa9e4066Sahrens dump_zap, /* object directory */ 873fa9e4066Sahrens dump_uint64, /* object array */ 874fa9e4066Sahrens dump_none, /* packed nvlist */ 875fa9e4066Sahrens dump_packed_nvlist, /* packed nvlist size */ 876fa9e4066Sahrens dump_none, /* bplist */ 877fa9e4066Sahrens dump_none, /* bplist header */ 878fa9e4066Sahrens dump_none, /* SPA space map header */ 879fa9e4066Sahrens dump_none, /* SPA space map */ 880fa9e4066Sahrens dump_none, /* ZIL intent log */ 881fa9e4066Sahrens dump_dnode, /* DMU dnode */ 882fa9e4066Sahrens dump_dmu_objset, /* DMU objset */ 883fa9e4066Sahrens dump_dsl_dir, /* DSL directory */ 884fa9e4066Sahrens dump_zap, /* DSL directory child map */ 885fa9e4066Sahrens dump_zap, /* DSL dataset snap map */ 886fa9e4066Sahrens dump_zap, /* DSL props */ 887fa9e4066Sahrens dump_dsl_dataset, /* DSL dataset */ 888fa9e4066Sahrens dump_znode, /* ZFS znode */ 889fa9e4066Sahrens dump_acl, /* ZFS ACL */ 890fa9e4066Sahrens dump_uint8, /* ZFS plain file */ 891fa9e4066Sahrens dump_zap, /* ZFS directory */ 892fa9e4066Sahrens dump_zap, /* ZFS master node */ 893fa9e4066Sahrens dump_zap, /* ZFS delete queue */ 894fa9e4066Sahrens dump_uint8, /* zvol object */ 895fa9e4066Sahrens dump_zap, /* zvol prop */ 896fa9e4066Sahrens dump_uint8, /* other uint8[] */ 897fa9e4066Sahrens dump_uint64, /* other uint64[] */ 898fa9e4066Sahrens dump_zap, /* other ZAP */ 899*ea8dc4b6Seschrock dump_zap, /* persistent error log */ 900fa9e4066Sahrens }; 901fa9e4066Sahrens 902fa9e4066Sahrens static void 903fa9e4066Sahrens dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header) 904fa9e4066Sahrens { 905fa9e4066Sahrens dmu_buf_t *db = NULL; 906fa9e4066Sahrens dmu_object_info_t doi; 907fa9e4066Sahrens dnode_t *dn; 908fa9e4066Sahrens void *bonus = NULL; 909fa9e4066Sahrens size_t bsize = 0; 910fa9e4066Sahrens char iblk[6], dblk[6], lsize[6], psize[6], bonus_size[6], segsize[6]; 911fa9e4066Sahrens char aux[50]; 912fa9e4066Sahrens int error; 913fa9e4066Sahrens 914fa9e4066Sahrens if (*print_header) { 915fa9e4066Sahrens (void) printf("\n Object lvl iblk dblk lsize" 916fa9e4066Sahrens " psize type\n"); 917fa9e4066Sahrens *print_header = 0; 918fa9e4066Sahrens } 919fa9e4066Sahrens 920fa9e4066Sahrens if (object == 0) { 921fa9e4066Sahrens dn = os->os->os_meta_dnode; 922fa9e4066Sahrens } else { 923*ea8dc4b6Seschrock error = dmu_bonus_hold(os, object, FTAG, &db); 924*ea8dc4b6Seschrock if (error) 925*ea8dc4b6Seschrock fatal("dmu_bonus_hold(%llu) failed, errno %u", 926*ea8dc4b6Seschrock object, error); 927fa9e4066Sahrens bonus = db->db_data; 928fa9e4066Sahrens bsize = db->db_size; 929fa9e4066Sahrens dn = ((dmu_buf_impl_t *)db)->db_dnode; 930fa9e4066Sahrens } 931fa9e4066Sahrens dmu_object_info_from_dnode(dn, &doi); 932fa9e4066Sahrens 933fa9e4066Sahrens nicenum(doi.doi_metadata_block_size, iblk); 934fa9e4066Sahrens nicenum(doi.doi_data_block_size, dblk); 935fa9e4066Sahrens nicenum(doi.doi_data_block_size * (doi.doi_max_block_offset + 1), 936fa9e4066Sahrens lsize); 937fa9e4066Sahrens nicenum(doi.doi_physical_blks << 9, psize); 938fa9e4066Sahrens nicenum(doi.doi_bonus_size, bonus_size); 939fa9e4066Sahrens 940fa9e4066Sahrens aux[0] = '\0'; 941fa9e4066Sahrens 942fa9e4066Sahrens if (doi.doi_checksum != ZIO_CHECKSUM_INHERIT || verbosity >= 6) 943fa9e4066Sahrens (void) snprintf(aux + strlen(aux), sizeof (aux), " (K=%s)", 944fa9e4066Sahrens zio_checksum_table[doi.doi_checksum].ci_name); 945fa9e4066Sahrens 946fa9e4066Sahrens if (doi.doi_compress != ZIO_COMPRESS_INHERIT || verbosity >= 6) 947fa9e4066Sahrens (void) snprintf(aux + strlen(aux), sizeof (aux), " (Z=%s)", 948fa9e4066Sahrens zio_compress_table[doi.doi_compress].ci_name); 949fa9e4066Sahrens 950fa9e4066Sahrens (void) printf("%10lld %3u %5s %5s %5s %5s %s%s\n", 951fa9e4066Sahrens (u_longlong_t)object, doi.doi_indirection, iblk, dblk, lsize, 952fa9e4066Sahrens psize, dmu_ot[doi.doi_type].ot_name, aux); 953fa9e4066Sahrens 954fa9e4066Sahrens if (doi.doi_bonus_type != DMU_OT_NONE && verbosity > 3) { 955fa9e4066Sahrens (void) printf("%10s %3s %5s %5s %5s %5s %s\n", 956fa9e4066Sahrens "", "", "", "", bonus_size, "bonus", 957fa9e4066Sahrens dmu_ot[doi.doi_bonus_type].ot_name); 958fa9e4066Sahrens } 959fa9e4066Sahrens 960fa9e4066Sahrens if (verbosity >= 4) { 961fa9e4066Sahrens object_viewer[doi.doi_bonus_type](os, object, bonus, bsize); 962fa9e4066Sahrens object_viewer[doi.doi_type](os, object, NULL, 0); 963fa9e4066Sahrens *print_header = 1; 964fa9e4066Sahrens } 965fa9e4066Sahrens 966fa9e4066Sahrens if (verbosity >= 5) 967fa9e4066Sahrens dump_indirect(os, object, NULL, 0); 968fa9e4066Sahrens 969fa9e4066Sahrens if (verbosity >= 5) { 970fa9e4066Sahrens /* 971fa9e4066Sahrens * Report the list of segments that comprise the object. 972fa9e4066Sahrens */ 973fa9e4066Sahrens uint64_t start = 0; 974fa9e4066Sahrens uint64_t end; 975fa9e4066Sahrens uint64_t blkfill = 1; 976fa9e4066Sahrens int minlvl = 1; 977fa9e4066Sahrens 978fa9e4066Sahrens if (dn->dn_type == DMU_OT_DNODE) { 979fa9e4066Sahrens minlvl = 0; 980fa9e4066Sahrens blkfill = DNODES_PER_BLOCK; 981fa9e4066Sahrens } 982fa9e4066Sahrens 983fa9e4066Sahrens for (;;) { 984fa9e4066Sahrens error = dnode_next_offset(dn, B_FALSE, &start, minlvl, 985fa9e4066Sahrens blkfill); 986fa9e4066Sahrens if (error) 987fa9e4066Sahrens break; 988fa9e4066Sahrens end = start; 989fa9e4066Sahrens error = dnode_next_offset(dn, B_TRUE, &end, minlvl, 990fa9e4066Sahrens blkfill); 991fa9e4066Sahrens nicenum(end - start, segsize); 992fa9e4066Sahrens (void) printf("\t\tsegment [%016llx, %016llx)" 993fa9e4066Sahrens " size %5s\n", (u_longlong_t)start, 994fa9e4066Sahrens (u_longlong_t)end, segsize); 995fa9e4066Sahrens if (error) 996fa9e4066Sahrens break; 997fa9e4066Sahrens start = end; 998fa9e4066Sahrens } 999fa9e4066Sahrens } 1000fa9e4066Sahrens 1001fa9e4066Sahrens if (db != NULL) 1002*ea8dc4b6Seschrock dmu_buf_rele(db, FTAG); 1003fa9e4066Sahrens } 1004fa9e4066Sahrens 1005fa9e4066Sahrens static char *objset_types[DMU_OST_NUMTYPES] = { 1006fa9e4066Sahrens "NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" }; 1007fa9e4066Sahrens 1008fa9e4066Sahrens /*ARGSUSED*/ 1009fa9e4066Sahrens static void 1010fa9e4066Sahrens dump_dir(objset_t *os) 1011fa9e4066Sahrens { 1012fa9e4066Sahrens dmu_objset_stats_t dds; 1013fa9e4066Sahrens uint64_t object, object_count; 1014fa9e4066Sahrens char numbuf[8]; 1015fbabab8fSmaybee char blkbuf[BP_SPRINTF_LEN]; 1016fa9e4066Sahrens char osname[MAXNAMELEN]; 1017fa9e4066Sahrens char *type = "UNKNOWN"; 1018fa9e4066Sahrens int verbosity = dump_opt['d']; 1019fa9e4066Sahrens int print_header = 1; 1020fa9e4066Sahrens int i, error; 1021fa9e4066Sahrens 1022fa9e4066Sahrens dmu_objset_stats(os, &dds); 1023fa9e4066Sahrens 1024fa9e4066Sahrens if (dds.dds_type < DMU_OST_NUMTYPES) 1025fa9e4066Sahrens type = objset_types[dds.dds_type]; 1026fa9e4066Sahrens 1027fa9e4066Sahrens if (dds.dds_type == DMU_OST_META) { 1028fa9e4066Sahrens dds.dds_creation_txg = TXG_INITIAL; 1029fa9e4066Sahrens dds.dds_last_txg = os->os->os_rootbp.blk_birth; 1030fa9e4066Sahrens dds.dds_objects_used = os->os->os_rootbp.blk_fill; 1031fa9e4066Sahrens dds.dds_space_refd = 1032fa9e4066Sahrens os->os->os_spa->spa_dsl_pool->dp_mos_dir->dd_used_bytes; 1033fa9e4066Sahrens } 1034fa9e4066Sahrens 1035fa9e4066Sahrens ASSERT3U(dds.dds_objects_used, ==, os->os->os_rootbp.blk_fill); 1036fa9e4066Sahrens 1037fa9e4066Sahrens nicenum(dds.dds_space_refd, numbuf); 1038fa9e4066Sahrens 1039fa9e4066Sahrens if (verbosity >= 4) { 1040fa9e4066Sahrens (void) strcpy(blkbuf, ", rootbp "); 1041fbabab8fSmaybee sprintf_blkptr(blkbuf + strlen(blkbuf), 1042fbabab8fSmaybee BP_SPRINTF_LEN - strlen(blkbuf), &os->os->os_rootbp); 1043fa9e4066Sahrens } else { 1044fa9e4066Sahrens blkbuf[0] = '\0'; 1045fa9e4066Sahrens } 1046fa9e4066Sahrens 1047fa9e4066Sahrens dmu_objset_name(os, osname); 1048fa9e4066Sahrens 1049fa9e4066Sahrens (void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, last_txg %llu, " 1050fa9e4066Sahrens "%s, %llu objects%s\n", 1051fa9e4066Sahrens osname, type, (u_longlong_t)dmu_objset_id(os), 1052fa9e4066Sahrens (u_longlong_t)dds.dds_creation_txg, 1053fa9e4066Sahrens (u_longlong_t)dds.dds_last_txg, 1054fa9e4066Sahrens numbuf, 1055fa9e4066Sahrens (u_longlong_t)dds.dds_objects_used, 1056fa9e4066Sahrens blkbuf); 1057fa9e4066Sahrens 1058fa9e4066Sahrens dump_intent_log(dmu_objset_zil(os)); 1059fa9e4066Sahrens 1060fa9e4066Sahrens if (dmu_objset_ds(os) != NULL) 1061fa9e4066Sahrens dump_bplist(dmu_objset_pool(os)->dp_meta_objset, 1062fa9e4066Sahrens dmu_objset_ds(os)->ds_phys->ds_deadlist_obj, "Deadlist"); 1063fa9e4066Sahrens 1064fa9e4066Sahrens if (verbosity < 2) 1065fa9e4066Sahrens return; 1066fa9e4066Sahrens 1067fa9e4066Sahrens if (zopt_objects != 0) { 1068fa9e4066Sahrens for (i = 0; i < zopt_objects; i++) 1069fa9e4066Sahrens dump_object(os, zopt_object[i], verbosity, 1070fa9e4066Sahrens &print_header); 1071fa9e4066Sahrens (void) printf("\n"); 1072fa9e4066Sahrens return; 1073fa9e4066Sahrens } 1074fa9e4066Sahrens 1075fa9e4066Sahrens dump_object(os, 0, verbosity, &print_header); 1076fa9e4066Sahrens object_count = 1; 1077fa9e4066Sahrens 1078fa9e4066Sahrens object = 0; 1079fa9e4066Sahrens while ((error = dmu_object_next(os, &object, B_FALSE)) == 0) { 1080fa9e4066Sahrens dump_object(os, object, verbosity, &print_header); 1081fa9e4066Sahrens object_count++; 1082fa9e4066Sahrens } 1083fa9e4066Sahrens 1084fa9e4066Sahrens ASSERT3U(object_count, ==, dds.dds_objects_used); 1085fa9e4066Sahrens 1086fa9e4066Sahrens (void) printf("\n"); 1087fa9e4066Sahrens 1088fa9e4066Sahrens if (error != ESRCH) 1089fa9e4066Sahrens fatal("dmu_object_next() = %d", error); 1090fa9e4066Sahrens } 1091fa9e4066Sahrens 1092fa9e4066Sahrens static void 1093fa9e4066Sahrens dump_uberblock(uberblock_t *ub) 1094fa9e4066Sahrens { 1095fa9e4066Sahrens time_t timestamp = ub->ub_timestamp; 1096fa9e4066Sahrens 1097fa9e4066Sahrens (void) printf("Uberblock\n\n"); 1098fa9e4066Sahrens (void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic); 1099fa9e4066Sahrens (void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version); 1100fa9e4066Sahrens (void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg); 1101fa9e4066Sahrens (void) printf("\tguid_sum = %llu\n", (u_longlong_t)ub->ub_guid_sum); 1102fa9e4066Sahrens (void) printf("\ttimestamp = %llu UTC = %s", 1103fa9e4066Sahrens (u_longlong_t)ub->ub_timestamp, asctime(localtime(×tamp))); 1104fa9e4066Sahrens if (dump_opt['u'] >= 3) { 1105fbabab8fSmaybee char blkbuf[BP_SPRINTF_LEN]; 1106fbabab8fSmaybee sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ub->ub_rootbp); 1107fa9e4066Sahrens (void) printf("\trootbp = %s\n", blkbuf); 1108fa9e4066Sahrens } 1109fa9e4066Sahrens (void) printf("\n"); 1110fa9e4066Sahrens } 1111fa9e4066Sahrens 1112fa9e4066Sahrens static void 1113fa9e4066Sahrens dump_config(const char *pool) 1114fa9e4066Sahrens { 1115fa9e4066Sahrens spa_t *spa = NULL; 1116fa9e4066Sahrens 1117fa9e4066Sahrens mutex_enter(&spa_namespace_lock); 1118fa9e4066Sahrens while ((spa = spa_next(spa)) != NULL) { 1119fa9e4066Sahrens if (pool == NULL) 1120fa9e4066Sahrens (void) printf("%s\n", spa_name(spa)); 1121fa9e4066Sahrens if (pool == NULL || strcmp(pool, spa_name(spa)) == 0) 1122fa9e4066Sahrens dump_nvlist(spa->spa_config, 4); 1123fa9e4066Sahrens } 1124fa9e4066Sahrens mutex_exit(&spa_namespace_lock); 1125fa9e4066Sahrens } 1126fa9e4066Sahrens 1127fa9e4066Sahrens static void 1128fa9e4066Sahrens dump_label(const char *dev) 1129fa9e4066Sahrens { 1130fa9e4066Sahrens int fd; 1131fa9e4066Sahrens vdev_label_t label; 1132fa9e4066Sahrens char *buf = label.vl_vdev_phys.vp_nvlist; 1133fa9e4066Sahrens size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist); 1134fa9e4066Sahrens struct stat64 statbuf; 1135fa9e4066Sahrens uint64_t psize; 1136fa9e4066Sahrens int l; 1137fa9e4066Sahrens 11380d981225Seschrock if ((fd = open64(dev, O_RDONLY)) < 0) { 1139fa9e4066Sahrens (void) printf("cannot open '%s': %s\n", dev, strerror(errno)); 1140fa9e4066Sahrens exit(1); 1141fa9e4066Sahrens } 1142fa9e4066Sahrens 1143fa9e4066Sahrens if (fstat64(fd, &statbuf) != 0) { 1144fa9e4066Sahrens (void) printf("failed to stat '%s': %s\n", dev, 1145fa9e4066Sahrens strerror(errno)); 1146fa9e4066Sahrens exit(1); 1147fa9e4066Sahrens } 1148fa9e4066Sahrens 1149fa9e4066Sahrens psize = statbuf.st_size; 1150fa9e4066Sahrens psize = P2ALIGN(psize, (uint64_t)sizeof (vdev_label_t)); 1151fa9e4066Sahrens 1152fa9e4066Sahrens for (l = 0; l < VDEV_LABELS; l++) { 1153fa9e4066Sahrens 1154fa9e4066Sahrens nvlist_t *config = NULL; 1155fa9e4066Sahrens 1156fa9e4066Sahrens (void) printf("--------------------------------------------\n"); 1157fa9e4066Sahrens (void) printf("LABEL %d\n", l); 1158fa9e4066Sahrens (void) printf("--------------------------------------------\n"); 1159fa9e4066Sahrens 11600d981225Seschrock if (pread64(fd, &label, sizeof (label), 1161fa9e4066Sahrens vdev_label_offset(psize, l, 0)) != sizeof (label)) { 1162fa9e4066Sahrens (void) printf("failed to read label %d\n", l); 1163fa9e4066Sahrens continue; 1164fa9e4066Sahrens } 1165fa9e4066Sahrens 1166fa9e4066Sahrens if (nvlist_unpack(buf, buflen, &config, 0) != 0) { 1167fa9e4066Sahrens (void) printf("failed to unpack label %d\n", l); 1168fa9e4066Sahrens continue; 1169fa9e4066Sahrens } 1170fa9e4066Sahrens dump_nvlist(config, 4); 1171fa9e4066Sahrens nvlist_free(config); 1172fa9e4066Sahrens } 1173fa9e4066Sahrens } 1174fa9e4066Sahrens 1175fa9e4066Sahrens /*ARGSUSED*/ 1176fa9e4066Sahrens static void 1177fa9e4066Sahrens dump_one_dir(char *dsname, void *arg) 1178fa9e4066Sahrens { 1179fa9e4066Sahrens int error; 1180fa9e4066Sahrens objset_t *os; 1181fa9e4066Sahrens 1182fa9e4066Sahrens error = dmu_objset_open(dsname, DMU_OST_ANY, 1183fa9e4066Sahrens DS_MODE_STANDARD | DS_MODE_READONLY, &os); 1184fa9e4066Sahrens if (error) { 1185fa9e4066Sahrens (void) printf("Could not open %s\n", dsname); 1186fa9e4066Sahrens return; 1187fa9e4066Sahrens } 1188fa9e4066Sahrens dump_dir(os); 1189fa9e4066Sahrens dmu_objset_close(os); 1190fa9e4066Sahrens } 1191fa9e4066Sahrens 1192fa9e4066Sahrens static void 1193fa9e4066Sahrens zdb_space_map_load(spa_t *spa) 1194fa9e4066Sahrens { 1195fa9e4066Sahrens vdev_t *rvd = spa->spa_root_vdev; 1196fa9e4066Sahrens vdev_t *vd; 1197fa9e4066Sahrens int c, m, error; 1198fa9e4066Sahrens 1199fa9e4066Sahrens for (c = 0; c < rvd->vdev_children; c++) { 1200fa9e4066Sahrens vd = rvd->vdev_child[c]; 1201fa9e4066Sahrens for (m = 0; m < vd->vdev_ms_count; m++) { 1202fa9e4066Sahrens metaslab_t *msp = vd->vdev_ms[m]; 1203fa9e4066Sahrens space_map_t *sm = &msp->ms_allocmap[0]; 1204fa9e4066Sahrens mutex_enter(&msp->ms_lock); 1205fa9e4066Sahrens error = space_map_load(sm, msp->ms_smo, SM_ALLOC, 1206fa9e4066Sahrens spa->spa_meta_objset, msp->ms_usable_end, 1207fa9e4066Sahrens sm->sm_size - msp->ms_usable_space); 1208fa9e4066Sahrens mutex_exit(&msp->ms_lock); 1209fa9e4066Sahrens if (error) 1210fa9e4066Sahrens fatal("%s bad space map #%d, error %d", 1211fa9e4066Sahrens spa->spa_name, c, error); 1212fa9e4066Sahrens } 1213fa9e4066Sahrens } 1214fa9e4066Sahrens } 1215fa9e4066Sahrens 1216fa9e4066Sahrens static int 1217*ea8dc4b6Seschrock zdb_space_map_claim(spa_t *spa, blkptr_t *bp, zbookmark_t *zb) 1218fa9e4066Sahrens { 1219fa9e4066Sahrens dva_t *dva = &bp->blk_dva[0]; 1220fa9e4066Sahrens uint64_t vdev = DVA_GET_VDEV(dva); 1221fa9e4066Sahrens uint64_t offset = DVA_GET_OFFSET(dva); 1222fa9e4066Sahrens uint64_t size = DVA_GET_ASIZE(dva); 1223fa9e4066Sahrens vdev_t *vd; 1224fa9e4066Sahrens metaslab_t *msp; 1225fa9e4066Sahrens space_map_t *allocmap, *freemap; 1226fa9e4066Sahrens int error; 1227fa9e4066Sahrens 1228fa9e4066Sahrens if ((vd = vdev_lookup_top(spa, vdev)) == NULL) 1229fa9e4066Sahrens return (ENXIO); 1230fa9e4066Sahrens 1231fa9e4066Sahrens if ((offset >> vd->vdev_ms_shift) >= vd->vdev_ms_count) 1232fa9e4066Sahrens return (ENXIO); 1233fa9e4066Sahrens 1234fa9e4066Sahrens if (DVA_GET_GANG(dva)) { 1235fa9e4066Sahrens zio_gbh_phys_t gbh; 1236fa9e4066Sahrens blkptr_t blk = *bp; 1237fa9e4066Sahrens int g; 1238fa9e4066Sahrens 1239fa9e4066Sahrens /* LINTED - compile time assert */ 1240fa9e4066Sahrens ASSERT(sizeof (zio_gbh_phys_t) == SPA_GANGBLOCKSIZE); 1241fa9e4066Sahrens size = vdev_psize_to_asize(vd, SPA_GANGBLOCKSIZE); 1242fa9e4066Sahrens DVA_SET_GANG(&blk.blk_dva[0], 0); 1243fa9e4066Sahrens DVA_SET_ASIZE(&blk.blk_dva[0], size); 1244fa9e4066Sahrens BP_SET_CHECKSUM(&blk, ZIO_CHECKSUM_GANG_HEADER); 1245fa9e4066Sahrens BP_SET_PSIZE(&blk, SPA_GANGBLOCKSIZE); 1246fa9e4066Sahrens BP_SET_LSIZE(&blk, SPA_GANGBLOCKSIZE); 1247fa9e4066Sahrens BP_SET_COMPRESS(&blk, ZIO_COMPRESS_OFF); 1248fa9e4066Sahrens error = zio_wait(zio_read(NULL, spa, &blk, 1249fa9e4066Sahrens &gbh, SPA_GANGBLOCKSIZE, NULL, NULL, 1250fa9e4066Sahrens ZIO_PRIORITY_SYNC_READ, 1251*ea8dc4b6Seschrock ZIO_FLAG_CANFAIL | ZIO_FLAG_CONFIG_HELD, zb)); 1252fa9e4066Sahrens if (error) 1253fa9e4066Sahrens return (error); 1254fa9e4066Sahrens if (BP_SHOULD_BYTESWAP(&blk)) 1255fa9e4066Sahrens byteswap_uint64_array(&gbh, SPA_GANGBLOCKSIZE); 1256fa9e4066Sahrens for (g = 0; g < SPA_GBH_NBLKPTRS; g++) { 1257fa9e4066Sahrens if (gbh.zg_blkptr[g].blk_birth == 0) 1258fa9e4066Sahrens break; 1259*ea8dc4b6Seschrock error = zdb_space_map_claim(spa, &gbh.zg_blkptr[g], zb); 1260fa9e4066Sahrens if (error) 1261fa9e4066Sahrens return (error); 1262fa9e4066Sahrens } 1263fa9e4066Sahrens } 1264fa9e4066Sahrens 1265fa9e4066Sahrens msp = vd->vdev_ms[offset >> vd->vdev_ms_shift]; 1266fa9e4066Sahrens allocmap = &msp->ms_allocmap[0]; 1267fa9e4066Sahrens freemap = &msp->ms_freemap[0]; 1268fa9e4066Sahrens 1269fa9e4066Sahrens mutex_enter(&msp->ms_lock); 1270fa9e4066Sahrens if (space_map_contains(freemap, offset, size)) { 1271fa9e4066Sahrens mutex_exit(&msp->ms_lock); 1272fa9e4066Sahrens return (EAGAIN); /* allocated more than once */ 1273fa9e4066Sahrens } 1274fa9e4066Sahrens 1275fa9e4066Sahrens if (!space_map_contains(allocmap, offset, size)) { 1276fa9e4066Sahrens mutex_exit(&msp->ms_lock); 1277fa9e4066Sahrens return (ESTALE); /* not allocated at all */ 1278fa9e4066Sahrens } 1279fa9e4066Sahrens 1280fa9e4066Sahrens space_map_remove(allocmap, offset, size); 1281fa9e4066Sahrens space_map_add(freemap, offset, size); 1282fa9e4066Sahrens 1283fa9e4066Sahrens mutex_exit(&msp->ms_lock); 1284fa9e4066Sahrens 1285fa9e4066Sahrens return (0); 1286fa9e4066Sahrens } 1287fa9e4066Sahrens 1288fa9e4066Sahrens static void 1289fa9e4066Sahrens zdb_leak(space_map_t *sm, uint64_t start, uint64_t size) 1290fa9e4066Sahrens { 1291fa9e4066Sahrens metaslab_t *msp; 1292fa9e4066Sahrens 1293fa9e4066Sahrens /* LINTED */ 1294fa9e4066Sahrens msp = (metaslab_t *)((char *)sm - offsetof(metaslab_t, ms_allocmap[0])); 1295fa9e4066Sahrens 1296fa9e4066Sahrens (void) printf("leaked space: vdev %llu, offset 0x%llx, size %llu\n", 1297fa9e4066Sahrens (u_longlong_t)msp->ms_group->mg_vd->vdev_id, 1298fa9e4066Sahrens (u_longlong_t)start, 1299fa9e4066Sahrens (u_longlong_t)size); 1300fa9e4066Sahrens } 1301fa9e4066Sahrens 1302fa9e4066Sahrens static void 1303fa9e4066Sahrens zdb_space_map_vacate(spa_t *spa) 1304fa9e4066Sahrens { 1305fa9e4066Sahrens vdev_t *rvd = spa->spa_root_vdev; 1306fa9e4066Sahrens vdev_t *vd; 1307fa9e4066Sahrens int c, m; 1308fa9e4066Sahrens 1309fa9e4066Sahrens for (c = 0; c < rvd->vdev_children; c++) { 1310fa9e4066Sahrens vd = rvd->vdev_child[c]; 1311fa9e4066Sahrens for (m = 0; m < vd->vdev_ms_count; m++) { 1312fa9e4066Sahrens metaslab_t *msp = vd->vdev_ms[m]; 1313fa9e4066Sahrens mutex_enter(&msp->ms_lock); 1314fa9e4066Sahrens space_map_vacate(&msp->ms_allocmap[0], zdb_leak, 1315fa9e4066Sahrens &msp->ms_allocmap[0]); 1316fa9e4066Sahrens space_map_vacate(&msp->ms_freemap[0], NULL, NULL); 1317fa9e4066Sahrens mutex_exit(&msp->ms_lock); 1318fa9e4066Sahrens } 1319fa9e4066Sahrens } 1320fa9e4066Sahrens } 1321fa9e4066Sahrens 1322fa9e4066Sahrens static void 1323fa9e4066Sahrens zdb_refresh_ubsync(spa_t *spa) 1324fa9e4066Sahrens { 1325fa9e4066Sahrens uberblock_t ub = { 0 }; 1326fa9e4066Sahrens vdev_t *rvd = spa->spa_root_vdev; 1327fa9e4066Sahrens zio_t *zio; 1328fa9e4066Sahrens 1329fa9e4066Sahrens /* 1330fa9e4066Sahrens * Reload the uberblock. 1331fa9e4066Sahrens */ 1332fa9e4066Sahrens zio = zio_root(spa, NULL, NULL, 1333fa9e4066Sahrens ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE); 1334fa9e4066Sahrens vdev_uberblock_load(zio, rvd, &ub); 1335fa9e4066Sahrens (void) zio_wait(zio); 1336fa9e4066Sahrens 1337fa9e4066Sahrens if (ub.ub_txg != 0) 1338fa9e4066Sahrens spa->spa_ubsync = ub; 1339fa9e4066Sahrens } 1340fa9e4066Sahrens 1341fa9e4066Sahrens /* 1342fa9e4066Sahrens * Verify that the sum of the sizes of all blocks in the pool adds up 1343fa9e4066Sahrens * to the SPA's sa_alloc total. 1344fa9e4066Sahrens */ 1345fa9e4066Sahrens typedef struct zdb_blkstats { 1346fa9e4066Sahrens uint64_t zb_asize; 1347fa9e4066Sahrens uint64_t zb_lsize; 1348fa9e4066Sahrens uint64_t zb_psize; 1349fa9e4066Sahrens uint64_t zb_count; 1350fa9e4066Sahrens } zdb_blkstats_t; 1351fa9e4066Sahrens 1352fa9e4066Sahrens #define DMU_OT_DEFERRED DMU_OT_NONE 1353fa9e4066Sahrens #define DMU_OT_TOTAL DMU_OT_NUMTYPES 1354fa9e4066Sahrens 1355fa9e4066Sahrens #define ZB_TOTAL ZB_MAXLEVEL 1356fa9e4066Sahrens 1357fa9e4066Sahrens typedef struct zdb_cb { 1358fa9e4066Sahrens zdb_blkstats_t zcb_type[ZB_TOTAL + 1][DMU_OT_TOTAL + 1]; 1359fa9e4066Sahrens uint64_t zcb_errors[256]; 1360fa9e4066Sahrens traverse_blk_cache_t *zcb_cache; 1361fa9e4066Sahrens int zcb_readfails; 1362fa9e4066Sahrens int zcb_haderrors; 1363fa9e4066Sahrens } zdb_cb_t; 1364fa9e4066Sahrens 1365fa9e4066Sahrens static void 1366fa9e4066Sahrens zdb_count_block(spa_t *spa, zdb_cb_t *zcb, blkptr_t *bp, int type) 1367fa9e4066Sahrens { 1368fa9e4066Sahrens int i, error; 1369fa9e4066Sahrens 1370fa9e4066Sahrens for (i = 0; i < 4; i++) { 1371fa9e4066Sahrens int l = (i < 2) ? BP_GET_LEVEL(bp) : ZB_TOTAL; 1372fa9e4066Sahrens int t = (i & 1) ? type : DMU_OT_TOTAL; 1373fa9e4066Sahrens zdb_blkstats_t *zb = &zcb->zcb_type[l][t]; 1374fa9e4066Sahrens 1375fa9e4066Sahrens zb->zb_asize += BP_GET_ASIZE(bp); 1376fa9e4066Sahrens zb->zb_lsize += BP_GET_LSIZE(bp); 1377fa9e4066Sahrens zb->zb_psize += BP_GET_PSIZE(bp); 1378fa9e4066Sahrens zb->zb_count++; 1379fa9e4066Sahrens } 1380fa9e4066Sahrens 1381fa9e4066Sahrens if (dump_opt['L']) 1382fa9e4066Sahrens return; 1383fa9e4066Sahrens 1384*ea8dc4b6Seschrock error = zdb_space_map_claim(spa, bp, &zcb->zcb_cache->bc_bookmark); 1385fa9e4066Sahrens 1386fa9e4066Sahrens if (error == 0) 1387fa9e4066Sahrens return; 1388fa9e4066Sahrens 1389fa9e4066Sahrens if (error == EAGAIN) 1390fa9e4066Sahrens (void) fatal("double-allocation, bp=%p", bp); 1391fa9e4066Sahrens 1392fa9e4066Sahrens if (error == ESTALE) 1393fa9e4066Sahrens (void) fatal("reference to freed block, bp=%p", bp); 1394fa9e4066Sahrens 1395fa9e4066Sahrens (void) fatal("fatal error %d in bp %p", error, bp); 1396fa9e4066Sahrens } 1397fa9e4066Sahrens 1398fa9e4066Sahrens static int 1399fa9e4066Sahrens zdb_blkptr_cb(traverse_blk_cache_t *bc, spa_t *spa, void *arg) 1400fa9e4066Sahrens { 1401fa9e4066Sahrens zbookmark_t *zb = &bc->bc_bookmark; 1402fa9e4066Sahrens zdb_cb_t *zcb = arg; 1403fa9e4066Sahrens blkptr_t *bp = &bc->bc_blkptr; 1404fa9e4066Sahrens dmu_object_type_t type = BP_GET_TYPE(bp); 1405fbabab8fSmaybee char blkbuf[BP_SPRINTF_LEN]; 1406fa9e4066Sahrens int error = 0; 1407fa9e4066Sahrens 1408fa9e4066Sahrens if (bc->bc_errno) { 1409fa9e4066Sahrens if (zcb->zcb_readfails++ < 10 && dump_opt['L']) { 1410fa9e4066Sahrens zdb_refresh_ubsync(spa); 1411fa9e4066Sahrens error = EAGAIN; 1412fa9e4066Sahrens } else { 1413fa9e4066Sahrens zcb->zcb_haderrors = 1; 1414fa9e4066Sahrens zcb->zcb_errors[bc->bc_errno]++; 1415fa9e4066Sahrens error = ERESTART; 1416fa9e4066Sahrens } 1417fa9e4066Sahrens 1418fa9e4066Sahrens if (dump_opt['b'] >= 3 || (dump_opt['b'] >= 2 && bc->bc_errno)) 1419fbabab8fSmaybee sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp); 1420fa9e4066Sahrens else 1421fa9e4066Sahrens blkbuf[0] = '\0'; 1422fa9e4066Sahrens 1423fa9e4066Sahrens (void) printf("zdb_blkptr_cb: Got error %d reading " 1424*ea8dc4b6Seschrock "<%llu, %llu, %lld, %llx> %s -- %s\n", 1425fa9e4066Sahrens bc->bc_errno, 1426fa9e4066Sahrens (u_longlong_t)zb->zb_objset, 1427fa9e4066Sahrens (u_longlong_t)zb->zb_object, 1428*ea8dc4b6Seschrock (u_longlong_t)zb->zb_level, 1429fa9e4066Sahrens (u_longlong_t)zb->zb_blkid, 1430fa9e4066Sahrens blkbuf, 1431fa9e4066Sahrens error == EAGAIN ? "retrying" : "skipping"); 1432fa9e4066Sahrens 1433fa9e4066Sahrens return (error); 1434fa9e4066Sahrens } 1435fa9e4066Sahrens 1436fa9e4066Sahrens zcb->zcb_readfails = 0; 1437fa9e4066Sahrens 1438fa9e4066Sahrens ASSERT(bp->blk_birth != 0); 1439fa9e4066Sahrens 1440fa9e4066Sahrens zdb_count_block(spa, zcb, bp, type); 1441fa9e4066Sahrens 1442fa9e4066Sahrens if (dump_opt['b'] >= 4) { 1443fbabab8fSmaybee sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, bp); 1444fa9e4066Sahrens (void) printf("objset %llu object %llu offset 0x%llx %s\n", 1445fa9e4066Sahrens (u_longlong_t)zb->zb_objset, 1446fa9e4066Sahrens (u_longlong_t)zb->zb_object, 1447fa9e4066Sahrens (u_longlong_t)blkid2offset(bc->bc_dnode, 1448fa9e4066Sahrens zb->zb_level, zb->zb_blkid), 1449fa9e4066Sahrens blkbuf); 1450fa9e4066Sahrens } 1451fa9e4066Sahrens 1452fa9e4066Sahrens return (0); 1453fa9e4066Sahrens } 1454fa9e4066Sahrens 1455fa9e4066Sahrens static int 1456fa9e4066Sahrens dump_block_stats(spa_t *spa) 1457fa9e4066Sahrens { 1458fa9e4066Sahrens traverse_handle_t *th; 1459fa9e4066Sahrens zdb_cb_t zcb = { 0 }; 1460*ea8dc4b6Seschrock traverse_blk_cache_t dummy_cache = { 0 }; 1461fa9e4066Sahrens zdb_blkstats_t *zb, *tzb; 1462fa9e4066Sahrens uint64_t alloc, space; 1463fa9e4066Sahrens int leaks = 0; 1464fa9e4066Sahrens int advance = zdb_advance; 1465fa9e4066Sahrens int flags; 1466fa9e4066Sahrens int e; 1467fa9e4066Sahrens 1468*ea8dc4b6Seschrock zcb.zcb_cache = &dummy_cache; 1469*ea8dc4b6Seschrock 1470fa9e4066Sahrens if (dump_opt['c']) 1471fa9e4066Sahrens advance |= ADVANCE_DATA; 1472fa9e4066Sahrens 1473*ea8dc4b6Seschrock advance |= ADVANCE_PRUNE | ADVANCE_ZIL; 1474fa9e4066Sahrens 1475fa9e4066Sahrens (void) printf("\nTraversing all blocks to %sverify" 1476fa9e4066Sahrens " nothing leaked ...\n", 1477fa9e4066Sahrens dump_opt['c'] ? "verify checksums and " : ""); 1478fa9e4066Sahrens 1479fa9e4066Sahrens /* 1480fa9e4066Sahrens * Load all space maps. As we traverse the pool, if we find a block 1481fa9e4066Sahrens * that's not in its space map, that indicates a double-allocation, 1482fa9e4066Sahrens * reference to a freed block, or an unclaimed block. Otherwise we 1483fa9e4066Sahrens * remove the block from the space map. If the space maps are not 1484fa9e4066Sahrens * empty when we're done, that indicates leaked blocks. 1485fa9e4066Sahrens */ 1486fa9e4066Sahrens if (!dump_opt['L']) 1487fa9e4066Sahrens zdb_space_map_load(spa); 1488fa9e4066Sahrens 1489fa9e4066Sahrens /* 1490fa9e4066Sahrens * If there's a deferred-free bplist, process that first. 1491fa9e4066Sahrens */ 1492fa9e4066Sahrens if (spa->spa_sync_bplist_obj != 0) { 1493fa9e4066Sahrens bplist_t *bpl = &spa->spa_sync_bplist; 1494fa9e4066Sahrens blkptr_t blk; 1495fa9e4066Sahrens uint64_t itor = 0; 1496fa9e4066Sahrens 1497*ea8dc4b6Seschrock VERIFY(0 == bplist_open(bpl, spa->spa_meta_objset, 1498*ea8dc4b6Seschrock spa->spa_sync_bplist_obj)); 1499fa9e4066Sahrens 1500fa9e4066Sahrens while (bplist_iterate(bpl, &itor, &blk) == 0) { 1501fa9e4066Sahrens zdb_count_block(spa, &zcb, &blk, DMU_OT_DEFERRED); 1502fa9e4066Sahrens if (dump_opt['b'] >= 4) { 1503fbabab8fSmaybee char blkbuf[BP_SPRINTF_LEN]; 1504fbabab8fSmaybee sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &blk); 1505fa9e4066Sahrens (void) printf("[%s] %s\n", 1506fa9e4066Sahrens "deferred free", blkbuf); 1507fa9e4066Sahrens } 1508fa9e4066Sahrens } 1509fa9e4066Sahrens 1510fa9e4066Sahrens bplist_close(bpl); 1511fa9e4066Sahrens } 1512fa9e4066Sahrens 1513fa9e4066Sahrens /* 1514*ea8dc4b6Seschrock * Now traverse the pool. If we're reading all data to verify 1515*ea8dc4b6Seschrock * checksums, do a scrubbing read so that we validate all copies. 1516fa9e4066Sahrens */ 1517fa9e4066Sahrens flags = ZIO_FLAG_CANFAIL; 1518fa9e4066Sahrens if (advance & ADVANCE_DATA) 1519fa9e4066Sahrens flags |= ZIO_FLAG_SCRUB; 1520fa9e4066Sahrens th = traverse_init(spa, zdb_blkptr_cb, &zcb, advance, flags); 1521fa9e4066Sahrens th->th_noread = zdb_noread; 1522fa9e4066Sahrens 1523*ea8dc4b6Seschrock traverse_add_pool(th, 0, spa_first_txg(spa)); 1524fa9e4066Sahrens 1525fa9e4066Sahrens while (traverse_more(th) == EAGAIN) 1526fa9e4066Sahrens continue; 1527fa9e4066Sahrens 1528fa9e4066Sahrens traverse_fini(th); 1529fa9e4066Sahrens 1530fa9e4066Sahrens if (zcb.zcb_haderrors) { 1531fa9e4066Sahrens (void) printf("\nError counts:\n\n"); 1532fa9e4066Sahrens (void) printf("\t%5s %s\n", "errno", "count"); 1533fa9e4066Sahrens for (e = 0; e < 256; e++) { 1534fa9e4066Sahrens if (zcb.zcb_errors[e] != 0) { 1535fa9e4066Sahrens (void) printf("\t%5d %llu\n", 1536fa9e4066Sahrens e, (u_longlong_t)zcb.zcb_errors[e]); 1537fa9e4066Sahrens } 1538fa9e4066Sahrens } 1539fa9e4066Sahrens } 1540fa9e4066Sahrens 1541fa9e4066Sahrens /* 1542fa9e4066Sahrens * Report any leaked segments. 1543fa9e4066Sahrens */ 1544fa9e4066Sahrens if (!dump_opt['L']) 1545fa9e4066Sahrens zdb_space_map_vacate(spa); 1546fa9e4066Sahrens 1547fa9e4066Sahrens if (dump_opt['L']) 1548fa9e4066Sahrens (void) printf("\n\n *** Live pool traversal; " 1549fa9e4066Sahrens "block counts are only approximate ***\n\n"); 1550fa9e4066Sahrens 1551fa9e4066Sahrens alloc = spa_get_alloc(spa); 1552fa9e4066Sahrens space = spa_get_space(spa); 1553fa9e4066Sahrens 1554fa9e4066Sahrens tzb = &zcb.zcb_type[ZB_TOTAL][DMU_OT_TOTAL]; 1555fa9e4066Sahrens 1556fa9e4066Sahrens if (tzb->zb_asize == alloc) { 1557fa9e4066Sahrens (void) printf("\n\tNo leaks (block sum matches space" 1558fa9e4066Sahrens " maps exactly)\n"); 1559fa9e4066Sahrens } else { 1560fa9e4066Sahrens (void) printf("block traversal size %llu != alloc %llu " 1561fa9e4066Sahrens "(leaked %lld)\n", 1562fa9e4066Sahrens (u_longlong_t)tzb->zb_asize, 1563fa9e4066Sahrens (u_longlong_t)alloc, 1564fa9e4066Sahrens (u_longlong_t)(alloc - tzb->zb_asize)); 1565fa9e4066Sahrens leaks = 1; 1566fa9e4066Sahrens } 1567fa9e4066Sahrens 1568fa9e4066Sahrens if (tzb->zb_count == 0) 1569fa9e4066Sahrens return (2); 1570fa9e4066Sahrens 1571fa9e4066Sahrens (void) printf("\n"); 1572fa9e4066Sahrens (void) printf("\tbp count: %10llu\n", 1573fa9e4066Sahrens (u_longlong_t)tzb->zb_count); 1574fa9e4066Sahrens (void) printf("\tbp logical: %10llu\t avg: %6llu\n", 1575fa9e4066Sahrens (u_longlong_t)tzb->zb_lsize, 1576fa9e4066Sahrens (u_longlong_t)(tzb->zb_lsize / tzb->zb_count)); 1577fa9e4066Sahrens (void) printf("\tbp physical: %10llu\t avg:" 1578fa9e4066Sahrens " %6llu\tcompression: %6.2f\n", 1579fa9e4066Sahrens (u_longlong_t)tzb->zb_psize, 1580fa9e4066Sahrens (u_longlong_t)(tzb->zb_psize / tzb->zb_count), 1581fa9e4066Sahrens (double)tzb->zb_lsize / tzb->zb_psize); 1582fa9e4066Sahrens (void) printf("\tbp allocated: %10llu\t avg:" 1583fa9e4066Sahrens " %6llu\tcompression: %6.2f\n", 1584fa9e4066Sahrens (u_longlong_t)tzb->zb_asize, 1585fa9e4066Sahrens (u_longlong_t)(tzb->zb_asize / tzb->zb_count), 1586fa9e4066Sahrens (double)tzb->zb_lsize / tzb->zb_asize); 1587fa9e4066Sahrens (void) printf("\tSPA allocated: %10llu\tused: %5.2f%%\n", 1588fa9e4066Sahrens (u_longlong_t)alloc, 100.0 * alloc / space); 1589fa9e4066Sahrens 1590fa9e4066Sahrens if (dump_opt['b'] >= 2) { 1591fa9e4066Sahrens int l, t, level; 1592fa9e4066Sahrens (void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE" 1593fa9e4066Sahrens "\t avg\t comp\t%%Total\tType\n"); 1594fa9e4066Sahrens 1595fa9e4066Sahrens for (t = 0; t <= DMU_OT_NUMTYPES; t++) { 1596fa9e4066Sahrens char csize[6], lsize[6], psize[6], asize[6], avg[6]; 1597fa9e4066Sahrens char *typename; 1598fa9e4066Sahrens 1599fa9e4066Sahrens typename = t == DMU_OT_DEFERRED ? "deferred free" : 1600fa9e4066Sahrens t == DMU_OT_TOTAL ? "Total" : dmu_ot[t].ot_name; 1601fa9e4066Sahrens 1602fa9e4066Sahrens if (zcb.zcb_type[ZB_TOTAL][t].zb_asize == 0) { 1603fa9e4066Sahrens (void) printf("%6s\t%5s\t%5s\t%5s" 1604fa9e4066Sahrens "\t%5s\t%5s\t%6s\t%s\n", 1605fa9e4066Sahrens "-", 1606fa9e4066Sahrens "-", 1607fa9e4066Sahrens "-", 1608fa9e4066Sahrens "-", 1609fa9e4066Sahrens "-", 1610fa9e4066Sahrens "-", 1611fa9e4066Sahrens "-", 1612fa9e4066Sahrens typename); 1613fa9e4066Sahrens continue; 1614fa9e4066Sahrens } 1615fa9e4066Sahrens 1616fa9e4066Sahrens for (l = ZB_TOTAL - 1; l >= -1; l--) { 1617fa9e4066Sahrens level = (l == -1 ? ZB_TOTAL : l); 1618fa9e4066Sahrens zb = &zcb.zcb_type[level][t]; 1619fa9e4066Sahrens 1620fa9e4066Sahrens if (zb->zb_asize == 0) 1621fa9e4066Sahrens continue; 1622fa9e4066Sahrens 1623fa9e4066Sahrens if (dump_opt['b'] < 3 && level != ZB_TOTAL) 1624fa9e4066Sahrens continue; 1625fa9e4066Sahrens 1626fa9e4066Sahrens if (level == 0 && zb->zb_asize == 1627fa9e4066Sahrens zcb.zcb_type[ZB_TOTAL][t].zb_asize) 1628fa9e4066Sahrens continue; 1629fa9e4066Sahrens 1630fa9e4066Sahrens nicenum(zb->zb_count, csize); 1631fa9e4066Sahrens nicenum(zb->zb_lsize, lsize); 1632fa9e4066Sahrens nicenum(zb->zb_psize, psize); 1633fa9e4066Sahrens nicenum(zb->zb_asize, asize); 1634fa9e4066Sahrens nicenum(zb->zb_asize / zb->zb_count, avg); 1635fa9e4066Sahrens 1636fa9e4066Sahrens (void) printf("%6s\t%5s\t%5s\t%5s\t%5s" 1637fa9e4066Sahrens "\t%5.2f\t%6.2f\t", 1638fa9e4066Sahrens csize, lsize, psize, asize, avg, 1639fa9e4066Sahrens (double)zb->zb_lsize / zb->zb_psize, 1640fa9e4066Sahrens 100.0 * zb->zb_asize / tzb->zb_asize); 1641fa9e4066Sahrens 1642fa9e4066Sahrens if (level == ZB_TOTAL) 1643fa9e4066Sahrens (void) printf("%s\n", typename); 1644fa9e4066Sahrens else 1645fa9e4066Sahrens (void) printf(" L%d %s\n", 1646fa9e4066Sahrens level, typename); 1647fa9e4066Sahrens } 1648fa9e4066Sahrens } 1649fa9e4066Sahrens } 1650fa9e4066Sahrens 1651fa9e4066Sahrens (void) printf("\n"); 1652fa9e4066Sahrens 1653fa9e4066Sahrens if (leaks) 1654fa9e4066Sahrens return (2); 1655fa9e4066Sahrens 1656fa9e4066Sahrens if (zcb.zcb_haderrors) 1657fa9e4066Sahrens return (3); 1658fa9e4066Sahrens 1659fa9e4066Sahrens return (0); 1660fa9e4066Sahrens } 1661fa9e4066Sahrens 1662fa9e4066Sahrens static void 1663fa9e4066Sahrens dump_zpool(spa_t *spa) 1664fa9e4066Sahrens { 1665fa9e4066Sahrens dsl_pool_t *dp = spa_get_dsl(spa); 1666fa9e4066Sahrens int rc = 0; 1667fa9e4066Sahrens 1668fa9e4066Sahrens if (dump_opt['u']) 1669fa9e4066Sahrens dump_uberblock(&spa->spa_uberblock); 1670fa9e4066Sahrens 1671fa9e4066Sahrens if (dump_opt['d'] || dump_opt['i']) { 1672fa9e4066Sahrens dump_dir(dp->dp_meta_objset); 1673fa9e4066Sahrens if (dump_opt['d'] >= 3) { 1674fa9e4066Sahrens dump_bplist(dp->dp_meta_objset, 1675fa9e4066Sahrens spa->spa_sync_bplist_obj, "Deferred frees"); 1676fa9e4066Sahrens dump_dtl(spa->spa_root_vdev, 0); 1677fa9e4066Sahrens dump_metaslabs(spa); 1678fa9e4066Sahrens } 1679fa9e4066Sahrens dmu_objset_find(spa->spa_name, dump_one_dir, NULL, 1680fa9e4066Sahrens DS_FIND_SNAPSHOTS); 1681fa9e4066Sahrens } 1682fa9e4066Sahrens 1683fa9e4066Sahrens if (dump_opt['b'] || dump_opt['c']) 1684fa9e4066Sahrens rc = dump_block_stats(spa); 1685fa9e4066Sahrens 1686fa9e4066Sahrens if (dump_opt['s']) 1687fa9e4066Sahrens show_pool_stats(spa); 1688fa9e4066Sahrens 1689fa9e4066Sahrens if (rc != 0) 1690fa9e4066Sahrens exit(rc); 1691fa9e4066Sahrens } 1692fa9e4066Sahrens 1693fa9e4066Sahrens int 1694fa9e4066Sahrens main(int argc, char **argv) 1695fa9e4066Sahrens { 1696fa9e4066Sahrens int i, c; 1697fa9e4066Sahrens struct rlimit rl = { 1024, 1024 }; 1698fa9e4066Sahrens spa_t *spa; 1699fa9e4066Sahrens objset_t *os = NULL; 1700fa9e4066Sahrens char *endstr; 1701fa9e4066Sahrens int dump_all = 1; 1702fa9e4066Sahrens int verbose = 0; 1703fa9e4066Sahrens int error; 1704fa9e4066Sahrens int flag, set; 1705*ea8dc4b6Seschrock vdev_knob_t *vk; 1706fa9e4066Sahrens 1707fa9e4066Sahrens (void) setrlimit(RLIMIT_NOFILE, &rl); 1708fa9e4066Sahrens 1709fa9e4066Sahrens dprintf_setup(&argc, argv); 1710fa9e4066Sahrens 1711fa9e4066Sahrens while ((c = getopt(argc, argv, "udibcsvCLO:B:Ul")) != -1) { 1712fa9e4066Sahrens switch (c) { 1713fa9e4066Sahrens case 'u': 1714fa9e4066Sahrens case 'd': 1715fa9e4066Sahrens case 'i': 1716fa9e4066Sahrens case 'b': 1717fa9e4066Sahrens case 'c': 1718fa9e4066Sahrens case 's': 1719fa9e4066Sahrens case 'C': 1720fa9e4066Sahrens case 'l': 1721fa9e4066Sahrens dump_opt[c]++; 1722fa9e4066Sahrens dump_all = 0; 1723fa9e4066Sahrens break; 1724fa9e4066Sahrens case 'L': 1725fa9e4066Sahrens dump_opt[c]++; 1726fa9e4066Sahrens break; 1727fa9e4066Sahrens case 'O': 1728fa9e4066Sahrens endstr = optarg; 1729fa9e4066Sahrens if (endstr[0] == '!') { 1730fa9e4066Sahrens endstr++; 1731fa9e4066Sahrens set = 0; 1732fa9e4066Sahrens } else { 1733fa9e4066Sahrens set = 1; 1734fa9e4066Sahrens } 1735fa9e4066Sahrens if (strcmp(endstr, "post") == 0) { 1736fa9e4066Sahrens flag = ADVANCE_PRE; 1737fa9e4066Sahrens set = !set; 1738fa9e4066Sahrens } else if (strcmp(endstr, "pre") == 0) { 1739fa9e4066Sahrens flag = ADVANCE_PRE; 1740fa9e4066Sahrens } else if (strcmp(endstr, "prune") == 0) { 1741fa9e4066Sahrens flag = ADVANCE_PRUNE; 1742fa9e4066Sahrens } else if (strcmp(endstr, "data") == 0) { 1743fa9e4066Sahrens flag = ADVANCE_DATA; 1744fa9e4066Sahrens } else if (strcmp(endstr, "holes") == 0) { 1745fa9e4066Sahrens flag = ADVANCE_HOLES; 1746fa9e4066Sahrens } else { 1747fa9e4066Sahrens usage(); 1748fa9e4066Sahrens } 1749fa9e4066Sahrens if (set) 1750fa9e4066Sahrens zdb_advance |= flag; 1751fa9e4066Sahrens else 1752fa9e4066Sahrens zdb_advance &= ~flag; 1753fa9e4066Sahrens break; 1754fa9e4066Sahrens case 'B': 1755fa9e4066Sahrens endstr = optarg - 1; 1756fa9e4066Sahrens zdb_noread.zb_objset = strtoull(endstr + 1, &endstr, 0); 1757fa9e4066Sahrens zdb_noread.zb_object = strtoull(endstr + 1, &endstr, 0); 1758fa9e4066Sahrens zdb_noread.zb_level = strtol(endstr + 1, &endstr, 0); 1759fa9e4066Sahrens zdb_noread.zb_blkid = strtoull(endstr + 1, &endstr, 16); 1760fa9e4066Sahrens (void) printf("simulating bad block " 1761*ea8dc4b6Seschrock "<%llu, %llu, %lld, %llx>\n", 1762fa9e4066Sahrens (u_longlong_t)zdb_noread.zb_objset, 1763fa9e4066Sahrens (u_longlong_t)zdb_noread.zb_object, 1764*ea8dc4b6Seschrock (u_longlong_t)zdb_noread.zb_level, 1765fa9e4066Sahrens (u_longlong_t)zdb_noread.zb_blkid); 1766fa9e4066Sahrens break; 1767fa9e4066Sahrens case 'v': 1768fa9e4066Sahrens verbose++; 1769fa9e4066Sahrens break; 1770fa9e4066Sahrens case 'U': 1771fa9e4066Sahrens spa_config_dir = "/tmp"; 1772fa9e4066Sahrens break; 1773fa9e4066Sahrens default: 1774fa9e4066Sahrens usage(); 1775fa9e4066Sahrens break; 1776fa9e4066Sahrens } 1777fa9e4066Sahrens } 1778fa9e4066Sahrens 1779fa9e4066Sahrens kernel_init(FREAD); 1780fa9e4066Sahrens 1781*ea8dc4b6Seschrock /* 1782*ea8dc4b6Seschrock * Disable vdev caching. If we don't do this, live pool traversal 1783*ea8dc4b6Seschrock * won't make progress because it will never see disk updates. 1784*ea8dc4b6Seschrock */ 1785*ea8dc4b6Seschrock for (vk = vdev_knob_next(NULL); vk != NULL; vk = vdev_knob_next(vk)) { 1786*ea8dc4b6Seschrock if (strcmp(vk->vk_name, "cache_size") == 0) 1787*ea8dc4b6Seschrock vk->vk_default = 0; 1788*ea8dc4b6Seschrock } 1789*ea8dc4b6Seschrock 1790fa9e4066Sahrens for (c = 0; c < 256; c++) { 1791fa9e4066Sahrens if (dump_all && c != 'L' && c != 'l') 1792fa9e4066Sahrens dump_opt[c] = 1; 1793fa9e4066Sahrens if (dump_opt[c]) 1794fa9e4066Sahrens dump_opt[c] += verbose; 1795fa9e4066Sahrens } 1796fa9e4066Sahrens 1797fa9e4066Sahrens argc -= optind; 1798fa9e4066Sahrens argv += optind; 1799fa9e4066Sahrens 1800fa9e4066Sahrens if (argc < 1) { 1801fa9e4066Sahrens if (dump_opt['C']) { 1802fa9e4066Sahrens dump_config(NULL); 1803fa9e4066Sahrens return (0); 1804fa9e4066Sahrens } 1805fa9e4066Sahrens usage(); 1806fa9e4066Sahrens } 1807fa9e4066Sahrens 1808fa9e4066Sahrens if (dump_opt['l']) { 1809fa9e4066Sahrens dump_label(argv[0]); 1810fa9e4066Sahrens return (0); 1811fa9e4066Sahrens } 1812fa9e4066Sahrens 1813fa9e4066Sahrens if (dump_opt['C']) 1814fa9e4066Sahrens dump_config(argv[0]); 1815fa9e4066Sahrens 1816fa9e4066Sahrens if (strchr(argv[0], '/') != NULL) { 1817fa9e4066Sahrens error = dmu_objset_open(argv[0], DMU_OST_ANY, 1818fa9e4066Sahrens DS_MODE_STANDARD | DS_MODE_READONLY, &os); 1819fa9e4066Sahrens } else { 1820fa9e4066Sahrens error = spa_open(argv[0], &spa, FTAG); 1821fa9e4066Sahrens } 1822fa9e4066Sahrens 1823fa9e4066Sahrens if (error) 1824fa9e4066Sahrens fatal("can't open %s: error %d", argv[0], error); 1825fa9e4066Sahrens 1826fa9e4066Sahrens argv++; 1827fa9e4066Sahrens if (--argc > 0) { 1828fa9e4066Sahrens zopt_objects = argc; 1829fa9e4066Sahrens zopt_object = calloc(zopt_objects, sizeof (uint64_t)); 1830fa9e4066Sahrens for (i = 0; i < zopt_objects; i++) { 1831fa9e4066Sahrens errno = 0; 1832fa9e4066Sahrens zopt_object[i] = strtoull(argv[i], NULL, 0); 1833fa9e4066Sahrens if (zopt_object[i] == 0 && errno != 0) 1834fa9e4066Sahrens fatal("bad object number %s: %s", 1835fa9e4066Sahrens argv[i], strerror(errno)); 1836fa9e4066Sahrens } 1837fa9e4066Sahrens } 1838fa9e4066Sahrens 1839fa9e4066Sahrens if (os != NULL) { 1840fa9e4066Sahrens dump_dir(os); 1841fa9e4066Sahrens dmu_objset_close(os); 1842fa9e4066Sahrens } else { 1843fa9e4066Sahrens dump_zpool(spa); 1844fa9e4066Sahrens spa_close(spa, FTAG); 1845fa9e4066Sahrens } 1846fa9e4066Sahrens 1847fa9e4066Sahrens kernel_fini(); 1848fa9e4066Sahrens 1849fa9e4066Sahrens return (0); 1850fa9e4066Sahrens } 1851