diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 0d9038f83190..bf2dc6bfe0f5 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -6335,8 +6335,6 @@ zfs_key_callback(zfs_handle_t *zhp, int depth, void *data) return (0); } - fprintf(stderr, "zfs_key_callback\r\n"); - switch (cb->keycmd) { case KEY_LOAD: ret = zfs_key_load(zhp, B_TRUE, B_TRUE, cb->recurse); diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c index c4d4b28d8365..6f33c7beb0b6 100644 --- a/module/zfs/zfs_ioctl.c +++ b/module/zfs/zfs_ioctl.c @@ -4851,6 +4851,7 @@ zfs_ioc_crypto_key_load(zfs_cmd_t *zc) spa_t *spa; zcrypt_key_t *wrappingkey = NULL; int error; + objset_t *os; if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) return (error); @@ -4868,6 +4869,15 @@ zfs_ioc_crypto_key_load(zfs_cmd_t *zc) if (error == EEXIST) zcrypt_key_free(wrappingkey); spa_close(spa, FTAG); + + if (!dmu_objset_hold(zc->zc_name, FTAG, &os)) { + if (dmu_objset_type(os) == DMU_OST_ZVOL) { + /* returns EEXISTS if already mounted */ + zvol_create_minor(zc->zc_name); + } + dmu_objset_rele(os, FTAG); + } + return (error); } @@ -4887,6 +4897,7 @@ zfs_ioc_crypto_key_inherit(zfs_cmd_t *zc) error = dsl_crypto_key_inherit(zc->zc_name); spa_close(spa, FTAG); + return (error); } @@ -4895,6 +4906,7 @@ zfs_ioc_crypto_key_unload(zfs_cmd_t *zc) { spa_t *spa; int error; + objset_t *os; if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) return (error); @@ -4906,6 +4918,14 @@ zfs_ioc_crypto_key_unload(zfs_cmd_t *zc) error = dsl_crypto_key_unload(zc->zc_name); spa_close(spa, FTAG); + + if (!dmu_objset_hold(zc->zc_name, FTAG, &os)) { + if (dmu_objset_type(os) == DMU_OST_ZVOL) { + zvol_remove_minor(zc->zc_name); + } + dmu_objset_rele(os, FTAG); + } + return (error); } diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index cf1d68c38e3a..1b89f36ba1f3 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -1240,7 +1240,7 @@ zvol_free(zvol_state_t *zv) static int __zvol_create_minor(const char *name) { - zvol_state_t *zv; + zvol_state_t *zv = NULL; objset_t *os; dmu_object_info_t *doi; uint64_t volsize; @@ -1315,7 +1315,7 @@ __zvol_create_minor(const char *name) out_dmu_objset_disown: dmu_objset_disown(os, zvol_tag); - zv->zv_objset = NULL; + if (zv) zv->zv_objset = NULL; out_doi: kmem_free(doi, sizeof(dmu_object_info_t)); out: