/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* This file contains the functions which analyze the status of a pool. This
* include both the status of an active pool, as well as the status exported
* pools. Returns one of the ZPOOL_STATUS_* defines describing the status of
* the pool. This status is independent (to a certain degree) from the state of
* the pool. A pool's state describes only whether or not it is capable of
* providing the necessary fault tolerance for data. The status describes the
* overall status of devices. A pool that is online can still have a device
* that is experiencing errors.
*
* Only a subset of the possible faults can be detected using 'zpool status',
* and not all possible errors correspond to a FMA message ID. The explanation
* is left up to the caller, depending on whether it is a live pool or an
* import.
*/
#include <libzfs.h>
#include <string.h>
#include <unistd.h>
#include <zone.h>
#include "libzfs_impl.h"
/*
* Message ID table. This must be kept in sync with the ZPOOL_STATUS_* defines
* in libzfs.h. Note that there are some status results which go past the end
* of this table, and hence have no associated message ID.
*/
static char *zfs_msgid_table[] = {
"ZFS-8000-14",
"ZFS-8000-6X",
"ZFS-8000-72",
"ZFS-8000-8A",
"ZFS-8000-A5",
"ZFS-8000-EY",
"ZFS-8000-HC",
"ZFS-8000-JQ",
"ZFS-8000-K4",
};
/* ARGSUSED */
static int
{
return (state == VDEV_STATE_UNUSABLE);
}
/* ARGSUSED */
static int
{
return (state == VDEV_STATE_DEGRADED);
}
/* ARGSUSED */
static int
{
return (state == VDEV_STATE_DEGRADED &&
aux == VDEV_AUX_DTL);
}
/* ARGSUSED */
static int
{
return (state == VDEV_STATE_OFFLINE);
}
/* ARGSUSED */
static int
{
return (state == VDEV_STATE_REMOVED);
}
/*
* Detect if any leaf devices that have seen errors or could not be opened.
*/
static boolean_t
{
&children) == 0) {
char *type;
/*
* Ignore problems within a 'replacing' vdev on a vdev being
* replaced, since we're presumably in the process of repairing
* any such errors, and don't want to call them out again.
* We'll pick up the fact that a resilver is happening later.
*/
&type) == 0);
start = 1;
return (B_TRUE);
} else {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Active pool health status.
*
* To determine the status for a pool, we make several passes over the config,
* picking the most egregious error we find. In order of importance, we do the
* following:
*
* - Check for a complete and valid configuration
* - Look for any faulted or missing devices in a non-replicated config
* - Check for any data errors
* - Check for any faulted or missing devices in a replicated config
* - Look for any devices showing errors
* - Check for any resilvering devices
*
* There can obviously be multiple errors within a single pool, so this routine
* only picks the most damaging of all the current errors to report.
*/
static zpool_status_t
{
&nvroot) == 0);
/*
* If we can't get vdev stats, the pool failed to go active
* either because a critical disk is missing, or the cachefile
* is out of date.
*/
return (ZPOOL_STATUS_CORRUPT_CACHE);
&version) == 0);
&stateval) == 0);
/*
* Currently resilvering a vdev
*/
return (ZPOOL_STATUS_RESILVERING);
/*
* Pool last accessed by another system.
*/
getzoneid() == GLOBAL_ZONEID &&
return (ZPOOL_STATUS_HOSTID_MISMATCH);
/*
* Newer on-disk version.
*/
return (ZPOOL_STATUS_VERSION_NEWER);
/*
* Check that the config is complete.
*/
return (ZPOOL_STATUS_BAD_GUID_SUM);
/*
* Check whether the pool has suspended due to failed I/O.
*/
&suspended) == 0) {
if (suspended == ZIO_FAILURE_MODE_CONTINUE)
return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
return (ZPOOL_STATUS_IO_FAILURE_WAIT);
}
/*
* Could not read a log.
*/
return (ZPOOL_STATUS_BAD_LOG);
}
/*
* Bad devices in non-replicated config.
*/
return (ZPOOL_STATUS_UNUSABLE_DEV_NR);
/*
* Corrupted pool metadata
*/
return (ZPOOL_STATUS_CORRUPT_POOL);
/*
* Persistent data errors.
*/
if (!isimport) {
return (ZPOOL_STATUS_CORRUPT_DATA);
}
/*
* Missing devices in a replicated config.
*/
return (ZPOOL_STATUS_UNUSABLE_DEV_R);
/*
* Devices with DTLs
*/
return (ZPOOL_STATUS_DEGRADED_DEV_DTL);
/*
* Devices with errors
*/
return (ZPOOL_STATUS_FAILING_DEV);
/*
* Offlined devices
*/
return (ZPOOL_STATUS_OFFLINE_DEV);
/*
* Removed device
*/
return (ZPOOL_STATUS_REMOVED_DEV);
/*
* Outdated, but usable, version
*/
if (version < SPA_VERSION)
return (ZPOOL_STATUS_VERSION_OLDER);
return (ZPOOL_STATUS_OK);
}
{
else
return (ret);
}
{
else
return (ret);
}
static void
{
return;
if (h == -1)
else
(void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n",
}
/*
* Print the DDT histogram and the column totals.
*/
void
{
int h;
(void) printf("\n");
(void) printf("bucket "
" allocated "
" referenced \n");
(void) printf("______ "
"______________________________ "
"______________________________\n");
(void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n",
"refcnt",
"blocks", "LSIZE", "PSIZE", "DSIZE",
"blocks", "LSIZE", "PSIZE", "DSIZE");
(void) printf("%6s %6s %5s %5s %5s %6s %5s %5s %5s\n",
"------",
"------", "-----", "-----", "-----",
"------", "-----", "-----", "-----");
for (h = 0; h < 64; h++)
(void) printf("\n");
}