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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29#ident	"@(#)snapdir_001_pos.ksh	1.2	07/01/09 SMI"
30#
31
32. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib
33
34###############################################################################
35#
36# __stc_assertion_start
37#
38# ID: snapdir_001_pos
39#
40# DESCRIPTION:
41# Setting a valid snapdir on a dataset, it should be successful.
42#
43# STRATEGY:
44# 1. Create pool, then create filesystem and volume within it.
45# 2. Create a snapshot for each dataset.
46# 3. Setting different valid snapdir to each dataset.
47# 4. Check the return value and make sure it is 0.
48# 5. Verify .zfs directory is hidden|visible according to the snapdir setting.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2006-02-17)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "both"
61
62function cleanup
63{
64	for dataset in $all_datasets; do
65		snapexists ${dataset}@snap && \
66			log_must $ZFS destroy ${dataset}@snap
67	done
68}
69
70function verify_snapdir_visible # $1 dataset, $2 hidden|visible
71{
72	typeset dataset=$1
73	typeset value=$2
74	typeset mtpt=$(get_prop mountpoint $dataset)
75	typeset name
76
77	CTLDIR=".zfs"
78
79	for name in `$LS -a $mtpt`; do
80		if [[ $name == $CTLDIR ]]; then
81			if [[ $value == "visible" ]]; then
82				return 0
83			else
84				return 1
85			fi
86		fi
87	done
88
89	if [[ $value == "visible" ]]; then
90		return 1
91	else
92		return 0
93	fi
94}
95
96
97typeset all_datasets
98
99if is_global_zone ; then
100	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL"
101else
102	all_datasets="$TESTPOOL $TESTPOOL/$TESTFS"
103fi
104
105log_onexit cleanup
106
107for dataset in $all_datasets; do
108	log_must $ZFS snapshot ${dataset}@snap
109done
110
111log_assert "Setting a valid snapdir property on a dataset succeeds."
112
113for dataset in $all_datasets; do
114	for value in hidden visible; do
115		if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then
116			set_n_check_prop "$value" "snapdir" \
117				"$dataset" "false"
118		else
119			set_n_check_prop "$value" "snapdir" \
120				"$dataset"
121			verify_snapdir_visible $dataset $value
122			[[ $? -eq 0 ]] || \
123				log_fail "$dataset/.zfs is not $value as expect."
124		fi
125	done
126done
127
128log_pass "Setting a valid snapdir property on a dataset succeeds."
129