FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_main.c
/*
 * Perform the import for the given configuration.  This passes the heavy
 * lifting off to zpool_import_props(), and then mounts the datasets contained
 * within the pool.
 */
Perform the import for the given configuration.  This passes the heavy
lifting off to zpool_import_props(), and then mounts the datasets contained
within the pool.
Perform the import for the given configuration . This passes the heavy lifting off to zpool_import_props () and then mounts the datasets contained within the pool .
static int
do_import(nvlist_t *config, const char *newname, const char *mntopts,
    nvlist_t *props, int flags)
{
	zpool_handle_t *zhp;
	char *name;
	uint64_t state;
	uint64_t version;
	verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
	    &name) == 0);
	verify(nvlist_lookup_uint64(config,
	    ZPOOL_CONFIG_POOL_STATE, &state) == 0);
	verify(nvlist_lookup_uint64(config,
	    ZPOOL_CONFIG_VERSION, &version) == 0);
	if (!SPA_VERSION_IS_SUPPORTED(version)) {
		(void) fprintf(stderr, gettext("cannot import '%s': pool "
		    "is formatted using an unsupported ZFS version\n"), name);
		return (1);
	} else if (state != POOL_STATE_EXPORTED &&
	    !(flags & ZFS_IMPORT_ANY_HOST)) {
		uint64_t hostid;
		if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
		    &hostid) == 0) {
			if ((unsigned long)hostid != gethostid()) {
				char *hostname;
				uint64_t timestamp;
				time_t t;
				verify(nvlist_lookup_string(config,
				    ZPOOL_CONFIG_HOSTNAME, &hostname) == 0);
				verify(nvlist_lookup_uint64(config,
				    ZPOOL_CONFIG_TIMESTAMP, &timestamp) == 0);
				t = timestamp;
				(void) fprintf(stderr, gettext("cannot import "
				    "'%s': pool may be in use from other "
				    "system, it was last accessed by %s "
				    "(hostid: 0x%lx) on %s"), name, hostname,
				    (unsigned long)hostid,
				    asctime(localtime(&t)));
				(void) fprintf(stderr, gettext("use '-f' to "
				    "import anyway\n"));
				return (1);
			}
		} else {
			(void) fprintf(stderr, gettext("cannot import '%s': "
			    "pool may be in use from other system\n"), name);
			(void) fprintf(stderr, gettext("use '-f' to import "
			    "anyway\n"));
			return (1);
		}
	}
	if (zpool_import_props(g_zfs, config, newname, props, flags) != 0)
		return (1);
	if (newname != NULL)
		name = (char *)newname;
	if ((zhp = zpool_open_canfail(g_zfs, name)) == NULL)
		return (1);
	if (zpool_get_state(zhp) != POOL_STATE_UNAVAIL &&
	    !(flags & ZFS_IMPORT_ONLY) &&
	    zpool_enable_datasets(zhp, mntopts, 0) != 0) {
		zpool_close(zhp);
		return (1);
	}
	zpool_close(zhp);
	return (0);
}
static int do_import ( nvlist_t * config , const char * newname , const char * mntopts , nvlist_t * props , int flags ) { zpool_handle_t * zhp ; char * name ; uint64_t state ; uint64_t version ; verify ( nvlist_lookup_string ( config , ZPOOL_CONFIG_POOL_NAME , & name ) == 0 ) ; verify ( nvlist_lookup_uint64 ( config , ZPOOL_CONFIG_POOL_STATE , & state ) == 0 ) ; verify ( nvlist_lookup_uint64 ( config , ZPOOL_CONFIG_VERSION , & version ) == 0 ) ; if ( ! SPA_VERSION_IS_SUPPORTED ( version ) ) { ( void ) fprintf ( stderr , gettext ( " " " \n " ) , name ) ; return ( 1 ) ; } else if ( state != POOL_STATE_EXPORTED && ! ( flags & ZFS_IMPORT_ANY_HOST ) ) { uint64_t hostid ; if ( nvlist_lookup_uint64 ( config , ZPOOL_CONFIG_HOSTID , & hostid ) == 0 ) { if ( ( unsigned long ) hostid != gethostid ( ) ) { char * hostname ; uint64_t timestamp ; time_t t ; verify ( nvlist_lookup_string ( config , ZPOOL_CONFIG_HOSTNAME , & hostname ) == 0 ) ; verify ( nvlist_lookup_uint64 ( config , ZPOOL_CONFIG_TIMESTAMP , & timestamp ) == 0 ) ; t = timestamp ; ( void ) fprintf ( stderr , gettext ( " " " " " " " " ) , name , hostname , ( unsigned long ) hostid , asctime ( localtime ( & t ) ) ) ; ( void ) fprintf ( stderr , gettext ( " " " \n " ) ) ; return ( 1 ) ; } } else { ( void ) fprintf ( stderr , gettext ( " " " \n " ) , name ) ; ( void ) fprintf ( stderr , gettext ( " " " \n " ) ) ; return ( 1 ) ; } } if ( zpool_import_props ( g_zfs , config , newname , props , flags ) != 0 ) return ( 1 ) ; if ( newname != NULL ) name = ( char * ) newname ; if ( ( zhp = zpool_open_canfail ( g_zfs , name ) ) == NULL ) return ( 1 ) ; if ( zpool_get_state ( zhp ) != POOL_STATE_UNAVAIL && ! ( flags & ZFS_IMPORT_ONLY ) && zpool_enable_datasets ( zhp , mntopts , 0 ) != 0 ) { zpool_close ( zhp ) ; return ( 1 ) ; } zpool_close ( zhp ) ; return ( 0 ) ; }
Perform the import for the given configuration.
Perform the import for the given configuration .