zfs-fuse/src/lib/libzpool/arc.c
/*
 * Cycle through L2ARC devices.  This is how L2ARC load balances.
 * If a device is returned, this also returns holding the spa config lock.
 */
Cycle through L2ARC devices.  This is how L2ARC load balances.
If a device is returned, this also returns holding the spa config lock.
Cycle through L2ARC devices . This is how L2ARC load balances . If a device is returned this also returns holding the spa config lock .
static l2arc_dev_t *
l2arc_dev_get_next(void)
{
	l2arc_dev_t *first, *next = NULL;
	mutex_enter(&spa_namespace_lock);
	mutex_enter(&l2arc_dev_mtx);
	if (l2arc_ndev == 0)
		goto out;
	first = NULL;
	next = l2arc_dev_last;
	do {
		if (next == NULL) {
			next = list_head(l2arc_dev_list);
		} else {
			next = list_next(l2arc_dev_list, next);
			if (next == NULL)
				next = list_head(l2arc_dev_list);
		}
		if (first == NULL)
			first = next;
		else if (next == first)
			break;
	} while (vdev_is_dead(next->l2ad_vdev));
	if (vdev_is_dead(next->l2ad_vdev))
		next = NULL;
	l2arc_dev_last = next;
out:
	mutex_exit(&l2arc_dev_mtx);
	if (next != NULL)
		spa_config_enter(next->l2ad_spa, SCL_L2ARC, next, RW_READER);
	mutex_exit(&spa_namespace_lock);
	return (next);
}
static l2arc_dev_t * l2arc_dev_get_next ( void ) { l2arc_dev_t * first , * next = NULL ; mutex_enter ( & spa_namespace_lock ) ; mutex_enter ( & l2arc_dev_mtx ) ; if ( l2arc_ndev == 0 ) goto out ; first = NULL ; next = l2arc_dev_last ; do { if ( next == NULL ) { next = list_head ( l2arc_dev_list ) ; } else { next = list_next ( l2arc_dev_list , next ) ; if ( next == NULL ) next = list_head ( l2arc_dev_list ) ; } if ( first == NULL ) first = next ; else if ( next == first ) break ; } while ( vdev_is_dead ( next -> l2ad_vdev ) ) ; if ( vdev_is_dead ( next -> l2ad_vdev ) ) next = NULL ; l2arc_dev_last = next ; out : mutex_exit ( & l2arc_dev_mtx ) ; if ( next != NULL ) spa_config_enter ( next -> l2ad_spa , SCL_L2ARC , next , RW_READER ) ; mutex_exit ( & spa_namespace_lock ) ; return ( next ) ; }
Cycle through L2ARC devices.
Cycle through L2ARC devices .
/*
	 * Lock out the removal of spas (spa_namespace_lock), then removal
	 * of cache devices (l2arc_dev_mtx).  Once a device has been selected,
	 * both locks will be dropped and a spa config lock held instead.
	 */ /* if there are no vdevs, there is nothing to do */ /* loop around the list looking for a non-faulted vdev */ /* if we have come back to the start, bail out */ /* if we were unable to find any usable vdevs, return NULL */ /*
	 * Grab the config lock to prevent the 'next' device from being
	 * removed while we are writing to it.
	 */