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# 'zpool import' should import a pool with Errata #3 while preventing
26# the user from performing read write operations
27#
28# STRATEGY:
29# 1. Import a pre-packaged pool with Errata #3
30# 2. Attempt to write to the effected datasets
31# 3. Attempt to read from the effected datasets
32# 4. Attempt to perform a raw send of the effected datasets
33# 5. Perform a regular send of the datasets under a new encryption root
34# 6. Verify the new datasets can be read from and written to
35# 7. Destroy the old effected datasets
36# 8. Reimport the pool and verify that the errata is no longer present
37#
38
39verify_runnable "global"
40
41POOL_NAME=cryptv0
42POOL_FILE=cryptv0.dat
43
44function uncompress_pool
45{
46	log_note "Creating pool from $POOL_FILE"
47	log_must bzcat \
48	    $STF_SUITE/tests/functional/cli_root/zpool_import/blockfiles/$POOL_FILE.bz2 \
49	    > /$TESTPOOL/$POOL_FILE
50	return 0
51}
52
53function cleanup
54{
55	poolexists $POOL_NAME && log_must zpool destroy $POOL_NAME
56	[[ -e /$TESTPOOL/$POOL_FILE ]] && rm /$TESTPOOL/$POOL_FILE
57	return 0
58}
59log_onexit cleanup
60
61log_assert "Verify that Errata 3 is properly handled"
62
63uncompress_pool
64log_must zpool import -d /$TESTPOOL/ $POOL_NAME
65log_must eval "zpool status $POOL_NAME | grep -q Errata" # also detects 'Errata #4'
66log_must eval "zpool status $POOL_NAME | grep -q ZFS-8000-ER"
67log_must eval "echo 'password' | zfs load-key $POOL_NAME/testfs"
68log_must eval "echo 'password' | zfs load-key $POOL_NAME/testvol"
69
70log_mustnot zfs mount $POOL_NAME/testfs
71log_must zfs mount -o ro $POOL_NAME/testfs
72
73old_mntpnt=$(get_prop mountpoint $POOL_NAME/testfs)
74log_must eval "ls $old_mntpnt | grep -q testfile"
75block_device_wait /dev/zvol/$POOL_NAME/testvol
76log_mustnot dd if=/dev/zero of=/dev/zvol/$POOL_NAME/testvol bs=512 count=1
77log_must dd if=/dev/zvol/$POOL_NAME/testvol of=/dev/null bs=512 count=1
78
79log_must zpool set feature@bookmark_v2=enabled $POOL_NAME # necessary for Errata #4
80
81log_must eval "echo 'password' | zfs create \
82	-o encryption=on -o keyformat=passphrase -o keylocation=prompt \
83	$POOL_NAME/encroot"
84log_mustnot eval "zfs send -w $POOL_NAME/testfs@snap1 | \
85	zfs recv $POOL_NAME/encroot/testfs"
86log_mustnot eval "zfs send -w $POOL_NAME/testvol@snap1 | \
87	zfs recv $POOL_NAME/encroot/testvol"
88
89log_must eval "zfs send $POOL_NAME/testfs@snap1 | \
90	zfs recv $POOL_NAME/encroot/testfs"
91log_must eval "zfs send $POOL_NAME/testvol@snap1 | \
92	zfs recv $POOL_NAME/encroot/testvol"
93block_device_wait /dev/zvol/$POOL_NAME/encroot/testvol
94log_must dd if=/dev/zero of=/dev/zvol/$POOL_NAME/encroot/testvol bs=512 count=1
95new_mntpnt=$(get_prop mountpoint $POOL_NAME/encroot/testfs)
96log_must eval "ls $new_mntpnt | grep -q testfile"
97log_must zfs destroy -r $POOL_NAME/testfs
98log_must zfs destroy -r $POOL_NAME/testvol
99
100log_must zpool export $POOL_NAME
101log_must zpool import -d /$TESTPOOL/ $POOL_NAME
102log_mustnot eval "zpool status $POOL_NAME | grep -q 'Errata #3'"
103log_pass "Errata 3 is properly handled"
104