usr/src/lib/libzfs/common/libzfs_status.c
changeset 12296 7cf402a7f374
parent 11149 8bad7424e2c2
child 13700 2889e2596bd6
equal deleted inserted replaced
12295:e16f396f04a1 12296:7cf402a7f374
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 /*
    21 /*
    22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
    22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    23  * Use is subject to license terms.
       
    24  */
    23  */
    25 
    24 
    26 /*
    25 /*
    27  * This file contains the functions which analyze the status of a pool.  This
    26  * This file contains the functions which analyze the status of a pool.  This
    28  * include both the status of an active pool, as well as the status exported
    27  * include both the status of an active pool, as well as the status exported
   136 	    &children) == 0) {
   135 	    &children) == 0) {
   137 		for (c = 0; c < children; c++)
   136 		for (c = 0; c < children; c++)
   138 			if (find_vdev_problem(child[c], func))
   137 			if (find_vdev_problem(child[c], func))
   139 				return (B_TRUE);
   138 				return (B_TRUE);
   140 	} else {
   139 	} else {
   141 		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_STATS,
   140 		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_VDEV_STATS,
   142 		    (uint64_t **)&vs, &c) == 0);
   141 		    (uint64_t **)&vs, &c) == 0);
   143 
   142 
   144 		if (func(vs->vs_state, vs->vs_aux,
   143 		if (func(vs->vs_state, vs->vs_aux,
   145 		    vs->vs_read_errors +
   144 		    vs->vs_read_errors +
   146 		    vs->vs_write_errors +
   145 		    vs->vs_write_errors +
   171 static zpool_status_t
   170 static zpool_status_t
   172 check_status(nvlist_t *config, boolean_t isimport)
   171 check_status(nvlist_t *config, boolean_t isimport)
   173 {
   172 {
   174 	nvlist_t *nvroot;
   173 	nvlist_t *nvroot;
   175 	vdev_stat_t *vs;
   174 	vdev_stat_t *vs;
   176 	uint_t vsc;
   175 	pool_scan_stat_t *ps = NULL;
       
   176 	uint_t vsc, psc;
   177 	uint64_t nerr;
   177 	uint64_t nerr;
   178 	uint64_t version;
   178 	uint64_t version;
   179 	uint64_t stateval;
   179 	uint64_t stateval;
   180 	uint64_t suspended;
   180 	uint64_t suspended;
   181 	uint64_t hostid = 0;
   181 	uint64_t hostid = 0;
   182 
   182 
   183 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
   183 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
   184 	    &version) == 0);
   184 	    &version) == 0);
   185 	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
   185 	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
   186 	    &nvroot) == 0);
   186 	    &nvroot) == 0);
   187 	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_STATS,
   187 	verify(nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS,
   188 	    (uint64_t **)&vs, &vsc) == 0);
   188 	    (uint64_t **)&vs, &vsc) == 0);
   189 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
   189 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_STATE,
   190 	    &stateval) == 0);
   190 	    &stateval) == 0);
       
   191 
       
   192 	/*
       
   193 	 * Currently resilvering a vdev
       
   194 	 */
       
   195 	(void) nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_SCAN_STATS,
       
   196 	    (uint64_t **)&ps, &psc);
       
   197 	if (ps && ps->pss_func == POOL_SCAN_RESILVER &&
       
   198 	    ps->pss_state == DSS_SCANNING)
       
   199 		return (ZPOOL_STATUS_RESILVERING);
       
   200 
       
   201 	/*
       
   202 	 * Pool last accessed by another system.
       
   203 	 */
   191 	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
   204 	(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID, &hostid);
   192 
       
   193 	/*
       
   194 	 * Pool last accessed by another system.
       
   195 	 */
       
   196 	if (hostid != 0 && (unsigned long)hostid != gethostid() &&
   205 	if (hostid != 0 && (unsigned long)hostid != gethostid() &&
   197 	    stateval == POOL_STATE_ACTIVE)
   206 	    stateval == POOL_STATE_ACTIVE)
   198 		return (ZPOOL_STATUS_HOSTID_MISMATCH);
   207 		return (ZPOOL_STATUS_HOSTID_MISMATCH);
   199 
   208 
   200 	/*
   209 	/*
   285 	/*
   294 	/*
   286 	 * Removed device
   295 	 * Removed device
   287 	 */
   296 	 */
   288 	if (find_vdev_problem(nvroot, vdev_removed))
   297 	if (find_vdev_problem(nvroot, vdev_removed))
   289 		return (ZPOOL_STATUS_REMOVED_DEV);
   298 		return (ZPOOL_STATUS_REMOVED_DEV);
   290 
       
   291 	/*
       
   292 	 * Currently resilvering
       
   293 	 */
       
   294 	if (!vs->vs_scrub_complete && vs->vs_scrub_type == POOL_SCRUB_RESILVER)
       
   295 		return (ZPOOL_STATUS_RESILVERING);
       
   296 
   299 
   297 	/*
   300 	/*
   298 	 * Outdated, but usable, version
   301 	 * Outdated, but usable, version
   299 	 */
   302 	 */
   300 	if (version < SPA_VERSION)
   303 	if (version < SPA_VERSION)