spa.c (ce4dcb97ca433b2a2f03fbae957dae0ff16f6f51) spa.c (d59a76183470685bdf0b88013d2baad1f04f030f)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 352 unchanged lines hidden (view full) ---

361
362 spa_prop_add_list(outnvl, prop, NULL, intval, src);
363
364 return (0);
365}
366
367int
368spa_prop_get_nvlist(spa_t *spa, char **props, unsigned int n_props,
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 352 unchanged lines hidden (view full) ---

361
362 spa_prop_add_list(outnvl, prop, NULL, intval, src);
363
364 return (0);
365}
366
367int
368spa_prop_get_nvlist(spa_t *spa, char **props, unsigned int n_props,
369 nvlist_t **outnvl)
369 nvlist_t *outnvl)
370{
371 int err = 0;
372
373 if (props == NULL)
374 return (0);
375
370{
371 int err = 0;
372
373 if (props == NULL)
374 return (0);
375
376 if (*outnvl == NULL) {
377 err = nvlist_alloc(outnvl, NV_UNIQUE_NAME, KM_SLEEP);
378 if (err)
379 return (err);
380 }
381
382 for (unsigned int i = 0; i < n_props && err == 0; i++) {
376 for (unsigned int i = 0; i < n_props && err == 0; i++) {
383 err = spa_prop_add(spa, props[i], *outnvl);
377 err = spa_prop_add(spa, props[i], outnvl);
384 }
385
386 return (err);
387}
388
389/*
390 * Add a user property (source=src, propname=propval) to an nvlist.
391 */

--- 9 unchanged lines hidden (view full) ---

401 VERIFY(nvlist_add_nvlist(nvl, propname, propval) == 0);
402 nvlist_free(propval);
403}
404
405/*
406 * Get property values from the spa configuration.
407 */
408static void
378 }
379
380 return (err);
381}
382
383/*
384 * Add a user property (source=src, propname=propval) to an nvlist.
385 */

--- 9 unchanged lines hidden (view full) ---

