* Pool Creation */
| 5624 | * Pool Creation |
| 5625 | */ |
| 5626 | int |
| 5627 | spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, |
| 5628 | nvlist_t *zplprops, dsl_crypto_params_t *dcp) |
| 5629 | { |
| 5630 | spa_t *spa; |
| 5631 | char *altroot = NULL; |
| 5632 | vdev_t *rvd; |
| 5633 | dsl_pool_t *dp; |
| 5634 | dmu_tx_t *tx; |
| 5635 | int error = 0; |
| 5636 | uint64_t txg = TXG_INITIAL; |
| 5637 | nvlist_t **spares, **l2cache; |
| 5638 | uint_t nspares, nl2cache; |
| 5639 | uint64_t version, obj, ndraid = 0; |
| 5640 | boolean_t has_features; |
| 5641 | boolean_t has_encryption; |
| 5642 | boolean_t has_allocclass; |
| 5643 | spa_feature_t feat; |
| 5644 | char *feat_name; |
| 5645 | char *poolname; |
| 5646 | nvlist_t *nvl; |
| 5647 | |
| 5648 | if (props == NULL || |
| 5649 | nvlist_lookup_string(props, "tname", &poolname) != 0) |
| 5650 | poolname = (char *)pool; |
| 5651 | |
| 5652 | /* |
| 5653 | * If this pool already exists, return failure. |
| 5654 | */ |
| 5655 | mutex_enter(&spa_namespace_lock); |
| 5656 | if (spa_lookup(poolname) != NULL) { |
| 5657 | mutex_exit(&spa_namespace_lock); |
| 5658 | return (SET_ERROR(EEXIST)); |
| 5659 | } |
| 5660 | |
| 5661 | /* |
| 5662 | * Allocate a new spa_t structure. |
| 5663 | */ |
| 5664 | nvl = fnvlist_alloc(); |
| 5665 | fnvlist_add_string(nvl, ZPOOL_CONFIG_POOL_NAME, pool); |
| 5666 | (void) nvlist_lookup_string(props, |
| 5667 | zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); |
| 5668 | spa = spa_add(poolname, nvl, altroot); |
| 5669 | fnvlist_free(nvl); |
| 5670 | spa_activate(spa, spa_mode_global); |
| 5671 | |
| 5672 | if (props && (error = spa_prop_validate(spa, props))) { |
| 5673 | spa_deactivate(spa); |
| 5674 | spa_remove(spa); |
| 5675 | mutex_exit(&spa_namespace_lock); |
| 5676 | return (error); |
| 5677 | } |
| 5678 | |
| 5679 | /* |
| 5680 | * Temporary pool names should never be written to disk. |
| 5681 | */ |
| 5682 | if (poolname != pool) |
| 5683 | spa->spa_import_flags |= ZFS_IMPORT_TEMP_NAME; |