xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_errata3.ksh (revision d2f7972d81337947df76c36b8c2a5f290829fa7a)
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
47	log_note "Creating pool from $POOL_FILE"
48	log_must bzcat \
49	    $STF_SUITE/tests/functional/cli_root/zpool_import/$POOL_FILE.bz2 \
50	    > /$TESTPOOL/$POOL_FILE
51	return 0
52}
53
54function cleanup
55{
56	poolexists $POOL_NAME && log_must zpool destroy $POOL_NAME
57	[[ -e /$TESTPOOL/$POOL_FILE ]] && rm /$TESTPOOL/$POOL_FILE
58	return 0
59}
60log_onexit cleanup
61
62log_assert "Verify that Errata 3 is properly handled"
63
64uncompress_pool
65log_must zpool import -d /$TESTPOOL/ $POOL_NAME
66log_must eval "zpool status $POOL_NAME | grep -q Errata" # also detects 'Errata #4'
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"
75log_mustnot dd if=/dev/zero of=/dev/zvol/rdsk/$POOL_NAME/testvol bs=512 count=1
76log_must dd if=/dev/zvol/rdsk/$POOL_NAME/testvol of=/dev/null bs=512 count=1
77log_must eval "echo 'password' | zfs create \
78	-o encryption=on -o keyformat=passphrase -o keylocation=prompt \
79	cryptv0/encroot"
80log_mustnot eval "zfs send -w $POOL_NAME/testfs@snap1 | \
81	zfs recv $POOL_NAME/encroot/testfs"
82log_mustnot eval "zfs send -w $POOL_NAME/testvol@snap1 | \
83	zfs recv $POOL_NAME/encroot/testvol"
84
85log_must eval "zfs send $POOL_NAME/testfs@snap1 | \
86	zfs recv $POOL_NAME/encroot/testfs"
87log_must eval "zfs send $POOL_NAME/testvol@snap1 | \
88	zfs recv $POOL_NAME/encroot/testvol"
89block_device_wait
90log_must dd if=/dev/zero of=/dev/zvol/rdsk/$POOL_NAME/encroot/testvol bs=512 count=1
91new_mntpnt=$(get_prop mountpoint $POOL_NAME/encroot/testfs)
92log_must eval "ls $new_mntpnt | grep -q testfile"
93log_must zfs destroy -r $POOL_NAME/testfs
94log_must zfs destroy -r $POOL_NAME/testvol
95
96log_must zpool export $POOL_NAME
97log_must zpool import -d /$TESTPOOL/ $POOL_NAME
98log_mustnot eval "zpool status $POOL_NAME | grep -q 'Errata #3'"
99log_pass "Errata 3 is properly handled"
100