395 VERIFY(nvlist_add_nvlist(nvl, propname, propval) == 0);
396 nvlist_free(propval);
397}
398
399/*
400 * Get property values from the spa configuration.
401 */
402static void
409spa_prop_get_config(spa_t *spa, nvlist_t **nvp)
403spa_prop_get_config(spa_t *spa, nvlist_t *nv)
410{
411 vdev_t *rvd = spa->spa_root_vdev;
412 dsl_pool_t *pool = spa->spa_dsl_pool;
413 uint64_t size, alloc, cap, version;
414 const zprop_source_t src = ZPROP_SRC_NONE;
415 spa_config_dirent_t *dp;
416 metaslab_class_t *mc = spa_normal_class(spa);
417

--- 5 unchanged lines hidden (view full) ---

423 alloc += metaslab_class_get_alloc(spa_dedup_class(spa));
424 alloc += metaslab_class_get_alloc(spa_embedded_log_class(spa));
425
426 size = metaslab_class_get_space(mc);
427 size += metaslab_class_get_space(spa_special_class(spa));
428 size += metaslab_class_get_space(spa_dedup_class(spa));
429 size += metaslab_class_get_space(spa_embedded_log_class(spa));
430
404{
405 vdev_t *rvd = spa->spa_root_vdev;
406 dsl_pool_t *pool = spa->spa_dsl_pool;
407 uint64_t size, alloc, cap, version;
408 const zprop_source_t src = ZPROP_SRC_NONE;
409 spa_config_dirent_t *dp;
410 metaslab_class_t *mc = spa_normal_class(spa);
411

--- 5 unchanged lines hidden (view full) ---

417 alloc += metaslab_class_get_alloc(spa_dedup_class(spa));
418 alloc += metaslab_class_get_alloc(spa_embedded_log_class(spa));
419
420 size = metaslab_class_get_space(mc);
421 size += metaslab_class_get_space(spa_special_class(spa));
422 size += metaslab_class_get_space(spa_dedup_class(spa));
423 size += metaslab_class_get_space(spa_embedded_log_class(spa));
424
431 spa_prop_add_list(*nvp, ZPOOL_PROP_NAME, spa_name(spa), 0, src);
432 spa_prop_add_list(*nvp, ZPOOL_PROP_SIZE, NULL, size, src);
433 spa_prop_add_list(*nvp, ZPOOL_PROP_ALLOCATED, NULL, alloc, src);
434 spa_prop_add_list(*nvp, ZPOOL_PROP_FREE, NULL,
425 spa_prop_add_list(nv, ZPOOL_PROP_NAME, spa_name(spa), 0, src);
426 spa_prop_add_list(nv, ZPOOL_PROP_SIZE, NULL, size, src);
427 spa_prop_add_list(nv, ZPOOL_PROP_ALLOCATED, NULL, alloc, src);
428 spa_prop_add_list(nv, ZPOOL_PROP_FREE, NULL,
435 size - alloc, src);
429 size - alloc, src);
436 spa_prop_add_list(*nvp, ZPOOL_PROP_CHECKPOINT, NULL,
430 spa_prop_add_list(nv, ZPOOL_PROP_CHECKPOINT, NULL,
437 spa->spa_checkpoint_info.sci_dspace, src);
438
431 spa->spa_checkpoint_info.sci_dspace, src);
432
439 spa_prop_add_list(*nvp, ZPOOL_PROP_FRAGMENTATION, NULL,
433 spa_prop_add_list(nv, ZPOOL_PROP_FRAGMENTATION, NULL,
440 metaslab_class_fragmentation(mc), src);
434 metaslab_class_fragmentation(mc), src);
441 spa_prop_add_list(*nvp, ZPOOL_PROP_EXPANDSZ, NULL,
435 spa_prop_add_list(nv, ZPOOL_PROP_EXPANDSZ, NULL,
442 metaslab_class_expandable_space(mc), src);
436 metaslab_class_expandable_space(mc), src);
443 spa_prop_add_list(*nvp, ZPOOL_PROP_READONLY, NULL,
437 spa_prop_add_list(nv, ZPOOL_PROP_READONLY, NULL,
444 (spa_mode(spa) == SPA_MODE_READ), src);
445
446 cap = (size == 0) ? 0 : (alloc * 100 / size);
438 (spa_mode(spa) == SPA_MODE_READ), src);
439
440 cap = (size == 0) ? 0 : (alloc * 100 / size);
447 spa_prop_add_list(*nvp, ZPOOL_PROP_CAPACITY, NULL, cap, src);
441 spa_prop_add_list(nv, ZPOOL_PROP_CAPACITY, NULL, cap, src);
448
442
449 spa_prop_add_list(*nvp, ZPOOL_PROP_DEDUPRATIO, NULL,
443 spa_prop_add_list(nv, ZPOOL_PROP_DEDUPRATIO, NULL,
450 ddt_get_pool_dedup_ratio(spa), src);
444 ddt_get_pool_dedup_ratio(spa), src);
451 spa_prop_add_list(*nvp, ZPOOL_PROP_BCLONEUSED, NULL,
445 spa_prop_add_list(nv, ZPOOL_PROP_BCLONEUSED, NULL,
452 brt_get_used(spa), src);
446 brt_get_used(spa), src);
453 spa_prop_add_list(*nvp, ZPOOL_PROP_BCLONESAVED, NULL,
447 spa_prop_add_list(nv, ZPOOL_PROP_BCLONESAVED, NULL,
454 brt_get_saved(spa), src);
448 brt_get_saved(spa), src);
455 spa_prop_add_list(*nvp, ZPOOL_PROP_BCLONERATIO, NULL,
449 spa_prop_add_list(nv, ZPOOL_PROP_BCLONERATIO, NULL,
456 brt_get_ratio(spa), src);
457
450 brt_get_ratio(spa), src);
451
458 spa_prop_add_list(*nvp, ZPOOL_PROP_DEDUP_TABLE_SIZE, NULL,
452 spa_prop_add_list(nv, ZPOOL_PROP_DEDUP_TABLE_SIZE, NULL,
459 ddt_get_ddt_dsize(spa), src);
460
453 ddt_get_ddt_dsize(spa), src);
454
461 spa_prop_add_list(*nvp, ZPOOL_PROP_HEALTH, NULL,
455 spa_prop_add_list(nv, ZPOOL_PROP_HEALTH, NULL,
462 rvd->vdev_state, src);
463
464 version = spa_version(spa);
465 if (version == zpool_prop_default_numeric(ZPOOL_PROP_VERSION)) {
456 rvd->vdev_state, src);
457
458 version = spa_version(spa);
459 if (version == zpool_prop_default_numeric(ZPOOL_PROP_VERSION)) {
466 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL,
460 spa_prop_add_list(nv, ZPOOL_PROP_VERSION, NULL,
467 version, ZPROP_SRC_DEFAULT);
468 } else {
461 version, ZPROP_SRC_DEFAULT);
462 } else {
469 spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL,
463 spa_prop_add_list(nv, ZPOOL_PROP_VERSION, NULL,
470 version, ZPROP_SRC_LOCAL);
471 }
464 version, ZPROP_SRC_LOCAL);
465 }
472 spa_prop_add_list(*nvp, ZPOOL_PROP_LOAD_GUID,
466 spa_prop_add_list(nv, ZPOOL_PROP_LOAD_GUID,
473 NULL, spa_load_guid(spa), src);
474 }
475
476 if (pool != NULL) {
477 /*
478 * The $FREE directory was introduced in SPA_VERSION_DEADLISTS,
479 * when opening pools before this version freedir will be NULL.
480 */
481 if (pool->dp_free_dir != NULL) {
467 NULL, spa_load_guid(spa), src);
468 }
469
470 if (pool != NULL) {
471 /*
472 * The $FREE directory was introduced in SPA_VERSION_DEADLISTS,
473 * when opening pools before this version freedir will be NULL.
474 */
475 if (pool->dp_free_dir != NULL) {
482 spa_prop_add_list(*nvp, ZPOOL_PROP_FREEING, NULL,
476 spa_prop_add_list(nv, ZPOOL_PROP_FREEING, NULL,
483 dsl_dir_phys(pool->dp_free_dir)->dd_used_bytes,
484 src);
485 } else {
477 dsl_dir_phys(pool->dp_free_dir)->dd_used_bytes,
478 src);
479 } else {
486 spa_prop_add_list(*nvp, ZPOOL_PROP_FREEING,
480 spa_prop_add_list(nv, ZPOOL_PROP_FREEING,
487 NULL, 0, src);
488 }
489
490 if (pool->dp_leak_dir != NULL) {
481 NULL, 0, src);
482 }
483
484 if (pool->dp_leak_dir != NULL) {
491 spa_prop_add_list(*nvp, ZPOOL_PROP_LEAKED, NULL,
485 spa_prop_add_list(nv, ZPOOL_PROP_LEAKED, NULL,
492 dsl_dir_phys(pool->dp_leak_dir)->dd_used_bytes,
493 src);
494 } else {
486 dsl_dir_phys(pool->dp_leak_dir)->dd_used_bytes,
487 src);
488 } else {
495 spa_prop_add_list(*nvp, ZPOOL_PROP_LEAKED,
489 spa_prop_add_list(nv, ZPOOL_PROP_LEAKED,
496 NULL, 0, src);
497 }
498 }
499
490 NULL, 0, src);
491 }
492 }
493
500 spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src);
494 spa_prop_add_list(nv, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src);
501
502 if (spa->spa_comment != NULL) {
495
496 if (spa->spa_comment != NULL) {
503 spa_prop_add_list(*nvp, ZPOOL_PROP_COMMENT, spa->spa_comment,
497 spa_prop_add_list(nv, ZPOOL_PROP_COMMENT, spa->spa_comment,
504 0, ZPROP_SRC_LOCAL);
505 }
506
507 if (spa->spa_compatibility != NULL) {
498 0, ZPROP_SRC_LOCAL);
499 }
500
501 if (spa->spa_compatibility != NULL) {
508 spa_prop_add_list(*nvp, ZPOOL_PROP_COMPATIBILITY,
502 spa_prop_add_list(nv, ZPOOL_PROP_COMPATIBILITY,
509 spa->spa_compatibility, 0, ZPROP_SRC_LOCAL);
510 }
511
512 if (spa->spa_root != NULL)
503 spa->spa_compatibility, 0, ZPROP_SRC_LOCAL);
504 }
505
506 if (spa->spa_root != NULL)
513 spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root,
507 spa_prop_add_list(nv, ZPOOL_PROP_ALTROOT, spa->spa_root,
514 0, ZPROP_SRC_LOCAL);
515
516 if (spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_BLOCKS)) {
508 0, ZPROP_SRC_LOCAL);
509
510 if (spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_BLOCKS)) {
517 spa_prop_add_list(*nvp, ZPOOL_PROP_MAXBLOCKSIZE, NULL,
511 spa_prop_add_list(nv, ZPOOL_PROP_MAXBLOCKSIZE, NULL,
518 MIN(zfs_max_recordsize, SPA_MAXBLOCKSIZE), ZPROP_SRC_NONE);
519 } else {
512 MIN(zfs_max_recordsize, SPA_MAXBLOCKSIZE), ZPROP_SRC_NONE);
513 } else {
520 spa_prop_add_list(*nvp, ZPOOL_PROP_MAXBLOCKSIZE, NULL,
514 spa_prop_add_list(nv, ZPOOL_PROP_MAXBLOCKSIZE, NULL,
521 SPA_OLD_MAXBLOCKSIZE, ZPROP_SRC_NONE);
522 }
523
524 if (spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_DNODE)) {
515 SPA_OLD_MAXBLOCKSIZE, ZPROP_SRC_NONE);
516 }
517
518 if (spa_feature_is_enabled(spa, SPA_FEATURE_LARGE_DNODE)) {
525 spa_prop_add_list(*nvp, ZPOOL_PROP_MAXDNODESIZE, NULL,
519 spa_prop_add_list(nv, ZPOOL_PROP_MAXDNODESIZE, NULL,
526 DNODE_MAX_SIZE, ZPROP_SRC_NONE);
527 } else {
520 DNODE_MAX_SIZE, ZPROP_SRC_NONE);
521 } else {
528 spa_prop_add_list(*nvp, ZPOOL_PROP_MAXDNODESIZE, NULL,
522 spa_prop_add_list(nv, ZPOOL_PROP_MAXDNODESIZE, NULL,
529 DNODE_MIN_SIZE, ZPROP_SRC_NONE);
530 }
531
532 if ((dp = list_head(&spa->spa_config_list)) != NULL) {
533 if (dp->scd_path == NULL) {
523 DNODE_MIN_SIZE, ZPROP_SRC_NONE);
524 }
525
526 if ((dp = list_head(&spa->spa_config_list)) != NULL) {
527 if (dp->scd_path == NULL) {
534 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE,
528 spa_prop_add_list(nv, ZPOOL_PROP_CACHEFILE,
535 "none", 0, ZPROP_SRC_LOCAL);
536 } else if (strcmp(dp->scd_path, spa_config_path) != 0) {
529 "none", 0, ZPROP_SRC_LOCAL);
530 } else if (strcmp(dp->scd_path, spa_config_path) != 0) {
537 spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE,
531 spa_prop_add_list(nv, ZPOOL_PROP_CACHEFILE,
538 dp->scd_path, 0, ZPROP_SRC_LOCAL);
539 }
540 }
541}
542
543/*
544 * Get zpool property values.
545 */
546int
532 dp->scd_path, 0, ZPROP_SRC_LOCAL);
533 }
534 }
535}
536
537/*
538 * Get zpool property values.
539 */
540int
547spa_prop_get(spa_t *spa, nvlist_t **nvp)
541spa_prop_get(spa_t *spa, nvlist_t *nv)
548{
549 objset_t *mos = spa->spa_meta_objset;
550 zap_cursor_t zc;
551 zap_attribute_t za;
552 dsl_pool_t *dp;
542{
543 objset_t *mos = spa->spa_meta_objset;
544 zap_cursor_t zc;
545 zap_attribute_t za;
546 dsl_pool_t *dp;
553 int err;
547 int err = 0;
554
548
555 if (*nvp == NULL) {
556 err = nvlist_alloc(nvp, NV_UNIQUE_NAME, KM_SLEEP);
557 if (err)
558 return (err);
559 }
560
561 dp = spa_get_dsl(spa);
562 dsl_pool_config_enter(dp, FTAG);
563 mutex_enter(&spa->spa_props_lock);
564
565 /*
566 * Get properties from the spa config.
567 */
549 dp = spa_get_dsl(spa);
550 dsl_pool_config_enter(dp, FTAG);
551 mutex_enter(&spa->spa_props_lock);
552
553 /*
554 * Get properties from the spa config.
555 */
568 spa_prop_get_config(spa, nvp);
556 spa_prop_get_config(spa, nv);
569
570 /* If no pool property object, no more prop to get. */
571 if (mos == NULL || spa->spa_pool_props_object == 0)
572 goto out;
573
574 /*
575 * Get properties from the MOS pool property object.
576 */

--- 28 unchanged lines hidden (view full) ---

605 KM_SLEEP);
606 dsl_dataset_name(ds, strval);
607 dsl_dataset_rele(ds, FTAG);
608 } else {
609 strval = NULL;
610 intval = za.za_first_integer;
611 }
612
557
558 /* If no pool property object, no more prop to get. */
559 if (mos == NULL || spa->spa_pool_props_object == 0)
560 goto out;
561
562 /*
563 * Get properties from the MOS pool property object.
564 */

