Deleted Added
full compact
libzfs_pool.c (236155) libzfs_pool.c (236884)
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

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

38#include <unistd.h>
39#include <sys/zfs_ioctl.h>
40#include <dlfcn.h>
41
42#include "zfs_namecheck.h"
43#include "zfs_prop.h"
44#include "libzfs_impl.h"
45#include "zfs_comutil.h"
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

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

38#include <unistd.h>
39#include <sys/zfs_ioctl.h>
40#include <dlfcn.h>
41
42#include "zfs_namecheck.h"
43#include "zfs_prop.h"
44#include "libzfs_impl.h"
45#include "zfs_comutil.h"
46#include "zfeature_common.h"
46
47static int read_efi_label(nvlist_t *config, diskaddr_t *sb);
48
49#define DISK_ROOT "/dev/dsk"
50#define RDISK_ROOT "/dev/rdsk"
51#define BACKUP_SLICE "s2"
52
53typedef struct prop_flags {

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

296
297 case PROP_TYPE_NUMBER:
298 intval = zpool_get_prop_int(zhp, prop, &src);
299
300 switch (prop) {
301 case ZPOOL_PROP_SIZE:
302 case ZPOOL_PROP_ALLOCATED:
303 case ZPOOL_PROP_FREE:
47
48static int read_efi_label(nvlist_t *config, diskaddr_t *sb);
49
50#define DISK_ROOT "/dev/dsk"
51#define RDISK_ROOT "/dev/rdsk"
52#define BACKUP_SLICE "s2"
53
54typedef struct prop_flags {

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

297
298 case PROP_TYPE_NUMBER:
299 intval = zpool_get_prop_int(zhp, prop, &src);
300
301 switch (prop) {
302 case ZPOOL_PROP_SIZE:
303 case ZPOOL_PROP_ALLOCATED:
304 case ZPOOL_PROP_FREE:
305 case ZPOOL_PROP_FREEING:
304 case ZPOOL_PROP_EXPANDSZ:
305 (void) zfs_nicenum(intval, buf, len);
306 break;
307
308 case ZPOOL_PROP_CAPACITY:
309 (void) snprintf(buf, len, "%llu%%",
310 (u_longlong_t)intval);
311 break;

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

321 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
322 verify(nvlist_lookup_uint64_array(nvroot,
323 ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &vsc)
324 == 0);
325
326 (void) strlcpy(buf, zpool_state_to_name(intval,
327 vs->vs_aux), len);
328 break;
306 case ZPOOL_PROP_EXPANDSZ:
307 (void) zfs_nicenum(intval, buf, len);
308 break;
309
310 case ZPOOL_PROP_CAPACITY:
311 (void) snprintf(buf, len, "%llu%%",
312 (u_longlong_t)intval);
313 break;

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

323 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0);
324 verify(nvlist_lookup_uint64_array(nvroot,
325 ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&vs, &vsc)
326 == 0);
327
328 (void) strlcpy(buf, zpool_state_to_name(intval,
329 vs->vs_aux), len);
330 break;
331 case ZPOOL_PROP_VERSION:
332 if (intval >= SPA_VERSION_FEATURES) {
333 (void) snprintf(buf, len, "-");
334 break;
335 }
336 /* FALLTHROUGH */
329 default:
330 (void) snprintf(buf, len, "%llu", intval);
331 }
332 break;
333
334 case PROP_TYPE_INDEX:
335 intval = zpool_get_prop_int(zhp, prop, &src);
336 if (zpool_prop_index_to_string(prop, intval, &strval)

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

425 (void) no_memory(hdl);
426 return (NULL);
427 }
428
429 elem = NULL;
430 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
431 const char *propname = nvpair_name(elem);
432
337 default:
338 (void) snprintf(buf, len, "%llu", intval);
339 }
340 break;
341
342 case PROP_TYPE_INDEX:
343 intval = zpool_get_prop_int(zhp, prop, &src);
344 if (zpool_prop_index_to_string(prop, intval, &strval)

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

433 (void) no_memory(hdl);
434 return (NULL);
435 }
436
437 elem = NULL;
438 while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
439 const char *propname = nvpair_name(elem);
440
441 prop = zpool_name_to_prop(propname);
442 if (prop == ZPROP_INVAL && zpool_prop_feature(propname)) {
443 int err;
444 zfeature_info_t *feature;
445 char *fname = strchr(propname, '@') + 1;
446
447 err = zfeature_lookup_name(fname, &feature);
448 if (err != 0) {
449 ASSERT3U(err, ==, ENOENT);
450 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
451 "invalid feature '%s'"), fname);
452 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
453 goto error;
454 }
455
456 if (nvpair_type(elem) != DATA_TYPE_STRING) {
457 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
458 "'%s' must be a string"), propname);
459 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
460 goto error;
461 }
462
463 (void) nvpair_value_string(elem, &strval);
464 if (strcmp(strval, ZFS_FEATURE_ENABLED) != 0) {
465 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
466 "property '%s' can only be set to "
467 "'enabled'"), propname);
468 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
469 goto error;
470 }
471
472 if (nvlist_add_uint64(retprops, propname, 0) != 0) {
473 (void) no_memory(hdl);
474 goto error;
475 }
476 continue;
477 }
478
433 /*
434 * Make sure this property is valid and applies to this type.
435 */
479 /*
480 * Make sure this property is valid and applies to this type.
481 */
436 if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) {
482 if (prop == ZPROP_INVAL) {
437 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
438 "invalid property '%s'"), propname);
439 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
440 goto error;
441 }
442
443 if (zpool_prop_readonly(prop)) {
444 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "

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

451 &strval, &intval, errbuf) != 0)
452 goto error;
453
454 /*
455 * Perform additional checking for specific properties.
456 */
457 switch (prop) {
458 case ZPOOL_PROP_VERSION:
483 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
484 "invalid property '%s'"), propname);
485 (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
486 goto error;
487 }
488
489 if (zpool_prop_readonly(prop)) {
490 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "'%s' "

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

497 &strval, &intval, errbuf) != 0)
498 goto error;
499
500 /*
501 * Perform additional checking for specific properties.
502 */
503 switch (prop) {
504 case ZPOOL_PROP_VERSION:
459 if (intval < version || intval > SPA_VERSION) {
505 if (intval < version ||
506 !SPA_VERSION_IS_SUPPORTED(intval)) {
460 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
461 "property '%s' number %d is invalid."),
462 propname, intval);
463 (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
464 goto error;
465 }
466 break;
467

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

675}
676
677int
678zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp)
679{
680 libzfs_handle_t *hdl = zhp->zpool_hdl;
681 zprop_list_t *entry;
682 char buf[ZFS_MAXPROPLEN];
507 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
508 "property '%s' number %d is invalid."),
509 propname, intval);
510 (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
511 goto error;
512 }
513 break;
514

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

