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 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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib
34
35#
36# DESCRIPTION:
37#	Verify "copies" property can be correctly set as 1,2 and 3 and different
38#	filesystem can have different value of "copies" property within the same pool.
39#
40# STRATEGY:
41#	1. Create different filesystems with copies set as 1,2,3;
42#	2. Verify that the "copies" property has been set correctly
43#
44
45verify_runnable "both"
46
47function cleanup
48{
49	typeset ds
50
51	for ds in $fs1 $fs2 $vol1 $vol2; do
52		if datasetexists $ds; then
53			log_must zfs destroy $ds
54		fi
55	done
56}
57
58log_assert "Verify 'copies' property with correct arguments works or not."
59log_onexit cleanup
60
61fs=$TESTPOOL/$TESTFS
62fs1=$TESTPOOL/$TESTFS1
63fs2=$TESTPOOL/$TESTFS2
64vol=$TESTPOOL/$TESTVOL
65vol1=$TESTPOOL/$TESTVOL1
66vol2=$TESTPOOL/$TESTVOL2
67
68#
69# Check the default value for copies property
70#
71for ds in $fs $vol; do
72	cmp_prop $ds 1
73done
74
75for val in 1 2 3; do
76	log_must zfs create -o copies=$val $fs1
77	if is_global_zone; then
78		log_must zfs create -V $VOLSIZE -o copies=$val $vol1
79		block_device_wait
80	else
81		log_must zfs create -o copies=$val $vol1
82	fi
83	for ds in $fs1 $vol1; do
84		cmp_prop $ds $val
85	done
86
87	for val2 in 3 2 1; do
88		log_must zfs create -o copies=$val2 $fs2
89		if is_global_zone; then
90			log_must zfs create -V $VOLSIZE -o copies=$val2 $vol2
91			block_device_wait
92		else
93			log_must zfs create -o copies=$val2 $vol2
94		fi
95		for ds in $fs2 $vol2; do
96			cmp_prop $ds $val2
97			log_must zfs destroy $ds
98			block_device_wait
99		done
100	done
101
102	for ds in $fs1 $vol1; do
103		log_must zfs destroy $ds
104		block_device_wait
105	done
106
107done
108
109for val in 3 2 1; do
110	for ds in $fs $vol; do
111		log_must zfs set copies=$val $ds
112		cmp_prop $ds $val
113	done
114done
115
116log_pass "'copies' property with correct arguments works as expected. "
117