Skip to content

Commit 8487945

Browse files
snajpagrahamc
andauthored
zcp: get_prop: fix encryptionroot and encryption
It was reported that channel programs' zfs.get_prop doesn't work for dataset properties encryption and encryptionroot. They are handled in get_special_prop due to the need to call dsl_dataset_crypt_stats to load those dsl props. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Pavel Snajdr <[email protected]> Co-authored-by: Graham Christensen <[email protected]> Closes #17280
1 parent 06fa8f3 commit 8487945

File tree

7 files changed

+104
-9
lines changed

7 files changed

+104
-9
lines changed

module/zfs/zcp_get.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,17 @@ get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname,
378378
break;
379379
}
380380

381+
case ZFS_PROP_ENCRYPTION:
381382
case ZFS_PROP_KEYSTATUS:
382383
case ZFS_PROP_KEYFORMAT: {
383384
/* provide defaults in case no crypto obj exists */
384385
setpoint[0] = '\0';
385-
if (zfs_prop == ZFS_PROP_KEYSTATUS)
386-
numval = ZFS_KEYSTATUS_NONE;
387-
else
386+
if (zfs_prop == ZFS_PROP_ENCRYPTION)
387+
numval = ZIO_CRYPT_OFF;
388+
else if (zfs_prop == ZFS_PROP_KEYFORMAT)
388389
numval = ZFS_KEYFORMAT_NONE;
390+
else if (zfs_prop == ZFS_PROP_KEYSTATUS)
391+
numval = ZFS_KEYSTATUS_NONE;
389392

390393
nvlist_t *nvl, *propval;
391394
nvl = fnvlist_alloc();
@@ -404,6 +407,29 @@ get_special_prop(lua_State *state, dsl_dataset_t *ds, const char *dsname,
404407
break;
405408
}
406409

410+
case ZFS_PROP_ENCRYPTION_ROOT: {
411+
setpoint[0] = '\0';
412+
strval[0] = '\0';
413+
414+
nvlist_t *nvl, *propval;
415+
nvl = fnvlist_alloc();
416+
dsl_dataset_crypt_stats(ds, nvl);
417+
if (nvlist_lookup_nvlist(nvl, zfs_prop_to_name(zfs_prop),
418+
&propval) == 0) {
419+
const char *dsname;
420+
const char *source;
421+
422+
if (nvlist_lookup_string(propval, ZPROP_VALUE,
423+
&dsname) == 0)
424+
strlcpy(strval, dsname, ZAP_MAXVALUELEN);
425+
if (nvlist_lookup_string(propval, ZPROP_SOURCE,
426+
&source) == 0)
427+
strlcpy(setpoint, source, sizeof (setpoint));
428+
}
429+
nvlist_free(nvl);
430+
break;
431+
}
432+
407433
case ZFS_PROP_SNAPSHOTS_CHANGED:
408434
numval = dsl_dir_snap_cmtime(ds->ds_dir).tv_sec;
409435
break;

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ tests = ['case_all_values', 'norm_all_values', 'mixed_create_failure',
120120
tags = ['functional', 'casenorm']
121121

122122
[tests/functional/channel_program/lua_core]
123-
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists',
123+
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists', 'tst.encryption',
124124
'tst.integer_illegal', 'tst.integer_overflow', 'tst.language_functions_neg',
125125
'tst.language_functions_pos', 'tst.large_prog', 'tst.libraries',
126126
'tst.memory_limit', 'tst.nested_neg', 'tst.nested_pos', 'tst.nvlist_to_lua',

tests/runfiles/sanity.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ tests = ['case_all_values', 'norm_all_values', 'sensitive_none_lookup',
6464
tags = ['functional', 'casenorm']
6565

6666
[tests/functional/channel_program/lua_core]
67-
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists',
67+
tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists', 'tst.encryption',
6868
'tst.integer_illegal', 'tst.integer_overflow', 'tst.language_functions_neg',
6969
'tst.language_functions_pos', 'tst.large_prog', 'tst.libraries',
7070
'tst.memory_limit', 'tst.nested_neg', 'tst.nested_pos', 'tst.nvlist_to_lua',

tests/zfs-tests/tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ nobase_dist_datadir_zfs_tests_tests_DATA += \
106106
functional/channel_program/lua_core/tst.args_to_lua.zcp \
107107
functional/channel_program/lua_core/tst.divide_by_zero.err \
108108
functional/channel_program/lua_core/tst.divide_by_zero.zcp \
109+
functional/channel_program/lua_core/tst.encryption.zcp \
109110
functional/channel_program/lua_core/tst.exists.zcp \
110111
functional/channel_program/lua_core/tst.large_prog.out \
111112
functional/channel_program/lua_core/tst.large_prog.zcp \
@@ -544,6 +545,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
544545
functional/channel_program/lua_core/setup.ksh \
545546
functional/channel_program/lua_core/tst.args_to_lua.ksh \
546547
functional/channel_program/lua_core/tst.divide_by_zero.ksh \
548+
functional/channel_program/lua_core/tst.encryption.ksh \
547549
functional/channel_program/lua_core/tst.exists.ksh \
548550
functional/channel_program/lua_core/tst.integer_illegal.ksh \
549551
functional/channel_program/lua_core/tst.integer_overflow.ksh \
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
#
15+
# Copyright (c) 2021 by Determinate Systems. All rights reserved.
16+
#
17+
18+
. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
19+
20+
#
21+
# DESCRIPTION:
22+
# zfs.exists should accurately report whether a dataset exists, and
23+
# report an error if a dataset is in another pool.
24+
25+
verify_runnable "global"
26+
27+
function cleanup
28+
{
29+
datasetexists $TESTPOOL/$TESTDATASET && \
30+
log_must zfs destroy -R $TESTPOOL/$TESTDATASET
31+
}
32+
log_onexit cleanup
33+
34+
TESTDATASET="channelprogramencryption"
35+
36+
passphrase="password"
37+
log_must eval "echo "$passphrase" | zfs create -o encryption=aes-256-ccm " \
38+
"-o keyformat=passphrase $TESTPOOL/$TESTDATASET"
39+
40+
log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.encryption.zcp \
41+
$TESTPOOL/$TESTDATASET
42+
43+
log_pass "zfs.get_prop(dataset, ...) on \"encryption\" and \"encryptionroot\" gives correct results"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- SPDX-License-Identifier: CDDL-1.0
2+
--
3+
-- This file and its contents are supplied under the terms of the
4+
-- Common Development and Distribution License ("CDDL"), version 1.0.
5+
-- You may only use this file in accordance with the terms of version
6+
-- 1.0 of the CDDL.
7+
--
8+
-- A full copy of the text of the CDDL should have accompanied this
9+
-- source. A copy of the CDDL is also available via the Internet at
10+
-- http://www.illumos.org/license/CDDL.
11+
--
12+
13+
--
14+
-- Copyright (c) 2021 by Determinate Systems. All rights reserved.
15+
--
16+
17+
-- ensure zfs.get_prop returns the correct values for "encryption"
18+
-- and "encryptionroot"
19+
20+
args = ...
21+
argv = args['argv']
22+
assert(zfs.get_prop(argv[1], "encryption") == "aes-256-ccm")
23+
assert(zfs.get_prop(argv[1], "encryptionroot") == argv[1])

tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424

2525
verify_runnable "global"
2626

27-
# create $TESTSNAP and $TESTCLONE
28-
create_snapshot
29-
create_clone
30-
3127
function cleanup
3228
{
3329
datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
3430
destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R
3531
}
32+
log_onexit cleanup
33+
34+
# create $TESTSNAP and $TESTCLONE
35+
create_snapshot
36+
create_clone
3637

3738
log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.exists.zcp \
3839
$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS@$TESTSNAP \

0 commit comments

Comments
 (0)