FreeBSD/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_config.c
/*
 * Refresh the vdev statistics associated with the given pool.  This is used in
 * iostat to show configuration changes and determine the delta from the last
 * time the function was called.  This function can fail, in case the pool has
 * been destroyed.
 */
Refresh the vdev statistics associated with the given pool.  This is used in
iostat to show configuration changes and determine the delta from the last
time the function was called.  This function can fail, in case the pool has
been destroyed.
Refresh the vdev statistics associated with the given pool . This is used in iostat to show configuration changes and determine the delta from the last time the function was called . This function can fail in case the pool has been destroyed .
int
zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing)
{
	zfs_cmd_t zc = { 0 };
	int error;
	nvlist_t *config;
	libzfs_handle_t *hdl = zhp->zpool_hdl;
	*missing = B_FALSE;
	(void) strcpy(zc.zc_name, zhp->zpool_name);
	if (zhp->zpool_config_size == 0)
		zhp->zpool_config_size = 1 << 16;
	if (zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size) != 0)
		return (-1);
	for (;;) {
		if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_POOL_STATS,
		    &zc) == 0) {
			error = zc.zc_cookie;
			break;
		}
		if (errno == ENOMEM) {
			if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
				zcmd_free_nvlists(&zc);
				return (-1);
			}
		} else {
			zcmd_free_nvlists(&zc);
			if (errno == ENOENT || errno == EINVAL)
				*missing = B_TRUE;
			zhp->zpool_state = POOL_STATE_UNAVAIL;
			return (0);
		}
	}
	if (zcmd_read_dst_nvlist(hdl, &zc, &config) != 0) {
		zcmd_free_nvlists(&zc);
		return (-1);
	}
	zcmd_free_nvlists(&zc);
	zhp->zpool_config_size = zc.zc_nvlist_dst_size;
	if (zhp->zpool_config != NULL) {
		uint64_t oldtxg, newtxg;
		verify(nvlist_lookup_uint64(zhp->zpool_config,
		    ZPOOL_CONFIG_POOL_TXG, &oldtxg) == 0);
		verify(nvlist_lookup_uint64(config,
		    ZPOOL_CONFIG_POOL_TXG, &newtxg) == 0);
		nvlist_free(zhp->zpool_old_config);
		if (oldtxg != newtxg) {
			nvlist_free(zhp->zpool_config);
			zhp->zpool_old_config = NULL;
		} else {
			zhp->zpool_old_config = zhp->zpool_config;
		}
	}
	zhp->zpool_config = config;
	if (error)
		zhp->zpool_state = POOL_STATE_UNAVAIL;
	else
		zhp->zpool_state = POOL_STATE_ACTIVE;
	return (0);
}
int zpool_refresh_stats ( zpool_handle_t * zhp , boolean_t * missing ) { zfs_cmd_t zc = { 0 } ; int error ; nvlist_t * config ; libzfs_handle_t * hdl = zhp -> zpool_hdl ; * missing = B_FALSE ; ( void ) strcpy ( zc . zc_name , zhp -> zpool_name ) ; if ( zhp -> zpool_config_size == 0 ) zhp -> zpool_config_size = 1 << 16 ; if ( zcmd_alloc_dst_nvlist ( hdl , & zc , zhp -> zpool_config_size ) != 0 ) return ( -1 ) ; for ( ; ; ) { if ( ioctl ( zhp -> zpool_hdl -> libzfs_fd , ZFS_IOC_POOL_STATS , & zc ) == 0 ) { error = zc . zc_cookie ; break ; } if ( errno == ENOMEM ) { if ( zcmd_expand_dst_nvlist ( hdl , & zc ) != 0 ) { zcmd_free_nvlists ( & zc ) ; return ( -1 ) ; } } else { zcmd_free_nvlists ( & zc ) ; if ( errno == ENOENT || errno == EINVAL ) * missing = B_TRUE ; zhp -> zpool_state = POOL_STATE_UNAVAIL ; return ( 0 ) ; } } if ( zcmd_read_dst_nvlist ( hdl , & zc , & config ) != 0 ) { zcmd_free_nvlists ( & zc ) ; return ( -1 ) ; } zcmd_free_nvlists ( & zc ) ; zhp -> zpool_config_size = zc . zc_nvlist_dst_size ; if ( zhp -> zpool_config != NULL ) { uint64_t oldtxg , newtxg ; verify ( nvlist_lookup_uint64 ( zhp -> zpool_config , ZPOOL_CONFIG_POOL_TXG , & oldtxg ) == 0 ) ; verify ( nvlist_lookup_uint64 ( config , ZPOOL_CONFIG_POOL_TXG , & newtxg ) == 0 ) ; nvlist_free ( zhp -> zpool_old_config ) ; if ( oldtxg != newtxg ) { nvlist_free ( zhp -> zpool_config ) ; zhp -> zpool_old_config = NULL ; } else { zhp -> zpool_old_config = zhp -> zpool_config ; } } zhp -> zpool_config = config ; if ( error ) zhp -> zpool_state = POOL_STATE_UNAVAIL ; else zhp -> zpool_state = POOL_STATE_ACTIVE ; return ( 0 ) ; }
Refresh the vdev statistics associated with the given pool.
Refresh the vdev statistics associated with the given pool .
/*
			 * The real error is returned in the zc_cookie field.
			 */