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 corrupted files after scrub
30#
31# STRATEGY:
32# 1. Create a pool, and a file
33# 2. Corrupt the file
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	destroy_pool $TESTPOOL2
50	rm -f $TESTDIR/vdev_a
51}
52
53log_assert "Verify reporting errors when deleting corrupted files after scrub"
54log_onexit cleanup
55
56typeset file="/$TESTPOOL2/$TESTFS1/$TESTFILE0"
57
58truncate -s $MINVDEVSIZE $TESTDIR/vdev_a
59log_must zpool create -f $TESTPOOL2 $TESTDIR/vdev_a
60log_must zfs create -o primarycache=none $TESTPOOL2/$TESTFS1
61log_must dd if=/dev/urandom of=$file bs=1024 count=1024 oflag=sync
62corrupt_blocks_at_level $file 0
63
64lastfs="$(zfs list -r $TESTPOOL2 | tail -1 | awk '{print $1}')"
65for i in {1..3}; do
66	log_must zfs snap $lastfs@snap$i
67	log_must zfs clone $lastfs@snap$i $TESTPOOL2/clone$i
68	lastfs="$(zfs list -r $TESTPOOL2/clone$i | tail -1 | awk '{print $1}')"
69done
70
71log_must zpool scrub -w $TESTPOOL2
72log_must rm $file /$TESTPOOL2/clone2/$TESTFILE0
73log_must zfs snap $TESTPOOL2/clone2@snapxx
74log_must zfs clone $TESTPOOL2/clone2@snapxx $TESTPOOL2/clonexx
75log_must zpool status -v $TESTPOOL2
76
77log_must eval "zpool status -v $TESTPOOL2 | \
78    grep \"Permanent errors have been detected\""
79log_must eval "zpool status -v | grep '$TESTPOOL2/$TESTFS1@snap1:/$TESTFILE0'"
80log_must eval "zpool status -v | grep '$TESTPOOL2/clone1/$TESTFILE0'"
81log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap2:/$TESTFILE0'"
82log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clone2/$TESTFILE0'"
83log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clonexx/$TESTFILE0'"
84log_must eval "zpool status -v | grep '$TESTPOOL2/clone2@snap3:/$TESTFILE0'"
85log_must eval "zpool status -v | grep '$TESTPOOL2/clone3/$TESTFILE0'"
86
87log_must zfs promote $TESTPOOL2/clone1
88log_must eval "zpool status -v $TESTPOOL2 | \
89    grep \"Permanent errors have been detected\""
90log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap1:/$TESTFILE0'"
91log_must eval "zpool status -v | grep '$TESTPOOL2/clone1/$TESTFILE0'"
92log_must eval "zpool status -v | grep '$TESTPOOL2/clone1@snap2:/$TESTFILE0'"
93log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clone2/$TESTFILE0'"
94log_mustnot eval "zpool status -v | grep '$TESTPOOL2/clonexx/$TESTFILE0'"
95log_must eval "zpool status -v | grep '$TESTPOOL2/clone2@snap3:/$TESTFILE0'"
96log_must eval "zpool status -v | grep '$TESTPOOL2/clone3/$TESTFILE0'"
97
98log_pass "Verify reporting errors when deleting corrupted files after scrub"
99