FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
/*
 * Check that a file is valid.  All we can do in this case is check that it's
 * not in use by another pool, and not in use by swap.
 */
Check that a file is valid.  All we can do in this case is check that it's
not in use by another pool, and not in use by swap.
Check that a file is valid . All we can do in this case is check that it ' s not in use by another pool and not in use by swap .
static int
check_file(const char *file, boolean_t force, boolean_t isspare)
{
	char  *name;
	int fd;
	int ret = 0;
	int err;
	pool_state_t state;
	boolean_t inuse;
#ifdef illumos
	if (dm_inuse_swap(file, &err)) {
		if (err)
			libdiskmgt_error(err);
		else
			vdev_error(gettext("%s is currently used by swap. "
			    "Please see swap(1M).\n"), file);
		return (-1);
	}
#endif
	if ((fd = open(file, O_RDONLY)) < 0)
		return (0);
	if (zpool_in_use(g_zfs, fd, &state, &name, &inuse) == 0 && inuse) {
		const char *desc;
		switch (state) {
		case POOL_STATE_ACTIVE:
			desc = gettext("active");
			break;
		case POOL_STATE_EXPORTED:
			desc = gettext("exported");
			break;
		case POOL_STATE_POTENTIALLY_ACTIVE:
			desc = gettext("potentially active");
			break;
		default:
			desc = gettext("unknown");
			break;
		}
		if (state == POOL_STATE_SPARE && isspare)
			return (0);
		if (state == POOL_STATE_ACTIVE ||
		    state == POOL_STATE_SPARE || !force) {
			switch (state) {
			case POOL_STATE_SPARE:
				vdev_error(gettext("%s is reserved as a hot "
				    "spare for pool %s\n"), file, name);
				break;
			default:
				vdev_error(gettext("%s is part of %s pool "
				    "'%s'\n"), file, desc, name);
				break;
			}
			ret = -1;
		}
		free(name);
	}
	(void) close(fd);
	return (ret);
}
static int check_file ( const char * file , boolean_t force , boolean_t isspare ) { char * name ; int fd ; int ret = 0 ; int err ; pool_state_t state ; boolean_t inuse ; #ifdef illumos if ( dm_inuse_swap ( file , & err ) ) { if ( err ) libdiskmgt_error ( err ) ; else vdev_error ( gettext ( " " " \n " ) , file ) ; return ( -1 ) ; } #endif if ( ( fd = open ( file , O_RDONLY ) ) < 0 ) return ( 0 ) ; if ( zpool_in_use ( g_zfs , fd , & state , & name , & inuse ) == 0 && inuse ) { const char * desc ; switch ( state ) { case POOL_STATE_ACTIVE : desc = gettext ( " " ) ; break ; case POOL_STATE_EXPORTED : desc = gettext ( " " ) ; break ; case POOL_STATE_POTENTIALLY_ACTIVE : desc = gettext ( " " ) ; break ; default : desc = gettext ( " " ) ; break ; } if ( state == POOL_STATE_SPARE && isspare ) return ( 0 ) ; if ( state == POOL_STATE_ACTIVE || state == POOL_STATE_SPARE || ! force ) { switch ( state ) { case POOL_STATE_SPARE : vdev_error ( gettext ( " " " \n " ) , file , name ) ; break ; default : vdev_error ( gettext ( " " " \n " ) , file , desc , name ) ; break ; } ret = -1 ; } free ( name ) ; } ( void ) close ( fd ) ; return ( ret ) ; }
Check that a file is valid.
Check that a file is valid .
/*
		 * Allow hot spares to be shared between pools.
		 */