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 https://opensource.org/licenses/CDDL-1.0. 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) 2016 by Delphix. All rights reserved. 30# Copyright (c) 2021 Matt Fiddaman 31# 32 33. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_common.kshlib 34. $STF_SUITE/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib 35 36# 37# DESCRIPTION: 38# Setting the valid option and properties, 'zfs get' should return the 39# correct property value. 40# 41# STRATEGY: 42# 1. Create pool, filesystem, volume, snapshot, and bookmark. 43# 2. Setting valid parameter, 'zfs get' should succeed. 44# 3. Compare the output property name with the original input property. 45# 46 47verify_runnable "both" 48 49typeset options=("" "-p" "-r" "-H") 50 51typeset -i i=${#options[*]} 52typeset -i j=0 53while ((j<${#depth_options[*]})); 54do 55 options[$i]=-"${depth_options[$j]}" 56 ((j+=1)) 57 ((i+=1)) 58done 59 60typeset -r uint64_max="18446744073709551615" 61 62typeset zfs_props=("type" used available creation volsize referenced \ 63 compressratio mounted origin recordsize quota reservation mountpoint \ 64 sharenfs checksum compression atime devices exec readonly setuid \ 65 snapdir aclinherit canmount primarycache secondarycache version \ 66 usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ 67 filesystem_limit snapshot_limit filesystem_count snapshot_count) 68if is_freebsd; then 69 typeset zfs_props_os=(jailed aclmode) 70else 71 typeset zfs_props_os=(zoned acltype) 72fi 73typeset userquota_props=(userquota@root groupquota@root userused@root \ 74 groupused@root) 75typeset all_props=("${zfs_props[@]}" \ 76 "${zfs_props_os[@]}" \ 77 "${userquota_props[@]}") 78typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ 79 $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP 80 $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE) 81 82typeset bookmark_props=(creation) 83typeset bookmark=($TESTPOOL/$TESTFS#$TESTBKMARK $TESTPOOL/$TESTVOL#$TESTBKMARK) 84 85# 86# According to dataset and option, checking if 'zfs get' return correct 87# property information. 88# 89# $1 dataset 90# $2 properties which are expected to output into $TESTDIR/$TESTFILE0 91# $3 option 92# 93function check_return_value 94{ 95 typeset dst=$1 96 typeset props=$2 97 typeset opt=$3 98 typeset -i found=0 99 typeset p 100 101 for p in $props; do 102 found=0 103 104 while read line; do 105 typeset item value _ 106 107 read -r _ item _ <<<"$line" 108 if [[ $item == $p ]]; then 109 ((found += 1)) 110 cols=$(echo $line | awk '{print NF}') 111 fi 112 113 read -r _ _ value _ <<<"$line" 114 if [[ $value == $uint64_max ]]; then 115 log_fail "'zfs get $opt $props $dst' return " \ 116 "UINT64_MAX constant." 117 fi 118 119 if ((found > 0)); then 120 break 121 fi 122 done < $TESTDIR/$TESTFILE0 123 124 if ((found == 0)); then 125 log_fail "'zfs get $opt $props $dst' return " \ 126 "error message.'$p' haven't been found." 127 elif [[ "$opt" == "-p" ]] && ((cols != 4)); then 128 log_fail "'zfs get $opt $props $dst' returned " \ 129 "$cols columns instead of 4." 130 fi 131 done 132 133 log_note "SUCCESS: 'zfs get $opt $prop $dst'." 134} 135 136log_assert "Setting the valid options and properties 'zfs get' should return " \ 137 "the correct property value." 138log_onexit cleanup 139 140# Create filesystem and volume's snapshot 141create_snapshot $TESTPOOL/$TESTFS $TESTSNAP 142create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP 143 144# Create second snapshot and clone it 145create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 146create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE 147 148# Create filesystem and volume's bookmark 149create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK 150create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK 151 152typeset -i i=0 153while ((i < ${#dataset[@]})); do 154 for opt in "${options[@]}"; do 155 for prop in ${all_props[@]}; do 156 log_must eval "zfs get $opt $prop ${dataset[i]} > $TESTDIR/$TESTFILE0" 157 check_return_value ${dataset[i]} "$prop" "$opt" 158 done 159 done 160 ((i += 1)) 161done 162 163i=0 164while ((i < ${#bookmark[@]})); do 165 for opt in "${options[@]}"; do 166 for prop in ${bookmark_props[@]}; do 167 log_must eval "zfs get $opt $prop ${bookmark[i]} > $TESTDIR/$TESTFILE0" 168 check_return_value ${bookmark[i]} "$prop" "$opt" 169 done 170 done 171 ((i += 1)) 172done 173 174log_pass "Setting the valid options to dataset, it should succeed and return " \ 175 "valid value. 'zfs get' pass." 176