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.
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.
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]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Copyright (c) 2013 Steven Hartland. All rights reserved.
29 * This file contains the functions which analyze the status of a pool. This
30 * include both the status of an active pool, as well as the status exported
31 * pools. Returns one of the ZPOOL_STATUS_* defines describing the status of
32 * the pool. This status is independent (to a certain degree) from the state of
33 * the pool. A pool's state describes only whether or not it is capable of
34 * providing the necessary fault tolerance for data. The status describes the
35 * overall status of devices. A pool that is online can still have a device
36 * that is experiencing errors.
38 * Only a subset of the possible faults can be detected using 'zpool status',
39 * and not all possible errors correspond to a FMA message ID. The explanation
40 * is left up to the caller, depending on whether it is a live pool or an
48 #include <sys/systeminfo.h>
49 #include "libzfs_impl.h"
50 #include "zfeature_common.h"
53 * Message ID table. This must be kept in sync with the ZPOOL_STATUS_* defines
54 * in include/libzfs.h. Note that there are some status results which go past
55 * the end of this table, and hence have no associated message ID.
57 static char *zfs_msgid_table[] = {
58 "ZFS-8000-14", /* ZPOOL_STATUS_CORRUPT_CACHE */
59 "ZFS-8000-2Q", /* ZPOOL_STATUS_MISSING_DEV_R */
60 "ZFS-8000-3C", /* ZPOOL_STATUS_MISSING_DEV_NR */
61 "ZFS-8000-4J", /* ZPOOL_STATUS_CORRUPT_LABEL_R */
62 "ZFS-8000-5E", /* ZPOOL_STATUS_CORRUPT_LABEL_NR */
63 "ZFS-8000-6X", /* ZPOOL_STATUS_BAD_GUID_SUM */
64 "ZFS-8000-72", /* ZPOOL_STATUS_CORRUPT_POOL */
65 "ZFS-8000-8A", /* ZPOOL_STATUS_CORRUPT_DATA */
66 "ZFS-8000-9P", /* ZPOOL_STATUS_FAILING_DEV */
67 "ZFS-8000-A5", /* ZPOOL_STATUS_VERSION_NEWER */
68 "ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_MISMATCH */
69 "ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_ACTIVE */
70 "ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_REQUIRED */
71 "ZFS-8000-HC", /* ZPOOL_STATUS_IO_FAILURE_WAIT */
72 "ZFS-8000-JQ", /* ZPOOL_STATUS_IO_FAILURE_CONTINUE */
73 "ZFS-8000-MM", /* ZPOOL_STATUS_IO_FAILURE_MMP */
74 "ZFS-8000-K4", /* ZPOOL_STATUS_BAD_LOG */
75 "ZFS-8000-ER", /* ZPOOL_STATUS_ERRATA */
77 * The following results have no message ID.
78 * ZPOOL_STATUS_UNSUP_FEAT_READ
79 * ZPOOL_STATUS_UNSUP_FEAT_WRITE
80 * ZPOOL_STATUS_FAULTED_DEV_R
81 * ZPOOL_STATUS_FAULTED_DEV_NR
82 * ZPOOL_STATUS_VERSION_OLDER
83 * ZPOOL_STATUS_FEAT_DISABLED
84 * ZPOOL_STATUS_RESILVERING
85 * ZPOOL_STATUS_OFFLINE_DEV
86 * ZPOOL_STATUS_REMOVED_DEV
91 #define NMSGID (sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0]))
95 vdev_missing(uint64_t state, uint64_t aux, uint64_t errs)
97 return (state == VDEV_STATE_CANT_OPEN &&
98 aux == VDEV_AUX_OPEN_FAILED);
103 vdev_faulted(uint64_t state, uint64_t aux, uint64_t errs)
105 return (state == VDEV_STATE_FAULTED);
110 vdev_errors(uint64_t state, uint64_t aux, uint64_t errs)
112 return (state == VDEV_STATE_DEGRADED || errs != 0);
117 vdev_broken(uint64_t state, uint64_t aux, uint64_t errs)
119 return (state == VDEV_STATE_CANT_OPEN);
124 vdev_offlined(uint64_t state, uint64_t aux, uint64_t errs)
126 return (state == VDEV_STATE_OFFLINE);
131 vdev_removed(uint64_t state, uint64_t aux, uint64_t errs)
133 return (state == VDEV_STATE_REMOVED);
137 * Detect if any leaf devices that have seen errors or could not be opened.
140 find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
148 * Ignore problems within a 'replacing' vdev, since we're presumably in
149 * the process of repairing any such errors, and don't want to call them
150 * out again. We'll pick up the fact that a resilver is happening
153 verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0);
154 if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
157 if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
159 for (c = 0; c < children; c++)
160 if (find_vdev_problem(child[c], func))
163 verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
164 (uint64_t **)&vs, &c) == 0);
166 if (func(vs->vs_state, vs->vs_aux,
168 vs->vs_write_errors +
169 vs->vs_checksum_errors))
174 * Check any L2 cache devs
176 if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_L2CACHE, &child,
178 for (c = 0; c < children; c++)
179 if (find_vdev_problem(child[c], func))
187 * Active pool health status.
189 * To determine the status for a pool, we make several passes over the config,
190 * picking the most egregious error we find. In order of importance, we do the
193 * - Check for a complete and valid configuration
194 * - Look for any faulted or missing devices in a non-replicated config
195 * - Check for any data errors
196 * - Check for any faulted or missing devices in a replicated config
197 * - Look for any devices showing errors
198 * - Check for any resilvering devices
200 * There can obviously be multiple errors within a single pool, so this routine
201 * only picks the most damaging of all the current errors to report.
203 static zpool_status_t
204 check_status(nvlist_t *config, boolean_t isimport, zpool_errata_t *erratap)
208 pool_scan_stat_t *ps = NULL;
216 unsigned long system_hostid = get_system_hostid();
218 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
220 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
222 verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
223 (uint64_t **)&vs, &vsc) == 0);
224 verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
228 * Currently resilvering a vdev
230 (void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
231 (uint64_t **)&ps, &psc);
232 if (ps != NULL && ps->pss_func == POOL_SCAN_RESILVER &&
233 ps->pss_state == DSS_SCANNING)
234 return (ZPOOL_STATUS_RESILVERING);
237 * The multihost property is set and the pool may be active.
239 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
240 vs->vs_aux == VDEV_AUX_ACTIVE) {
241 mmp_state_t mmp_state;
244 nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
245 mmp_state = fnvlist_lookup_uint64(nvinfo,
246 ZPOOL_CONFIG_MMP_STATE);
248 if (mmp_state == MMP_STATE_ACTIVE)
249 return (ZPOOL_STATUS_HOSTID_ACTIVE);
250 else if (mmp_state == MMP_STATE_NO_HOSTID)
251 return (ZPOOL_STATUS_HOSTID_REQUIRED);
253 return (ZPOOL_STATUS_HOSTID_MISMATCH);
257 * Pool last accessed by another system.
259 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
260 if (hostid != 0 && (unsigned long)hostid != system_hostid &&
261 stateval == POOL_STATE_ACTIVE)
262 return (ZPOOL_STATUS_HOSTID_MISMATCH);
265 * Newer on-disk version.
267 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
268 vs->vs_aux == VDEV_AUX_VERSION_NEWER)
269 return (ZPOOL_STATUS_VERSION_NEWER);
272 * Unsupported feature(s).
274 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
275 vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
278 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO,
280 if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
281 return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
282 return (ZPOOL_STATUS_UNSUP_FEAT_READ);
286 * Check that the config is complete.
288 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
289 vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
290 return (ZPOOL_STATUS_BAD_GUID_SUM);
293 * Check whether the pool has suspended.
295 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
299 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED_REASON,
300 &reason) == 0 && reason == ZIO_SUSPEND_MMP)
301 return (ZPOOL_STATUS_IO_FAILURE_MMP);
303 if (suspended == ZIO_FAILURE_MODE_CONTINUE)
304 return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
305 return (ZPOOL_STATUS_IO_FAILURE_WAIT);
309 * Could not read a log.
311 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
312 vs->vs_aux == VDEV_AUX_BAD_LOG) {
313 return (ZPOOL_STATUS_BAD_LOG);
317 * Bad devices in non-replicated config.
319 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
320 find_vdev_problem(nvroot, vdev_faulted))
321 return (ZPOOL_STATUS_FAULTED_DEV_NR);
323 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
324 find_vdev_problem(nvroot, vdev_missing))
325 return (ZPOOL_STATUS_MISSING_DEV_NR);
327 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
328 find_vdev_problem(nvroot, vdev_broken))
329 return (ZPOOL_STATUS_CORRUPT_LABEL_NR);
332 * Corrupted pool metadata
334 if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
335 vs->vs_aux == VDEV_AUX_CORRUPT_DATA)
336 return (ZPOOL_STATUS_CORRUPT_POOL);
339 * Persistent data errors.
342 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
343 &nerr) == 0 && nerr != 0)
344 return (ZPOOL_STATUS_CORRUPT_DATA);
348 * Missing devices in a replicated config.
350 if (find_vdev_problem(nvroot, vdev_faulted))
351 return (ZPOOL_STATUS_FAULTED_DEV_R);
352 if (find_vdev_problem(nvroot, vdev_missing))
353 return (ZPOOL_STATUS_MISSING_DEV_R);
354 if (find_vdev_problem(nvroot, vdev_broken))
355 return (ZPOOL_STATUS_CORRUPT_LABEL_R);
358 * Devices with errors
360 if (!isimport && find_vdev_problem(nvroot, vdev_errors))
361 return (ZPOOL_STATUS_FAILING_DEV);
366 if (find_vdev_problem(nvroot, vdev_offlined))
367 return (ZPOOL_STATUS_OFFLINE_DEV);
372 if (find_vdev_problem(nvroot, vdev_removed))
373 return (ZPOOL_STATUS_REMOVED_DEV);
376 * Informational errata available.
378 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRATA, &errata);
381 return (ZPOOL_STATUS_ERRATA);
385 * Outdated, but usable, version
387 if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION)
388 return (ZPOOL_STATUS_VERSION_OLDER);
391 * Usable pool with disabled features
393 if (version >= SPA_VERSION_FEATURES) {
398 feat = fnvlist_lookup_nvlist(config,
399 ZPOOL_CONFIG_LOAD_INFO);
400 if (nvlist_exists(feat, ZPOOL_CONFIG_ENABLED_FEAT))
401 feat = fnvlist_lookup_nvlist(feat,
402 ZPOOL_CONFIG_ENABLED_FEAT);
404 feat = fnvlist_lookup_nvlist(config,
405 ZPOOL_CONFIG_FEATURE_STATS);
408 for (i = 0; i < SPA_FEATURES; i++) {
409 zfeature_info_t *fi = &spa_feature_table[i];
410 if (!nvlist_exists(feat, fi->fi_guid))
411 return (ZPOOL_STATUS_FEAT_DISABLED);
415 return (ZPOOL_STATUS_OK);
419 zpool_get_status(zpool_handle_t *zhp, char **msgid, zpool_errata_t *errata)
421 zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE, errata);
426 *msgid = zfs_msgid_table[ret];
432 zpool_import_status(nvlist_t *config, char **msgid, zpool_errata_t *errata)
434 zpool_status_t ret = check_status(config, B_TRUE, errata);
439 *msgid = zfs_msgid_table[ret];