usr/src/lib/libzfs/common/libzfs_status.c
changeset 2082 76b439ec3ac1
parent 1760 e1ad2821c30d
child 3975 6674f5d79069
equal deleted inserted replaced
2081:34f1e4f08632 2082:76b439ec3ac1
   114 }
   114 }
   115 
   115 
   116 /*
   116 /*
   117  * Detect if any leaf devices that have seen errors or could not be opened.
   117  * Detect if any leaf devices that have seen errors or could not be opened.
   118  */
   118  */
   119 static int
   119 static boolean_t
   120 find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
   120 find_vdev_problem(nvlist_t *vdev, int (*func)(uint64_t, uint64_t, uint64_t))
   121 {
   121 {
   122 	nvlist_t **child;
   122 	nvlist_t **child;
   123 	vdev_stat_t *vs;
   123 	vdev_stat_t *vs;
   124 	uint_t c, children;
   124 	uint_t c, children;
   130 	 * out again.  We'll pick up the fact that a resilver is happening
   130 	 * out again.  We'll pick up the fact that a resilver is happening
   131 	 * later.
   131 	 * later.
   132 	 */
   132 	 */
   133 	verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0);
   133 	verify(nvlist_lookup_string(vdev, ZPOOL_CONFIG_TYPE, &type) == 0);
   134 	if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
   134 	if (strcmp(type, VDEV_TYPE_REPLACING) == 0)
   135 		return (FALSE);
   135 		return (B_FALSE);
   136 
   136 
   137 	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
   137 	if (nvlist_lookup_nvlist_array(vdev, ZPOOL_CONFIG_CHILDREN, &child,
   138 	    &children) == 0) {
   138 	    &children) == 0) {
   139 		for (c = 0; c < children; c++)
   139 		for (c = 0; c < children; c++)
   140 			if (find_vdev_problem(child[c], func))
   140 			if (find_vdev_problem(child[c], func))
   141 				return (TRUE);
   141 				return (B_TRUE);
   142 	} else {
   142 	} else {
   143 		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_STATS,
   143 		verify(nvlist_lookup_uint64_array(vdev, ZPOOL_CONFIG_STATS,
   144 		    (uint64_t **)&vs, &c) == 0);
   144 		    (uint64_t **)&vs, &c) == 0);
   145 
   145 
   146 		if (func(vs->vs_state, vs->vs_aux,
   146 		if (func(vs->vs_state, vs->vs_aux,
   147 		    vs->vs_read_errors +
   147 		    vs->vs_read_errors +
   148 		    vs->vs_write_errors +
   148 		    vs->vs_write_errors +
   149 		    vs->vs_checksum_errors))
   149 		    vs->vs_checksum_errors))
   150 			return (TRUE);
   150 			return (B_TRUE);
   151 	}
   151 	}
   152 
   152 
   153 	return (FALSE);
   153 	return (B_FALSE);
   154 }
   154 }
   155 
   155 
   156 /*
   156 /*
   157  * Active pool health status.
   157  * Active pool health status.
   158  *
   158  *
   169  *
   169  *
   170  * There can obviously be multiple errors within a single pool, so this routine
   170  * There can obviously be multiple errors within a single pool, so this routine
   171  * only picks the most damaging of all the current errors to report.
   171  * only picks the most damaging of all the current errors to report.
   172  */
   172  */
   173 static zpool_status_t
   173 static zpool_status_t
   174 check_status(nvlist_t *config, int isimport)
   174 check_status(nvlist_t *config, boolean_t isimport)
   175 {
   175 {
   176 	nvlist_t *nvroot;
   176 	nvlist_t *nvroot;
   177 	vdev_stat_t *vs;
   177 	vdev_stat_t *vs;
   178 	uint_t vsc;
   178 	uint_t vsc;
   179 	uint64_t nerr;
   179 	uint64_t nerr;
   263 }
   263 }
   264 
   264 
   265 zpool_status_t
   265 zpool_status_t
   266 zpool_get_status(zpool_handle_t *zhp, char **msgid)
   266 zpool_get_status(zpool_handle_t *zhp, char **msgid)
   267 {
   267 {
   268 	zpool_status_t ret = check_status(zhp->zpool_config, FALSE);
   268 	zpool_status_t ret = check_status(zhp->zpool_config, B_FALSE);
   269 
   269 
   270 	if (ret >= NMSGID)
   270 	if (ret >= NMSGID)
   271 		*msgid = NULL;
   271 		*msgid = NULL;
   272 	else
   272 	else
   273 		*msgid = msgid_table_active[ret];
   273 		*msgid = msgid_table_active[ret];
   276 }
   276 }
   277 
   277 
   278 zpool_status_t
   278 zpool_status_t
   279 zpool_import_status(nvlist_t *config, char **msgid)
   279 zpool_import_status(nvlist_t *config, char **msgid)
   280 {
   280 {
   281 	zpool_status_t ret = check_status(config, TRUE);
   281 	zpool_status_t ret = check_status(config, B_TRUE);
   282 
   282 
   283 	if (ret >= NMSGID)
   283 	if (ret >= NMSGID)
   284 		*msgid = NULL;
   284 		*msgid = NULL;
   285 	else
   285 	else
   286 		*msgid = msgid_table[ret];
   286 		*msgid = msgid_table[ret];