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 2008 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_upgrade/zfs_upgrade.kshlib
34
35#
36# DESCRIPTION:
37# Valid version values should be positive integers only.
38#
39# STRATEGY:
40# 1) Form an array of invalid reservation values (negative and
41# incorrectly formed)
42# 2) Attempt to set each invalid version value in turn on a
43# filesystem and volume.
44# 3) Verify that attempt fails and the version value remains
45# unchanged
46#
47
48verify_runnable "both"
49
50log_assert "Verify invalid version values are rejected"
51
52typeset values=('' '-1' '-1.0' '-1.8' '-9999999999999999' \
53	'0x1' '0b' '1b' '1.1b' '0' '0.000' '1.234')
54
55#
56# Function to loop through a series of bad reservation
57# values, checking they are when we attempt to set them
58# on a dataset.
59#
60function set_n_check # data-set
61{
62	typeset obj=$1
63	typeset -i i=0
64	typeset -i j=0
65
66	orig_val=$(get_prop version $obj)
67
68	while (($i < ${#values[*]})); do
69		zfs set version=${values[$i]} $obj  > /dev/null 2>&1
70		if [[ $? -eq 0 ]]; then
71			log_note "zfs set version=${values[$i]} $obj"
72			log_fail "The above version set returned 0!"
73		fi
74
75		new_val=$(get_prop version $obj)
76
77		if [[ $new_val != $orig_val ]]; then
78			log_fail "$obj : version values changed " \
79				"($orig_val : $new_val)"
80		fi
81
82		((i = i + 1))
83	done
84}
85
86for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL
87do
88	set_n_check $dataset
89done
90
91log_pass "Invalid version values correctly rejected"
92