Skip to content

zcp: get_prop: fix encryptionroot and encryption #17280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions module/zfs/zcp_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,17 @@ get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname,
break;
}

case ZFS_PROP_ENCRYPTION:
case ZFS_PROP_KEYSTATUS:
case ZFS_PROP_KEYFORMAT: {
/* provide defaults in case no crypto obj exists */
setpoint[0] = '\0';
if (zfs_prop == ZFS_PROP_KEYSTATUS)
numval = ZFS_KEYSTATUS_NONE;
else
if (zfs_prop == ZFS_PROP_ENCRYPTION)
numval = ZIO_CRYPT_OFF;
else if (zfs_prop == ZFS_PROP_KEYFORMAT)
numval = ZFS_KEYFORMAT_NONE;
else if (zfs_prop == ZFS_PROP_KEYSTATUS)
numval = ZFS_KEYSTATUS_NONE;

nvlist_t *nvl, *propval;
nvl = fnvlist_alloc();
Expand All @@ -404,6 +407,29 @@ get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname,
break;
}

case ZFS_PROP_ENCRYPTION_ROOT: {
setpoint[0] = '\0';
strval[0] = '\0';

nvlist_t *nvl, *propval;
nvl = fnvlist_alloc();
dsl_dataset_crypt_stats(ds, nvl);
if (nvlist_lookup_nvlist(nvl, zfs_prop_to_name(zfs_prop),
&propval) == 0) {
const char *dsname;
const char *source;

if (nvlist_lookup_string(propval, ZPROP_VALUE,
&dsname) == 0)
strlcpy(strval, dsname, ZAP_MAXVALUELEN);
if (nvlist_lookup_string(propval, ZPROP_SOURCE,
&source) == 0)
strlcpy(setpoint, source, sizeof (setpoint));
}
nvlist_free(nvl);
break;
}

case ZFS_PROP_SNAPSHOTS_CHANGED:
numval = dsl_dir_snap_cmtime(ds->ds_dir).tv_sec;
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ tests = ['case_all_values', 'norm_all_values', 'mixed_create_failure',
tags = ['functional', 'casenorm']

[tests/functional/channel_program/lua_core]
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists',
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists', 'tst.encryption',
'tst.integer_illegal', 'tst.integer_overflow', 'tst.language_functions_neg',
'tst.language_functions_pos', 'tst.large_prog', 'tst.libraries',
'tst.memory_limit', 'tst.nested_neg', 'tst.nested_pos', 'tst.nvlist_to_lua',
Expand Down
2 changes: 1 addition & 1 deletion tests/runfiles/sanity.run
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tests = ['case_all_values', 'norm_all_values', 'sensitive_none_lookup',
tags = ['functional', 'casenorm']

[tests/functional/channel_program/lua_core]
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists',
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists', 'tst.encryption',
'tst.integer_illegal', 'tst.integer_overflow', 'tst.language_functions_neg',
'tst.language_functions_pos', 'tst.large_prog', 'tst.libraries',
'tst.memory_limit', 'tst.nested_neg', 'tst.nested_pos', 'tst.nvlist_to_lua',
Expand Down
2 changes: 2 additions & 0 deletions tests/zfs-tests/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ nobase_dist_datadir_zfs_tests_tests_DATA += \
functional/channel_program/lua_core/tst.args_to_lua.zcp \
functional/channel_program/lua_core/tst.divide_by_zero.err \
functional/channel_program/lua_core/tst.divide_by_zero.zcp \
functional/channel_program/lua_core/tst.encryption.zcp \
functional/channel_program/lua_core/tst.exists.zcp \
functional/channel_program/lua_core/tst.large_prog.out \
functional/channel_program/lua_core/tst.large_prog.zcp \
Expand Down Expand Up @@ -543,6 +544,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/channel_program/lua_core/setup.ksh \
functional/channel_program/lua_core/tst.args_to_lua.ksh \
functional/channel_program/lua_core/tst.divide_by_zero.ksh \
functional/channel_program/lua_core/tst.encryption.ksh \
functional/channel_program/lua_core/tst.exists.ksh \
functional/channel_program/lua_core/tst.integer_illegal.ksh \
functional/channel_program/lua_core/tst.integer_overflow.ksh \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2021 by Determinate Systems. All rights reserved.
#

. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib

#
# DESCRIPTION:
# zfs.exists should accurately report whether a dataset exists, and
# report an error if a dataset is in another pool.

verify_runnable "global"

function cleanup
{
datasetexists $TESTPOOL/$TESTDATASET && \
log_must zfs destroy -R $TESTPOOL/$TESTDATASET
}
log_onexit cleanup

TESTDATASET="channelprogramencryption"

passphrase="password"
log_must eval "echo "$passphrase" | zfs create -o encryption=aes-256-ccm " \
"-o keyformat=passphrase $TESTPOOL/$TESTDATASET"

log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.encryption.zcp \
$TESTPOOL/$TESTDATASET

log_pass "zfs.get_prop(dataset, ...) on \"encryption\" and \"encryptionroot\" gives correct results"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- SPDX-License-Identifier: CDDL-1.0
--
-- This file and its contents are supplied under the terms of the
-- Common Development and Distribution License ("CDDL"), version 1.0.
-- You may only use this file in accordance with the terms of version
-- 1.0 of the CDDL.
--
-- A full copy of the text of the CDDL should have accompanied this
-- source. A copy of the CDDL is also available via the Internet at
-- http://www.illumos.org/license/CDDL.
--

--
-- Copyright (c) 2021 by Determinate Systems. All rights reserved.
--

-- ensure zfs.get_prop returns the correct values for "encryption"
-- and "encryptionroot"

args = ...
argv = args['argv']
assert(zfs.get_prop(argv[1], "encryption") == "aes-256-ccm")
assert(zfs.get_prop(argv[1], "encryptionroot") == argv[1])
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@

verify_runnable "global"

# create $TESTSNAP and $TESTCLONE
create_snapshot
create_clone

function cleanup
{
datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R
}
log_onexit cleanup

# create $TESTSNAP and $TESTCLONE
create_snapshot
create_clone

log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.exists.zcp \
$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS@$TESTSNAP \
Expand Down
Loading