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