722}
723
724int
725zpool_expand_proplist(zpool_handle_t *zhp, zprop_list_t **plp)
726{
727 libzfs_handle_t *hdl = zhp->zpool_hdl;
728 zprop_list_t *entry;
729 char buf[ZFS_MAXPROPLEN];
730 nvlist_t *features = NULL;
731 zprop_list_t **last;
732 boolean_t firstexpand = (NULL == *plp);
683
684 if (zprop_expand_list(hdl, plp, ZFS_TYPE_POOL) != 0)
685 return (-1);
686
733
734 if (zprop_expand_list(hdl, plp, ZFS_TYPE_POOL) != 0)
735 return (-1);
736
737 last = plp;
738 while (*last != NULL)
739 last = &(*last)->pl_next;
740
741 if ((*plp)->pl_all)
742 features = zpool_get_features(zhp);
743
744 if ((*plp)->pl_all && firstexpand) {
745 for (int i = 0; i < SPA_FEATURES; i++) {
746 zprop_list_t *entry = zfs_alloc(hdl,
747 sizeof (zprop_list_t));
748 entry->pl_prop = ZPROP_INVAL;
749 entry->pl_user_prop = zfs_asprintf(hdl, "feature@%s",
750 spa_feature_table[i].fi_uname);
751 entry->pl_width = strlen(entry->pl_user_prop);
752 entry->pl_all = B_TRUE;
753
754 *last = entry;
755 last = &entry->pl_next;
756 }
757 }
758
759 /* add any unsupported features */
760 for (nvpair_t *nvp = nvlist_next_nvpair(features, NULL);
761 nvp != NULL; nvp = nvlist_next_nvpair(features, nvp)) {
762 char *propname;
763 boolean_t found;
764 zprop_list_t *entry;
765
766 if (zfeature_is_supported(nvpair_name(nvp)))
767 continue;
768
769 propname = zfs_asprintf(hdl, "unsupported@%s",
770 nvpair_name(nvp));
771
772 /*
773 * Before adding the property to the list make sure that no
774 * other pool already added the same property.
775 */
776 found = B_FALSE;
777 entry = *plp;
778 while (entry != NULL) {
779 if (entry->pl_user_prop != NULL &&
780 strcmp(propname, entry->pl_user_prop) == 0) {
781 found = B_TRUE;
782 break;
783 }
784 entry = entry->pl_next;
785 }
786 if (found) {
787 free(propname);
788 continue;
789 }
790
791 entry = zfs_alloc(hdl, sizeof (zprop_list_t));
792 entry->pl_prop = ZPROP_INVAL;
793 entry->pl_user_prop = propname;
794 entry->pl_width = strlen(entry->pl_user_prop);
795 entry->pl_all = B_TRUE;
796
797 *last = entry;
798 last = &entry->pl_next;
799 }
800
687 for (entry = *plp; entry != NULL; entry = entry->pl_next) {
688
689 if (entry->pl_fixed)
690 continue;
691
692 if (entry->pl_prop != ZPROP_INVAL &&
693 zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
694 NULL) == 0) {
695 if (strlen(buf) > entry->pl_width)
696 entry->pl_width = strlen(buf);
697 }
698 }
699
700 return (0);
701}
702
801 for (entry = *plp; entry != NULL; entry = entry->pl_next) {
802
803 if (entry->pl_fixed)
804 continue;
805
806 if (entry->pl_prop != ZPROP_INVAL &&
807 zpool_get_prop(zhp, entry->pl_prop, buf, sizeof (buf),
808 NULL) == 0) {
809 if (strlen(buf) > entry->pl_width)
810 entry->pl_width = strlen(buf);
811 }
812 }
813
814 return (0);
815}
816
817/*
818 * Get the state for the given feature on the given ZFS pool.
819 */
820int
821zpool_prop_get_feature(zpool_handle_t *zhp, const char *propname, char *buf,
822 size_t len)
823{
824 uint64_t refcount;
825 boolean_t found = B_FALSE;
826 nvlist_t *features = zpool_get_features(zhp);
827 boolean_t supported;
828 const char *feature = strchr(propname, '@') + 1;
703
829
830 supported = zpool_prop_feature(propname);
831 ASSERT(supported || zpool_prop_unsupported(propname));
832
833 /*
834 * Convert from feature name to feature guid. This conversion is
835 * unecessary for unsupported@... properties because they already
836 * use guids.
837 */
838 if (supported) {
839 int ret;
840 zfeature_info_t *fi;
841
842 ret = zfeature_lookup_name(feature, &fi);
843 if (ret != 0) {
844 (void) strlcpy(buf, "-", len);
845 return (ENOTSUP);
846 }
847 feature = fi->fi_guid;
848 }
849
850 if (nvlist_lookup_uint64(features, feature, &refcount) == 0)
851 found = B_TRUE;
852
853 if (supported) {
854 if (!found) {
855 (void) strlcpy(buf, ZFS_FEATURE_DISABLED, len);
856 } else {
857 if (refcount == 0)
858 (void) strlcpy(buf, ZFS_FEATURE_ENABLED, len);
859 else
860 (void) strlcpy(buf, ZFS_FEATURE_ACTIVE, len);
861 }
862 } else {
863 if (found) {
864 if (refcount == 0) {
865 (void) strcpy(buf, ZFS_UNSUPPORTED_INACTIVE);
866 } else {
867 (void) strcpy(buf, ZFS_UNSUPPORTED_READONLY);
868 }
869 } else {
870 (void) strlcpy(buf, "-", len);
871 return (ENOTSUP);
872 }
873 }
874
875 return (0);
876}
877
704/*
705 * Don't start the slice at the default block of 34; many storage
706 * devices will use a stripe width of 128k, so start there instead.
707 */
708#define NEW_START_BLOCK 256
709
710/*
711 * Validate the given pool name, optionally putting an extended error message in

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

1281 uint64_t rewindto;
1282 int64_t loss = -1;
1283 struct tm t;
1284 char timestr[128];
1285
1286 if (!hdl->libzfs_printerr || config == NULL)
1287 return;
1288
878/*
879 * Don't start the slice at the default block of 34; many storage
880 * devices will use a stripe width of 128k, so start there instead.
881 */
882#define NEW_START_BLOCK 256
883
884/*
885 * Validate the given pool name, optionally putting an extended error message in

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

1455 uint64_t rewindto;
1456 int64_t loss = -1;
1457 struct tm t;
1458 char timestr[128];
1459
1460 if (!hdl->libzfs_printerr || config == NULL)
1461 return;
1462
1289 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0)
1463 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
1464 nvlist_lookup_nvlist(nv, ZPOOL_CONFIG_REWIND_INFO, &nv) != 0) {
1290 return;
1465 return;
1466 }
1291
1292 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
1293 return;
1294 (void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
1295
1296 if (localtime_r((time_t *)&rewindto, &t) != NULL &&
1297 strftime(timestr, 128, 0, &t) != 0) {
1298 if (dryrun) {

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

1338
1339 if (reason >= 0)
1340 (void) printf(dgettext(TEXT_DOMAIN, "action: "));
1341 else
1342 (void) printf(dgettext(TEXT_DOMAIN, "\t"));
1343
1344 /* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */
1345 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
1467
1468 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
1469 return;
1470 (void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
1471
1472 if (localtime_r((time_t *)&rewindto, &t) != NULL &&
1473 strftime(timestr, 128, 0, &t) != 0) {
1474 if (dryrun) {

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

1514
1515 if (reason >= 0)
1516 (void) printf(dgettext(TEXT_DOMAIN, "action: "));
1517 else
1518 (void) printf(dgettext(TEXT_DOMAIN, "\t"));
1519
1520 /* All attempted rewinds failed if ZPOOL_CONFIG_LOAD_TIME missing */
1521 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nv) != 0 ||
1522 nvlist_lookup_nvlist(nv, ZPOOL_CONFIG_REWIND_INFO, &nv) != 0 ||
1346 nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
1347 goto no_info;
1348
1349 (void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
1350 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
1351 &edata);
1352
1353 (void) printf(dgettext(TEXT_DOMAIN,

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

1460
1461 for (c = 0; c < children; c++) {
1462 vname = zpool_vdev_name(hdl, NULL, child[c], B_TRUE);
1463 print_vdev_tree(hdl, vname, child[c], indent + 2);
1464 free(vname);
1465 }
1466}
1467
1523 nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_TIME, &rewindto) != 0)
1524 goto no_info;
1525
1526 (void) nvlist_lookup_int64(nv, ZPOOL_CONFIG_REWIND_TIME, &loss);
1527 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_LOAD_DATA_ERRORS,
1528 &edata);
1529
1530 (void) printf(dgettext(TEXT_DOMAIN,

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

1637
1638 for (c = 0; c < children; c++) {
1639 vname = zpool_vdev_name(hdl, NULL, child[c], B_TRUE);
1640 print_vdev_tree(hdl, vname, child[c], indent + 2);
1641 free(vname);
1642 }
1643}
1644
1645void
1646zpool_print_unsup_feat(nvlist_t *config)
1647{
1648 nvlist_t *nvinfo, *unsup_feat;
1649
1650 verify(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_LOAD_INFO, &nvinfo) ==
1651 0);
1652 verify(nvlist_lookup_nvlist(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT,
1653 &unsup_feat) == 0);
1654
1655 for (nvpair_t *nvp = nvlist_next_nvpair(unsup_feat, NULL); nvp != NULL;
1656 nvp = nvlist_next_nvpair(unsup_feat, nvp)) {
1657 char *desc;
1658
1659 verify(nvpair_type(nvp) == DATA_TYPE_STRING);
1660 verify(nvpair_value_string(nvp, &desc) == 0);
1661
1662 if (strlen(desc) > 0)
1663 (void) printf("\t%s (%s)\n", nvpair_name(nvp), desc);
1664 else
1665 (void) printf("\t%s\n", nvpair_name(nvp));
1666 }
1667}
1668
1468/*
1469 * Import the given pool using the known configuration and a list of
1470 * properties to be set. The configuration should have come from
1471 * zpool_find_import(). The 'newname' parameters control whether the pool
1472 * is imported with a different name.
1473 */
1474int
1475zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,

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

