119370Spst#!/bin/ksh -p
219370Spst#
319370Spst# CDDL HEADER START
419370Spst#
519370Spst# The contents of this file are subject to the terms of the
698944Sobrien# Common Development and Distribution License (the "License").
798944Sobrien# You may not use this file except in compliance with the License.
819370Spst#
919370Spst# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1019370Spst# or https://opensource.org/licenses/CDDL-1.0.
1119370Spst# See the License for the specific language governing permissions
1219370Spst# and limitations under the License.
1319370Spst#
1419370Spst# When distributing Covered Code, include this CDDL HEADER in each
1519370Spst# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1619370Spst# If applicable, add the following below this CDDL HEADER, with the
1719370Spst# fields enclosed by brackets "[]" replaced with your own identifying
1819370Spst# information: Portions Copyright [yyyy] [name of copyright owner]
1946283Sdfr#
2046283Sdfr# CDDL HEADER END
2119370Spst#
2219370Spst
2319370Spst#
2419370Spst# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2519370Spst# Use is subject to license terms.
2619370Spst#
2719370Spst
2819370Spst#
2919370Spst# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
3019370Spst#
3119370Spst
3219370Spst. $STF_SUITE/include/libtest.shlib
3319370Spst
3419370Spst#
3519370Spst# DESCRIPTION:
3619370Spst# With ZFS_ABORT set, all zpool commands should be able to abort and generate a core file.
3719370Spst#
3819370Spst# STRATEGY:
3919370Spst# 1. Create an array of zpool command
4019370Spst# 2. Execute each command in the array
4119370Spst# 3. Verify the command aborts and generate a core file
4219370Spst#
4319370Spst
4419370Spstverify_runnable "global"
4519370Spst
4619370Spstfunction cleanup
4719370Spst{
4819370Spst	unset ZFS_ABORT
4919370Spst
5019370Spst	log_must pop_coredump_pattern "$coresavepath"
5198944Sobrien	log_must rm -rf $corepath $vdev1 $vdev2 $vdev3
5219370Spst
5319370Spst	# Clean up the pool created if we failed to abort.
5498944Sobrien	poolexists $pool && destroy_pool $pool
5519370Spst}
5619370Spst
5719370Spstlog_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
5898944Sobrienlog_onexit cleanup
5998944Sobrien
6019370Spstcorepath=$TESTDIR/core
6119370Spstcorefile=$corepath/core.zpool
6298944Sobriencoresavepath=$corepath/save
6398944Sobrienlog_must rm -rf $corepath
6498944Sobrienlog_must mkdir $corepath
6598944Sobrien
6619370Spstpool=pool.$$
6719370Spstvdev1=$TESTDIR/file1
6819370Spstvdev2=$TESTDIR/file2
6919370Spstvdev3=$TESTDIR/file3
7098944Sobrienlog_must mkfile $MINVDEVSIZE $vdev1 $vdev2 $vdev3
7198944Sobrien
7219370Spstset -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
7319370Spst	"status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \
7498944Sobrien	"export $pool" "import -d $TESTDIR $pool" "offline $pool $vdev1" \
7598944Sobrien	"online $pool $vdev1" "clear $pool" "detach $pool $vdev2" \
7619370Spst	"attach $pool $vdev1 $vdev2" "replace $pool $vdev2 $vdev3" \
7719370Spst	"scrub $pool" "destroy -f $pool"
7819370Spst
7919370Spstset -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status" \
8019370Spst		"online" "offline" "clear" "attach" "detach" "replace" "scrub" \
8198944Sobrien		"import" "export" "upgrade" "history -?" "get" "set"
8219370Spst
8319370Spstlog_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
8419370Spstlog_must export ZFS_ABORT=yes
8519370Spst
8619370Spstfor subcmd in "${cmds[@]}" "${badparams[@]}"; do
8719370Spst	log_mustnot eval "zpool $subcmd"
8819370Spst	log_must rm "$corefile"
8919370Spstdone
9019370Spst
9119370Spstlog_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."
9219370Spst