libzfs_status.c revision 245479
164562Sgshapiro/*
2261363Sgshapiro * CDDL HEADER START
364562Sgshapiro *
464562Sgshapiro * The contents of this file are subject to the terms of the
564562Sgshapiro * Common Development and Distribution License (the "License").
664562Sgshapiro * You may not use this file except in compliance with the License.
764562Sgshapiro *
864562Sgshapiro * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
964562Sgshapiro * or http://www.opensolaris.org/os/licensing.
1064562Sgshapiro * See the License for the specific language governing permissions
1164562Sgshapiro * and limitations under the License.
1264562Sgshapiro *
1364562Sgshapiro * When distributing Covered Code, include this CDDL HEADER in each
1464562Sgshapiro * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1590792Sgshapiro * If applicable, add the following below this CDDL HEADER, with the
1690792Sgshapiro * fields enclosed by brackets "[]" replaced with your own identifying
1764562Sgshapiro * information: Portions Copyright [yyyy] [name of copyright owner]
18266692Sgshapiro *
1964562Sgshapiro * CDDL HEADER END
2090792Sgshapiro */
2190792Sgshapiro
2264562Sgshapiro/*
2364562Sgshapiro * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2464562Sgshapiro * Copyright (c) 2012 by Delphix. All rights reserved.
2564562Sgshapiro */
2664562Sgshapiro
2764562Sgshapiro/*
2864562Sgshapiro * This file contains the functions which analyze the status of a pool.  This
2964562Sgshapiro * include both the status of an active pool, as well as the status exported
3064562Sgshapiro * pools.  Returns one of the ZPOOL_STATUS_* defines describing the status of
3164562Sgshapiro * the pool.  This status is independent (to a certain degree) from the state of
3264562Sgshapiro * the pool.  A pool's state describes only whether or not it is capable of
3364562Sgshapiro * providing the necessary fault tolerance for data.  The status describes the
3464562Sgshapiro * overall status of devices.  A pool that is online can still have a device
3564562Sgshapiro * that is experiencing errors.
3664562Sgshapiro *
3764562Sgshapiro * Only a subset of the possible faults can be detected using 'zpool status',
3864562Sgshapiro * and not all possible errors correspond to a FMA message ID.  The explanation
3964562Sgshapiro * is left up to the caller, depending on whether it is a live pool or an
4064562Sgshapiro * import.
4164562Sgshapiro */
4264562Sgshapiro
4364562Sgshapiro#include <libzfs.h>
4464562Sgshapiro#include <string.h>
4564562Sgshapiro#include <unistd.h>
4664562Sgshapiro#include "libzfs_impl.h"
4764562Sgshapiro#include "zfeature_common.h"
4864562Sgshapiro
4964562Sgshapiro/*
5064562Sgshapiro * Message ID table.  This must be kept in sync with the ZPOOL_STATUS_* defines
5164562Sgshapiro * in libzfs.h.  Note that there are some status results which go past the end
5264562Sgshapiro * of this table, and hence have no associated message ID.
5364562Sgshapiro */
5464562Sgshapirostatic char *zfs_msgid_table[] = {
5564562Sgshapiro	"ZFS-8000-14",
5664562Sgshapiro	"ZFS-8000-2Q",
5764562Sgshapiro	"ZFS-8000-3C",
5864562Sgshapiro	"ZFS-8000-4J",
5964562Sgshapiro	"ZFS-8000-5E",
6064562Sgshapiro	"ZFS-8000-6X",
6198121Sgshapiro	"ZFS-8000-72",
6264562Sgshapiro	"ZFS-8000-8A",
6364562Sgshapiro	"ZFS-8000-9P",
6490792Sgshapiro	"ZFS-8000-A5",
6564562Sgshapiro	"ZFS-8000-EY",
6664562Sgshapiro	"ZFS-8000-HC",
6790792Sgshapiro	"ZFS-8000-JQ",
6864562Sgshapiro	"ZFS-8000-K4",
6964562Sgshapiro};
7090792Sgshapiro
7164562Sgshapiro#define	NMSGID	(sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0]))
7264562Sgshapiro
7364562Sgshapiro/* ARGSUSED */
7490792Sgshapirostatic int
7590792Sgshapirovdev_missing(uint64_t state, uint64_t aux, uint64_t errs)
7664562Sgshapiro{
7764562Sgshapiro	return (state == VDEV_STATE_CANT_OPEN &&
7864562Sgshapiro	    aux == VDEV_AUX_OPEN_FAILED);
7964562Sgshapiro}
8064562Sgshapiro
8164562Sgshapiro/* ARGSUSED */
8264562Sgshapirostatic int
8364562Sgshapirovdev_faulted(uint64_t state, uint64_t aux, uint64_t errs)
8464562Sgshapiro{
8564562Sgshapiro	return (state == VDEV_STATE_FAULTED);
8664562Sgshapiro}
8764562Sgshapiro
8864562Sgshapiro/* ARGSUSED */
8964562Sgshapirostatic int
9064562Sgshapirovdev_errors(uint64_t state, uint64_t aux, uint64_t errs)
9164562Sgshapiro{
9264562Sgshapiro	return (state == VDEV_STATE_DEGRADED || errs != 0);
9364562Sgshapiro}
9464562Sgshapiro
9564562Sgshapiro/* ARGSUSED */
9690792Sgshapirostatic int
9764562Sgshapirovdev_broken(uint64_t state, uint64_t aux, uint64_t errs)
9864562Sgshapiro{
9964562Sgshapiro	return (state == VDEV_STATE_CANT_OPEN);
10064562Sgshapiro}
10164562Sgshapiro
10264562Sgshapiro/* ARGSUSED */
10364562Sgshapirostatic int
10464562Sgshapirovdev_offlined(uint64_t state, uint64_t aux, uint64_t errs)
10564562Sgshapiro{
10664562Sgshapiro	return (state == VDEV_STATE_OFFLINE);
10764562Sgshapiro}
10864562Sgshapiro
10964562Sgshapiro/* ARGSUSED */
11064562Sgshapirostatic int
11164562Sgshapirovdev_removed(uint64_t state, uint64_t aux, uint64_t errs)
11264562Sgshapiro{
11364562Sgshapiro	return (state == VDEV_STATE_REMOVED);
11464562Sgshapiro}
11564562Sgshapiro
11664562Sgshapiro/*
11764562Sgshapiro * Detect if any leaf devices that have seen errors or could not be opened.
11864562Sgshapiro */
11964562Sgshapirostatic boolean_t
12064562Sgshapirofind_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
12164562Sgshapiro{
12264562Sgshapiro	nvlist_t **child;
12364562Sgshapiro	vdev_stat_t *vs;
12464562Sgshapiro	uint_t c, children;
12564562Sgshapiro	char *type;
12664562Sgshapiro
12764562Sgshapiro	/*
12864562Sgshapiro	 * Ignore problems within a 'replacing' vdev, since we're presumably in
12964562Sgshapiro	 * the process of repairing any such errors, and don't want to call them
13064562Sgshapiro	 * out again.  We'll pick up the fact that a resilver is happening
13164562Sgshapiro	 * later.
13264562Sgshapiro	 */
13364562Sgshapiro	verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0);
13464562Sgshapiro	if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
13564562Sgshapiro		return (B_FALSE);
13664562Sgshapiro
13764562Sgshapiro	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
13864562Sgshapiro	    &children) == 0) {
13964562Sgshapiro		for (c = 0; c < children; c++)
14064562Sgshapiro			if (find_vdev_problem(child[c], func))
14164562Sgshapiro				return (B_TRUE);
14290792Sgshapiro	} else {
14364562Sgshapiro		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
14464562Sgshapiro		    (uint64_t **)&vs, &c) == 0);
14564562Sgshapiro
14664562Sgshapiro		if (func(vs->vs_state, vs->vs_aux,
14764562Sgshapiro		    vs->vs_read_errors +
14864562Sgshapiro		    vs->vs_write_errors +
14964562Sgshapiro		    vs->vs_checksum_errors))
15064562Sgshapiro			return (B_TRUE);
15164562Sgshapiro	}
15290792Sgshapiro
15364562Sgshapiro	/*
15464562Sgshapiro	 * Check any L2 cache devs
15564562Sgshapiro	 */
15664562Sgshapiro	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_L2CACHE, &child,
15764562Sgshapiro	    &children) == 0) {
15864562Sgshapiro		for (c = 0; c < children; c++)
15964562Sgshapiro			if (find_vdev_problem(child[c], func))
16064562Sgshapiro				return (B_TRUE);
16164562Sgshapiro	}
16264562Sgshapiro
16364562Sgshapiro	return (B_FALSE);
16464562Sgshapiro}
16564562Sgshapiro
16664562Sgshapiro/*
16764562Sgshapiro * Active pool health status.
16864562Sgshapiro *
16964562Sgshapiro * To determine the status for a pool, we make several passes over the config,
17064562Sgshapiro * picking the most egregious error we find.  In order of importance, we do the
17164562Sgshapiro * following:
17264562Sgshapiro *
17364562Sgshapiro *	- Check for a complete and valid configuration
17464562Sgshapiro *	- Look for any faulted or missing devices in a non-replicated config
17564562Sgshapiro *	- Check for any data errors
17664562Sgshapiro *	- Check for any faulted or missing devices in a replicated config
17764562Sgshapiro *	- Look for any devices showing errors
17864562Sgshapiro *	- Check for any resilvering devices
17964562Sgshapiro *
18064562Sgshapiro * There can obviously be multiple errors within a single pool, so this routine
18164562Sgshapiro * only picks the most damaging of all the current errors to report.
18264562Sgshapiro */
18364562Sgshapirostatic zpool_status_t
18464562Sgshapirocheck_status(nvlist_t *config, boolean_t isimport)
18564562Sgshapiro{
18664562Sgshapiro	nvlist_t *nvroot;
18764562Sgshapiro	vdev_stat_t *vs;
18864562Sgshapiro	pool_scan_stat_t *ps = NULL;
18964562Sgshapiro	uint_t vsc, psc;
19064562Sgshapiro	uint64_t nerr;
19190792Sgshapiro	uint64_t version;
19264562Sgshapiro	uint64_t stateval;
19364562Sgshapiro	uint64_t suspended;
19464562Sgshapiro	uint64_t hostid = 0;
19564562Sgshapiro
19664562Sgshapiro	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
19764562Sgshapiro	    &version) == 0);
19864562Sgshapiro	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
19964562Sgshapiro	    &nvroot) == 0);
20064562Sgshapiro	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
20164562Sgshapiro	    (uint64_t **)&vs, &vsc) == 0);
20264562Sgshapiro	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
20364562Sgshapiro	    &stateval) == 0);
20464562Sgshapiro
20564562Sgshapiro	/*
20664562Sgshapiro	 * Currently resilvering a vdev
20764562Sgshapiro	 */
20864562Sgshapiro	(void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
20990792Sgshapiro	    (uint64_t **)&ps, &psc);
21064562Sgshapiro	if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
21164562Sgshapiro	    ps->pss_state == DSS_SCANNING)
21264562Sgshapiro		return (ZPOOL_STATUS_RESILVERING);
21364562Sgshapiro
21464562Sgshapiro	/*
21564562Sgshapiro	 * Pool last accessed by another system.
21664562Sgshapiro	 */
21764562Sgshapiro	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
21864562Sgshapiro	if (hostid != 0 && (unsigned long)hostid != gethostid() &&
21964562Sgshapiro	    stateval == POOL_STATE_ACTIVE)
22064562Sgshapiro		return (ZPOOL_STATUS_HOSTID_MISMATCH);
22164562Sgshapiro
22264562Sgshapiro	/*
22364562Sgshapiro	 * Newer on-disk version.
22464562Sgshapiro	 */
22564562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
22664562Sgshapiro	    vs->vs_aux == VDEV_AUX_VERSION_NEWER)
22764562Sgshapiro		return (ZPOOL_STATUS_VERSION_NEWER);
22864562Sgshapiro
22964562Sgshapiro	/*
23064562Sgshapiro	 * Unsupported feature(s).
23164562Sgshapiro	 */
23264562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
23364562Sgshapiro	    vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
23464562Sgshapiro		nvlist_t *nvinfo;
23564562Sgshapiro
23664562Sgshapiro		verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
23764562Sgshapiro		    &nvinfo) == 0);
23864562Sgshapiro		if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
23964562Sgshapiro			return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
24064562Sgshapiro		return (ZPOOL_STATUS_UNSUP_FEAT_READ);
24190792Sgshapiro	}
24264562Sgshapiro
24390792Sgshapiro	/*
24490792Sgshapiro	 * Check that the config is complete.
24564562Sgshapiro	 */
24690792Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
24790792Sgshapiro	    vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
24890792Sgshapiro		return (ZPOOL_STATUS_BAD_GUID_SUM);
24990792Sgshapiro
25064562Sgshapiro	/*
25164562Sgshapiro	 * Check whether the pool has suspended due to failed I/O.
25264562Sgshapiro	 */
25364562Sgshapiro	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
25464562Sgshapiro	    &suspended) == 0) {
25564562Sgshapiro		if (suspended == ZIO_FAILURE_MODE_CONTINUE)
25664562Sgshapiro			return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
25764562Sgshapiro		return (ZPOOL_STATUS_IO_FAILURE_WAIT);
25864562Sgshapiro	}
25964562Sgshapiro
26090792Sgshapiro	/*
26190792Sgshapiro	 * Could not read a log.
26264562Sgshapiro	 */
26364562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
26464562Sgshapiro	    vs->vs_aux == VDEV_AUX_BAD_LOG) {
26564562Sgshapiro		return (ZPOOL_STATUS_BAD_LOG);
26664562Sgshapiro	}
26764562Sgshapiro
26890792Sgshapiro	/*
26990792Sgshapiro	 * Bad devices in non-replicated config.
27064562Sgshapiro	 */
27164562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
27264562Sgshapiro	    find_vdev_problem(nvroot, vdev_faulted))
27364562Sgshapiro		return (ZPOOL_STATUS_FAULTED_DEV_NR);
27464562Sgshapiro
27564562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
27690792Sgshapiro	    find_vdev_problem(nvroot, vdev_missing))
27790792Sgshapiro		return (ZPOOL_STATUS_MISSING_DEV_NR);
27864562Sgshapiro
27964562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
28064562Sgshapiro	    find_vdev_problem(nvroot, vdev_broken))
28164562Sgshapiro		return (ZPOOL_STATUS_CORRUPT_LABEL_NR);
28264562Sgshapiro
28364562Sgshapiro	/*
28490792Sgshapiro	 * Corrupted pool metadata
28590792Sgshapiro	 */
28664562Sgshapiro	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
28764562Sgshapiro	    vs->vs_aux == VDEV_AUX_CORRUPT_DATA)
28864562Sgshapiro		return (ZPOOL_STATUS_CORRUPT_POOL);
28964562Sgshapiro
29064562Sgshapiro	/*
29190792Sgshapiro	 * Persistent data errors.
29290792Sgshapiro	 */
29364562Sgshapiro	if (!isimport) {
29464562Sgshapiro		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
29564562Sgshapiro		    &nerr) == 0 && nerr != 0)
29664562Sgshapiro			return (ZPOOL_STATUS_CORRUPT_DATA);
29764562Sgshapiro	}
29890792Sgshapiro
29990792Sgshapiro	/*
30064562Sgshapiro	 * Missing devices in a replicated config.
30164562Sgshapiro	 */
30264562Sgshapiro	if (find_vdev_problem(nvroot, vdev_faulted))
30364562Sgshapiro		return (ZPOOL_STATUS_FAULTED_DEV_R);
30464562Sgshapiro	if (find_vdev_problem(nvroot, vdev_missing))
30564562Sgshapiro		return (ZPOOL_STATUS_MISSING_DEV_R);
30664562Sgshapiro	if (find_vdev_problem(nvroot, vdev_broken))
307132943Sgshapiro		return (ZPOOL_STATUS_CORRUPT_LABEL_R);
30890792Sgshapiro
30964562Sgshapiro	/*
31064562Sgshapiro	 * Devices with errors
31164562Sgshapiro	 */
31264562Sgshapiro	if (!isimport && find_vdev_problem(nvroot, vdev_errors))
31364562Sgshapiro		return (ZPOOL_STATUS_FAILING_DEV);
31490792Sgshapiro
31564562Sgshapiro	/*
31664562Sgshapiro	 * Offlined devices
31764562Sgshapiro	 */
31864562Sgshapiro	if (find_vdev_problem(nvroot, vdev_offlined))
31964562Sgshapiro		return (ZPOOL_STATUS_OFFLINE_DEV);
32064562Sgshapiro
32164562Sgshapiro	/*
32264562Sgshapiro	 * Removed device
32364562Sgshapiro	 */
32464562Sgshapiro	if (find_vdev_problem(nvroot, vdev_removed))
32564562Sgshapiro		return (ZPOOL_STATUS_REMOVED_DEV);
32664562Sgshapiro
32764562Sgshapiro	/*
32864562Sgshapiro	 * Outdated, but usable, version
32964562Sgshapiro	 */
33064562Sgshapiro	if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION)
33164562Sgshapiro		return (ZPOOL_STATUS_VERSION_OLDER);
33264562Sgshapiro
33364562Sgshapiro	/*
33464562Sgshapiro	 * Usable pool with disabled features
33564562Sgshapiro	 */
33664562Sgshapiro	if (version >= SPA_VERSION_FEATURES) {
33764562Sgshapiro		int i;
33864562Sgshapiro		nvlist_t *feat;
33964562Sgshapiro
34064562Sgshapiro		if (isimport) {
34164562Sgshapiro			feat = fnvlist_lookup_nvlist(config,
34264562Sgshapiro			    ZPOOL_CONFIG_LOAD_INFO);
34364562Sgshapiro			feat = fnvlist_lookup_nvlist(feat,
34464562Sgshapiro			    ZPOOL_CONFIG_ENABLED_FEAT);
34564562Sgshapiro		} else {
34664562Sgshapiro			feat = fnvlist_lookup_nvlist(config,
34764562Sgshapiro			    ZPOOL_CONFIG_FEATURE_STATS);
34864562Sgshapiro		}
34964562Sgshapiro
35064562Sgshapiro		for (i = 0; i < SPA_FEATURES; i++) {
35164562Sgshapiro			zfeature_info_t *fi = &spa_feature_table[i];
35264562Sgshapiro			if (!nvlist_exists(feat, fi->fi_guid))
35364562Sgshapiro				return (ZPOOL_STATUS_FEAT_DISABLED);
35490792Sgshapiro		}
35564562Sgshapiro	}
35690792Sgshapiro
35764562Sgshapiro	return (ZPOOL_STATUS_OK);
35864562Sgshapiro}
35964562Sgshapiro
36064562Sgshapirozpool_status_t
36164562Sgshapirozpool_get_status(zpool_handle_t *zhp, char **msgid)
36264562Sgshapiro{
36390792Sgshapiro	zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE);
36464562Sgshapiro
36564562Sgshapiro	if (ret >= NMSGID)
36664562Sgshapiro		*msgid = NULL;
36790792Sgshapiro	else
36864562Sgshapiro		*msgid = zfs_msgid_table[ret];
36964562Sgshapiro
37090792Sgshapiro	return (ret);
37164562Sgshapiro}
37264562Sgshapiro
37364562Sgshapirozpool_status_t
37464562Sgshapirozpool_import_status(nvlist_t *config, char **msgid)
37564562Sgshapiro{
37664562Sgshapiro	zpool_status_t ret = check_status(config, B_TRUE);
37764562Sgshapiro
37864562Sgshapiro	if (ret >= NMSGID)
37964562Sgshapiro		*msgid = NULL;
38064562Sgshapiro	else
38164562Sgshapiro		*msgid = zfs_msgid_table[ret];
38264562Sgshapiro
38364562Sgshapiro	return (ret);
38464562Sgshapiro}
38564562Sgshapiro
38664562Sgshapirostatic void
38764562Sgshapirodump_ddt_stat(const ddt_stat_t *dds, int h)
38864562Sgshapiro{
38964562Sgshapiro	char refcnt[6];
39064562Sgshapiro	char blocks[6], lsize[6], psize[6], dsize[6];
39164562Sgshapiro	char ref_blocks[6], ref_lsize[6], ref_psize[6], ref_dsize[6];
39264562Sgshapiro
39364562Sgshapiro	if (dds == NULL || dds->dds_blocks == 0)
39464562Sgshapiro		return;
39564562Sgshapiro
39664562Sgshapiro	if (h == -1)
39764562Sgshapiro		(void) strcpy(refcnt, "Total");
39864562Sgshapiro	else
39964562Sgshapiro		zfs_nicenum(1ULL << h, refcnt, sizeof (refcnt));
40064562Sgshapiro
40164562Sgshapiro	zfs_nicenum(dds->dds_blocks, blocks, sizeof (blocks));
40264562Sgshapiro	zfs_nicenum(dds->dds_lsize, lsize, sizeof (lsize));
40364562Sgshapiro	zfs_nicenum(dds->dds_psize, psize, sizeof (psize));
40464562Sgshapiro	zfs_nicenum(dds->dds_dsize, dsize, sizeof (dsize));
40564562Sgshapiro	zfs_nicenum(dds->dds_ref_blocks, ref_blocks, sizeof (ref_blocks));
40664562Sgshapiro	zfs_nicenum(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize));
40764562Sgshapiro	zfs_nicenum(dds->dds_ref_psize, ref_psize, sizeof (ref_psize));
40864562Sgshapiro	zfs_nicenum(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize));
40998121Sgshapiro
41064562Sgshapiro	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
41164562Sgshapiro	    refcnt,
41264562Sgshapiro	    blocks, lsize, psize, dsize,
41364562Sgshapiro	    ref_blocks, ref_lsize, ref_psize, ref_dsize);
41464562Sgshapiro}
41564562Sgshapiro
41690792Sgshapiro/*
41790792Sgshapiro * Print the DDT histogram and the column totals.
41890792Sgshapiro */
41964562Sgshapirovoid
42064562Sgshapirozpool_dump_ddt(const ddt_stat_t *dds_total, const ddt_histogram_t *ddh)
42164562Sgshapiro{
42264562Sgshapiro	int h;
42364562Sgshapiro
42490792Sgshapiro	(void) printf("\n");
42564562Sgshapiro
42664562Sgshapiro	(void) printf("bucket   "
42764562Sgshapiro	    "           allocated             "
42864562Sgshapiro	    "          referenced          \n");
42964562Sgshapiro	(void) printf("______   "
43064562Sgshapiro	    "______________________________   "
43190792Sgshapiro	    "______________________________\n");
43264562Sgshapiro
43364562Sgshapiro	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
43464562Sgshapiro	    "refcnt",
43564562Sgshapiro	    "blocks", "LSIZE", "PSIZE", "DSIZE",
43664562Sgshapiro	    "blocks", "LSIZE", "PSIZE", "DSIZE");
43764562Sgshapiro
43864562Sgshapiro	(void) printf("%6s   %6s   %5s   %5s   %5s   %6s   %5s   %5s   %5s\n",
43964562Sgshapiro	    "------",
44064562Sgshapiro	    "------", "-----", "-----", "-----",
44164562Sgshapiro	    "------", "-----", "-----", "-----");
44264562Sgshapiro
44364562Sgshapiro	for (h = 0; h < 64; h++)
44464562Sgshapiro		dump_ddt_stat(&ddh->ddh_stat[h], h);
44564562Sgshapiro
44664562Sgshapiro	dump_ddt_stat(dds_total, -1);
44764562Sgshapiro
44864562Sgshapiro	(void) printf("\n");
44964562Sgshapiro}
45064562Sgshapiro