1#!/usr/local/bin/ksh93 -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. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
28
29###############################################################################
30#
31# __stc_assertion_start
32#
33# ID: snapdir_001_pos
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# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2006-02-17)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57function cleanup
58{
59	for dataset in $all_datasets; do
60		snapexists ${dataset}@snap && \
61			log_must $ZFS destroy ${dataset}@snap
62	done
63}
64
65function verify_snapdir_visible # $1 dataset, $2 hidden|visible
66{
67	typeset dataset=$1
68	typeset value=$2
69	typeset mtpt=$(get_prop mountpoint $dataset)
70	typeset name
71
72	CTLDIR=".zfs"
73
74	for name in `$LS -a $mtpt`; do
75		if [[ $name == $CTLDIR ]]; then
76			if [[ $value == "visible" ]]; then
77				return 0
78			else
79				return 1
80			fi
81		fi
82	done
83
84	if [[ $value == "visible" ]]; then
85		return 1
86	else
87		return 0
88	fi
89}
90
91
92typeset all_datasets
93
94if is_global_zone ; then
95	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL"
96else
97	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS"
98fi
99
100log_onexit cleanup
101
102for dataset in $all_datasets; do
103	log_must $ZFS snapshot ${dataset}@snap
104done
105
106log_assert "Setting a valid snapdir property on a dataset succeeds."
107
108for dataset in $all_datasets; do
109	for value in hidden visible; do
110		if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then
111			set_n_check_prop "$value" "snapdir" \
112				"$dataset" "false"
113		else
114			set_n_check_prop "$value" "snapdir" \
115				"$dataset"
116			verify_snapdir_visible $dataset $value
117			[[ $? -eq 0 ]] || \
118				log_fail "$dataset/.zfs is not $value as expect."
119		fi
120	done
121done
122
123log_pass "Setting a valid snapdir property on a dataset succeeds."
124