@@ -201,6 +201,7 @@ extern int zfs_abd_scatter_enabled;
201201
202202static ztest_shared_opts_t * ztest_shared_opts ;
203203static ztest_shared_opts_t ztest_opts ;
204+ static char * ztest_wkeydata = "abcdefghijklmnopqrstuvwxyz012345" ;
204205
205206typedef struct ztest_shared_ds {
206207 uint64_t zd_seq ;
@@ -1180,6 +1181,42 @@ ztest_spa_prop_set_uint64(zpool_prop_t prop, uint64_t value)
11801181 return (error );
11811182}
11821183
1184+ static int
1185+ ztest_dmu_objset_own (const char * name , dmu_objset_type_t type ,
1186+ boolean_t readonly , boolean_t decrypt , void * tag , objset_t * * osp )
1187+ {
1188+ int err ;
1189+
1190+ err = dmu_objset_own (name , type , readonly , decrypt , tag , osp );
1191+ if (decrypt && err == EACCES ) {
1192+ char ddname [ZFS_MAX_DATASET_NAME_LEN ];
1193+ dsl_crypto_params_t * dcp ;
1194+ nvlist_t * crypto_args = fnvlist_alloc ();
1195+ char * cp = NULL ;
1196+
1197+ /* spa_keystore_load_wkey() expects a dsl dir name */
1198+ strcpy (ddname , name );
1199+ cp = strchr (ddname , '@' );
1200+ if (cp != NULL )
1201+ * cp = '\0' ;
1202+
1203+ fnvlist_add_uint8_array (crypto_args , "wkeydata" ,
1204+ (uint8_t * )ztest_wkeydata , WRAPPING_KEY_LEN );
1205+ VERIFY0 (dsl_crypto_params_create_nvlist (DCP_CMD_NONE , NULL ,
1206+ crypto_args , & dcp ));
1207+ err = spa_keystore_load_wkey (ddname , dcp , B_FALSE );
1208+ dsl_crypto_params_free (dcp , B_FALSE );
1209+ fnvlist_free (crypto_args );
1210+
1211+ if (err != 0 )
1212+ return (err );
1213+
1214+ err = dmu_objset_own (name , type , readonly , decrypt , tag , osp );
1215+ }
1216+
1217+ return (err );
1218+ }
1219+
11831220
11841221/*
11851222 * Object and range lock mechanics
@@ -1921,7 +1958,7 @@ ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap)
19211958 dmu_write (os , lr -> lr_foid , offset , length , data , tx );
19221959 } else {
19231960 bcopy (data , abuf -> b_data , length );
1924- dmu_assign_arcbuf (db , offset , abuf , tx );
1961+ dmu_assign_arcbuf_by_dbuf (db , offset , abuf , tx );
19251962 }
19261963
19271964 (void ) ztest_log_write (zd , tx , lr );
@@ -3532,11 +3569,57 @@ ztest_objset_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
35323569static int
35333570ztest_dataset_create (char * dsname )
35343571{
3535- uint64_t zilset = ztest_random (100 );
3536- int err = dmu_objset_create (dsname , DMU_OST_OTHER , 0 , NULL ,
3572+ int err ;
3573+ uint64_t rand ;
3574+ dsl_crypto_params_t * dcp = NULL ;
3575+
3576+ /*
3577+ * 50% of the time, we create encrypted datasets
3578+ * using a random cipher suite and a hard-coded
3579+ * wrapping key.
3580+ */
3581+ rand = ztest_random (2 );
3582+ if (rand != 0 ) {
3583+ nvlist_t * crypto_args = fnvlist_alloc ();
3584+ nvlist_t * props = fnvlist_alloc ();
3585+
3586+ /* slight bias towards the default cipher suite */
3587+ rand = ztest_random (ZIO_CRYPT_FUNCTIONS );
3588+ if (rand < ZIO_CRYPT_AES_128_CCM )
3589+ rand = ZIO_CRYPT_ON ;
3590+
3591+ fnvlist_add_uint64 (props ,
3592+ zfs_prop_to_name (ZFS_PROP_ENCRYPTION ), rand );
3593+ fnvlist_add_uint8_array (crypto_args , "wkeydata" ,
3594+ (uint8_t * )ztest_wkeydata , WRAPPING_KEY_LEN );
3595+
3596+ /*
3597+ * These parameters aren't really used by the kernel. They
3598+ * are simply stored so that userspace knows how to load
3599+ * the wrapping key.
3600+ */
3601+ fnvlist_add_uint64 (props ,
3602+ zfs_prop_to_name (ZFS_PROP_KEYFORMAT ), ZFS_KEYFORMAT_RAW );
3603+ fnvlist_add_string (props ,
3604+ zfs_prop_to_name (ZFS_PROP_KEYLOCATION ), "prompt" );
3605+ fnvlist_add_uint64 (props ,
3606+ zfs_prop_to_name (ZFS_PROP_PBKDF2_SALT ), 0ULL );
3607+ fnvlist_add_uint64 (props ,
3608+ zfs_prop_to_name (ZFS_PROP_PBKDF2_ITERS ), 0ULL );
3609+
3610+ VERIFY0 (dsl_crypto_params_create_nvlist (DCP_CMD_NONE , props ,
3611+ crypto_args , & dcp ));
3612+
3613+ fnvlist_free (crypto_args );
3614+ fnvlist_free (props );
3615+ }
3616+
3617+ err = dmu_objset_create (dsname , DMU_OST_OTHER , 0 , dcp ,
35373618 ztest_objset_create_cb , NULL );
3619+ dsl_crypto_params_free (dcp , !!err );
35383620
3539- if (err || zilset < 80 )
3621+ rand = ztest_random (100 );
3622+ if (err || rand < 80 )
35403623 return (err );
35413624
35423625 if (ztest_opts .zo_verbose >= 5 )
@@ -3556,7 +3639,8 @@ ztest_objset_destroy_cb(const char *name, void *arg)
35563639 /*
35573640 * Verify that the dataset contains a directory object.
35583641 */
3559- VERIFY0 (dmu_objset_own (name , DMU_OST_OTHER , B_TRUE , B_TRUE , FTAG , & os ));
3642+ VERIFY0 (ztest_dmu_objset_own (name , DMU_OST_OTHER , B_TRUE ,
3643+ B_TRUE , FTAG , & os ));
35603644 error = dmu_object_info (os , ZTEST_DIROBJ , & doi );
35613645 if (error != ENOENT ) {
35623646 /* We could have crashed in the middle of destroying it */
@@ -3640,11 +3724,12 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
36403724 * (invoked from ztest_objset_destroy_cb()) should just throw it away.
36413725 */
36423726 if (ztest_random (2 ) == 0 &&
3643- dmu_objset_own (name , DMU_OST_OTHER , B_FALSE ,
3727+ ztest_dmu_objset_own (name , DMU_OST_OTHER , B_FALSE ,
36443728 B_TRUE , FTAG , & os ) == 0 ) {
36453729 ztest_zd_init (zdtmp , NULL , os );
36463730 zil_replay (os , zdtmp , ztest_replay_vector );
36473731 ztest_zd_fini (zdtmp );
3732+ txg_wait_synced (dmu_objset_pool (os ), 0 );
36483733 dmu_objset_disown (os , B_TRUE , FTAG );
36493734 }
36503735
@@ -3659,8 +3744,8 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
36593744 /*
36603745 * Verify that the destroyed dataset is no longer in the namespace.
36613746 */
3662- VERIFY3U (ENOENT , = = , dmu_objset_own (name , DMU_OST_OTHER , B_TRUE , B_TRUE ,
3663- FTAG , & os ));
3747+ VERIFY3U (ENOENT , = = , ztest_dmu_objset_own (name , DMU_OST_OTHER , B_TRUE ,
3748+ B_TRUE , FTAG , & os ));
36643749
36653750 /*
36663751 * Verify that we can create a new dataset.
@@ -3674,7 +3759,7 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
36743759 fatal (0 , "dmu_objset_create(%s) = %d" , name , error );
36753760 }
36763761
3677- VERIFY0 (dmu_objset_own (name , DMU_OST_OTHER , B_FALSE , B_TRUE ,
3762+ VERIFY0 (ztest_dmu_objset_own (name , DMU_OST_OTHER , B_FALSE , B_TRUE ,
36783763 FTAG , & os ));
36793764
36803765 ztest_zd_init (zdtmp , NULL , os );
@@ -3710,10 +3795,11 @@ ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
37103795 /*
37113796 * Verify that we cannot own an objset that is already owned.
37123797 */
3713- VERIFY3U (EBUSY , = = ,
3714- dmu_objset_own ( name , DMU_OST_OTHER , B_FALSE , B_TRUE , FTAG , & os2 ));
3798+ VERIFY3U (EBUSY , = = , ztest_dmu_objset_own ( name , DMU_OST_OTHER ,
3799+ B_FALSE , B_TRUE , FTAG , & os2 ));
37153800
37163801 zil_close (zilog );
3802+ txg_wait_synced (spa_get_dsl (os -> os_spa ), 0 );
37173803 dmu_objset_disown (os , B_TRUE , FTAG );
37183804 ztest_zd_fini (zdtmp );
37193805out :
@@ -3868,7 +3954,7 @@ ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id)
38683954 fatal (0 , "dmu_objset_create(%s) = %d" , clone2name , error );
38693955 }
38703956
3871- error = dmu_objset_own (snap2name , DMU_OST_ANY , B_TRUE , B_TRUE ,
3957+ error = ztest_dmu_objset_own (snap2name , DMU_OST_ANY , B_TRUE , B_TRUE ,
38723958 FTAG , & os );
38733959 if (error )
38743960 fatal (0 , "dmu_objset_own(%s) = %d" , snap2name , error );
@@ -4260,7 +4346,7 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
42604346 * bigobj, at the tail of the nth chunk
42614347 *
42624348 * The chunk size is set equal to bigobj block size so that
4263- * dmu_assign_arcbuf () can be tested for object updates.
4349+ * dmu_assign_arcbuf_by_dbuf () can be tested for object updates.
42644350 */
42654351
42664352 /*
@@ -4322,7 +4408,7 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
43224408 /*
43234409 * In iteration 5 (i == 5) use arcbufs
43244410 * that don't match bigobj blksz to test
4325- * dmu_assign_arcbuf () when it can't directly
4411+ * dmu_assign_arcbuf_by_dbuf () when it can't directly
43264412 * assign an arcbuf to a dbuf.
43274413 */
43284414 for (j = 0 ; j < s ; j ++ ) {
@@ -4368,8 +4454,8 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
43684454
43694455 /*
43704456 * 50% of the time don't read objects in the 1st iteration to
4371- * test dmu_assign_arcbuf () for the case when there're no
4372- * existing dbufs for the specified offsets.
4457+ * test dmu_assign_arcbuf_by_dbuf () for the case when there are
4458+ * no existing dbufs for the specified offsets.
43734459 */
43744460 if (i != 0 || ztest_random (2 ) != 0 ) {
43754461 error = dmu_read (os , packobj , packoff ,
@@ -4414,12 +4500,12 @@ ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
44144500 FTAG , & dbt , DMU_READ_NO_PREFETCH ) == 0 );
44154501 }
44164502 if (i != 5 || chunksize < (SPA_MINBLOCKSIZE * 2 )) {
4417- dmu_assign_arcbuf (bonus_db , off ,
4503+ dmu_assign_arcbuf_by_dbuf (bonus_db , off ,
44184504 bigbuf_arcbufs [j ], tx );
44194505 } else {
4420- dmu_assign_arcbuf (bonus_db , off ,
4506+ dmu_assign_arcbuf_by_dbuf (bonus_db , off ,
44214507 bigbuf_arcbufs [2 * j ], tx );
4422- dmu_assign_arcbuf (bonus_db ,
4508+ dmu_assign_arcbuf_by_dbuf (bonus_db ,
44234509 off + chunksize / 2 ,
44244510 bigbuf_arcbufs [2 * j + 1 ], tx );
44254511 }
@@ -6262,7 +6348,8 @@ ztest_dataset_open(int d)
62626348 }
62636349 ASSERT (error == 0 || error == EEXIST );
62646350
6265- VERIFY0 (dmu_objset_own (name , DMU_OST_OTHER , B_FALSE , B_TRUE , zd , & os ));
6351+ VERIFY0 (ztest_dmu_objset_own (name , DMU_OST_OTHER , B_FALSE ,
6352+ B_TRUE , zd , & os ));
62666353 (void ) rw_unlock (& ztest_name_lock );
62676354
62686355 ztest_zd_init (zd , ZTEST_GET_SHARED_DS (d ), os );
@@ -6303,6 +6390,7 @@ ztest_dataset_close(int d)
63036390 ztest_ds_t * zd = & ztest_ds [d ];
63046391
63056392 zil_close (zd -> zd_zilog );
6393+ txg_wait_synced (spa_get_dsl (zd -> zd_os -> os_spa ), 0 );
63066394 dmu_objset_disown (zd -> zd_os , B_TRUE , zd );
63076395
63086396 ztest_zd_fini (zd );
@@ -6355,7 +6443,7 @@ ztest_run(ztest_shared_t *zs)
63556443 ztest_spa = spa ;
63566444
63576445 dmu_objset_stats_t dds ;
6358- VERIFY0 (dmu_objset_own (ztest_opts .zo_pool ,
6446+ VERIFY0 (ztest_dmu_objset_own (ztest_opts .zo_pool ,
63596447 DMU_OST_ANY , B_TRUE , B_TRUE , FTAG , & os ));
63606448 dsl_pool_config_enter (dmu_objset_pool (os ), FTAG );
63616449 dmu_objset_fast_stat (os , & dds );
@@ -6582,11 +6670,10 @@ ztest_freeze(void)
65826670 VERIFY3U (0 , = = , spa_open (ztest_opts .zo_pool , & spa , FTAG ));
65836671 ASSERT (spa_freeze_txg (spa ) == UINT64_MAX );
65846672 VERIFY3U (0 , = = , ztest_dataset_open (0 ));
6585- ztest_dataset_close (0 );
6586-
65876673 spa -> spa_debug = B_TRUE ;
65886674 ztest_spa = spa ;
65896675 txg_wait_synced (spa_get_dsl (spa ), 0 );
6676+ ztest_dataset_close (0 );
65906677 ztest_reguid (NULL , 0 );
65916678
65926679 spa_close (spa , FTAG );
0 commit comments