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) 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 106 typeset value 107 108 item=$(echo $line | awk '{print $2}' 2>&1) 109 if [[ $item == $p ]]; then 110 ((found += 1)) 111 cols=$(echo $line | awk '{print NF}') 112 fi 113 114 value=$(echo $line | awk '{print $3}' 2>&1) 115 if [[ $value == $uint64_max ]]; then 116 log_fail "'zfs get $opt $props $dst' return " \ 117 "UINT64_MAX constant." 118 fi 119 120 if ((found > 0)); then 121 break 122 fi 123 done < $TESTDIR/$TESTFILE0 124 125 if ((found == 0)); then 126 log_fail "'zfs get $opt $props $dst' return " \ 127 "error message.'$p' haven't been found." 128 elif [[ "$opt" == "-p" ]] && ((cols != 4)); then 129 log_fail "'zfs get $opt $props $dst' returned " \ 130 "$cols columns instead of 4." 131 fi 132 done 133 134 log_note "SUCCESS: 'zfs get $opt $prop $dst'." 135} 136 137log_assert "Setting the valid options and properties 'zfs get' should return " \ 138 "the correct property value." 139log_onexit cleanup 140 141# Create filesystem and volume's snapshot 142create_snapshot $TESTPOOL/$TESTFS $TESTSNAP 143create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP 144 145# Create second snapshot and clone it 146create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 147create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE 148 149# Create filesystem and volume's bookmark 150create_bookmark $TESTPOOL/$TESTFS $TESTSNAP $TESTBKMARK 151create_bookmark $TESTPOOL/$TESTVOL $TESTSNAP $TESTBKMARK 152 153typeset -i i=0 154while ((i < ${#dataset[@]})); do 155 for opt in "${options[@]}"; do 156 for prop in ${all_props[@]}; do 157 log_must eval "zfs get $opt $prop ${dataset[i]} > $TESTDIR/$TESTFILE0" 158 check_return_value ${dataset[i]} "$prop" "$opt" 159 done 160 done 161 ((i += 1)) 162done 163 164i=0 165while ((i < ${#bookmark[@]})); do 166 for opt in "${options[@]}"; do 167 for prop in ${bookmark_props[@]}; do 168 log_must eval "zfs get $opt $prop ${bookmark[i]} > $TESTDIR/$TESTFILE0" 169 check_return_value ${bookmark[i]} "$prop" "$opt" 170 done 171 done 172 ((i += 1)) 173done 174 175log_pass "Setting the valid options to dataset, it should succeed and return " \ 176 "valid value. 'zfs get' pass." 177