1f38cb554SJohn Wren Kennedy# 2f38cb554SJohn Wren Kennedy# CDDL HEADER START 3f38cb554SJohn Wren Kennedy# 4f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 5f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 6f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 7f38cb554SJohn Wren Kennedy# 8f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 10f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 11f38cb554SJohn Wren Kennedy# and limitations under the License. 12f38cb554SJohn Wren Kennedy# 13f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 14f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 16f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 17f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 18f38cb554SJohn Wren Kennedy# 19f38cb554SJohn Wren Kennedy# CDDL HEADER END 20f38cb554SJohn Wren Kennedy# 21f38cb554SJohn Wren Kennedy 22f38cb554SJohn Wren Kennedy# 23f38cb554SJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24f38cb554SJohn Wren Kennedy# Use is subject to license terms. 25f38cb554SJohn Wren Kennedy# 26f38cb554SJohn Wren Kennedy 27f38cb554SJohn Wren Kennedy# 281d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 29f67950b2SNasf-Fan# Copyright 2019 Joyent, Inc. 30f38cb554SJohn Wren Kennedy# 31f38cb554SJohn Wren Kennedy 32f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 33f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/userquota/userquota.cfg 34f38cb554SJohn Wren Kennedy 35f38cb554SJohn Wren Kennedy# 36f38cb554SJohn Wren Kennedy# reset the userquota and groupquota and delete temporary files 37f38cb554SJohn Wren Kennedy# 38f38cb554SJohn Wren Kennedyfunction cleanup_quota 39f38cb554SJohn Wren Kennedy{ 40f38cb554SJohn Wren Kennedy if datasetexists $QFS; then 411d32ba66SJohn Wren Kennedy log_must zfs set userquota@$QUSER1=none $QFS 42f67950b2SNasf-Fan log_must zfs set userobjquota@$QUSER1=none $QFS 431d32ba66SJohn Wren Kennedy log_must zfs set userquota@$QUSER2=none $QFS 44f67950b2SNasf-Fan log_must zfs set userobjquota@$QUSER2=none $QFS 451d32ba66SJohn Wren Kennedy log_must zfs set groupquota@$QGROUP=none $QFS 46f67950b2SNasf-Fan log_must zfs set groupobjquota@$QGROUP=none $QFS 47f38cb554SJohn Wren Kennedy recovery_writable $QFS 48f38cb554SJohn Wren Kennedy fi 49f38cb554SJohn Wren Kennedy 501d32ba66SJohn Wren Kennedy [[ -f $QFILE ]] && log_must rm -f $QFILE 511d32ba66SJohn Wren Kennedy [[ -f $OFILE ]] && log_must rm -f $OFILE 5209fbbb7dSAllan Jude sync_all_pools 53f38cb554SJohn Wren Kennedy 54f67950b2SNasf-Fan return 0 55f38cb554SJohn Wren Kennedy} 56f38cb554SJohn Wren Kennedy 57f38cb554SJohn Wren Kennedy# 58f38cb554SJohn Wren Kennedy# delete user and group that created during the test 59f38cb554SJohn Wren Kennedy# 60f38cb554SJohn Wren Kennedyfunction clean_user_group 61f38cb554SJohn Wren Kennedy{ 62f38cb554SJohn Wren Kennedy for usr in $QUSER1 $QUSER2; do 63f38cb554SJohn Wren Kennedy log_must del_user $usr 64f38cb554SJohn Wren Kennedy done 65f38cb554SJohn Wren Kennedy 66f38cb554SJohn Wren Kennedy log_must del_group $QGROUP 67f38cb554SJohn Wren Kennedy 68f38cb554SJohn Wren Kennedy return 0 69f38cb554SJohn Wren Kennedy} 70f38cb554SJohn Wren Kennedy 71f38cb554SJohn Wren Kennedy# 72f38cb554SJohn Wren Kennedy# make the $QFS's mountpoint writable for all users 73f38cb554SJohn Wren Kennedy# 74f38cb554SJohn Wren Kennedyfunction mkmount_writable 75f38cb554SJohn Wren Kennedy{ 76f38cb554SJohn Wren Kennedy typeset fs=$1 77f38cb554SJohn Wren Kennedy typeset mntp=$(get_prop mountpoint $fs) 781d32ba66SJohn Wren Kennedy log_must chmod 0777 $mntp 79f38cb554SJohn Wren Kennedy} 80f38cb554SJohn Wren Kennedy 81f38cb554SJohn Wren Kennedy# 82f38cb554SJohn Wren Kennedy# recovery the directory permission for $QFS 83f38cb554SJohn Wren Kennedy# 84f38cb554SJohn Wren Kennedyfunction recovery_writable 85f38cb554SJohn Wren Kennedy{ 86f38cb554SJohn Wren Kennedy typeset fs=$1 87f38cb554SJohn Wren Kennedy typeset mntp=$(get_prop mountpoint $fs) 881d32ba66SJohn Wren Kennedy log_must chmod 0755 $mntp 89f38cb554SJohn Wren Kennedy} 90f38cb554SJohn Wren Kennedy 91f38cb554SJohn Wren Kennedy# 92f38cb554SJohn Wren Kennedy# check the quota value of a specific FS 93f38cb554SJohn Wren Kennedy# 94f38cb554SJohn Wren Kennedyfunction check_quota 95f38cb554SJohn Wren Kennedy{ 96f38cb554SJohn Wren Kennedy typeset fs=$2 97f38cb554SJohn Wren Kennedy typeset prop=$1 98f38cb554SJohn Wren Kennedy typeset expected=$3 99f38cb554SJohn Wren Kennedy typeset value=$(get_prop $prop $fs) 100f38cb554SJohn Wren Kennedy 101f38cb554SJohn Wren Kennedy if (($value != $expected)); then 102f38cb554SJohn Wren Kennedy return 1 103f38cb554SJohn Wren Kennedy fi 104f38cb554SJohn Wren Kennedy} 105f38cb554SJohn Wren Kennedy 106f38cb554SJohn Wren Kennedy# 107f38cb554SJohn Wren Kennedy# zfs get prop, which return raw value not -p value. 108f38cb554SJohn Wren Kennedy# 109f38cb554SJohn Wren Kennedyfunction get_value # property dataset 110f38cb554SJohn Wren Kennedy{ 111f38cb554SJohn Wren Kennedy typeset prop_val 112f38cb554SJohn Wren Kennedy typeset prop=$1 113f38cb554SJohn Wren Kennedy typeset dataset=$2 114f38cb554SJohn Wren Kennedy 115*6520eed5SToomas Soome prop_val=$(zfs get -H -p -o value $prop $dataset 2>/dev/null) 116f38cb554SJohn Wren Kennedy if [[ $? -ne 0 ]]; then 117f38cb554SJohn Wren Kennedy log_note "Unable to get $prop property for dataset " \ 118f38cb554SJohn Wren Kennedy "$dataset" 119f38cb554SJohn Wren Kennedy return 1 120f38cb554SJohn Wren Kennedy fi 121f38cb554SJohn Wren Kennedy 1221d32ba66SJohn Wren Kennedy echo $prop_val 123f38cb554SJohn Wren Kennedy return 0 124f38cb554SJohn Wren Kennedy} 125