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
61	# $mtpt/.zfs always actually exists so [ -d $mtpt/.zfs ] is always true
62	if ls -a $mtpt | grep -xFq .zfs; then
63		[ $value = "visible" ]
64	else
65		[ $value != "visible" ]
66	fi
67}
68
69
70typeset all_datasets
71
72if is_global_zone ; then
73	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL"
74else
75	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS"
76fi
77
78log_onexit cleanup
79
80for dataset in $all_datasets; do
81	log_must zfs snapshot ${dataset}@snap
82done
83
84log_assert "Setting a valid snapdir property on a dataset succeeds."
85
86for dataset in $all_datasets; do
87	for value in hidden visible; do
88		if [ "$dataset" = "$TESTPOOL/$TESTVOL" ]; then
89			set_n_check_prop "$value" "snapdir" \
90				"$dataset" "false"
91		else
92			set_n_check_prop "$value" "snapdir" \
93				"$dataset"
94			verify_snapdir_visible $dataset $value ||
95				log_fail "$dataset/.zfs is not $value as expected."
96		fi
97	done
98done
99
100log_pass "Setting a valid snapdir property on a dataset succeeds."
101