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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 /* Portions Copyright 2010 Robert Milkowski */
27
28 #include <mdb/mdb_ctf.h>
29 #include <sys/zfs_context.h>
30 #include <sys/mdb_modapi.h>
31 #include <sys/dbuf.h>
32 #include <sys/dmu_objset.h>
33 #include <sys/dsl_dir.h>
34 #include <sys/dsl_pool.h>
35 #include <sys/metaslab_impl.h>
36 #include <sys/space_map.h>
37 #include <sys/list.h>
38 #include <sys/spa_impl.h>
39 #include <sys/vdev_impl.h>
40 #include <sys/zap_leaf.h>
41 #include <sys/zap_impl.h>
42 #include <ctype.h>
43 #include <sys/zfs_acl.h>
1220 aux = "CORRUPT_DATA";
1221 break;
1222 case VDEV_AUX_NO_REPLICAS:
1223 aux = "NO_REPLICAS";
1224 break;
1225 case VDEV_AUX_BAD_GUID_SUM:
1226 aux = "BAD_GUID_SUM";
1227 break;
1228 case VDEV_AUX_TOO_SMALL:
1229 aux = "TOO_SMALL";
1230 break;
1231 case VDEV_AUX_BAD_LABEL:
1232 aux = "BAD_LABEL";
1233 break;
1234 case VDEV_AUX_VERSION_NEWER:
1235 aux = "VERS_NEWER";
1236 break;
1237 case VDEV_AUX_VERSION_OLDER:
1238 aux = "VERS_OLDER";
1239 break;
1240 case VDEV_AUX_SPARED:
1241 aux = "SPARED";
1242 break;
1243 case VDEV_AUX_ERR_EXCEEDED:
1244 aux = "ERR_EXCEEDED";
1245 break;
1246 case VDEV_AUX_IO_FAILURE:
1247 aux = "IO_FAILURE";
1248 break;
1249 case VDEV_AUX_BAD_LOG:
1250 aux = "BAD_LOG";
1251 break;
1252 case VDEV_AUX_EXTERNAL:
1253 aux = "EXTERNAL";
1254 break;
1255 case VDEV_AUX_SPLIT_POOL:
1256 aux = "SPLIT_POOL";
1257 break;
1258 default:
1259 aux = "UNKNOWN";
2165 mdb_warn("failed to read 'dmu_ot'");
2166 return (DCMD_ERR);
2167 }
2168
2169 if (mdb_getopts(argc, argv,
2170 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2171 NULL) != argc)
2172 return (DCMD_USAGE);
2173
2174 if (!(flags & DCMD_ADDRSPEC))
2175 return (DCMD_USAGE);
2176
2177 if (GETMEMB(addr, struct spa, spa_dsl_pool, addr) ||
2178 GETMEMB(addr, struct dsl_pool, dp_blkstats, addr) ||
2179 mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
2180 mdb_warn("failed to read data at %p;", addr);
2181 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2182 return (DCMD_ERR);
2183 }
2184
2185 tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_NUMTYPES];
2186 if (tzb->zb_gangs != 0) {
2187 mdb_printf("Ganged blocks: %llu\n",
2188 (longlong_t)tzb->zb_gangs);
2189 }
2190
2191 ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
2192 tzb->zb_ditto_3_of_3_samevdev;
2193 if (ditto != 0) {
2194 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2195 (longlong_t)ditto);
2196 }
2197
2198 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2199 "\t avg\t comp\t%%Total\tType\n");
2200
2201 for (t = 0; t <= DMU_OT_NUMTYPES; t++) {
2202 char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
2203 char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
2204 char avg[NICENUM_BUFLEN];
2205 char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
2206 char typename[64];
2207 int l;
2208
2209
2210 if (t == DMU_OT_DEFERRED)
2211 strcpy(typename, "deferred free");
2212 else if (t == DMU_OT_TOTAL)
2213 strcpy(typename, "Total");
2214 else if (mdb_readstr(typename, sizeof (typename),
2215 (uintptr_t)dmu_ot[t].ot_name) == -1) {
2216 mdb_warn("failed to read type name");
2217 return (DCMD_ERR);
2218 }
2219
2220 if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
2221 continue;
2222
2223 for (l = -1; l < DN_MAX_LEVELS; l++) {
2224 int level = (l == -1 ? DN_MAX_LEVELS : l);
2225 zfs_blkstat_t *zb = &stats.zab_type[level][t];
2226
2227 if (zb->zb_asize == 0)
2228 continue;
2229
2230 /*
2231 * Don't print each level unless requested.
|
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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 */
26
27 /* Portions Copyright 2010 Robert Milkowski */
28
29 #include <mdb/mdb_ctf.h>
30 #include <sys/zfs_context.h>
31 #include <sys/mdb_modapi.h>
32 #include <sys/dbuf.h>
33 #include <sys/dmu_objset.h>
34 #include <sys/dsl_dir.h>
35 #include <sys/dsl_pool.h>
36 #include <sys/metaslab_impl.h>
37 #include <sys/space_map.h>
38 #include <sys/list.h>
39 #include <sys/spa_impl.h>
40 #include <sys/vdev_impl.h>
41 #include <sys/zap_leaf.h>
42 #include <sys/zap_impl.h>
43 #include <ctype.h>
44 #include <sys/zfs_acl.h>
1221 aux = "CORRUPT_DATA";
1222 break;
1223 case VDEV_AUX_NO_REPLICAS:
1224 aux = "NO_REPLICAS";
1225 break;
1226 case VDEV_AUX_BAD_GUID_SUM:
1227 aux = "BAD_GUID_SUM";
1228 break;
1229 case VDEV_AUX_TOO_SMALL:
1230 aux = "TOO_SMALL";
1231 break;
1232 case VDEV_AUX_BAD_LABEL:
1233 aux = "BAD_LABEL";
1234 break;
1235 case VDEV_AUX_VERSION_NEWER:
1236 aux = "VERS_NEWER";
1237 break;
1238 case VDEV_AUX_VERSION_OLDER:
1239 aux = "VERS_OLDER";
1240 break;
1241 case VDEV_AUX_UNSUP_FEAT:
1242 aux = "UNSUP_FEAT";
1243 break;
1244 case VDEV_AUX_SPARED:
1245 aux = "SPARED";
1246 break;
1247 case VDEV_AUX_ERR_EXCEEDED:
1248 aux = "ERR_EXCEEDED";
1249 break;
1250 case VDEV_AUX_IO_FAILURE:
1251 aux = "IO_FAILURE";
1252 break;
1253 case VDEV_AUX_BAD_LOG:
1254 aux = "BAD_LOG";
1255 break;
1256 case VDEV_AUX_EXTERNAL:
1257 aux = "EXTERNAL";
1258 break;
1259 case VDEV_AUX_SPLIT_POOL:
1260 aux = "SPLIT_POOL";
1261 break;
1262 default:
1263 aux = "UNKNOWN";
2169 mdb_warn("failed to read 'dmu_ot'");
2170 return (DCMD_ERR);
2171 }
2172
2173 if (mdb_getopts(argc, argv,
2174 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2175 NULL) != argc)
2176 return (DCMD_USAGE);
2177
2178 if (!(flags & DCMD_ADDRSPEC))
2179 return (DCMD_USAGE);
2180
2181 if (GETMEMB(addr, struct spa, spa_dsl_pool, addr) ||
2182 GETMEMB(addr, struct dsl_pool, dp_blkstats, addr) ||
2183 mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
2184 mdb_warn("failed to read data at %p;", addr);
2185 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2186 return (DCMD_ERR);
2187 }
2188
2189 tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_TOTAL];
2190 if (tzb->zb_gangs != 0) {
2191 mdb_printf("Ganged blocks: %llu\n",
2192 (longlong_t)tzb->zb_gangs);
2193 }
2194
2195 ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
2196 tzb->zb_ditto_3_of_3_samevdev;
2197 if (ditto != 0) {
2198 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2199 (longlong_t)ditto);
2200 }
2201
2202 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2203 "\t avg\t comp\t%%Total\tType\n");
2204
2205 for (t = 0; t <= DMU_OT_TOTAL; t++) {
2206 char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
2207 char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
2208 char avg[NICENUM_BUFLEN];
2209 char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
2210 char typename[64];
2211 int l;
2212
2213
2214 if (t == DMU_OT_DEFERRED)
2215 strcpy(typename, "deferred free");
2216 else if (t == DMU_OT_OTHER)
2217 strcpy(typename, "other");
2218 else if (t == DMU_OT_TOTAL)
2219 strcpy(typename, "Total");
2220 else if (mdb_readstr(typename, sizeof (typename),
2221 (uintptr_t)dmu_ot[t].ot_name) == -1) {
2222 mdb_warn("failed to read type name");
2223 return (DCMD_ERR);
2224 }
2225
2226 if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
2227 continue;
2228
2229 for (l = -1; l < DN_MAX_LEVELS; l++) {
2230 int level = (l == -1 ? DN_MAX_LEVELS : l);
2231 zfs_blkstat_t *zb = &stats.zab_type[level][t];
2232
2233 if (zb->zb_asize == 0)
2234 continue;
2235
2236 /*
2237 * Don't print each level unless requested.
|