FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
/*
 * Determine if the given path is a hot spare within the given configuration.
 */
Determine if the given path is a hot spare within the given configuration.
Determine if the given path is a hot spare within the given configuration .
static boolean_t
is_spare(nvlist_t *config, const char *path)
{
	int fd;
	pool_state_t state;
	char *name = NULL;
	nvlist_t *label;
	uint64_t guid, spareguid;
	nvlist_t *nvroot;
	nvlist_t **spares;
	uint_t i, nspares;
	boolean_t inuse;
	if ((fd = open(path, O_RDONLY)) < 0)
		return (B_FALSE);
	if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) != 0 ||
	    !inuse ||
	    state != POOL_STATE_SPARE ||
	    zpool_read_label(fd, &label) != 0) {
		free(name);
		(void) close(fd);
		return (B_FALSE);
	}
	free(name);
	(void) close(fd);
	verify(nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) == 0);
	nvlist_free(label);
	verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE,
	    &nvroot) == 0);
	if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES,
	    &spares, &nspares) == 0) {
		for (i = 0; i < nspares; i++) {
			verify(nvlist_lookup_uint64(spares[i],
			    ZPOOL_CONFIG_GUID, &spareguid) == 0);
			if (spareguid == guid)
				return (B_TRUE);
		}
	}
	return (B_FALSE);
}
static boolean_t is_spare ( nvlist_t * config , const char * path ) { int fd ; pool_state_t state ; char * name = NULL ; nvlist_t * label ; uint64_t guid , spareguid ; nvlist_t * nvroot ; nvlist_t * * spares ; uint_t i , nspares ; boolean_t inuse ; if ( ( fd = open ( path , O_RDONLY ) ) < 0 ) return ( B_FALSE ) ; if ( zpool_in_use ( g_zfs , fd , & state , & name , & inuse ) != 0 || ! inuse || state != POOL_STATE_SPARE || zpool_read_label ( fd , & label ) != 0 ) { free ( name ) ; ( void ) close ( fd ) ; return ( B_FALSE ) ; } free ( name ) ; ( void ) close ( fd ) ; verify ( nvlist_lookup_uint64 ( label , ZPOOL_CONFIG_GUID , & guid ) == 0 ) ; nvlist_free ( label ) ; verify ( nvlist_lookup_nvlist ( config , ZPOOL_CONFIG_VDEV_TREE , & nvroot ) == 0 ) ; if ( nvlist_lookup_nvlist_array ( nvroot , ZPOOL_CONFIG_SPARES , & spares , & nspares ) == 0 ) { for ( i = 0 ; i < nspares ; i ++ ) { verify ( nvlist_lookup_uint64 ( spares [ i ] , ZPOOL_CONFIG_GUID , & spareguid ) == 0 ) ; if ( spareguid == guid ) return ( B_TRUE ) ; } } return ( B_FALSE ) ; }
Determine if the given path is a hot spare within the given configuration.
Determine if the given path is a hot spare within the given configuration .