FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
 *
 *	-v	Display statistics for individual vdevs
 *	-T	Display a timestamp in date(1) or Unix format
 *
 * This command can be tricky because we want to be able to deal with pool
 * creation/destruction as well as vdev configuration changes.  The bulk of this
 * processing is handled by the pool_list_* routines in zpool_iter.c.  We rely
 * on pool_list_update() to detect the addition of new pools.  Configuration
 * changes are all handled within libzfs.
 */


This command can be tricky because we want to be able to deal with pool
creation/destruction as well as vdev configuration changes.  The bulk of this
processing is handled by the pool_list_* routines in zpool_iter.c.  We rely
on pool_list_update() to detect the addition of new pools.  Configuration
changes are all handled within libzfs.
This command can be tricky because we want to be able to deal with pool creation / destruction as well as vdev configuration changes . The bulk of this processing is handled by the pool_list_ * routines in zpool_iter . c . We rely on pool_list_update () to detect the addition of new pools . Configuration changes are all handled within libzfs .
int
zpool_do_iostat(int argc, char **argv)
{
	int c;
	int ret;
	int npools;
	unsigned long interval = 0, count = 0;
	zpool_list_t *list;
	boolean_t verbose = B_FALSE;
	iostat_cbdata_t cb;
	while ((c = getopt(argc, argv, "T:v")) != -1) {
		switch (c) {
		case 'T':
			get_timestamp_arg(*optarg);
			break;
		case 'v':
			verbose = B_TRUE;
			break;
		case '?':
			(void) fprintf(stderr, gettext("invalid option '%c'\n"),
			    optopt);
			usage(B_FALSE);
		}
	}
	argc -= optind;
	argv += optind;
	get_interval_count(&argc, argv, &interval, &count);
	ret = 0;
	if ((list = pool_list_get(argc, argv, NULL, &ret)) == NULL)
		return (1);
	if (pool_list_count(list) == 0 && argc != 0) {
		pool_list_free(list);
		return (1);
	}
	if (pool_list_count(list) == 0 && interval == 0) {
		pool_list_free(list);
		(void) fprintf(stderr, gettext("no pools available\n"));
		return (1);
	}
	cb.cb_list = list;
	cb.cb_verbose = verbose;
	cb.cb_iteration = 0;
	cb.cb_namewidth = 0;
	for (;;) {
		pool_list_update(list);
		if ((npools = pool_list_count(list)) == 0)
			break;
		(void) pool_list_iter(list, B_FALSE, refresh_iostat, &cb);
		cb.cb_namewidth = 0;
		(void) pool_list_iter(list, B_FALSE, get_namewidth, &cb);
		if (timestamp_fmt != NODATE)
			print_timestamp(timestamp_fmt);
		if (++cb.cb_iteration == 1 || verbose)
			print_iostat_header(&cb);
		(void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
		if (npools > 1 && !verbose)
			print_iostat_separator(&cb);
		if (verbose)
			(void) printf("\n");
		(void) fflush(stdout);
		if (interval == 0)
			break;
		if (count != 0 && --count == 0)
			break;
		(void) sleep(interval);
	}
	pool_list_free(list);
	return (ret);
}
int zpool_do_iostat ( int argc , char * * argv ) { int c ; int ret ; int npools ; unsigned long interval = 0 , count = 0 ; zpool_list_t * list ; boolean_t verbose = B_FALSE ; iostat_cbdata_t cb ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : get_timestamp_arg ( * optarg ) ; break ; case ' ' : verbose = B_TRUE ; break ; case ' ' : ( void ) fprintf ( stderr , gettext ( " \n " ) , optopt ) ; usage ( B_FALSE ) ; } } argc -= optind ; argv += optind ; get_interval_count ( & argc , argv , & interval , & count ) ; ret = 0 ; if ( ( list = pool_list_get ( argc , argv , NULL , & ret ) ) == NULL ) return ( 1 ) ; if ( pool_list_count ( list ) == 0 && argc != 0 ) { pool_list_free ( list ) ; return ( 1 ) ; } if ( pool_list_count ( list ) == 0 && interval == 0 ) { pool_list_free ( list ) ; ( void ) fprintf ( stderr , gettext ( " \n " ) ) ; return ( 1 ) ; } cb . cb_list = list ; cb . cb_verbose = verbose ; cb . cb_iteration = 0 ; cb . cb_namewidth = 0 ; for ( ; ; ) { pool_list_update ( list ) ; if ( ( npools = pool_list_count ( list ) ) == 0 ) break ; ( void ) pool_list_iter ( list , B_FALSE , refresh_iostat , & cb ) ; cb . cb_namewidth = 0 ; ( void ) pool_list_iter ( list , B_FALSE , get_namewidth , & cb ) ; if ( timestamp_fmt != NODATE ) print_timestamp ( timestamp_fmt ) ; if ( ++ cb . cb_iteration == 1 || verbose ) print_iostat_header ( & cb ) ; ( void ) pool_list_iter ( list , B_FALSE , print_iostat , & cb ) ; if ( npools > 1 && ! verbose ) print_iostat_separator ( & cb ) ; if ( verbose ) ( void ) printf ( " \n " ) ; ( void ) fflush ( stdout ) ; if ( interval == 0 ) break ; if ( count != 0 && -- count == 0 ) break ; ( void ) sleep ( interval ) ; } pool_list_free ( list ) ; return ( ret ) ; }
zpool iostat [-v] [-T d|u] [pool] ... [interval [count]]
      -v      Display statistics for individual vdevs
      -T      Display a timestamp in date(1) or Unix format
zpool iostat [ - v ] [ - T d|u ] [ pool ] ... [ interval [ count ]] - v Display statistics for individual vdevs - T Display a timestamp in date ( 1 ) or Unix format
/* check options */ /*
	 * Construct the list of all interesting pools.
	 */ /*
	 * Enter the main iostat loop.
	 */ /*
		 * Refresh all statistics.  This is done as an explicit step
		 * before calculating the maximum name width, so that any
		 * configuration changes are properly accounted for.
		 */ /*
		 * Iterate over all pools to determine the maximum width
		 * for the pool / device name column across all pools.
		 */ /*
		 * If it's the first time, or verbose mode, print the header.
		 */ /*
		 * If there's more than one pool, and we're not in verbose mode
		 * (which prints a separator for us), then print a separator.
		 */ /*
		 * Flush the output so that redirection to a file isn't buffered
		 * indefinitely.
		 */