1# vim: filetype=sh 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. $STF_SUITE/include/libtest.kshlib 28. $STF_SUITE/tests/userquota/userquota.cfg 29 30 31# 32# Check if the test box support userquota or not. 33# 34function is_userquota_supported 35{ 36 if ! fs_prop_exist "userquota@..."; then 37 return 1 38 fi 39 40 return 0 41} 42 43# 44# reset the userquota and groupquota and delete temporary files 45# 46function cleanup_quota 47{ 48 if datasetexists $QFS; then 49 log_must $ZFS set userquota@$QUSER1=none $QFS 50 log_must $ZFS set userquota@$QUSER2=none $QFS 51 log_must $ZFS set groupquota@$QGROUP=none $QFS 52 recovery_writable $QFS 53 fi 54 55 [[ -f $QFILE ]] && log_must $RM -f $QFILE 56 [[ -f $OFILE ]] && log_must $RM -f $OFILE 57 58 return 0 59} 60 61# 62# delete user and group that created during the test 63# 64function clean_user_group 65{ 66 for usr in $QUSER1 $QUSER2; do 67 log_must del_user $usr 68 done 69 70 log_must del_group $QGROUP 71 72 return 0 73} 74 75# 76# make the $QFS's mountpoint writable for all users 77# 78function mkmount_writable 79{ 80 typeset fs=$1 81 typeset mntp=$(get_prop mountpoint $fs) 82 log_must $CHMOD 0777 $mntp 83} 84 85# 86# recovery the directory permission for $QFS 87# 88function recovery_writable 89{ 90 typeset fs=$1 91 typeset mntp=$(get_prop mountpoint $fs) 92 log_must $CHMOD 0755 $mntp 93} 94 95# 96# run command as specific user 97# 98function user_run 99{ 100 typeset user=$1 101 typeset group=$($GROUPS $user) 102 103 shift 104 105 eval \$RUNWATTR -u \$user -g \$group \"$@\" > /dev/null 2>&1 106 return $? 107} 108 109# 110# check the quota value of a specific FS 111# 112function check_quota 113{ 114 typeset fs=$2 115 typeset prop=$1 116 typeset expected=$3 117 typeset value=$(get_prop $prop $fs) 118 119 if (( $value != $expected )); then 120 return 1 121 fi 122} 123 124# 125# zfs get prop, which return raw value not -p value. 126# 127function get_value # property dataset 128{ 129 typeset prop_val 130 typeset prop=$1 131 typeset dataset=$2 132 133 prop_val=$($ZFS get -H -o value $prop $dataset 2>/dev/null) 134 if [[ $? -ne 0 ]]; then 135 log_note "Unable to get $prop property for dataset " \ 136 "$dataset" 137 return 1 138 fi 139 140 $ECHO $prop_val 141 return 0 142} 143