1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2022 George Amanakis. All rights reserved.
25#
26
27#
28# DESCRIPTION:
29# Verify correct output with 'zpool status -v' after corrupting a file
30#
31# STRATEGY:
32# 1. Create a pool, an encrypted filesystem and a file
33# 2. zinject checksum errors
34# 3. Unmount the filesystem and unload the key
35# 4. Scrub the pool
36# 5. Verify we report that errors were detected but we do not report
37#	the filename since the key is not loaded.
38# 6. Load the key and mount the encrypted fs.
39# 7. Verify we report errors in the pool in 'zpool status -v'
40
41. $STF_SUITE/include/libtest.shlib
42
43verify_runnable "both"
44
45DISK=${DISKS%% *}
46
47function cleanup
48{
49	log_must zinject -c all
50	destroy_pool $TESTPOOL2
51	rm -f $TESTDIR/vdev_a
52}
53
54log_assert "Verify reporting errors with unloaded keys works"
55log_onexit cleanup
56
57typeset passphrase="password"
58typeset file="/$TESTPOOL2/$TESTFS1/$TESTFILE0"
59
60truncate -s $MINVDEVSIZE $TESTDIR/vdev_a
61log_must zpool create -f -o feature@head_errlog=enabled $TESTPOOL2 $TESTDIR/vdev_a
62
63log_must eval "echo $passphrase > /$TESTPOOL2/pwd"
64
65log_must zfs create -o encryption=aes-256-ccm -o keyformat=passphrase \
66    -o keylocation=file:///$TESTPOOL2/pwd -o primarycache=none \
67    $TESTPOOL2/$TESTFS1
68
69log_must dd if=/dev/urandom of=$file bs=1024 count=1024 oflag=sync
70log_must eval "echo 'aaaaaaaa' >> "$file
71
72corrupt_blocks_at_level $file 0
73log_must zfs umount $TESTPOOL2/$TESTFS1
74log_must zfs unload-key -a
75log_must zpool sync $TESTPOOL2
76log_must zpool scrub $TESTPOOL2
77log_must zpool wait -t scrub $TESTPOOL2
78log_must zpool status -v $TESTPOOL2
79log_mustnot eval "zpool status -v $TESTPOOL2 | \
80    grep \"permission denied\""
81log_mustnot eval "zpool status -v $TESTPOOL2 | grep '$file'"
82
83log_must eval "cat /$TESTPOOL2/pwd | zfs load-key $TESTPOOL2/$TESTFS1"
84log_must zfs mount $TESTPOOL2/$TESTFS1
85log_must zpool status -v $TESTPOOL2
86log_must eval "zpool status -v $TESTPOOL2 | \
87    grep \"Permanent errors have been detected\""
88log_must eval "zpool status -v $TESTPOOL2 | grep '$file'"
89
90log_pass "Verify reporting errors with unloaded keys works"
91