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 2009 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2012, 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# User property could be set via creation time by 'zfs snapshot -o' 37# 38# STRATEGY: 39# 1. Create snapshot and give '-o property=value' 40# 2. Verify the snapshot be created and user property have been set. 41# 42 43verify_runnable "both" 44 45function cleanup 46{ 47 for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do 48 typeset fssnap=$fs@snap 49 if datasetexists $fssnap ; then 50 log_must zfs destroy -rf $fssnap 51 fi 52 done 53 cleanup_user_prop $TESTPOOL 54} 55 56function nonexist_user_prop 57{ 58 typeset user_prop=$1 59 typeset dtst=$2 60 61 typeset source=$(get_source $user_prop $dtst) 62 typeset value=$(get_prop $user_prop $dtst) 63 if [[ $source == '-' && $value == '-' ]]; then 64 return 0 65 else 66 return 1 67 fi 68} 69 70log_assert "User property could be set upon snapshot via 'zfs snapshot -o'." 71log_onexit cleanup 72 73typeset snap_property= 74 75for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do 76 typeset fssnap=$fs@snap 77 prop_name=$(valid_user_property 10) 78 value=$(user_property_value 16) 79 80 log_must eval "zfs snapshot -o $prop_name='$value' $fssnap" 81 log_must snapexists $fssnap 82 log_mustnot nonexist_user_prop $prop_name $fssnap 83 84 log_must zfs destroy -f $fssnap 85 86 prop_name2=$(valid_user_property 10) 87 value2=$(user_property_value 16) 88 89 log_must eval "zfs snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap" 90 log_must snapexists $fssnap 91 log_mustnot nonexist_user_prop $prop_name $fssnap 92 log_mustnot nonexist_user_prop $prop_name2 $fssnap 93done 94 95cleanup 96 97prop_name=$(valid_user_property 10) 98value=$(user_property_value 16) 99 100log_must eval "zfs snapshot -r -o $prop_name='$value' $TESTPOOL@snap" 101for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do 102 typeset fssnap=$fs@snap 103 log_must snapexists $fssnap 104 log_mustnot nonexist_user_prop $prop_name $fssnap 105 106 log_must zfs destroy -rf $fssnap 107done 108 109cleanup 110 111prop_name2=$(valid_user_property 10) 112value2=$(user_property_value 16) 113 114log_must eval "zfs snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap" 115for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do 116 typeset fssnap=$fs@snap 117 log_must snapexists $fssnap 118 log_mustnot nonexist_user_prop $prop_name $fssnap 119 log_mustnot nonexist_user_prop $prop_name2 $fssnap 120 121 log_must zfs destroy -rf $fssnap 122done 123 124log_pass "User property could be set upon snapshot via 'zfs snapshot -o'." 125