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 && \ 52 log_must zfs destroy ${dataset}@snap 53 done 54} 55 56function verify_snapdir_visible # $1 dataset, $2 hidden|visible 57{ 58 typeset dataset=$1 59 typeset value=$2 60 typeset mtpt=$(get_prop mountpoint $dataset) 61 typeset name 62 63 for name in `ls -a $mtpt`; do 64 if [[ $name == ".zfs" ]]; then 65 if [[ $value == "visible" ]]; then 66 return 0 67 else 68 return 1 69 fi 70 fi 71 done 72 73 if [[ $value == "visible" ]]; then 74 return 1 75 else 76 return 0 77 fi 78} 79 80 81typeset all_datasets 82 83if is_global_zone ; then 84 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL" 85else 86 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS" 87fi 88 89log_onexit cleanup 90 91for dataset in $all_datasets; do 92 log_must zfs snapshot ${dataset}@snap 93done 94 95log_assert "Setting a valid snapdir property on a dataset succeeds." 96 97for dataset in $all_datasets; do 98 for value in hidden visible; do 99 if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then 100 set_n_check_prop "$value" "snapdir" \ 101 "$dataset" "false" 102 else 103 set_n_check_prop "$value" "snapdir" \ 104 "$dataset" 105 verify_snapdir_visible $dataset $value 106 [[ $? -eq 0 ]] || \ 107 log_fail "$dataset/.zfs is not $value as expect." 108 fi 109 done 110done 111 112log_pass "Setting a valid snapdir property on a dataset succeeds." 113