1#!/usr/local/bin/ksh93 -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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)zfs_snapshot_007_neg.ksh	1.1	09/05/19 SMI"
28#
29
30. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
31
32#################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfs_snapshot_007_pos
37#
38# DESCRIPTION:
39#	'zfs snapshot -o' cannot set properties other than user property
40#
41# STRATEGY:
42#	1. Create snapshot and give '-o property=value' with regular property.
43#	2. Verify the snapshot creation failed.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2009-04-27)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57function cleanup
58{
59	for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
60		typeset fssnap=$fs@snap
61		if datasetexists $fssnap ; then
62			log_must $ZFS destroy -rf $fssnap
63		fi
64	done
65	cleanup_user_prop $TESTPOOL
66}
67
68function nonexist_user_prop
69{
70	typeset user_prop=$1
71	typeset dtst=$2
72
73	typeset source=$(get_source $user_prop $dtst)
74	typeset value=$(get_prop $user_prop $dtst)
75	if [[ $source == '-' && $value == '-' ]]; then
76		return 0
77	else
78		return 1
79	fi
80}
81
82log_assert "'zfs snapshot -o' cannot set properties other than user property."
83log_onexit cleanup
84
85typeset ro_props="type used available avail creation referenced refer compressratio \
86	mounted origin"
87typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \
88	sharenfs checksum compression compress atime devices exec readonly rdonly \
89	setuid zoned"
90
91$ZFS upgrade -v > /dev/null 2>&1
92if [[ $? -eq 0 ]]; then
93	snap_ro_props="$snap_ro_props version"
94fi
95
96
97for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
98	typeset fssnap=$fs@snap
99	prop_name=$(valid_user_property 10)
100	value=$(user_property_value 16)
101
102	log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap"
103	log_must snapexists $fssnap
104	log_mustnot nonexist_user_prop $prop_name $fssnap
105
106	log_must $ZFS destroy -f $fssnap
107
108	prop_name2=$(valid_user_property 10)
109	value2=$(user_property_value 16)
110
111	log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap"
112	log_must snapexists $fssnap
113	log_mustnot nonexist_user_prop $prop_name $fssnap
114	log_mustnot nonexist_user_prop $prop_name2 $fssnap
115
116	log_must $ZFS destroy -f $fssnap
117done
118
119cleanup
120
121prop_name=$(valid_user_property 10)
122value=$(user_property_value 16)
123
124log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap"
125for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
126	typeset fssnap=$fs@snap
127	log_must snapexists $fssnap
128	log_mustnot nonexist_user_prop $prop_name $fssnap
129done
130
131cleanup
132
133prop_name2=$(valid_user_property 10)
134value2=$(user_property_value 16)
135
136log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap"
137for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do
138	typeset fssnap=$fs@snap
139	log_must snapexists $fssnap
140	log_mustnot nonexist_user_prop $prop_name $fssnap
141	log_mustnot nonexist_user_prop $prop_name2 $fssnap
142done
143
144log_pass "'zfs snapshot -o' cannot set properties other than user property."
145