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