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 && destroy_dataset $TESTPOOL/$TESTFS1
41	datasetexists $TESTPOOL/$TESTFS2 && destroy_dataset $TESTPOOL/$TESTFS2
42	datasetexists $TESTPOOL/zvol && destroy_dataset $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 -o encryption=on -o keyformat=passphrase \
54	-o keylocation=$(get_https_base_url)/PASSPHRASE $TESTPOOL/$TESTFS2
55
56log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
57	-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
58
59typeset DISK2 _
60read -r _ DISK2 _ <<<"$DISKS"
61log_must zpool create -O encryption=on -O keyformat=passphrase \
62	-O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2
63
64log_must zfs unmount $TESTPOOL/$TESTFS1
65log_must_busy zfs unload-key $TESTPOOL/$TESTFS1
66
67log_must zfs unmount $TESTPOOL/$TESTFS2
68log_must_busy zfs unload-key $TESTPOOL/$TESTFS2
69
70log_must_busy zfs unload-key $TESTPOOL/zvol
71
72log_must zfs unmount $TESTPOOL1
73log_must_busy zfs unload-key $TESTPOOL1
74
75log_must zfs load-key -a
76
77log_must key_available $TESTPOOL1
78log_must key_available $TESTPOOL/zvol
79log_must key_available $TESTPOOL/$TESTFS1
80log_must key_available $TESTPOOL/$TESTFS2
81
82log_must zfs mount $TESTPOOL1
83log_must zfs mount $TESTPOOL/$TESTFS1
84log_must zfs mount $TESTPOOL/$TESTFS2
85
86log_pass "'zfs load-key -a' loads keys for all datasets"
87