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) 2023 George Amanakis. All rights reserved.
25#
26
27#
28# DESCRIPTION:
29# Verify reporting errors when deleting files
30#
31# STRATEGY:
32# 1. Create a pool, and a file
33# 2. zinject checksum errors
34# 3. Create snapshots and clones like:
35# 	fs->snap1->clone1->snap2->clone2->...
36# 4. Read the original file and immediately delete it
37# 5. Delete the file in clone2
38# 6. Snapshot clone2->snapxx and clone into snapxx->clonexx
39# 7. Verify we report errors in the pool in 'zpool status -v'
40# 8. Promote clone1
41# 9. Verify we report errors in the pool in 'zpool status -v'
42
43. $STF_SUITE/include/libtest.shlib
44
45verify_runnable "both"
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 when deleting files"
55log_onexit cleanup
56
57typeset file="/$TESTPOOL2/$TESTFILE0"
58
59truncate -s $MINVDEVSIZE $TESTDIR/vdev_a
60log_must zpool create -f -o feature@head_errlog=enabled $TESTPOOL2 $TESTDIR/vdev_a
61log_must dd if=/dev/urandom of=$file bs=1024 count=1024 oflag=sync
62log_must zinject -t data -e checksum -f 100 -am $file
63
64for i in {1..3}; do
65	lastfs="$(zfs list -r $TESTPOOL2 | tail -1 | awk '{print $1}')"
66	log_must zfs snap $lastfs@snap$i
67	log_must zfs clone $lastfs@snap$i $TESTPOOL2/clone$i
68done
69
70log_mustnot dd if=$file of=/dev/null bs=1024
71log_must rm $file /$TESTPOOL2/clone2/$TESTFILE0
72log_must zfs snap $TESTPOOL2/clone2@snapxx
73log_must zfs clone $TESTPOOL2/clone2@snapxx $TESTPOOL2/clonexx
74log_must zpool status -v $TESTPOOL2
75
76log_must eval "zpool status -v $TESTPOOL2 | \
77    grep \"Permanent errors have been detected\""
78log_must eval "zpool status -v | grep '$TESTPOOL2@snap1:/$TESTFILE0'"
79log_must eval "zpool status -v | grep '$TESTPOOL2/clone1/$TESTFILE0'"
80log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap2:/$TESTFILE0'"
81log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clone2/$TESTFILE0'"
82log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clonexx/$TESTFILE0'"
83log_must eval "zpool status -v | grep '$TESTPOOL2/clone2@snap3:/$TESTFILE0'"
84log_must eval "zpool status -v | grep '$TESTPOOL2/clone3/$TESTFILE0'"
85
86log_must zfs promote $TESTPOOL2/clone1
87log_must eval "zpool status -v $TESTPOOL2 | \
88    grep \"Permanent errors have been detected\""
89log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap1:/$TESTFILE0'"
90log_must eval "zpool status -v | grep '$TESTPOOL2/clone1/$TESTFILE0'"
91log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap2:/$TESTFILE0'"
92log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clone2/$TESTFILE0'"
93log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clonexx/$TESTFILE0'"
94log_must eval "zpool status -v | grep '$TESTPOOL2/clone2@snap3:/$TESTFILE0'"
95log_must eval "zpool status -v | grep '$TESTPOOL2/clone3/$TESTFILE0'"
96
97log_pass "Verify reporting errors when deleting files"
98