--- 28 unchanged lines hidden (view full) ---

593 KM_SLEEP);
594 dsl_dataset_name(ds, strval);
595 dsl_dataset_rele(ds, FTAG);
596 } else {
597 strval = NULL;
598 intval = za.za_first_integer;
599 }
600
613 spa_prop_add_list(*nvp, prop, strval, intval, src);
601 spa_prop_add_list(nv, prop, strval, intval, src);
614
615 if (strval != NULL)
616 kmem_free(strval, ZFS_MAX_DATASET_NAME_LEN);
617
618 break;
619
620 case 1:
621 /* string property */
622 strval = kmem_alloc(za.za_num_integers, KM_SLEEP);
623 err = zap_lookup(mos, spa->spa_pool_props_object,
624 za.za_name, 1, za.za_num_integers, strval);
625 if (err) {
626 kmem_free(strval, za.za_num_integers);
627 break;
628 }
629 if (prop != ZPOOL_PROP_INVAL) {
602
603 if (strval != NULL)
604 kmem_free(strval, ZFS_MAX_DATASET_NAME_LEN);
605
606 break;
607
608 case 1:
609 /* string property */
610 strval = kmem_alloc(za.za_num_integers, KM_SLEEP);
611 err = zap_lookup(mos, spa->spa_pool_props_object,
612 za.za_name, 1, za.za_num_integers, strval);
613 if (err) {
614 kmem_free(strval, za.za_num_integers);
615 break;
616 }
617 if (prop != ZPOOL_PROP_INVAL) {
630 spa_prop_add_list(*nvp, prop, strval, 0, src);
618 spa_prop_add_list(nv, prop, strval, 0, src);
631 } else {
632 src = ZPROP_SRC_LOCAL;
619 } else {
620 src = ZPROP_SRC_LOCAL;
633 spa_prop_add_user(*nvp, za.za_name, strval,
621 spa_prop_add_user(nv, za.za_name, strval,
634 src);
635 }
636 kmem_free(strval, za.za_num_integers);
637 break;
638
639 default:
640 break;
641 }
642 }
643 zap_cursor_fini(&zc);
644out:
645 mutex_exit(&spa->spa_props_lock);
646 dsl_pool_config_exit(dp, FTAG);
622 src);
623 }
624 kmem_free(strval, za.za_num_integers);
625 break;
626
627 default:
628 break;
629 }
630 }
631 zap_cursor_fini(&zc);
632out:
633 mutex_exit(&spa->spa_props_lock);
634 dsl_pool_config_exit(dp, FTAG);
647 if (err && err != ENOENT) {
648 nvlist_free(*nvp);
649 *nvp = NULL;
635
636 if (err && err != ENOENT)
650 return (err);
637 return (err);
651 }
652
653 return (0);
654}
655
656/*
657 * Validate the given pool properties nvlist and modify the list
658 * for the property values to be set.
659 */

--- 10380 unchanged lines hidden ---
638
639 return (0);
640}
641
642/*
643 * Validate the given pool properties nvlist and modify the list
644 * for the property values to be set.
645 */

--- 10380 unchanged lines hidden ---