xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh (revision 508a0e8cf1600b06c1f7361ad76e736710d3fdf8)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2017 Datto, Inc. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib
23
24#
25# DESCRIPTION:
26# 'zfs load-key -a' should load keys for all datasets.
27#
28# STRATEGY:
29# 1. Create an encrypted filesystem, encrypted zvol, and an encrypted pool
30# 2. Unmount all datasets and unload their keys
31# 3. Attempt to load all dataset keys
32# 4. Verify each dataset has its key loaded
33# 5. Attempt to mount the pool and filesystem
34#
35
36verify_runnable "both"
37
38function cleanup
39{
40	datasetexists $TESTPOOL/$TESTFS1 && \
41		log_must zfs destroy $TESTPOOL/$TESTFS1
42	datasetexists $TESTPOOL/zvol && log_must zfs destroy $TESTPOOL/zvol
43	poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1
44}
45log_onexit cleanup
46
47log_assert "'zfs load-key -a' should load keys for all datasets"
48
49log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey"
50log_must zfs create -o encryption=on -o keyformat=passphrase \
51	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1
52
53log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
54	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
55
56typeset DISK2="$(echo $DISKS | awk '{ print $2}')"
57log_must zpool create -O encryption=on -O keyformat=passphrase \
58	-O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2
59
60log_must zfs unmount $TESTPOOL/$TESTFS1
61log_must zfs unload-key $TESTPOOL/$TESTFS1
62
63log_must zfs unload-key $TESTPOOL/zvol
64
65log_must zfs unmount $TESTPOOL1
66log_must zfs unload-key $TESTPOOL1
67
68log_must zfs load-key -a
69
70log_must key_available $TESTPOOL1
71log_must key_available $TESTPOOL/zvol
72log_must key_available $TESTPOOL/$TESTFS1
73
74log_must zfs mount $TESTPOOL1
75log_must zfs mount $TESTPOOL/$TESTFS1
76
77log_pass "'zfs load-key -a' loads keys for all datasets"
78