1f38cb554SJohn Wren Kennedy#!/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29f78cdc34SPaul Dagnelie# Copyright (c) 2013, 2018 by Delphix. All rights reserved.
30dcdeca0aSAndrew Stormont# Copyright 2019 RackTop Systems.
31f38cb554SJohn Wren Kennedy#
32f38cb554SJohn Wren Kennedy
33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/slog/slog.kshlib
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# DESCRIPTION:
37f38cb554SJohn Wren Kennedy#	log device can survive when one of pool device get corrupted
38f38cb554SJohn Wren Kennedy#
39f38cb554SJohn Wren Kennedy# STRATEGY:
40f38cb554SJohn Wren Kennedy#	1. Create pool with slog devices
41f38cb554SJohn Wren Kennedy#	2. Corrupt the data on one disk.
42f38cb554SJohn Wren Kennedy#	3. Verify the log is fine
43f38cb554SJohn Wren Kennedy#
44f38cb554SJohn Wren Kennedy
45f38cb554SJohn Wren Kennedyverify_runnable "global"
46f38cb554SJohn Wren Kennedy
47f38cb554SJohn Wren Kennedylog_assert "log device can survive when one of the pool device get corrupted."
48d8849d7dSChunwei Chenlog_must setup
49f38cb554SJohn Wren Kennedy
5020596fe4SJohn Wren Kennedyfor type in "mirror" "raidz" "raidz2"; do
5120596fe4SJohn Wren Kennedy	for spare in "" "spare"; do
52dcdeca0aSAndrew Stormont		log_must zpool create $TESTPOOL $type $VDEV $spare $SDEV \
53f38cb554SJohn Wren Kennedy			log $LDEV
54f38cb554SJohn Wren Kennedy
55f78cdc34SPaul Dagnelie                # Create a file to be corrupted
56f78cdc34SPaul Dagnelie                dd if=/dev/urandom of=/$TESTPOOL/filler bs=1024k count=50
57f78cdc34SPaul Dagnelie
58f78cdc34SPaul Dagnelie                #
59f78cdc34SPaul Dagnelie                # Ensure the file has been synced out before attempting to
60f78cdc34SPaul Dagnelie                # corrupt its contents.
61f78cdc34SPaul Dagnelie                #
62*09fbbb7dSAllan Jude                sync_all_pools
63f78cdc34SPaul Dagnelie
64f78cdc34SPaul Dagnelie		#
65f38cb554SJohn Wren Kennedy		# Corrupt a pool device to make the pool DEGRADED
66f38cb554SJohn Wren Kennedy		# The oseek value below is to skip past the vdev label.
67f78cdc34SPaul Dagnelie		#
681d32ba66SJohn Wren Kennedy		log_must dd if=/dev/urandom of=$VDIR/a bs=1024k oseek=4 \
69f38cb554SJohn Wren Kennedy		    conv=notrunc count=50
701d32ba66SJohn Wren Kennedy		log_must zpool scrub $TESTPOOL
71f38cb554SJohn Wren Kennedy		log_must display_status $TESTPOOL
72f38cb554SJohn Wren Kennedy
7320596fe4SJohn Wren Kennedy		log_must wait_for_degraded $TESTPOOL
74f38cb554SJohn Wren Kennedy
751d32ba66SJohn Wren Kennedy		zpool status -v $TESTPOOL | grep logs | \
761d32ba66SJohn Wren Kennedy			grep "DEGRADED" 2>&1 >/dev/null
77f38cb554SJohn Wren Kennedy		if (( $? == 0 )); then
78f38cb554SJohn Wren Kennedy			log_fail "log device should display correct status"
79f38cb554SJohn Wren Kennedy		fi
80f38cb554SJohn Wren Kennedy
811d32ba66SJohn Wren Kennedy		log_must zpool destroy -f $TESTPOOL
82f38cb554SJohn Wren Kennedy	done
83f38cb554SJohn Wren Kennedydone
84f38cb554SJohn Wren Kennedy
85f38cb554SJohn Wren Kennedylog_pass "log device can survive when one of the pool device get corrupted."
86