FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * Print the configuration of an exported pool.  Iterate over all vdevs in the
 * pool, printing out the name and status for each one.
 */
Print the configuration of an exported pool.  Iterate over all vdevs in the
pool, printing out the name and status for each one.
Print the configuration of an exported pool . Iterate over all vdevs in the pool printing out the name and status for each one .
void
print_import_config(const char *name, nvlist_t *nv, int namewidth, int depth)
{
	nvlist_t **child;
	uint_t c, children;
	vdev_stat_t *vs;
	char *type, *vname;
	verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) == 0);
	if (strcmp(type, VDEV_TYPE_MISSING) == 0 ||
	    strcmp(type, VDEV_TYPE_HOLE) == 0)
		return;
	verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
	    (uint64_t **)&vs, &c) == 0);
	(void) printf("\t%*s%-*s", depth, "", namewidth - depth, name);
	(void) printf("  %s", zpool_state_to_name(vs->vs_state, vs->vs_aux));
	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_ERR_EXCEEDED:
			(void) printf(gettext("too many errors"));
			break;
		default:
			(void) printf(gettext("corrupted data"));
			break;
		}
	}
	(void) printf("\n");
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
	    &child, &children) != 0)
		return;
	for (c = 0; c < children; c++) {
		uint64_t is_log = B_FALSE;
		(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
		    &is_log);
		if (is_log)
			continue;
		vname = zpool_vdev_name(g_zfs, NULL, child[c], B_TRUE);
		print_import_config(vname, child[c], namewidth, depth + 2);
		free(vname);
	}
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
	    &child, &children) == 0) {
		(void) printf(gettext("\tcache\n"));
		for (c = 0; c < children; c++) {
			vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
			(void) printf("\t  %s\n", vname);
			free(vname);
		}
	}
	if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
	    &child, &children) == 0) {
		(void) printf(gettext("\tspares\n"));
		for (c = 0; c < children; c++) {
			vname = zpool_vdev_name(g_zfs, NULL, child[c], B_FALSE);
			(void) printf("\t  %s\n", vname);
			free(vname);
		}
	}
}
void print_import_config ( const char * name , nvlist_t * nv , int namewidth , int depth ) { nvlist_t * * child ; uint_t c , children ; vdev_stat_t * vs ; char * type , * vname ; verify ( nvlist_lookup_string ( nv , ZPOOL_CONFIG_TYPE , & type ) == 0 ) ; if ( strcmp ( type , VDEV_TYPE_MISSING ) == 0 || strcmp ( type , VDEV_TYPE_HOLE ) == 0 ) return ; verify ( nvlist_lookup_uint64_array ( nv , ZPOOL_CONFIG_VDEV_STATS , ( uint64_t * * ) & vs , & c ) == 0 ) ; ( void ) printf ( " \t " , depth , " " , namewidth - depth , name ) ; ( void ) printf ( " " , zpool_state_to_name ( vs -> vs_state , vs -> vs_aux ) ) ; 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_ERR_EXCEEDED : ( void ) printf ( gettext ( " " ) ) ; break ; default : ( void ) printf ( gettext ( " " ) ) ; break ; } } ( void ) printf ( " \n " ) ; if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_CHILDREN , & child , & children ) != 0 ) return ; for ( c = 0 ; c < children ; c ++ ) { uint64_t is_log = B_FALSE ; ( void ) nvlist_lookup_uint64 ( child [ c ] , ZPOOL_CONFIG_IS_LOG , & is_log ) ; if ( is_log ) continue ; vname = zpool_vdev_name ( g_zfs , NULL , child [ c ] , B_TRUE ) ; print_import_config ( vname , child [ c ] , namewidth , depth + 2 ) ; free ( vname ) ; } if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_L2CACHE , & child , & children ) == 0 ) { ( void ) printf ( gettext ( " \t \n " ) ) ; for ( c = 0 ; c < children ; c ++ ) { vname = zpool_vdev_name ( g_zfs , NULL , child [ c ] , B_FALSE ) ; ( void ) printf ( " \t \n " , vname ) ; free ( vname ) ; } } if ( nvlist_lookup_nvlist_array ( nv , ZPOOL_CONFIG_SPARES , & child , & children ) == 0 ) { ( void ) printf ( gettext ( " \t \n " ) ) ; for ( c = 0 ; c < children ; c ++ ) { vname = zpool_vdev_name ( g_zfs , NULL , child [ c ] , B_FALSE ) ; ( void ) printf ( " \t \n " , vname ) ; free ( vname ) ; } } }
Print the configuration of an exported pool.
Print the configuration of an exported pool .