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
23#
24# DESCRIPTION:
25# Scrubs must work on an encrypted dataset with an unloaded key.
26#
27# STRATEGY:
28# 1. Create an encrypted dataset
29# 2. Generate data on the dataset
30# 3. Unmount the encrypted dataset and unload its key
31# 4. Start a scrub
32# 5. Wait for the scrub to complete
33# 6. Verify the scrub had no errors
34# 7. Load the dataset key and mount it
35#
36
37verify_runnable "global"
38
39function cleanup
40{
41	datasetexists $TESTPOOL/$TESTFS2 && \
42		log_must zfs destroy $TESTPOOL/$TESTFS2
43}
44log_onexit cleanup
45
46log_assert "Scrubs must work on an encrypted dataset with an unloaded key"
47
48log_must eval "echo 'password' | zfs create -o encryption=on" \
49	"-o keyformat=passphrase $TESTPOOL/$TESTFS2"
50
51typeset mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS2)
52log_must mkfile 10m $mntpnt/file1
53
54for i in 2..10; do
55	log_must mkfile 512b $mntpnt/file$i
56done
57
58log_must zfs unmount $TESTPOOL/$TESTFS2
59log_must zfs unload-key $TESTPOOL/$TESTFS2
60
61log_must zpool scrub $TESTPOOL
62
63while ! is_pool_scrubbed $TESTPOOL; do
64	sleep 1
65done
66
67log_must check_pool_status $TESTPOOL "scan" "with 0 errors"
68
69log_must eval "echo 'password' | zfs mount -l $TESTPOOL/$TESTFS2"
70
71log_pass "Scrubs work on an encrypted dataset with an unloaded key"
72