1# $NetBSD: t_rquotad.sh,v 1.9 2020/08/20 13:58:30 riastradh 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 mount_ffs /dk /rump/export 114 115#set a quota limit (and check that we can read it back) 116 for q in ${expect} ; do 117 local id=$(id -${q}) 118 atf_check -s exit:0 \ 119 env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export edquota -$q -s10k/20 -h40M/50k \ 120 -t 2W/3D ${id} 121 atf_check -s exit:0 \ 122-o "match:0 10 40960 2weeks 1 20 51200 3days" \ 123-o "match:Disk quotas for .*: $" \ 124 env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export quota -${q} -v 125 done 126 127 # start rpcbind. we want /var/run/rpcbind.sock 128 export RUMPHIJACK='blanket=/var/run,socket=all' 129 atf_check -s exit:0 rpcbind 130 131 # ok, then we want mountd in the similar fashion 132 export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all' 133 atf_check -s exit:0 mountd /rump/etc/exports 134 135 # and nfs 136 export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all' 137 atf_check -s exit:0 nfsd 138 139 #finally, rpc.rquotad 140 export RUMPHIJACK='blanket=/var/run:/export,vfs=getvfsstat,socket=all' 141 atf_check -s exit:0 /usr/libexec/rpc.rquotad 142 143 # now start a client server 144 export RUMP_SERVER=unix://clientsock 145 RUMP_SOCKETS_LIST="${RUMP_SOCKETS_LIST} clientsock" 146 unset RUMPHIJACK 147 unset LD_PRELOAD 148 149 atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet \ 150 -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\ 151 ${RUMP_SERVER} 152 153 atf_check -s exit:0 rump.ifconfig shmif0 create 154 atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus 155 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100 156 157 export LD_PRELOAD=/usr/lib/librumphijack.so 158 159 atf_check -s exit:0 mkdir /rump/mnt 160 atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt 161 162 #now try a quota(8) call 163 export RUMPHIJACK='blanket=/mnt,socket=all,path=/rump,vfs=getvfsstat' 164 for q in ${expect} ; do 165 local id=$(id -${q}) 166 atf_check -s exit:0 \ 167-o "match:/mnt 0 10 40960 1 20 51200 " \ 168-o "match:Disk quotas for .*: $" \ 169 quota -${q} -v 170 done 171 172 unset LD_PRELOAD 173 rump_quota_shutdown 174} 175