zdb.c (235701) | zdb.c (243674) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 4 unchanged lines hidden (view full) --- 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ |
21 |
|
21/* 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. | 22/* 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
24 * Copyright (c) 2012 by Delphix. All rights reserved. |
|
23 */ 24 25#include <stdio.h> 26#include <stdio_ext.h> 27#include <stdlib.h> 28#include <ctype.h> 29#include <sys/zfs_context.h> 30#include <sys/spa.h> --- 18 unchanged lines hidden (view full) --- 49#include <sys/stat.h> 50#include <sys/resource.h> 51#include <sys/dmu_traverse.h> 52#include <sys/zio_checksum.h> 53#include <sys/zio_compress.h> 54#include <sys/zfs_fuid.h> 55#include <sys/arc.h> 56#include <sys/ddt.h> | 25 */ 26 27#include <stdio.h> 28#include <stdio_ext.h> 29#include <stdlib.h> 30#include <ctype.h> 31#include <sys/zfs_context.h> 32#include <sys/spa.h> --- 18 unchanged lines hidden (view full) --- 51#include <sys/stat.h> 52#include <sys/resource.h> 53#include <sys/dmu_traverse.h> 54#include <sys/zio_checksum.h> 55#include <sys/zio_compress.h> 56#include <sys/zfs_fuid.h> 57#include <sys/arc.h> 58#include <sys/ddt.h> |
59#include <sys/zfeature.h> |
|
57#undef ZFS_MAXNAMELEN 58#undef verify 59#include <libzfs.h> 60 61#define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \ 62 zio_compress_table[(idx)].ci_name : "UNKNOWN") 63#define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \ 64 zio_checksum_table[(idx)].ci_name : "UNKNOWN") 65#define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \ | 60#undef ZFS_MAXNAMELEN 61#undef verify 62#include <libzfs.h> 63 64#define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \ 65 zio_compress_table[(idx)].ci_name : "UNKNOWN") 66#define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \ 67 zio_checksum_table[(idx)].ci_name : "UNKNOWN") 68#define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \ |
66 dmu_ot[(idx)].ot_name : "UNKNOWN") | 69 dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \ 70 dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN") |
67#define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES) 68 69#ifndef lint 70extern int zfs_recover; 71#else 72int zfs_recover; 73#endif 74 --- 1008 unchanged lines hidden (view full) --- 1083 char used[32], compressed[32], uncompressed[32], unique[32]; 1084 char blkbuf[BP_SPRINTF_LEN]; 1085 1086 if (ds == NULL) 1087 return; 1088 1089 ASSERT(size == sizeof (*ds)); 1090 crtime = ds->ds_creation_time; | 71#define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES) 72 73#ifndef lint 74extern int zfs_recover; 75#else 76int zfs_recover; 77#endif 78 --- 1008 unchanged lines hidden (view full) --- 1087 char used[32], compressed[32], uncompressed[32], unique[32]; 1088 char blkbuf[BP_SPRINTF_LEN]; 1089 1090 if (ds == NULL) 1091 return; 1092 1093 ASSERT(size == sizeof (*ds)); 1094 crtime = ds->ds_creation_time; |
1091 zdb_nicenum(ds->ds_used_bytes, used); | 1095 zdb_nicenum(ds->ds_referenced_bytes, used); |
1092 zdb_nicenum(ds->ds_compressed_bytes, compressed); 1093 zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed); 1094 zdb_nicenum(ds->ds_unique_bytes, unique); 1095 sprintf_blkptr(blkbuf, &ds->ds_bp); 1096 1097 (void) printf("\t\tdir_obj = %llu\n", 1098 (u_longlong_t)ds->ds_dir_obj); 1099 (void) printf("\t\tprev_snap_obj = %llu\n", --- 27 unchanged lines hidden (view full) --- 1127 (u_longlong_t)ds->ds_next_clones_obj); 1128 (void) printf("\t\tprops_obj = %llu\n", 1129 (u_longlong_t)ds->ds_props_obj); 1130 (void) printf("\t\tbp = %s\n", blkbuf); 1131} 1132 1133/* ARGSUSED */ 1134static int | 1096 zdb_nicenum(ds->ds_compressed_bytes, compressed); 1097 zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed); 1098 zdb_nicenum(ds->ds_unique_bytes, unique); 1099 sprintf_blkptr(blkbuf, &ds->ds_bp); 1100 1101 (void) printf("\t\tdir_obj = %llu\n", 1102 (u_longlong_t)ds->ds_dir_obj); 1103 (void) printf("\t\tprev_snap_obj = %llu\n", --- 27 unchanged lines hidden (view full) --- 1131 (u_longlong_t)ds->ds_next_clones_obj); 1132 (void) printf("\t\tprops_obj = %llu\n", 1133 (u_longlong_t)ds->ds_props_obj); 1134 (void) printf("\t\tbp = %s\n", blkbuf); 1135} 1136 1137/* ARGSUSED */ 1138static int |
1139dump_bptree_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) 1140{ 1141 char blkbuf[BP_SPRINTF_LEN]; 1142 1143 if (bp->blk_birth != 0) { 1144 sprintf_blkptr(blkbuf, bp); 1145 (void) printf("\t%s\n", blkbuf); 1146 } 1147 return (0); 1148} 1149 1150static void 1151dump_bptree(objset_t *os, uint64_t obj, char *name) 1152{ 1153 char bytes[32]; 1154 bptree_phys_t *bt; 1155 dmu_buf_t *db; 1156 1157 if (dump_opt['d'] < 3) 1158 return; 1159 1160 VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db)); 1161 bt = db->db_data; 1162 zdb_nicenum(bt->bt_bytes, bytes); 1163 (void) printf("\n %s: %llu datasets, %s\n", 1164 name, (unsigned long long)(bt->bt_end - bt->bt_begin), bytes); 1165 dmu_buf_rele(db, FTAG); 1166 1167 if (dump_opt['d'] < 5) 1168 return; 1169 1170 (void) printf("\n"); 1171 1172 (void) bptree_iterate(os, obj, B_FALSE, dump_bptree_cb, NULL, NULL); 1173} 1174 1175/* ARGSUSED */ 1176static int |
|
1135dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) 1136{ 1137 char blkbuf[BP_SPRINTF_LEN]; 1138 1139 ASSERT(bp->blk_birth != 0); 1140 sprintf_blkptr_compact(blkbuf, bp); 1141 (void) printf("\t%s\n", blkbuf); 1142 return (0); --- 735 unchanged lines hidden (view full) --- 1878 uint64_t zb_count; 1879} zdb_blkstats_t; 1880 1881/* 1882 * Extended object types to report deferred frees and dedup auto-ditto blocks. 1883 */ 1884#define ZDB_OT_DEFERRED (DMU_OT_NUMTYPES + 0) 1885#define ZDB_OT_DITTO (DMU_OT_NUMTYPES + 1) | 1177dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx) 1178{ 1179 char blkbuf[BP_SPRINTF_LEN]; 1180 1181 ASSERT(bp->blk_birth != 0); 1182 sprintf_blkptr_compact(blkbuf, bp); 1183 (void) printf("\t%s\n", blkbuf); 1184 return (0); --- 735 unchanged lines hidden (view full) --- 1920 uint64_t zb_count; 1921} zdb_blkstats_t; 1922 1923/* 1924 * Extended object types to report deferred frees and dedup auto-ditto blocks. 1925 */ 1926#define ZDB_OT_DEFERRED (DMU_OT_NUMTYPES + 0) 1927#define ZDB_OT_DITTO (DMU_OT_NUMTYPES + 1) |
1886#define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 2) | 1928#define ZDB_OT_OTHER (DMU_OT_NUMTYPES + 2) 1929#define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 3) |
1887 1888static char *zdb_ot_extname[] = { 1889 "deferred free", 1890 "dedup ditto", | 1930 1931static char *zdb_ot_extname[] = { 1932 "deferred free", 1933 "dedup ditto", |
1934 "other", |
|
1891 "Total", 1892}; 1893 1894#define ZB_TOTAL DN_MAX_LEVELS 1895 1896typedef struct zdb_cb { 1897 zdb_blkstats_t zcb_type[ZB_TOTAL + 1][ZDB_OT_TOTAL + 1]; 1898 uint64_t zcb_dedup_asize; --- 64 unchanged lines hidden (view full) --- 1963 dmu_object_type_t type; 1964 boolean_t is_metadata; 1965 1966 if (bp == NULL) 1967 return (0); 1968 1969 type = BP_GET_TYPE(bp); 1970 | 1935 "Total", 1936}; 1937 1938#define ZB_TOTAL DN_MAX_LEVELS 1939 1940typedef struct zdb_cb { 1941 zdb_blkstats_t zcb_type[ZB_TOTAL + 1][ZDB_OT_TOTAL + 1]; 1942 uint64_t zcb_dedup_asize; --- 64 unchanged lines hidden (view full) --- 2007 dmu_object_type_t type; 2008 boolean_t is_metadata; 2009 2010 if (bp == NULL) 2011 return (0); 2012 2013 type = BP_GET_TYPE(bp); 2014 |
1971 zdb_count_block(zcb, zilog, bp, type); | 2015 zdb_count_block(zcb, zilog, bp, 2016 (type & DMU_OT_NEWTYPE) ? ZDB_OT_OTHER : type); |
1972 | 2017 |
1973 is_metadata = (BP_GET_LEVEL(bp) != 0 || dmu_ot[type].ot_metadata); | 2018 is_metadata = (BP_GET_LEVEL(bp) != 0 || DMU_OT_IS_METADATA(type)); |
1974 1975 if (dump_opt['c'] > 1 || (dump_opt['c'] && is_metadata)) { 1976 int ioerr; 1977 size_t size = BP_GET_PSIZE(bp); 1978 void *data = malloc(size); 1979 int flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCRUB | ZIO_FLAG_RAW; 1980 1981 /* If it's an intent log block, failure is expected. */ --- 210 unchanged lines hidden (view full) --- 2192 * If there's a deferred-free bplist, process that first. 2193 */ 2194 (void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj, 2195 count_block_cb, &zcb, NULL); 2196 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) { 2197 (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj, 2198 count_block_cb, &zcb, NULL); 2199 } | 2019 2020 if (dump_opt['c'] > 1 || (dump_opt['c'] && is_metadata)) { 2021 int ioerr; 2022 size_t size = BP_GET_PSIZE(bp); 2023 void *data = malloc(size); 2024 int flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCRUB | ZIO_FLAG_RAW; 2025 2026 /* If it's an intent log block, failure is expected. */ --- 210 unchanged lines hidden (view full) --- 2237 * If there's a deferred-free bplist, process that first. 2238 */ 2239 (void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj, 2240 count_block_cb, &zcb, NULL); 2241 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) { 2242 (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj, 2243 count_block_cb, &zcb, NULL); 2244 } |
2245 if (spa_feature_is_active(spa, 2246 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) { 2247 VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset, 2248 spa->spa_dsl_pool->dp_bptree_obj, B_FALSE, count_block_cb, 2249 &zcb, NULL)); 2250 } |
|
2200 2201 if (dump_opt['c'] > 1) 2202 flags |= TRAVERSE_PREFETCH_DATA; 2203 2204 zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb); 2205 2206 if (zcb.zcb_haderrors) { 2207 (void) printf("\nError counts:\n\n"); --- 160 unchanged lines hidden (view full) --- 2368 (void) printf("traversing objset %llu, %llu objects, " 2369 "%lu blocks so far\n", 2370 (u_longlong_t)zb->zb_objset, 2371 (u_longlong_t)bp->blk_fill, 2372 avl_numnodes(t)); 2373 } 2374 2375 if (BP_IS_HOLE(bp) || BP_GET_CHECKSUM(bp) == ZIO_CHECKSUM_OFF || | 2251 2252 if (dump_opt['c'] > 1) 2253 flags |= TRAVERSE_PREFETCH_DATA; 2254 2255 zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb); 2256 2257 if (zcb.zcb_haderrors) { 2258 (void) printf("\nError counts:\n\n"); --- 160 unchanged lines hidden (view full) --- 2419 (void) printf("traversing objset %llu, %llu objects, " 2420 "%lu blocks so far\n", 2421 (u_longlong_t)zb->zb_objset, 2422 (u_longlong_t)bp->blk_fill, 2423 avl_numnodes(t)); 2424 } 2425 2426 if (BP_IS_HOLE(bp) || BP_GET_CHECKSUM(bp) == ZIO_CHECKSUM_OFF || |
2376 BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) | 2427 BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp))) |
2377 return (0); 2378 2379 ddt_key_fill(&zdde_search.zdde_key, bp); 2380 2381 zdde = avl_find(t, &zdde_search, &where); 2382 2383 if (zdde == NULL) { 2384 zdde = umem_zalloc(sizeof (*zdde), UMEM_NOFAIL); --- 88 unchanged lines hidden (view full) --- 2473 dump_metaslabs(spa); 2474 2475 if (dump_opt['d'] || dump_opt['i']) { 2476 dump_dir(dp->dp_meta_objset); 2477 if (dump_opt['d'] >= 3) { 2478 dump_bpobj(&spa->spa_deferred_bpobj, "Deferred frees"); 2479 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) { 2480 dump_bpobj(&spa->spa_dsl_pool->dp_free_bpobj, | 2428 return (0); 2429 2430 ddt_key_fill(&zdde_search.zdde_key, bp); 2431 2432 zdde = avl_find(t, &zdde_search, &where); 2433 2434 if (zdde == NULL) { 2435 zdde = umem_zalloc(sizeof (*zdde), UMEM_NOFAIL); --- 88 unchanged lines hidden (view full) --- 2524 dump_metaslabs(spa); 2525 2526 if (dump_opt['d'] || dump_opt['i']) { 2527 dump_dir(dp->dp_meta_objset); 2528 if (dump_opt['d'] >= 3) { 2529 dump_bpobj(&spa->spa_deferred_bpobj, "Deferred frees"); 2530 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) { 2531 dump_bpobj(&spa->spa_dsl_pool->dp_free_bpobj, |
2481 "Pool frees"); | 2532 "Pool snapshot frees"); |
2482 } | 2533 } |
2534 2535 if (spa_feature_is_active(spa, 2536 &spa_feature_table[SPA_FEATURE_ASYNC_DESTROY])) { 2537 dump_bptree(spa->spa_meta_objset, 2538 spa->spa_dsl_pool->dp_bptree_obj, 2539 "Pool dataset frees"); 2540 } |
|
2483 dump_dtl(spa->spa_root_vdev, 0); 2484 } 2485 (void) dmu_objset_find(spa_name(spa), dump_one_dir, 2486 NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN); 2487 } 2488 if (dump_opt['b'] || dump_opt['c']) 2489 rc = dump_block_stats(spa); 2490 --- 673 unchanged lines hidden --- | 2541 dump_dtl(spa->spa_root_vdev, 0); 2542 } 2543 (void) dmu_objset_find(spa_name(spa), dump_one_dir, 2544 NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN); 2545 } 2546 if (dump_opt['b'] || dump_opt['c']) 2547 rc = dump_block_stats(spa); 2548 --- 673 unchanged lines hidden --- |