xref: /titanic_44/usr/src/test/zfs-tests/tests/functional/inuse/inuse_002_pos.ksh (revision f38cb554a534c6df738be3f4d23327e69888e634)
1#!/usr/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 http://www.opensolaris.org/os/licensing.
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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/inuse/inuse.cfg
34
35#
36# DESCRIPTION:
37# ZFS will not interfere with devices that are in use by SVM
38#
39# STRATEGY:
40# 1. Create SVM device d99 with a disk
41# 2. Try to create a ZFS pool with same disk
42# 3. Try a use the same disk as a spare device
43#
44
45verify_runnable "global"
46
47function cleanup
48{
49	poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1
50
51	poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2
52
53	$METASTAT d99 > /dev/null 2>&1
54	(( $? == 0 )) && $METACLEAR -f d99
55
56	typeset metadb=""
57	typeset i=""
58
59	metadb=`$METADB | $CUT -f6 | $GREP dev | $UNIQ`
60	for i in $metadb; do
61		$METADB -fd $i > /dev/null 2>&1
62	done
63
64	#
65	# Tidy up the disks we used.
66	#
67	cleanup_devices $vdisks $sdisks
68}
69
70log_assert "Ensure ZFS does not interfere with devices in use by SVM"
71
72log_onexit cleanup
73
74for num in 0 1 2; do
75	eval typeset slice=\${FS_SIDE$num}
76	disk=${slice%s*}
77	slice=${slice##*s}
78	if [[ $WRAPPER == *"smi"* && \
79		$disk == ${saved_disk} ]]; then
80		cyl=$(get_endslice $disk ${saved_slice})
81		log_must set_partition $slice "$cyl" $FS_SIZE $disk
82	else
83		log_must set_partition $slice "" $FS_SIZE $disk
84	fi
85	saved_disk=$disk
86	saved_slice=$slice
87done
88
89log_note "Configuring metadb with $FS_SIDE1"
90log_must $METADB -a -f -c 3 $FS_SIDE1
91
92log_note "Configure d99 with $FS_SIDE0"
93log_must $METAINIT d99 1 1 $FS_SIDE0
94
95log_note "Attempt to zpool the device in use by SVM"
96log_mustnot $ZPOOL create $TESTPOOL1 $FS_SIDE0
97log_mustnot poolexists $TESTPOOL1
98
99log_note "Attempt to take device in use by SVM as spare device"
100log_mustnot $ZPOOL create $TESTPOOL1 $FS_SIDE2 spare $FS_SIDE0
101log_mustnot poolexists $TESTPOOL1
102
103log_note "Attempt to zpool a metadb device in use by SVM"
104log_mustnot $ZPOOL create $TESTPOOL2 $FS_SIDE1
105log_mustnot poolexists $TESTPOOL2
106
107log_note "Attempt to take device in use by SVM as spare device"
108log_mustnot $ZPOOL create $TESTPOOL2 $FS_SIDE2 spare $FS_SIDE1
109log_mustnot poolexists $TESTPOOL2
110
111log_pass "Unable to zpool a device in use by SVM"
112