FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * Print out configuration state as requested by status_callback.
 */
Print out configuration state as requested by status_callback.
Print out configuration state as requested by status_callback .
void
print_status_config(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
    int namewidth, int depth, boolean_t isspare)
{
	nvlist_t **child;
	uint_t c, vsc, children;
	pool_scan_stat_t *ps = NULL;
	vdev_stat_t *vs;
	char rbuf[6], wbuf[6], cbuf[6];
	char *vname;
	uint64_t notpresent;
	uint64_t ashift;
	spare_cbdata_t cb;
	const char *state;
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
	    &child, &children) != 0)
		children = 0;
	verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
	    (uint64_t **)&vs, &vsc) == 0);
	state = zpool_state_to_name(vs->vs_state, vs->vs_aux);
	if (isspare) {
		if (vs->vs_aux == VDEV_AUX_SPARED)
			state = "INUSE";
		else if (vs->vs_state == VDEV_STATE_HEALTHY)
			state = "AVAIL";
	}
	(void) printf("\t%*s%-*s  %-8s", depth, "", namewidth - depth,
	    name, state);
	if (!isspare) {
		zfs_nicenum(vs->vs_read_errors, rbuf, sizeof (rbuf));
		zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
		zfs_nicenum(vs->vs_checksum_errors, cbuf, sizeof (cbuf));
		(void) printf(" %5s %5s %5s", rbuf, wbuf, cbuf);
	}
	if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
	    &notpresent) == 0 ||
	    vs->vs_state <= VDEV_STATE_CANT_OPEN) {
		char *path;
		if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0)
			(void) printf("  was %s", path);
	} else if (vs->vs_aux != 0) {
		(void) printf("  ");
		switch (vs->vs_aux) {
		case VDEV_AUX_OPEN_FAILED:
			(void) printf(gettext("cannot open"));
			break;
		case VDEV_AUX_BAD_GUID_SUM:
			(void) printf(gettext("missing device"));
			break;
		case VDEV_AUX_NO_REPLICAS:
			(void) printf(gettext("insufficient replicas"));
			break;
		case VDEV_AUX_VERSION_NEWER:
			(void) printf(gettext("newer version"));
			break;
		case VDEV_AUX_UNSUP_FEAT:
			(void) printf(gettext("unsupported feature(s)"));
			break;
		case VDEV_AUX_ASHIFT_TOO_BIG:
			(void) printf(gettext("unsupported minimum blocksize"));
			break;
		case VDEV_AUX_SPARED:
			verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID,
			    &cb.cb_guid) == 0);
			if (zpool_iter(g_zfs, find_spare, &cb) == 1) {
				if (strcmp(zpool_get_name(cb.cb_zhp),
				    zpool_get_name(zhp)) == 0)
					(void) printf(gettext("currently in "
					    "use"));
				else
					(void) printf(gettext("in use by "
					    "pool '%s'"),
					    zpool_get_name(cb.cb_zhp));
				zpool_close(cb.cb_zhp);
			} else {
				(void) printf(gettext("currently in use"));
			}
			break;
		case VDEV_AUX_ERR_EXCEEDED:
			(void) printf(gettext("too many errors"));
			break;
		case VDEV_AUX_IO_FAILURE:
			(void) printf(gettext("experienced I/O failures"));
			break;
		case VDEV_AUX_BAD_LOG:
			(void) printf(gettext("bad intent log"));
			break;
		case VDEV_AUX_EXTERNAL:
			(void) printf(gettext("external device fault"));
			break;
		case VDEV_AUX_SPLIT_POOL:
			(void) printf(gettext("split into new pool"));
			break;
		default:
			(void) printf(gettext("corrupted data"));
			break;
		}
	} else if (children == 0 && !isspare &&
	    VDEV_STAT_VALID(vs_physical_ashift, vsc) &&
	    vs->vs_configured_ashift < vs->vs_physical_ashift) {
		(void) printf(
		    gettext("  block size: %dB configured, %dB native"),
		    1 << vs->vs_configured_ashift, 1 << vs->vs_physical_ashift);
	}
	(void) nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_SCAN_STATS,
	    (uint64_t **)&ps, &c);
	if (ps && ps->pss_state == DSS_SCANNING &&
	    vs->vs_scan_processed != 0 && children == 0) {
		(void) printf(gettext("  (%s)"),
		    (ps->pss_func == POOL_SCAN_RESILVER) ?
		    "resilvering" : "repairing");
	}
	(void) printf("\n");
	for (c = 0; c < children; c++) {
		uint64_t islog = B_FALSE, ishole = B_FALSE;
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
		    &islog);
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
		    &ishole);
		if (islog || ishole)
			continue;
		vname = zpool_vdev_name(g_zfs, zhp, child[c], B_TRUE);
		print_status_config(zhp, vname, child[c],
		    namewidth, depth + 2, isspare);
		free(vname);
	}
}
void print_status_config ( zpool_handle_t * zhp , const char * name , nvlist_t * nv , int namewidth , int depth , boolean_t isspare ) { nvlist_t * * child ; uint_t c , vsc , children ; pool_scan_stat_t * ps = NULL ; vdev_stat_t * vs ; char rbuf [ 6 ] , wbuf [ 6 ] , cbuf [ 6 ] ; char * vname ; uint64_t notpresent ; uint64_t ashift ; spare_cbdata_t cb ; const char * state ; if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_CHILDREN , & child , & children ) != 0 ) children = 0 ; verify ( nvlist_lookup_uint64_array ( nv , ZPOOL_CONFIG_VDEV_STATS , ( uint64_t * * ) & vs , & vsc ) == 0 ) ; state = zpool_state_to_name ( vs -> vs_state , vs -> vs_aux ) ; if ( isspare ) { if ( vs -> vs_aux == VDEV_AUX_SPARED ) state = " " ; else if ( vs -> vs_state == VDEV_STATE_HEALTHY ) state = " " ; } ( void ) printf ( " \t " , depth , " " , namewidth - depth , name , state ) ; if ( ! isspare ) { zfs_nicenum ( vs -> vs_read_errors , rbuf , sizeof ( rbuf ) ) ; zfs_nicenum ( vs -> vs_write_errors , wbuf , sizeof ( wbuf ) ) ; zfs_nicenum ( vs -> vs_checksum_errors , cbuf , sizeof ( cbuf ) ) ; ( void ) printf ( " " , rbuf , wbuf , cbuf ) ; } if ( nvlist_lookup_uint64 ( nv , ZPOOL_CONFIG_NOT_PRESENT , & notpresent ) == 0 || vs -> vs_state <= VDEV_STATE_CANT_OPEN ) { char * path ; if ( nvlist_lookup_string ( nv , ZPOOL_CONFIG_PATH , & path ) == 0 ) ( void ) printf ( " " , path ) ; } else if ( vs -> vs_aux != 0 ) { ( void ) printf ( " " ) ; switch ( vs -> vs_aux ) { case VDEV_AUX_OPEN_FAILED : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_BAD_GUID_SUM : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_NO_REPLICAS : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_VERSION_NEWER : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_UNSUP_FEAT : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_ASHIFT_TOO_BIG : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_SPARED : verify ( nvlist_lookup_uint64 ( nv , ZPOOL_CONFIG_GUID , & cb . cb_guid ) == 0 ) ; if ( zpool_iter ( g_zfs , find_spare , & cb ) == 1 ) { if ( strcmp ( zpool_get_name ( cb . cb_zhp ) , zpool_get_name ( zhp ) ) == 0 ) ( void ) printf ( gettext ( " " " " ) ) ; else ( void ) printf ( gettext ( " " " " ) , zpool_get_name ( cb . cb_zhp ) ) ; zpool_close ( cb . cb_zhp ) ; } else { ( void ) printf ( gettext ( " " ) ) ; } break ; case VDEV_AUX_ERR_EXCEEDED : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_IO_FAILURE : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_BAD_LOG : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_EXTERNAL : ( void ) printf ( gettext ( " " ) ) ; break ; case VDEV_AUX_SPLIT_POOL : ( void ) printf ( gettext ( " " ) ) ; break ; default : ( void ) printf ( gettext ( " " ) ) ; break ; } } else if ( children == 0 && ! isspare && VDEV_STAT_VALID ( vs_physical_ashift , vsc ) && vs -> vs_configured_ashift < vs -> vs_physical_ashift ) { ( void ) printf ( gettext ( " " ) , 1 << vs -> vs_configured_ashift , 1 << vs -> vs_physical_ashift ) ; } ( void ) nvlist_lookup_uint64_array ( nv , ZPOOL_CONFIG_SCAN_STATS , ( uint64_t * * ) & ps , & c ) ; if ( ps && ps -> pss_state == DSS_SCANNING && vs -> vs_scan_processed != 0 && children == 0 ) { ( void ) printf ( gettext ( " " ) , ( ps -> pss_func == POOL_SCAN_RESILVER ) ? " " : " " ) ; } ( void ) printf ( " \n " ) ; for ( c = 0 ; c < children ; c ++ ) { uint64_t islog = B_FALSE , ishole = B_FALSE ; ( void ) nvlist_lookup_uint64 ( child [ c ] , ZPOOL_CONFIG_IS_LOG , & islog ) ; ( void ) nvlist_lookup_uint64 ( child [ c ] , ZPOOL_CONFIG_IS_HOLE , & ishole ) ; if ( islog || ishole ) continue ; vname = zpool_vdev_name ( g_zfs , zhp , child [ c ] , B_TRUE ) ; print_status_config ( zhp , vname , child [ c ] , namewidth , depth + 2 , isspare ) ; free ( vname ) ; } }
Print out configuration state as requested by status_callback.
Print out configuration state as requested by status_callback .
/*
		 * For hot spares, we use the terms 'INUSE' and 'AVAILABLE' for
		 * online drives.
		 */ /* Don't print logs or holes here */