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/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
33
34#
35# DESCRIPTION:
36# Setting a valid snapdir on a dataset, it should be successful.
37#
38# STRATEGY:
39# 1. Create pool, then create filesystem and volume within it.
40# 2. Create a snapshot for each dataset.
41# 3. Setting different valid snapdir to each dataset.
42# 4. Check the return value and make sure it is 0.
43# 5. Verify .zfs directory is hidden|visible according to the snapdir setting.
44#
45
46verify_runnable "both"
47
48function cleanup
49{
50	for dataset in $all_datasets; do
51		snapexists ${dataset}@snap && destroy_dataset ${dataset}@snap
52	done
53}
54
55function verify_snapdir_visible # $1 dataset, $2 hidden|visible
56{
57	typeset dataset=$1
58	typeset value=$2
59	typeset mtpt=$(get_prop mountpoint $dataset)
60	typeset name
61
62	for name in `ls -a $mtpt`; do
63		if [[ $name == ".zfs" ]]; then
64			if [[ $value == "visible" ]]; then
65				return 0
66			else
67				return 1
68			fi
69		fi
70	done
71
72	if [[ $value == "visible" ]]; then
73		return 1
74	else
75		return 0
76	fi
77}
78
79
80typeset all_datasets
81
82if is_global_zone ; then
83	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL"
84else
85	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS"
86fi
87
88log_onexit cleanup
89
90for dataset in $all_datasets; do
91	log_must zfs snapshot ${dataset}@snap
92done
93
94log_assert "Setting a valid snapdir property on a dataset succeeds."
95
96for dataset in $all_datasets; do
97	for value in hidden visible; do
98		if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then
99			set_n_check_prop "$value" "snapdir" \
100				"$dataset" "false"
101		else
102			set_n_check_prop "$value" "snapdir" \
103				"$dataset"
104			verify_snapdir_visible $dataset $value
105			[[ $? -eq 0 ]] || \
106				log_fail "$dataset/.zfs is not $value as expect."
107		fi
108	done
109done
110
111log_pass "Setting a valid snapdir property on a dataset succeeds."
112