1475 static void
1476 zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
1477 {
1478 rrm_exit(&zfsvfs->z_teardown_lock, tag);
1479
1480 if (zfsvfs->z_vfs) {
1481 VFS_RELE(zfsvfs->z_vfs);
1482 } else {
1483 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1484 zfsvfs_free(zfsvfs);
1485 }
1486 }
1487
1488 static int
1489 zfs_ioc_pool_create(zfs_cmd_t *zc)
1490 {
1491 int error;
1492 nvlist_t *config, *props = NULL;
1493 nvlist_t *rootprops = NULL;
1494 nvlist_t *zplprops = NULL;
1495
1496 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1497 zc->zc_iflags, &config))
1498 return (error);
1499
1500 if (zc->zc_nvlist_src_size != 0 && (error =
1501 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1502 zc->zc_iflags, &props))) {
1503 nvlist_free(config);
1504 return (error);
1505 }
1506
1507 if (props) {
1508 nvlist_t *nvl = NULL;
1509 uint64_t version = SPA_VERSION;
1510
1511 (void) nvlist_lookup_uint64(props,
1512 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1513 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1514 error = SET_ERROR(EINVAL);
1515 goto pool_props_bad;
1516 }
1517 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1518 if (nvl) {
1519 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1520 if (error != 0) {
1521 nvlist_free(config);
1522 nvlist_free(props);
1523 return (error);
1524 }
1525 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1526 }
1527 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1528 error = zfs_fill_zplprops_root(version, rootprops,
1529 zplprops, NULL);
1530 if (error != 0)
1531 goto pool_props_bad;
1532 }
1533
1534 error = spa_create(zc->zc_name, config, props, zplprops);
1535
1536 /*
1537 * Set the remaining root properties
1538 */
1539 if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
1540 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1541 (void) spa_destroy(zc->zc_name);
1542
1543 pool_props_bad:
1544 nvlist_free(rootprops);
1545 nvlist_free(zplprops);
1546 nvlist_free(config);
1547 nvlist_free(props);
1548
1549 return (error);
1550 }
1551
1552 static int
1553 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1554 {
1555 int error;
1556 zfs_log_history(zc);
1557 error = spa_destroy(zc->zc_name);
1558 if (error == 0)
1559 zvol_remove_minors(zc->zc_name);
1560 return (error);
1561 }
|
1475 static void
1476 zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
1477 {
1478 rrm_exit(&zfsvfs->z_teardown_lock, tag);
1479
1480 if (zfsvfs->z_vfs) {
1481 VFS_RELE(zfsvfs->z_vfs);
1482 } else {
1483 dmu_objset_disown(zfsvfs->z_os, zfsvfs);
1484 zfsvfs_free(zfsvfs);
1485 }
1486 }
1487
1488 static int
1489 zfs_ioc_pool_create(zfs_cmd_t *zc)
1490 {
1491 int error;
1492 nvlist_t *config, *props = NULL;
1493 nvlist_t *rootprops = NULL;
1494 nvlist_t *zplprops = NULL;
1495 char *spa_name = zc->zc_name;
1496
1497 if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
1498 zc->zc_iflags, &config))
1499 return (error);
1500
1501 if (zc->zc_nvlist_src_size != 0 && (error =
1502 get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
1503 zc->zc_iflags, &props))) {
1504 nvlist_free(config);
1505 return (error);
1506 }
1507
1508 if (props) {
1509 nvlist_t *nvl = NULL;
1510 uint64_t version = SPA_VERSION;
1511 char *tname;
1512
1513 (void) nvlist_lookup_uint64(props,
1514 zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
1515 if (!SPA_VERSION_IS_SUPPORTED(version)) {
1516 error = SET_ERROR(EINVAL);
1517 goto pool_props_bad;
1518 }
1519 (void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
1520 if (nvl) {
1521 error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
1522 if (error != 0) {
1523 nvlist_free(config);
1524 nvlist_free(props);
1525 return (error);
1526 }
1527 (void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
1528 }
1529 VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
1530 error = zfs_fill_zplprops_root(version, rootprops,
1531 zplprops, NULL);
1532 if (error != 0)
1533 goto pool_props_bad;
1534
1535 if (nvlist_lookup_string(props,
1536 zpool_prop_to_name(ZPOOL_PROP_TNAME), &tname) == 0)
1537 spa_name = tname;
1538 }
1539
1540 error = spa_create(zc->zc_name, config, props, zplprops);
1541
1542 /*
1543 * Set the remaining root properties
1544 */
1545 if (!error && (error = zfs_set_prop_nvlist(spa_name,
1546 ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
1547 (void) spa_destroy(spa_name);
1548
1549 pool_props_bad:
1550 nvlist_free(rootprops);
1551 nvlist_free(zplprops);
1552 nvlist_free(config);
1553 nvlist_free(props);
1554
1555 return (error);
1556 }
1557
1558 static int
1559 zfs_ioc_pool_destroy(zfs_cmd_t *zc)
1560 {
1561 int error;
1562 zfs_log_history(zc);
1563 error = spa_destroy(zc->zc_name);
1564 if (error == 0)
1565 zvol_remove_minors(zc->zc_name);
1566 return (error);
1567 }
|