1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * 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 */ 21ad135b5dSChristopher Siden 22fa9e4066Sahrens /* 233f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24ad135b5dSChristopher Siden * Copyright (c) 2012 by Delphix. All rights reserved. 25*7f2416efSSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved. 26fa9e4066Sahrens */ 27fa9e4066Sahrens 28fa9e4066Sahrens /* 29fa9e4066Sahrens * This file contains the functions which analyze the status of a pool. This 30fa9e4066Sahrens * include both the status of an active pool, as well as the status exported 31fa9e4066Sahrens * pools. Returns one of the ZPOOL_STATUS_* defines describing the status of 32fa9e4066Sahrens * the pool. This status is independent (to a certain degree) from the state of 333d7072f8Seschrock * the pool. A pool's state describes only whether or not it is capable of 34fa9e4066Sahrens * providing the necessary fault tolerance for data. The status describes the 35fa9e4066Sahrens * overall status of devices. A pool that is online can still have a device 36fa9e4066Sahrens * that is experiencing errors. 37fa9e4066Sahrens * 38fa9e4066Sahrens * Only a subset of the possible faults can be detected using 'zpool status', 39fa9e4066Sahrens * and not all possible errors correspond to a FMA message ID. The explanation 40fa9e4066Sahrens * is left up to the caller, depending on whether it is a live pool or an 41fa9e4066Sahrens * import. 42fa9e4066Sahrens */ 43fa9e4066Sahrens 44fa9e4066Sahrens #include <libzfs.h> 45fa9e4066Sahrens #include <string.h> 4695173954Sek110237 #include <unistd.h> 47fa9e4066Sahrens #include "libzfs_impl.h" 4857221772SChristopher Siden #include "zfeature_common.h" 49fa9e4066Sahrens 50fa9e4066Sahrens /* 513d7072f8Seschrock * Message ID table. This must be kept in sync with the ZPOOL_STATUS_* defines 52fa9e4066Sahrens * in libzfs.h. Note that there are some status results which go past the end 53fa9e4066Sahrens * of this table, and hence have no associated message ID. 54fa9e4066Sahrens */ 5595173954Sek110237 static char *zfs_msgid_table[] = { 56fa9e4066Sahrens "ZFS-8000-14", 57fa9e4066Sahrens "ZFS-8000-2Q", 58fa9e4066Sahrens "ZFS-8000-3C", 59fa9e4066Sahrens "ZFS-8000-4J", 60fa9e4066Sahrens "ZFS-8000-5E", 61fa9e4066Sahrens "ZFS-8000-6X", 62fa9e4066Sahrens "ZFS-8000-72", 63fa9e4066Sahrens "ZFS-8000-8A", 64fa9e4066Sahrens "ZFS-8000-9P", 6595173954Sek110237 "ZFS-8000-A5", 6632b87932Sek110237 "ZFS-8000-EY", 6732b87932Sek110237 "ZFS-8000-HC", 68b87f3af3Sperrin "ZFS-8000-JQ", 69b87f3af3Sperrin "ZFS-8000-K4", 70fa9e4066Sahrens }; 71fa9e4066Sahrens 7295173954Sek110237 #define NMSGID (sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0])) 73fa9e4066Sahrens 74fa9e4066Sahrens /* ARGSUSED */ 75fa9e4066Sahrens static int 76fa9e4066Sahrens vdev_missing(uint64_t state, uint64_t aux, uint64_t errs) 77fa9e4066Sahrens { 78fa9e4066Sahrens return (state == VDEV_STATE_CANT_OPEN && 79fa9e4066Sahrens aux == VDEV_AUX_OPEN_FAILED); 80fa9e4066Sahrens } 81fa9e4066Sahrens 82fa9e4066Sahrens /* ARGSUSED */ 83fa9e4066Sahrens static int 843d7072f8Seschrock vdev_faulted(uint64_t state, uint64_t aux, uint64_t errs) 853d7072f8Seschrock { 863d7072f8Seschrock return (state == VDEV_STATE_FAULTED); 873d7072f8Seschrock } 883d7072f8Seschrock 893d7072f8Seschrock /* ARGSUSED */ 903d7072f8Seschrock static int 91fa9e4066Sahrens vdev_errors(uint64_t state, uint64_t aux, uint64_t errs) 92fa9e4066Sahrens { 933d7072f8Seschrock return (state == VDEV_STATE_DEGRADED || errs != 0); 94fa9e4066Sahrens } 95fa9e4066Sahrens 96fa9e4066Sahrens /* ARGSUSED */ 97fa9e4066Sahrens static int 98fa9e4066Sahrens vdev_broken(uint64_t state, uint64_t aux, uint64_t errs) 99fa9e4066Sahrens { 100fa9e4066Sahrens return (state == VDEV_STATE_CANT_OPEN); 101fa9e4066Sahrens } 102fa9e4066Sahrens 103fa9e4066Sahrens /* ARGSUSED */ 104fa9e4066Sahrens static int 105fa9e4066Sahrens vdev_offlined(uint64_t state, uint64_t aux, uint64_t errs) 106fa9e4066Sahrens { 107fa9e4066Sahrens return (state == VDEV_STATE_OFFLINE); 108fa9e4066Sahrens } 109fa9e4066Sahrens 110c25309d4SGeorge Wilson /* ARGSUSED */ 111c25309d4SGeorge Wilson static int 112c25309d4SGeorge Wilson vdev_removed(uint64_t state, uint64_t aux, uint64_t errs) 113c25309d4SGeorge Wilson { 114c25309d4SGeorge Wilson return (state == VDEV_STATE_REMOVED); 115c25309d4SGeorge Wilson } 116c25309d4SGeorge Wilson 117fa9e4066Sahrens /* 118fa9e4066Sahrens * Detect if any leaf devices that have seen errors or could not be opened. 119fa9e4066Sahrens */ 12099653d4eSeschrock static boolean_t 121fa9e4066Sahrens find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t)) 122fa9e4066Sahrens { 123fa9e4066Sahrens nvlist_t **child; 124fa9e4066Sahrens vdev_stat_t *vs; 125fa9e4066Sahrens uint_t c, children; 126fa9e4066Sahrens char *type; 127fa9e4066Sahrens 128fa9e4066Sahrens /* 129fa9e4066Sahrens * Ignore problems within a 'replacing' vdev, since we're presumably in 130fa9e4066Sahrens * the process of repairing any such errors, and don't want to call them 131fa9e4066Sahrens * out again. We'll pick up the fact that a resilver is happening 132fa9e4066Sahrens * later. 133fa9e4066Sahrens */ 134fa9e4066Sahrens verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0); 135fa9e4066Sahrens if (strcmp(type, VDEV_TYPE_REPLACING) == 0) 13699653d4eSeschrock return (B_FALSE); 137fa9e4066Sahrens 138fa9e4066Sahrens if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child, 139fa9e4066Sahrens &children) == 0) { 140fa9e4066Sahrens for (c = 0; c < children; c++) 141fa9e4066Sahrens if (find_vdev_problem(child[c], func)) 14299653d4eSeschrock return (B_TRUE); 143fa9e4066Sahrens } else { 1443f9d6ad7SLin Ling verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS, 145fa9e4066Sahrens (uint64_t **)&vs, &c) == 0); 146fa9e4066Sahrens 147fa9e4066Sahrens if (func(vs->vs_state, vs->vs_aux, 148fa9e4066Sahrens vs->vs_read_errors + 149fa9e4066Sahrens vs->vs_write_errors + 150fa9e4066Sahrens vs->vs_checksum_errors)) 15199653d4eSeschrock return (B_TRUE); 152fa9e4066Sahrens } 153fa9e4066Sahrens 154*7f2416efSSteven Hartland /* 155*7f2416efSSteven Hartland * Check any L2 cache devs 156*7f2416efSSteven Hartland */ 157*7f2416efSSteven Hartland if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_L2CACHE, &child, 158*7f2416efSSteven Hartland &children) == 0) { 159*7f2416efSSteven Hartland for (c = 0; c < children; c++) 160*7f2416efSSteven Hartland if (find_vdev_problem(child[c], func)) 161*7f2416efSSteven Hartland return (B_TRUE); 162*7f2416efSSteven Hartland } 163*7f2416efSSteven Hartland 16499653d4eSeschrock return (B_FALSE); 165fa9e4066Sahrens } 166fa9e4066Sahrens 167fa9e4066Sahrens /* 168fa9e4066Sahrens * Active pool health status. 169fa9e4066Sahrens * 170fa9e4066Sahrens * To determine the status for a pool, we make several passes over the config, 171fa9e4066Sahrens * picking the most egregious error we find. In order of importance, we do the 172fa9e4066Sahrens * following: 173fa9e4066Sahrens * 174fa9e4066Sahrens * - Check for a complete and valid configuration 1753d7072f8Seschrock * - Look for any faulted or missing devices in a non-replicated config 176fa9e4066Sahrens * - Check for any data errors 1773d7072f8Seschrock * - Check for any faulted or missing devices in a replicated config 178ea8dc4b6Seschrock * - Look for any devices showing errors 179fa9e4066Sahrens * - Check for any resilvering devices 180fa9e4066Sahrens * 181fa9e4066Sahrens * There can obviously be multiple errors within a single pool, so this routine 182fa9e4066Sahrens * only picks the most damaging of all the current errors to report. 183fa9e4066Sahrens */ 184fa9e4066Sahrens static zpool_status_t 185e14bb325SJeff Bonwick check_status(nvlist_t *config, boolean_t isimport) 186fa9e4066Sahrens { 187fa9e4066Sahrens nvlist_t *nvroot; 188fa9e4066Sahrens vdev_stat_t *vs; 1893f9d6ad7SLin Ling pool_scan_stat_t *ps = NULL; 1903f9d6ad7SLin Ling uint_t vsc, psc; 191ea8dc4b6Seschrock uint64_t nerr; 192eaca9bbdSeschrock uint64_t version; 19395173954Sek110237 uint64_t stateval; 194e14bb325SJeff Bonwick uint64_t suspended; 19595173954Sek110237 uint64_t hostid = 0; 196fa9e4066Sahrens 197eaca9bbdSeschrock verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, 198eaca9bbdSeschrock &version) == 0); 199fa9e4066Sahrens verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, 200fa9e4066Sahrens &nvroot) == 0); 2013f9d6ad7SLin Ling verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS, 202fa9e4066Sahrens (uint64_t **)&vs, &vsc) == 0); 20395173954Sek110237 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE, 20495173954Sek110237 &stateval) == 0); 2053f9d6ad7SLin Ling 2063f9d6ad7SLin Ling /* 2073f9d6ad7SLin Ling * Currently resilvering a vdev 2083f9d6ad7SLin Ling */ 2093f9d6ad7SLin Ling (void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS, 2103f9d6ad7SLin Ling (uint64_t **)&ps, &psc); 2113f9d6ad7SLin Ling if (ps && ps->pss_func == POOL_SCAN_RESILVER && 2123f9d6ad7SLin Ling ps->pss_state == DSS_SCANNING) 2133f9d6ad7SLin Ling return (ZPOOL_STATUS_RESILVERING); 21495173954Sek110237 21595173954Sek110237 /* 21695173954Sek110237 * Pool last accessed by another system. 21795173954Sek110237 */ 2183f9d6ad7SLin Ling (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid); 21995173954Sek110237 if (hostid != 0 && (unsigned long)hostid != gethostid() && 22095173954Sek110237 stateval == POOL_STATE_ACTIVE) 22195173954Sek110237 return (ZPOOL_STATUS_HOSTID_MISMATCH); 222fa9e4066Sahrens 223fa9e4066Sahrens /* 224eaca9bbdSeschrock * Newer on-disk version. 225eaca9bbdSeschrock */ 226eaca9bbdSeschrock if (vs->vs_state == VDEV_STATE_CANT_OPEN && 227eaca9bbdSeschrock vs->vs_aux == VDEV_AUX_VERSION_NEWER) 228eaca9bbdSeschrock return (ZPOOL_STATUS_VERSION_NEWER); 229eaca9bbdSeschrock 230eaca9bbdSeschrock /* 231ad135b5dSChristopher Siden * Unsupported feature(s). 232ad135b5dSChristopher Siden */ 233ad135b5dSChristopher Siden if (vs->vs_state == VDEV_STATE_CANT_OPEN && 234ad135b5dSChristopher Siden vs->vs_aux == VDEV_AUX_UNSUP_FEAT) { 235ad135b5dSChristopher Siden nvlist_t *nvinfo; 236ad135b5dSChristopher Siden 237ad135b5dSChristopher Siden verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, 238ad135b5dSChristopher Siden &nvinfo) == 0); 239ad135b5dSChristopher Siden if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY)) 240ad135b5dSChristopher Siden return (ZPOOL_STATUS_UNSUP_FEAT_WRITE); 241ad135b5dSChristopher Siden return (ZPOOL_STATUS_UNSUP_FEAT_READ); 242ad135b5dSChristopher Siden } 243ad135b5dSChristopher Siden 244ad135b5dSChristopher Siden /* 245fa9e4066Sahrens * Check that the config is complete. 246fa9e4066Sahrens */ 247fa9e4066Sahrens if (vs->vs_state == VDEV_STATE_CANT_OPEN && 248ea8dc4b6Seschrock vs->vs_aux == VDEV_AUX_BAD_GUID_SUM) 249fa9e4066Sahrens return (ZPOOL_STATUS_BAD_GUID_SUM); 250fa9e4066Sahrens 251fa9e4066Sahrens /* 252e14bb325SJeff Bonwick * Check whether the pool has suspended due to failed I/O. 25332b87932Sek110237 */ 254e14bb325SJeff Bonwick if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED, 255e14bb325SJeff Bonwick &suspended) == 0) { 256e14bb325SJeff Bonwick if (suspended == ZIO_FAILURE_MODE_CONTINUE) 25732b87932Sek110237 return (ZPOOL_STATUS_IO_FAILURE_CONTINUE); 25832b87932Sek110237 return (ZPOOL_STATUS_IO_FAILURE_WAIT); 25932b87932Sek110237 } 26032b87932Sek110237 26132b87932Sek110237 /* 262b87f3af3Sperrin * Could not read a log. 263b87f3af3Sperrin */ 264b87f3af3Sperrin if (vs->vs_state == VDEV_STATE_CANT_OPEN && 265b87f3af3Sperrin vs->vs_aux == VDEV_AUX_BAD_LOG) { 266b87f3af3Sperrin return (ZPOOL_STATUS_BAD_LOG); 267b87f3af3Sperrin } 268b87f3af3Sperrin 269b87f3af3Sperrin /* 2703d7072f8Seschrock * Bad devices in non-replicated config. 271fa9e4066Sahrens */ 272ea8dc4b6Seschrock if (vs->vs_state == VDEV_STATE_CANT_OPEN && 2733d7072f8Seschrock find_vdev_problem(nvroot, vdev_faulted)) 2743d7072f8Seschrock return (ZPOOL_STATUS_FAULTED_DEV_NR); 2753d7072f8Seschrock 2763d7072f8Seschrock if (vs->vs_state == VDEV_STATE_CANT_OPEN && 277ea8dc4b6Seschrock find_vdev_problem(nvroot, vdev_missing)) 278fa9e4066Sahrens return (ZPOOL_STATUS_MISSING_DEV_NR); 279ea8dc4b6Seschrock 280ea8dc4b6Seschrock if (vs->vs_state == VDEV_STATE_CANT_OPEN && 281ea8dc4b6Seschrock find_vdev_problem(nvroot, vdev_broken)) 282ea8dc4b6Seschrock return (ZPOOL_STATUS_CORRUPT_LABEL_NR); 283ea8dc4b6Seschrock 284ea8dc4b6Seschrock /* 285ea8dc4b6Seschrock * Corrupted pool metadata 286ea8dc4b6Seschrock */ 287ea8dc4b6Seschrock if (vs->vs_state == VDEV_STATE_CANT_OPEN && 288ea8dc4b6Seschrock vs->vs_aux == VDEV_AUX_CORRUPT_DATA) 289ea8dc4b6Seschrock return (ZPOOL_STATUS_CORRUPT_POOL); 290ea8dc4b6Seschrock 291ea8dc4b6Seschrock /* 292ea8dc4b6Seschrock * Persistent data errors. 293ea8dc4b6Seschrock */ 294ea8dc4b6Seschrock if (!isimport) { 295ea8dc4b6Seschrock if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT, 296ea8dc4b6Seschrock &nerr) == 0 && nerr != 0) 297ea8dc4b6Seschrock return (ZPOOL_STATUS_CORRUPT_DATA); 298fa9e4066Sahrens } 299fa9e4066Sahrens 300fa9e4066Sahrens /* 301ea8dc4b6Seschrock * Missing devices in a replicated config. 302fa9e4066Sahrens */ 3033d7072f8Seschrock if (find_vdev_problem(nvroot, vdev_faulted)) 3043d7072f8Seschrock return (ZPOOL_STATUS_FAULTED_DEV_R); 305ea8dc4b6Seschrock if (find_vdev_problem(nvroot, vdev_missing)) 306ea8dc4b6Seschrock return (ZPOOL_STATUS_MISSING_DEV_R); 307ea8dc4b6Seschrock if (find_vdev_problem(nvroot, vdev_broken)) 308fa9e4066Sahrens return (ZPOOL_STATUS_CORRUPT_LABEL_R); 309fa9e4066Sahrens 310fa9e4066Sahrens /* 311fa9e4066Sahrens * Devices with errors 312fa9e4066Sahrens */ 313fa9e4066Sahrens if (!isimport && find_vdev_problem(nvroot, vdev_errors)) 314fa9e4066Sahrens return (ZPOOL_STATUS_FAILING_DEV); 315fa9e4066Sahrens 316fa9e4066Sahrens /* 317fa9e4066Sahrens * Offlined devices 318fa9e4066Sahrens */ 319fa9e4066Sahrens if (find_vdev_problem(nvroot, vdev_offlined)) 320fa9e4066Sahrens return (ZPOOL_STATUS_OFFLINE_DEV); 321fa9e4066Sahrens 322fa9e4066Sahrens /* 323c25309d4SGeorge Wilson * Removed device 324c25309d4SGeorge Wilson */ 325c25309d4SGeorge Wilson if (find_vdev_problem(nvroot, vdev_removed)) 326c25309d4SGeorge Wilson return (ZPOOL_STATUS_REMOVED_DEV); 327c25309d4SGeorge Wilson 328c25309d4SGeorge Wilson /* 329eaca9bbdSeschrock * Outdated, but usable, version 330fa9e4066Sahrens */ 331ad135b5dSChristopher Siden if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION) 332eaca9bbdSeschrock return (ZPOOL_STATUS_VERSION_OLDER); 333fa9e4066Sahrens 33457221772SChristopher Siden /* 33557221772SChristopher Siden * Usable pool with disabled features 33657221772SChristopher Siden */ 33757221772SChristopher Siden if (version >= SPA_VERSION_FEATURES) { 33857221772SChristopher Siden int i; 33957221772SChristopher Siden nvlist_t *feat; 34057221772SChristopher Siden 34157221772SChristopher Siden if (isimport) { 34257221772SChristopher Siden feat = fnvlist_lookup_nvlist(config, 34357221772SChristopher Siden ZPOOL_CONFIG_LOAD_INFO); 34457221772SChristopher Siden feat = fnvlist_lookup_nvlist(feat, 34557221772SChristopher Siden ZPOOL_CONFIG_ENABLED_FEAT); 34657221772SChristopher Siden } else { 34757221772SChristopher Siden feat = fnvlist_lookup_nvlist(config, 34857221772SChristopher Siden ZPOOL_CONFIG_FEATURE_STATS); 34957221772SChristopher Siden } 35057221772SChristopher Siden 35157221772SChristopher Siden for (i = 0; i < SPA_FEATURES; i++) { 35257221772SChristopher Siden zfeature_info_t *fi = &spa_feature_table[i]; 35357221772SChristopher Siden if (!nvlist_exists(feat, fi->fi_guid)) 35457221772SChristopher Siden return (ZPOOL_STATUS_FEAT_DISABLED); 35557221772SChristopher Siden } 35657221772SChristopher Siden } 35757221772SChristopher Siden 358fa9e4066Sahrens return (ZPOOL_STATUS_OK); 359fa9e4066Sahrens } 360fa9e4066Sahrens 361fa9e4066Sahrens zpool_status_t 362fa9e4066Sahrens zpool_get_status(zpool_handle_t *zhp, char **msgid) 363fa9e4066Sahrens { 364e14bb325SJeff Bonwick zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE); 365fa9e4066Sahrens 366fa9e4066Sahrens if (ret >= NMSGID) 367fa9e4066Sahrens *msgid = NULL; 368fa9e4066Sahrens else 3693d7072f8Seschrock *msgid = zfs_msgid_table[ret]; 370fa9e4066Sahrens 371fa9e4066Sahrens return (ret); 372fa9e4066Sahrens } 373fa9e4066Sahrens 374fa9e4066Sahrens zpool_status_t 375fa9e4066Sahrens zpool_import_status(nvlist_t *config, char **msgid) 376fa9e4066Sahrens { 377e14bb325SJeff Bonwick zpool_status_t ret = check_status(config, B_TRUE); 378fa9e4066Sahrens 379fa9e4066Sahrens if (ret >= NMSGID) 380fa9e4066Sahrens *msgid = NULL; 381fa9e4066Sahrens else 38295173954Sek110237 *msgid = zfs_msgid_table[ret]; 383fa9e4066Sahrens 384fa9e4066Sahrens return (ret); 385fa9e4066Sahrens } 3869eb19f4dSGeorge Wilson 3879eb19f4dSGeorge Wilson static void 3889eb19f4dSGeorge Wilson dump_ddt_stat(const ddt_stat_t *dds, int h) 3899eb19f4dSGeorge Wilson { 3909eb19f4dSGeorge Wilson char refcnt[6]; 3919eb19f4dSGeorge Wilson char blocks[6], lsize[6], psize[6], dsize[6]; 3929eb19f4dSGeorge Wilson char ref_blocks[6], ref_lsize[6], ref_psize[6], ref_dsize[6]; 3939eb19f4dSGeorge Wilson 3949eb19f4dSGeorge Wilson if (dds == NULL || dds->dds_blocks == 0) 3959eb19f4dSGeorge Wilson return; 3969eb19f4dSGeorge Wilson 3979eb19f4dSGeorge Wilson if (h == -1) 3989eb19f4dSGeorge Wilson (void) strcpy(refcnt, "Total"); 3999eb19f4dSGeorge Wilson else 4009eb19f4dSGeorge Wilson zfs_nicenum(1ULL << h, refcnt, sizeof (refcnt)); 4019eb19f4dSGeorge Wilson 4029eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_blocks, blocks, sizeof (blocks)); 4039eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_lsize, lsize, sizeof (lsize)); 4049eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_psize, psize, sizeof (psize)); 4059eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_dsize, dsize, sizeof (dsize)); 4069eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_ref_blocks, ref_blocks, sizeof (ref_blocks)); 4079eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_ref_lsize, ref_lsize, sizeof (ref_lsize)); 4089eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_ref_psize, ref_psize, sizeof (ref_psize)); 4099eb19f4dSGeorge Wilson zfs_nicenum(dds->dds_ref_dsize, ref_dsize, sizeof (ref_dsize)); 4109eb19f4dSGeorge Wilson 4119eb19f4dSGeorge Wilson (void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n", 4129eb19f4dSGeorge Wilson refcnt, 4139eb19f4dSGeorge Wilson blocks, lsize, psize, dsize, 4149eb19f4dSGeorge Wilson ref_blocks, ref_lsize, ref_psize, ref_dsize); 4159eb19f4dSGeorge Wilson } 4169eb19f4dSGeorge Wilson 4179eb19f4dSGeorge Wilson /* 4189eb19f4dSGeorge Wilson * Print the DDT histogram and the column totals. 4199eb19f4dSGeorge Wilson */ 4209eb19f4dSGeorge Wilson void 4219eb19f4dSGeorge Wilson zpool_dump_ddt(const ddt_stat_t *dds_total, const ddt_histogram_t *ddh) 4229eb19f4dSGeorge Wilson { 4239eb19f4dSGeorge Wilson int h; 4249eb19f4dSGeorge Wilson 4259eb19f4dSGeorge Wilson (void) printf("\n"); 4269eb19f4dSGeorge Wilson 4279eb19f4dSGeorge Wilson (void) printf("bucket " 4289eb19f4dSGeorge Wilson " allocated " 4299eb19f4dSGeorge Wilson " referenced \n"); 4309eb19f4dSGeorge Wilson (void) printf("______ " 4319eb19f4dSGeorge Wilson "______________________________ " 4329eb19f4dSGeorge Wilson "______________________________\n"); 4339eb19f4dSGeorge Wilson 4349eb19f4dSGeorge Wilson (void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n", 4359eb19f4dSGeorge Wilson "refcnt", 4369eb19f4dSGeorge Wilson "blocks", "LSIZE", "PSIZE", "DSIZE", 4379eb19f4dSGeorge Wilson "blocks", "LSIZE", "PSIZE", "DSIZE"); 4389eb19f4dSGeorge Wilson 4399eb19f4dSGeorge Wilson (void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n", 4409eb19f4dSGeorge Wilson "------", 4419eb19f4dSGeorge Wilson "------", "-----", "-----", "-----", 4429eb19f4dSGeorge Wilson "------", "-----", "-----", "-----"); 4439eb19f4dSGeorge Wilson 4449eb19f4dSGeorge Wilson for (h = 0; h < 64; h++) 4459eb19f4dSGeorge Wilson dump_ddt_stat(&ddh->ddh_stat[h], h); 4469eb19f4dSGeorge Wilson 4479eb19f4dSGeorge Wilson dump_ddt_stat(dds_total, -1); 4489eb19f4dSGeorge Wilson 4499eb19f4dSGeorge Wilson (void) printf("\n"); 4509eb19f4dSGeorge Wilson } 451