xref: /freebsd/sys/contrib/openzfs/lib/libzfs/libzfs_status.c (revision d8fbbd371ca11d9ad4b29b9d3a316885a5da0b15)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25  * Copyright (c) 2012 by Delphix. All rights reserved.
26  * Copyright (c) 2013 Steven Hartland. All rights reserved.
27  * Copyright (c) 2021, Colm Buckley <colm@tuatha.org>
28  */
29 
30 /*
31  * This file contains the functions which analyze the status of a pool.  This
32  * include both the status of an active pool, as well as the status exported
33  * pools.  Returns one of the ZPOOL_STATUS_* defines describing the status of
34  * the pool.  This status is independent (to a certain degree) from the state of
35  * the pool.  A pool's state describes only whether or not it is capable of
36  * providing the necessary fault tolerance for data.  The status describes the
37  * overall status of devices.  A pool that is online can still have a device
38  * that is experiencing errors.
39  *
40  * Only a subset of the possible faults can be detected using 'zpool status',
41  * and not all possible errors correspond to a FMA message ID.  The explanation
42  * is left up to the caller, depending on whether it is a live pool or an
43  * import.
44  */
45 
46 #include <libzfs.h>
47 #include <libzutil.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <unistd.h>
51 #include <sys/systeminfo.h>
52 #include "libzfs_impl.h"
53 #include "zfeature_common.h"
54 
55 /*
56  * Message ID table.  This must be kept in sync with the ZPOOL_STATUS_* defines
57  * in include/libzfs.h.  Note that there are some status results which go past
58  * the end of this table, and hence have no associated message ID.
59  */
60 static const char *const zfs_msgid_table[] = {
61 	"ZFS-8000-14", /* ZPOOL_STATUS_CORRUPT_CACHE */
62 	"ZFS-8000-2Q", /* ZPOOL_STATUS_MISSING_DEV_R */
63 	"ZFS-8000-3C", /* ZPOOL_STATUS_MISSING_DEV_NR */
64 	"ZFS-8000-4J", /* ZPOOL_STATUS_CORRUPT_LABEL_R */
65 	"ZFS-8000-5E", /* ZPOOL_STATUS_CORRUPT_LABEL_NR */
66 	"ZFS-8000-6X", /* ZPOOL_STATUS_BAD_GUID_SUM */
67 	"ZFS-8000-72", /* ZPOOL_STATUS_CORRUPT_POOL */
68 	"ZFS-8000-8A", /* ZPOOL_STATUS_CORRUPT_DATA */
69 	"ZFS-8000-9P", /* ZPOOL_STATUS_FAILING_DEV */
70 	"ZFS-8000-A5", /* ZPOOL_STATUS_VERSION_NEWER */
71 	"ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_MISMATCH */
72 	"ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_ACTIVE */
73 	"ZFS-8000-EY", /* ZPOOL_STATUS_HOSTID_REQUIRED */
74 	"ZFS-8000-HC", /* ZPOOL_STATUS_IO_FAILURE_WAIT */
75 	"ZFS-8000-JQ", /* ZPOOL_STATUS_IO_FAILURE_CONTINUE */
76 	"ZFS-8000-MM", /* ZPOOL_STATUS_IO_FAILURE_MMP */
77 	"ZFS-8000-K4", /* ZPOOL_STATUS_BAD_LOG */
78 	"ZFS-8000-ER", /* ZPOOL_STATUS_ERRATA */
79 	/*
80 	 * The following results have no message ID.
81 	 *	ZPOOL_STATUS_UNSUP_FEAT_READ
82 	 *	ZPOOL_STATUS_UNSUP_FEAT_WRITE
83 	 *	ZPOOL_STATUS_FAULTED_DEV_R
84 	 *	ZPOOL_STATUS_FAULTED_DEV_NR
85 	 *	ZPOOL_STATUS_VERSION_OLDER
86 	 *	ZPOOL_STATUS_FEAT_DISABLED
87 	 *	ZPOOL_STATUS_RESILVERING
88 	 *	ZPOOL_STATUS_OFFLINE_DEV
89 	 *	ZPOOL_STATUS_REMOVED_DEV
90 	 *	ZPOOL_STATUS_REBUILDING
91 	 *	ZPOOL_STATUS_REBUILD_SCRUB
92 	 *	ZPOOL_STATUS_COMPATIBILITY_ERR
93 	 *	ZPOOL_STATUS_INCOMPATIBLE_FEAT
94 	 *	ZPOOL_STATUS_OK
95 	 */
96 };
97 
98 #define	NMSGID	(sizeof (zfs_msgid_table) / sizeof (zfs_msgid_table[0]))
99 
100 static int
vdev_missing(vdev_stat_t * vs,uint_t vsc,void * arg)101 vdev_missing(vdev_stat_t *vs, uint_t vsc, void *arg)
102 {
103 	(void) vsc, (void) arg;
104 	return (vs->vs_state == VDEV_STATE_CANT_OPEN &&
105 	    vs->vs_aux == VDEV_AUX_OPEN_FAILED);
106 }
107 
108 static int
vdev_faulted(vdev_stat_t * vs,uint_t vsc,void * arg)109 vdev_faulted(vdev_stat_t *vs, uint_t vsc, void *arg)
110 {
111 	(void) vsc, (void) arg;
112 	return (vs->vs_state == VDEV_STATE_FAULTED);
113 }
114 
115 static int
vdev_errors(vdev_stat_t * vs,uint_t vsc,void * arg)116 vdev_errors(vdev_stat_t *vs, uint_t vsc, void *arg)
117 {
118 	(void) vsc, (void) arg;
119 	return (vs->vs_state == VDEV_STATE_DEGRADED ||
120 	    vs->vs_read_errors != 0 || vs->vs_write_errors != 0 ||
121 	    vs->vs_checksum_errors != 0);
122 }
123 
124 static int
vdev_broken(vdev_stat_t * vs,uint_t vsc,void * arg)125 vdev_broken(vdev_stat_t *vs, uint_t vsc, void *arg)
126 {
127 	(void) vsc, (void) arg;
128 	return (vs->vs_state == VDEV_STATE_CANT_OPEN);
129 }
130 
131 static int
vdev_offlined(vdev_stat_t * vs,uint_t vsc,void * arg)132 vdev_offlined(vdev_stat_t *vs, uint_t vsc, void *arg)
133 {
134 	(void) vsc, (void) arg;
135 	return (vs->vs_state == VDEV_STATE_OFFLINE);
136 }
137 
138 static int
vdev_removed(vdev_stat_t * vs,uint_t vsc,void * arg)139 vdev_removed(vdev_stat_t *vs, uint_t vsc, void *arg)
140 {
141 	(void) vsc, (void) arg;
142 	return (vs->vs_state == VDEV_STATE_REMOVED);
143 }
144 
145 static int
vdev_non_native_ashift(vdev_stat_t * vs,uint_t vsc,void * arg)146 vdev_non_native_ashift(vdev_stat_t *vs, uint_t vsc, void *arg)
147 {
148 	uint64_t ashift = *(uint64_t *)arg;
149 
150 	return (VDEV_STAT_VALID(vs_physical_ashift, vsc) &&
151 	    (ashift == 0 || vs->vs_configured_ashift < ashift) &&
152 	    vs->vs_configured_ashift < vs->vs_physical_ashift);
153 }
154 
155 /*
156  * Detect if any leaf devices that have seen errors or could not be opened.
157  * Returns:
158  *   - EDOM if a failure domain in dRAID vdev is down
159  *   - ENXIO if any device is problematic
160  *   - 0 (zero) otherwise
161  */
162 static int
find_vdev_problem(nvlist_t * vdev,int (* func)(vdev_stat_t *,uint_t,void *),void * arg,boolean_t ignore_replacing)163 find_vdev_problem(nvlist_t *vdev, int (*func)(vdev_stat_t *, uint_t, void *),
164     void *arg, boolean_t ignore_replacing)
165 {
166 	nvlist_t **child;
167 	uint_t c, children;
168 
169 	/*
170 	 * Ignore problems within a 'replacing' vdev, since we're presumably in
171 	 * the process of repairing any such errors, and don't want to call them
172 	 * out again.  We'll pick up the fact that a resilver is happening
173 	 * later.
174 	 */
175 	if (ignore_replacing == B_TRUE) {
176 		const char *type = fnvlist_lookup_string(vdev,
177 		    ZPOOL_CONFIG_TYPE);
178 		if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
179 			return (0);
180 	}
181 
182 	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
183 	    &children) == 0) {
184 
185 		uint64_t fgrp_children = 0;
186 		(void) nvlist_lookup_uint64(vdev, ZPOOL_CONFIG_DRAID_NCHILDREN,
187 		    &fgrp_children);
188 
189 		for (c = 0; c < fgrp_children; c++) {
190 			int nfgrps = children / fgrp_children;
191 			int nfaults = 0;
192 			for (int g = 0; g < nfgrps; g++) {
193 				if (find_vdev_problem(child[c +
194 				    (g * fgrp_children)], func, arg,
195 				    ignore_replacing))
196 					nfaults++;
197 			}
198 			if (nfaults == nfgrps)
199 				return (EDOM);
200 		}
201 
202 		for (c = 0; c < children; c++) {
203 			int res;
204 			if ((res = find_vdev_problem(child[c], func, arg,
205 			    ignore_replacing)))
206 				return (res);
207 		}
208 	} else {
209 		uint_t vsc;
210 		vdev_stat_t *vs = (vdev_stat_t *)fnvlist_lookup_uint64_array(
211 		    vdev, ZPOOL_CONFIG_VDEV_STATS, &vsc);
212 		if (func(vs, vsc, arg) != 0)
213 			return (ENXIO);
214 	}
215 
216 	/*
217 	 * Check any L2 cache devs
218 	 */
219 	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_L2CACHE, &child,
220 	    &children) == 0) {
221 		for (c = 0; c < children; c++) {
222 			if (find_vdev_problem(child[c], func, arg,
223 			    ignore_replacing))
224 				return (ENXIO);
225 		}
226 	}
227 
228 	return (0);
229 }
230 
231 /*
232  * Active pool health status.
233  *
234  * To determine the status for a pool, we make several passes over the config,
235  * picking the most egregious error we find.  In order of importance, we do the
236  * following:
237  *
238  *	- Check for a complete and valid configuration
239  *	- Look for any faulted or missing devices in a non-replicated config
240  *	- Check for any data errors
241  *	- Check for any faulted or missing devices in a replicated config
242  *	- Look for any devices showing errors
243  *	- Check for any resilvering or rebuilding devices
244  *
245  * There can obviously be multiple errors within a single pool, so this routine
246  * only picks the most damaging of all the current errors to report.
247  */
248 static zpool_status_t
check_status(nvlist_t * config,boolean_t isimport,zpool_errata_t * erratap,const char * compat,uint64_t ashift)249 check_status(nvlist_t *config, boolean_t isimport,
250     zpool_errata_t *erratap, const char *compat, uint64_t ashift)
251 {
252 	pool_scan_stat_t *ps = NULL;
253 	uint_t vsc, psc;
254 	uint64_t suspended;
255 	uint64_t hostid = 0;
256 	uint64_t errata = 0;
257 	unsigned long system_hostid = get_system_hostid();
258 
259 	uint64_t version = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION);
260 	nvlist_t *nvroot = fnvlist_lookup_nvlist(config,
261 	    ZPOOL_CONFIG_VDEV_TREE);
262 	vdev_stat_t *vs = (vdev_stat_t *)fnvlist_lookup_uint64_array(nvroot,
263 	    ZPOOL_CONFIG_VDEV_STATS, &vsc);
264 	uint64_t stateval = fnvlist_lookup_uint64(config,
265 	    ZPOOL_CONFIG_POOL_STATE);
266 
267 	/*
268 	 * Currently resilvering a vdev
269 	 */
270 	(void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
271 	    (uint64_t **)&ps, &psc);
272 	if (ps != NULL && ps->pss_func == POOL_SCAN_RESILVER &&
273 	    ps->pss_state == DSS_SCANNING)
274 		return (ZPOOL_STATUS_RESILVERING);
275 
276 	/*
277 	 * Currently rebuilding a vdev, check top-level vdevs.
278 	 */
279 	vdev_rebuild_stat_t *vrs = NULL;
280 	nvlist_t **child;
281 	uint_t c, i, children;
282 	uint64_t rebuild_end_time = 0;
283 	if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN,
284 	    &child, &children) == 0) {
285 		for (c = 0; c < children; c++) {
286 			if ((nvlist_lookup_uint64_array(child[c],
287 			    ZPOOL_CONFIG_REBUILD_STATS,
288 			    (uint64_t **)&vrs, &i) == 0) && (vrs != NULL)) {
289 				uint64_t state = vrs->vrs_state;
290 
291 				if (state == VDEV_REBUILD_ACTIVE) {
292 					return (ZPOOL_STATUS_REBUILDING);
293 				} else if (state == VDEV_REBUILD_COMPLETE &&
294 				    vrs->vrs_end_time > rebuild_end_time) {
295 					rebuild_end_time = vrs->vrs_end_time;
296 				}
297 			}
298 		}
299 
300 		/*
301 		 * If we can determine when the last scrub was run, and it
302 		 * was before the last rebuild completed, then recommend
303 		 * that the pool be scrubbed to verify all checksums.  When
304 		 * ps is NULL we can infer the pool has never been scrubbed.
305 		 */
306 		if (rebuild_end_time > 0) {
307 			if (ps != NULL) {
308 				if ((ps->pss_state == DSS_FINISHED &&
309 				    ps->pss_func == POOL_SCAN_SCRUB &&
310 				    rebuild_end_time > ps->pss_end_time) ||
311 				    ps->pss_state == DSS_NONE)
312 					return (ZPOOL_STATUS_REBUILD_SCRUB);
313 			} else {
314 				return (ZPOOL_STATUS_REBUILD_SCRUB);
315 			}
316 		}
317 	}
318 
319 	/*
320 	 * The multihost property is set and the pool may be active.
321 	 */
322 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
323 	    vs->vs_aux == VDEV_AUX_ACTIVE) {
324 		mmp_state_t mmp_state;
325 		nvlist_t *nvinfo;
326 
327 		nvinfo = fnvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO);
328 		mmp_state = fnvlist_lookup_uint64(nvinfo,
329 		    ZPOOL_CONFIG_MMP_STATE);
330 
331 		if (mmp_state == MMP_STATE_ACTIVE)
332 			return (ZPOOL_STATUS_HOSTID_ACTIVE);
333 		else if (mmp_state == MMP_STATE_NO_HOSTID)
334 			return (ZPOOL_STATUS_HOSTID_REQUIRED);
335 		else
336 			return (ZPOOL_STATUS_HOSTID_MISMATCH);
337 	}
338 
339 	/*
340 	 * Pool last accessed by another system.
341 	 */
342 	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
343 	if (hostid != 0 && (unsigned long)hostid != system_hostid &&
344 	    stateval == POOL_STATE_ACTIVE)
345 		return (ZPOOL_STATUS_HOSTID_MISMATCH);
346 
347 	/*
348 	 * Newer on-disk version.
349 	 */
350 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
351 	    vs->vs_aux == VDEV_AUX_VERSION_NEWER)
352 		return (ZPOOL_STATUS_VERSION_NEWER);
353 
354 	/*
355 	 * Unsupported feature(s).
356 	 */
357 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
358 	    vs->vs_aux == VDEV_AUX_UNSUP_FEAT) {
359 		nvlist_t *nvinfo = fnvlist_lookup_nvlist(config,
360 		    ZPOOL_CONFIG_LOAD_INFO);
361 		if (nvlist_exists(nvinfo, ZPOOL_CONFIG_CAN_RDONLY))
362 			return (ZPOOL_STATUS_UNSUP_FEAT_WRITE);
363 		return (ZPOOL_STATUS_UNSUP_FEAT_READ);
364 	}
365 
366 	/*
367 	 * Check that the config is complete.
368 	 */
369 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
370 	    vs->vs_aux == VDEV_AUX_BAD_GUID_SUM)
371 		return (ZPOOL_STATUS_BAD_GUID_SUM);
372 
373 	/*
374 	 * Check whether the pool has suspended.
375 	 */
376 	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED,
377 	    &suspended) == 0) {
378 		uint64_t reason;
379 
380 		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_SUSPENDED_REASON,
381 		    &reason) == 0 && reason == ZIO_SUSPEND_MMP)
382 			return (ZPOOL_STATUS_IO_FAILURE_MMP);
383 
384 		if (suspended == ZIO_FAILURE_MODE_CONTINUE)
385 			return (ZPOOL_STATUS_IO_FAILURE_CONTINUE);
386 		return (ZPOOL_STATUS_IO_FAILURE_WAIT);
387 	}
388 
389 	/*
390 	 * Could not read a log.
391 	 */
392 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
393 	    vs->vs_aux == VDEV_AUX_BAD_LOG) {
394 		return (ZPOOL_STATUS_BAD_LOG);
395 	}
396 
397 	/*
398 	 * Bad devices in non-replicated config.
399 	 */
400 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
401 	    find_vdev_problem(nvroot, vdev_faulted, NULL, B_TRUE))
402 		return (ZPOOL_STATUS_FAULTED_DEV_NR);
403 
404 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
405 	    find_vdev_problem(nvroot, vdev_missing, NULL, B_TRUE))
406 		return (ZPOOL_STATUS_MISSING_DEV_NR);
407 
408 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
409 	    find_vdev_problem(nvroot, vdev_broken, NULL, B_TRUE))
410 		return (ZPOOL_STATUS_CORRUPT_LABEL_NR);
411 
412 	/*
413 	 * Corrupted pool metadata
414 	 */
415 	if (vs->vs_state == VDEV_STATE_CANT_OPEN &&
416 	    vs->vs_aux == VDEV_AUX_CORRUPT_DATA)
417 		return (ZPOOL_STATUS_CORRUPT_POOL);
418 
419 	/*
420 	 * Persistent data errors.
421 	 */
422 	if (!isimport) {
423 		uint64_t nerr;
424 		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRCOUNT,
425 		    &nerr) == 0 && nerr != 0)
426 			return (ZPOOL_STATUS_CORRUPT_DATA);
427 	}
428 
429 	/*
430 	 * Missing devices in a replicated config.
431 	 */
432 	if (find_vdev_problem(nvroot, vdev_faulted, NULL, B_TRUE) == EDOM)
433 		return (ZPOOL_STATUS_FAULTED_FDOM_R);
434 	if (find_vdev_problem(nvroot, vdev_missing, NULL, B_TRUE) == EDOM)
435 		return (ZPOOL_STATUS_FAULTED_FDOM_R);
436 	if (find_vdev_problem(nvroot, vdev_faulted, NULL, B_TRUE))
437 		return (ZPOOL_STATUS_FAULTED_DEV_R);
438 	if (find_vdev_problem(nvroot, vdev_missing, NULL, B_TRUE))
439 		return (ZPOOL_STATUS_MISSING_DEV_R);
440 	if (find_vdev_problem(nvroot, vdev_broken, NULL, B_TRUE))
441 		return (ZPOOL_STATUS_CORRUPT_LABEL_R);
442 
443 	/*
444 	 * Devices with errors
445 	 */
446 	if (!isimport && find_vdev_problem(nvroot, vdev_errors, NULL, B_TRUE))
447 		return (ZPOOL_STATUS_FAILING_DEV);
448 
449 	/*
450 	 * Offlined devices
451 	 */
452 	if (find_vdev_problem(nvroot, vdev_offlined, NULL, B_TRUE))
453 		return (ZPOOL_STATUS_OFFLINE_DEV);
454 
455 	/*
456 	 * Removed device
457 	 */
458 	if (find_vdev_problem(nvroot, vdev_removed, NULL, B_TRUE))
459 		return (ZPOOL_STATUS_REMOVED_DEV);
460 
461 	/*
462 	 * Suboptimal, but usable, ashift configuration.
463 	 */
464 	if (!isimport &&
465 	    getenv("ZPOOL_STATUS_NON_NATIVE_ASHIFT_IGNORE") == NULL &&
466 	    find_vdev_problem(nvroot, vdev_non_native_ashift, &ashift, B_FALSE))
467 		return (ZPOOL_STATUS_NON_NATIVE_ASHIFT);
468 
469 	/*
470 	 * Informational errata available.
471 	 */
472 	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_ERRATA, &errata);
473 	if (errata) {
474 		*erratap = errata;
475 		return (ZPOOL_STATUS_ERRATA);
476 	}
477 
478 	/*
479 	 * Outdated, but usable, version
480 	 */
481 	if (SPA_VERSION_IS_SUPPORTED(version) && version != SPA_VERSION) {
482 		/* "legacy" compatibility disables old version reporting */
483 		if (compat != NULL && strcmp(compat, ZPOOL_COMPAT_LEGACY) == 0)
484 			return (ZPOOL_STATUS_OK);
485 		else
486 			return (ZPOOL_STATUS_VERSION_OLDER);
487 	}
488 
489 	/*
490 	 * Usable pool with disabled or superfluous features
491 	 * (superfluous = beyond what's requested by 'compatibility')
492 	 */
493 	if (version >= SPA_VERSION_FEATURES) {
494 		int i;
495 		nvlist_t *feat;
496 
497 		if (isimport) {
498 			feat = fnvlist_lookup_nvlist(config,
499 			    ZPOOL_CONFIG_LOAD_INFO);
500 			if (nvlist_exists(feat, ZPOOL_CONFIG_ENABLED_FEAT))
501 				feat = fnvlist_lookup_nvlist(feat,
502 				    ZPOOL_CONFIG_ENABLED_FEAT);
503 		} else {
504 			feat = fnvlist_lookup_nvlist(config,
505 			    ZPOOL_CONFIG_FEATURE_STATS);
506 		}
507 
508 		/* check against all features, or limited set? */
509 		boolean_t c_features[SPA_FEATURES];
510 
511 		switch (zpool_load_compat(compat, c_features, NULL, 0)) {
512 		case ZPOOL_COMPATIBILITY_OK:
513 		case ZPOOL_COMPATIBILITY_WARNTOKEN:
514 			break;
515 		default:
516 			return (ZPOOL_STATUS_COMPATIBILITY_ERR);
517 		}
518 		for (i = 0; i < SPA_FEATURES; i++) {
519 			zfeature_info_t *fi = &spa_feature_table[i];
520 			if (!fi->fi_zfs_mod_supported ||
521 			    (fi->fi_flags & ZFEATURE_FLAG_NO_UPGRADE))
522 				continue;
523 			if (c_features[i] && !nvlist_exists(feat, fi->fi_guid))
524 				return (ZPOOL_STATUS_FEAT_DISABLED);
525 			if (!c_features[i] && nvlist_exists(feat, fi->fi_guid))
526 				return (ZPOOL_STATUS_INCOMPATIBLE_FEAT);
527 		}
528 	}
529 
530 	return (ZPOOL_STATUS_OK);
531 }
532 
533 zpool_status_t
zpool_get_status(zpool_handle_t * zhp,const char ** msgid,zpool_errata_t * errata)534 zpool_get_status(zpool_handle_t *zhp, const char **msgid,
535     zpool_errata_t *errata)
536 {
537 	/*
538 	 * pass in the desired feature set, as
539 	 * it affects check for disabled features
540 	 */
541 	char compatibility[ZFS_MAXPROPLEN];
542 	if (zpool_get_prop(zhp, ZPOOL_PROP_COMPATIBILITY, compatibility,
543 	    ZFS_MAXPROPLEN, NULL, B_FALSE) != 0)
544 		compatibility[0] = '\0';
545 
546 	uint64_t ashift = zpool_get_prop_int(zhp, ZPOOL_PROP_ASHIFT, NULL);
547 
548 	zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE, errata,
549 	    compatibility, ashift);
550 
551 	if (msgid != NULL) {
552 		if (ret >= NMSGID)
553 			*msgid = NULL;
554 		else
555 			*msgid = zfs_msgid_table[ret];
556 	}
557 	return (ret);
558 }
559 
560 zpool_status_t
zpool_import_status(nvlist_t * config,const char ** msgid,zpool_errata_t * errata)561 zpool_import_status(nvlist_t *config, const char **msgid,
562     zpool_errata_t *errata)
563 {
564 	zpool_status_t ret = check_status(config, B_TRUE, errata, NULL, 0);
565 
566 	if (ret >= NMSGID)
567 		*msgid = NULL;
568 	else
569 		*msgid = zfs_msgid_table[ret];
570 
571 	return (ret);
572 }
573