162 #include <sys/sunddi.h>
163 #include <sys/sunldi.h>
164 #include <sys/policy.h>
165 #include <sys/zone.h>
166 #include <sys/nvpair.h>
167 #include <sys/pathname.h>
168 #include <sys/mount.h>
169 #include <sys/sdt.h>
170 #include <sys/fs/zfs.h>
171 #include <sys/zfs_ctldir.h>
172 #include <sys/zfs_dir.h>
173 #include <sys/zfs_onexit.h>
174 #include <sys/zvol.h>
175 #include <sys/dsl_scan.h>
176 #include <sharefs/share.h>
177 #include <sys/dmu_objset.h>
178 #include <sys/dmu_send.h>
179 #include <sys/dsl_destroy.h>
180 #include <sys/dsl_userhold.h>
181 #include <sys/zfeature.h>
182
183 #include "zfs_namecheck.h"
184 #include "zfs_prop.h"
185 #include "zfs_deleg.h"
186 #include "zfs_comutil.h"
187
188 extern struct modlfs zfs_modlfs;
189
190 extern void zfs_init(void);
191 extern void zfs_fini(void);
192
193 ldi_ident_t zfs_li = NULL;
194 dev_info_t *zfs_dip;
195
196 uint_t zfs_fsyncer_key;
197 extern uint_t rrw_tsd_key;
198 static uint_t zfs_allow_log_key;
199
200 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
201 typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
2393 * Setting the LZ4 compression algorithm activates
2394 * the feature.
2395 */
2396 if (!spa_feature_is_active(spa, feature)) {
2397 if ((err = zfs_prop_activate_feature(spa,
2398 feature)) != 0) {
2399 spa_close(spa, FTAG);
2400 return (err);
2401 }
2402 }
2403
2404 spa_close(spa, FTAG);
2405 }
2406 /*
2407 * We still want the default set action to be performed in the
2408 * caller, we only performed zfeature settings here.
2409 */
2410 err = -1;
2411 break;
2412 }
2413
2414 default:
2415 err = -1;
2416 }
2417
2418 return (err);
2419 }
2420
2421 /*
2422 * This function is best effort. If it fails to set any of the given properties,
2423 * it continues to set as many as it can and returns the last error
2424 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2425 * with the list of names of all the properties that failed along with the
2426 * corresponding error numbers.
2427 *
2428 * If every property is set successfully, zero is returned and errlist is not
2429 * modified.
2430 */
2431 int
2432 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2433 nvlist_t *errlist)
3680
3681 /*
3682 * If this is a bootable dataset then
3683 * verify that the compression algorithm
3684 * is supported for booting. We must return
3685 * something other than ENOTSUP since it
3686 * implies a downrev pool version.
3687 */
3688 if (zfs_is_bootfs(dsname) &&
3689 !BOOTFS_COMPRESS_VALID(intval)) {
3690 return (SET_ERROR(ERANGE));
3691 }
3692 }
3693 break;
3694
3695 case ZFS_PROP_COPIES:
3696 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3697 return (SET_ERROR(ENOTSUP));
3698 break;
3699
3700 case ZFS_PROP_DEDUP:
3701 if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
3702 return (SET_ERROR(ENOTSUP));
3703 break;
3704
3705 case ZFS_PROP_SHARESMB:
3706 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
3707 return (SET_ERROR(ENOTSUP));
3708 break;
3709
3710 case ZFS_PROP_ACLINHERIT:
3711 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3712 nvpair_value_uint64(pair, &intval) == 0) {
3713 if (intval == ZFS_ACL_PASSTHROUGH_X &&
3714 zfs_earlier_version(dsname,
3715 SPA_VERSION_PASSTHROUGH_X))
3716 return (SET_ERROR(ENOTSUP));
3717 }
3718 break;
3719 }
3720
3721 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
3722 }
3723
3724 /*
3725 * Checks for a race condition to make sure we don't increment a feature flag
3726 * multiple times.
3727 */
3728 static int
3729 zfs_prop_activate_feature_check(void *arg, dmu_tx_t *tx)
3730 {
3731 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
3732 zfeature_info_t *feature = arg;
3733
3734 if (!spa_feature_is_active(spa, feature))
3735 return (0);
3736 else
3737 return (SET_ERROR(EBUSY));
3738 }
3739
|
162 #include <sys/sunddi.h>
163 #include <sys/sunldi.h>
164 #include <sys/policy.h>
165 #include <sys/zone.h>
166 #include <sys/nvpair.h>
167 #include <sys/pathname.h>
168 #include <sys/mount.h>
169 #include <sys/sdt.h>
170 #include <sys/fs/zfs.h>
171 #include <sys/zfs_ctldir.h>
172 #include <sys/zfs_dir.h>
173 #include <sys/zfs_onexit.h>
174 #include <sys/zvol.h>
175 #include <sys/dsl_scan.h>
176 #include <sharefs/share.h>
177 #include <sys/dmu_objset.h>
178 #include <sys/dmu_send.h>
179 #include <sys/dsl_destroy.h>
180 #include <sys/dsl_userhold.h>
181 #include <sys/zfeature.h>
182 #include <sys/zio_checksum.h>
183
184 #include "zfs_namecheck.h"
185 #include "zfs_prop.h"
186 #include "zfs_deleg.h"
187 #include "zfs_comutil.h"
188
189 extern struct modlfs zfs_modlfs;
190
191 extern void zfs_init(void);
192 extern void zfs_fini(void);
193
194 ldi_ident_t zfs_li = NULL;
195 dev_info_t *zfs_dip;
196
197 uint_t zfs_fsyncer_key;
198 extern uint_t rrw_tsd_key;
199 static uint_t zfs_allow_log_key;
200
201 typedef int zfs_ioc_legacy_func_t(zfs_cmd_t *);
202 typedef int zfs_ioc_func_t(const char *, nvlist_t *, nvlist_t *);
2394 * Setting the LZ4 compression algorithm activates
2395 * the feature.
2396 */
2397 if (!spa_feature_is_active(spa, feature)) {
2398 if ((err = zfs_prop_activate_feature(spa,
2399 feature)) != 0) {
2400 spa_close(spa, FTAG);
2401 return (err);
2402 }
2403 }
2404
2405 spa_close(spa, FTAG);
2406 }
2407 /*
2408 * We still want the default set action to be performed in the
2409 * caller, we only performed zfeature settings here.
2410 */
2411 err = -1;
2412 break;
2413 }
2414 case ZFS_PROP_CHECKSUM:
2415 case ZFS_PROP_DEDUP:
2416 {
2417 zfeature_info_t *feature = NULL;
2418 spa_t *spa;
2419
2420 if (intval == ZIO_CHECKSUM_SHA512)
2421 feature = &spa_feature_table[SPA_FEATURE_SHA512];
2422 else if (intval == ZIO_CHECKSUM_SKEIN)
2423 feature = &spa_feature_table[SPA_FEATURE_SKEIN];
2424 else if (intval == ZIO_CHECKSUM_EDONR)
2425 feature = &spa_feature_table[SPA_FEATURE_EDONR];
2426 if (feature == NULL) {
2427 /* No features need to be activated for this cksum */
2428 err = -1;
2429 break;
2430 }
2431 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
2432 return (err);
2433 if (!spa_feature_is_active(spa, feature)) {
2434 /* Salted checksums must store the salt in the MOS */
2435 if (zio_checksum_table[intval].ci_salted)
2436 err = spa_activate_salted_cksum(spa, feature);
2437 else
2438 err = zfs_prop_activate_feature(spa, feature);
2439 }
2440 spa_close(spa, FTAG);
2441 if (err == 0) {
2442 /*
2443 * We want the default set action to be performed in
2444 * the caller, we only perform feature checks here.
2445 */
2446 err = -1;
2447 }
2448 break;
2449 }
2450
2451 default:
2452 err = -1;
2453 }
2454
2455 return (err);
2456 }
2457
2458 /*
2459 * This function is best effort. If it fails to set any of the given properties,
2460 * it continues to set as many as it can and returns the last error
2461 * encountered. If the caller provides a non-NULL errlist, it will be filled in
2462 * with the list of names of all the properties that failed along with the
2463 * corresponding error numbers.
2464 *
2465 * If every property is set successfully, zero is returned and errlist is not
2466 * modified.
2467 */
2468 int
2469 zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
2470 nvlist_t *errlist)
3717
3718 /*
3719 * If this is a bootable dataset then
3720 * verify that the compression algorithm
3721 * is supported for booting. We must return
3722 * something other than ENOTSUP since it
3723 * implies a downrev pool version.
3724 */
3725 if (zfs_is_bootfs(dsname) &&
3726 !BOOTFS_COMPRESS_VALID(intval)) {
3727 return (SET_ERROR(ERANGE));
3728 }
3729 }
3730 break;
3731
3732 case ZFS_PROP_COPIES:
3733 if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
3734 return (SET_ERROR(ENOTSUP));
3735 break;
3736
3737 case ZFS_PROP_SHARESMB:
3738 if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
3739 return (SET_ERROR(ENOTSUP));
3740 break;
3741
3742 case ZFS_PROP_ACLINHERIT:
3743 if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
3744 nvpair_value_uint64(pair, &intval) == 0) {
3745 if (intval == ZFS_ACL_PASSTHROUGH_X &&
3746 zfs_earlier_version(dsname,
3747 SPA_VERSION_PASSTHROUGH_X))
3748 return (SET_ERROR(ENOTSUP));
3749 }
3750 break;
3751
3752 case ZFS_PROP_CHECKSUM:
3753 case ZFS_PROP_DEDUP: {
3754 zfeature_info_t *feature = NULL;
3755
3756 /* dedup feature version checks */
3757 if (prop == ZFS_PROP_DEDUP &&
3758 zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
3759 return (SET_ERROR(ENOTSUP));
3760
3761 if (nvpair_value_uint64(pair, &intval) != 0)
3762 return (SET_ERROR(EINVAL));
3763
3764 /* check prop value is enabled in features */
3765 if (intval == ZIO_CHECKSUM_SHA512)
3766 feature = &spa_feature_table[SPA_FEATURE_SHA512];
3767 else if (intval == ZIO_CHECKSUM_SKEIN)
3768 feature = &spa_feature_table[SPA_FEATURE_SKEIN];
3769 else if (intval == ZIO_CHECKSUM_EDONR)
3770 feature = &spa_feature_table[SPA_FEATURE_EDONR];
3771
3772 if (feature != NULL) {
3773 spa_t *spa;
3774
3775 if ((err = spa_open(dsname, &spa, FTAG)) != 0)
3776 return (err);
3777 /*
3778 * Salted checksums are not supported on root pools.
3779 */
3780 if (spa_bootfs(spa) != 0 &&
3781 intval < ZIO_CHECKSUM_FUNCTIONS &&
3782 zio_checksum_table[intval].ci_salted != 0) {
3783 spa_close(spa, FTAG);
3784 return (SET_ERROR(ERANGE));
3785 }
3786 if (!spa_feature_is_enabled(spa, feature)) {
3787 spa_close(spa, FTAG);
3788 return (SET_ERROR(ENOTSUP));
3789 }
3790 spa_close(spa, FTAG);
3791 }
3792 break;
3793 }
3794 }
3795
3796 return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
3797 }
3798
3799 /*
3800 * Checks for a race condition to make sure we don't increment a feature flag
3801 * multiple times.
3802 */
3803 static int
3804 zfs_prop_activate_feature_check(void *arg, dmu_tx_t *tx)
3805 {
3806 spa_t *spa = dmu_tx_pool(tx)->dp_spa;
3807 zfeature_info_t *feature = arg;
3808
3809 if (!spa_feature_is_active(spa, feature))
3810 return (0);
3811 else
3812 return (SET_ERROR(EBUSY));
3813 }
3814
|