1566 thename);
1567 else
1568 (void) snprintf(desc, sizeof (desc),
1569 dgettext(TEXT_DOMAIN, "cannot import '%s' as '%s'"),
1570 origname, thename);
1571
1572 switch (error) {
1573 case ENOTSUP:
1669/*
1670 * Import the given pool using the known configuration and a list of
1671 * properties to be set. The configuration should have come from
1672 * zpool_find_import(). The 'newname' parameters control whether the pool
1673 * is imported with a different name.
1674 */
1675int
1676zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,

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

1767 thename);
1768 else
1769 (void) snprintf(desc, sizeof (desc),
1770 dgettext(TEXT_DOMAIN, "cannot import '%s' as '%s'"),
1771 origname, thename);
1772
1773 switch (error) {
1774 case ENOTSUP:
1775 if (nv != NULL && nvlist_lookup_nvlist(nv,
1776 ZPOOL_CONFIG_LOAD_INFO, &nvinfo) == 0 &&
1777 nvlist_exists(nvinfo, ZPOOL_CONFIG_UNSUP_FEAT)) {
1778 (void) printf(dgettext(TEXT_DOMAIN, "This "
1779 "pool uses the following feature(s) not "
1780 "supported by this system:\n"));
1781 zpool_print_unsup_feat(nv);
1782 if (nvlist_exists(nvinfo,
1783 ZPOOL_CONFIG_CAN_RDONLY)) {
1784 (void) printf(dgettext(TEXT_DOMAIN,
1785 "All unsupported features are only "
1786 "required for writing to the pool."
1787 "\nThe pool can be imported using "
1788 "'-o readonly=on'.\n"));
1789 }
1790 }
1574 /*
1575 * Unsupported version.
1576 */
1577 (void) zfs_error(hdl, EZFS_BADVERSION, desc);
1578 break;
1579
1580 case EINVAL:
1581 (void) zfs_error(hdl, EZFS_INVALCONFIG, desc);

--- 2348 unchanged lines hidden ---
1791 /*
1792 * Unsupported version.
1793 */
1794 (void) zfs_error(hdl, EZFS_BADVERSION, desc);
1795 break;
1796
1797 case EINVAL:
1798 (void) zfs_error(hdl, EZFS_INVALCONFIG, desc);

--- 2348 unchanged lines hidden ---