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