1# $NetBSD: t_rquotad.sh,v 1.10 2023/05/28 08:17:00 hannken Exp $ 2# 3# Copyright (c) 2011 Manuel Bouyer 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28# Like test_case_root() in ../ffs/ffs_common.sh, plus cleanup of both 29# rump servers. 30 31test_case_rquotad() 32{ 33 local name="${1}"; shift 34 local check_function="${1}"; shift 35 local descr="${1}"; shift 36 37 atf_test_case "${name}" cleanup 38 39 eval "${name}_head() { \ 40 atf_set "descr" "${descr}" 41 atf_set "require.user" "root" 42 atf_set "timeout" "360" 43 }" 44 eval "${name}_body() { \ 45 RUMP_SOCKETS_LIST=\${RUMP_SOCKET}; \ 46 export RUMP_SERVER=unix://\${RUMP_SOCKET}; \ 47 ${check_function} " "${@}" "; \ 48 }" 49 # Can't use RUMP_SOCKETS_LIST here because it is not set in 50 # the cleanup shell. 51 eval "${name}_cleanup() { \ 52 for s in \${RUMP_SOCKET} clientsock; do \ 53 RUMP_SERVER=unix://\${s} rump.halt 2>/dev/null || true; \ 54 done; \ 55 }" 56 tests="${tests} ${name}" 57} 58 59for e in le be; do 60 for v in 1; do 61 for q in "user" "group" "both"; do 62 test_case_rquotad get_nfs_${e}_${v}_${q} get_nfs_quota \ 63 "get NFS quota with ${q} enabled" ${e} ${v} ${q} 64 done 65 done 66done 67 68get_nfs_quota() 69{ 70 create_ffs $* 71 local q=$3 72 local expect 73 74 case ${q} in 75 user) 76 expect=u 77 ;; 78 group) 79 expect=g 80 ;; 81 both) 82 expect="u g" 83 ;; 84 *) 85 atf_fail "wrong quota type" 86 ;; 87 esac 88 89#start a nfs server 90 91 atf_check -s exit:0 rump_server -lrumpvfs -lrumpdev -lrumpnet \ 92 -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6 \ 93 -lrumpnet_local -lrumpnet_shmif -lrumpdev_disk -lrumpfs_ffs \ 94 -lrumpfs_nfs -lrumpfs_nfsserver \ 95 -d key=/dk,hostpath=${IMG},size=host ${RUMP_SERVER} 96 97 atf_check -s exit:0 rump.ifconfig shmif0 create 98 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 99 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.1 100 101 export RUMPHIJACK_RETRYCONNECT=die 102 export LD_PRELOAD=/usr/lib/librumphijack.so 103 104 atf_check -s exit:0 mkdir /rump/etc 105 atf_check -s exit:0 mkdir /rump/export 106 atf_check -s exit:0 mkdir -p /rump/var/run 107 atf_check -s exit:0 mkdir -p /rump/var/db 108 atf_check -s exit:0 touch /rump/var/db/mountdtab 109 110 /bin/echo "/export -noresvport -noresvmnt 10.1.1.100" | \ 111 dd of=/rump/etc/exports 2> /dev/null 112 113 atf_check -s exit:0 -e ignore env RUMPHIJACK='path=/rump,blanket=/dk' \ 114 mount_ffs /dk /rump/export 115 116#set a quota limit (and check that we can read it back) 117 for q in ${expect} ; do 118 local id=$(id -${q}) 119 atf_check -s exit:0 \ 120 env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export edquota -$q -s10k/20 -h40M/50k \ 121 -t 2W/3D ${id} 122 atf_check -s exit:0 \ 123-o "match:0 10 40960 2weeks 1 20 51200 3days" \ 124-o "match:Disk quotas for .*: $" \ 125 env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export quota -${q} -v 126 done 127 128 # start rpcbind. we want /var/run/rpcbind.sock 129 export RUMPHIJACK='blanket=/var/run,socket=all' 130 atf_check -s exit:0 rpcbind 131 132 # ok, then we want mountd in the similar fashion 133 export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all' 134 atf_check -s exit:0 mountd /rump/etc/exports 135 136 # and nfs 137 export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all' 138 atf_check -s exit:0 nfsd 139 140 #finally, rpc.rquotad 141 export RUMPHIJACK='blanket=/var/run:/export,vfs=getvfsstat,socket=all' 142 atf_check -s exit:0 /usr/libexec/rpc.rquotad 143 144 # now start a client server 145 export RUMP_SERVER=unix://clientsock 146 RUMP_SOCKETS_LIST="${RUMP_SOCKETS_LIST} clientsock" 147 unset RUMPHIJACK 148 unset LD_PRELOAD 149 150 atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \ 151 -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\ 152 ${RUMP_SERVER} 153 154 atf_check -s exit:0 rump.ifconfig shmif0 create 155 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 156 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100 157 158 export LD_PRELOAD=/usr/lib/librumphijack.so 159 160 atf_check -s exit:0 mkdir /rump/mnt 161 atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt 162 163 #now try a quota(8) call 164 export RUMPHIJACK='blanket=/mnt,socket=all,path=/rump,vfs=getvfsstat' 165 for q in ${expect} ; do 166 local id=$(id -${q}) 167 atf_check -s exit:0 \ 168-o "match:/mnt 0 10 40960 1 20 51200 " \ 169-o "match:Disk quotas for .*: $" \ 170 quota -${q} -v 171 done 172 173 unset LD_PRELOAD 174 rump_quota_shutdown 175} 176