xref: /freebsd/contrib/netbsd-tests/fs/nfs/t_rquotad.sh (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1# $NetBSD: t_rquotad.sh,v 1.5 2016/08/10 23:25:39 kre 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#
27for e in le be; do
28  for v in 1; do
29    for q in "user" "group" "both"; do
30	test_case_root get_nfs_${e}_${v}_${q} get_nfs_quota \
31		"get NFS quota with ${q} enabled" ${e} ${v} ${q}
32    done
33  done
34done
35
36get_nfs_quota()
37{
38	create_ffs $*
39	local q=$3
40	local expect
41
42	case ${q} in
43	user)
44		expect=u
45		;;
46	group)
47		expect=g
48		;;
49	both)
50		expect="u g"
51		;;
52	*)
53		atf_fail "wrong quota type"
54		;;
55	esac
56
57#start a a nfs server
58
59	atf_check -s exit:0 rump_server -lrumpvfs -lrumpdev -lrumpnet   \
60	    -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6          \
61	    -lrumpnet_local -lrumpnet_shmif -lrumpdev_disk -lrumpfs_ffs \
62	    -lrumpfs_nfs -lrumpfs_nfsserver                             \
63	    -d key=/dk,hostpath=${IMG},size=host ${RUMP_SERVER}
64
65	atf_check -s exit:0 rump.ifconfig shmif0 create
66	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
67	atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.1
68
69	export RUMPHIJACK_RETRYCONNECT=die
70	export LD_PRELOAD=/usr/lib/librumphijack.so
71
72	atf_check -s exit:0 mkdir /rump/etc
73	atf_check -s exit:0 mkdir /rump/export
74	atf_check -s exit:0 mkdir -p /rump/var/run
75	atf_check -s exit:0 mkdir -p /rump/var/db
76	atf_check -s exit:0 touch /rump/var/db/mountdtab
77
78	/bin/echo "/export -noresvport -noresvmnt 10.1.1.100" | \
79		dd of=/rump/etc/exports 2> /dev/null
80
81	atf_check -s exit:0 -e ignore mount_ffs /dk /rump/export
82
83#set a quota limit (and check that we can read it back)
84	for q in ${expect} ; do
85		local id=$(id -${q})
86		atf_check -s exit:0 \
87		   env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export edquota -$q -s10k/20 -h40M/50k \
88		   -t 2W/3D ${id}
89		atf_check -s exit:0 \
90-o "match:0       10    40960  2weeks       1      20   51200   3days" \
91-o "match:Disk quotas for .*: $" \
92		    env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=vfs=getvfsstat,blanket=/export quota -${q} -v
93	done
94
95	# start rpcbind.  we want /var/run/rpcbind.sock
96	export RUMPHIJACK='blanket=/var/run,socket=all'
97	atf_check -s exit:0 rpcbind
98
99	# ok, then we want mountd in the similar fashion
100	export RUMPHIJACK='blanket=/var/run:/var/db:/export,socket=all,path=/rump,vfs=all'
101	atf_check -s exit:0 mountd /rump/etc/exports
102
103	# and nfs
104	export RUMPHIJACK='blanket=/var/run,socket=all,vfs=all'
105	atf_check -s exit:0 nfsd
106
107	#finally, rpc.rquotad
108	export RUMPHIJACK='blanket=/var/run:/export,vfs=getvfsstat,socket=all'
109	atf_check -s exit:0 /usr/libexec/rpc.rquotad
110
111	# now start a client server
112	export RUMP_SERVER=unix://clientsock
113	RUMP_SOCKETS_LIST="${RUMP_SOCKETS_LIST} clientsock"
114	unset RUMPHIJACK
115	unset LD_PRELOAD
116
117	atf_check -s exit:0 rump_server -lrumpvfs -lrumpnet -lrumpdev   \
118            -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpfs_nfs\
119            ${RUMP_SERVER}
120
121        atf_check -s exit:0 rump.ifconfig shmif0 create
122        atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
123        atf_check -s exit:0 rump.ifconfig shmif0 inet 10.1.1.100
124
125        export LD_PRELOAD=/usr/lib/librumphijack.so
126
127        atf_check -s exit:0 mkdir /rump/mnt
128        atf_check -s exit:0 mount_nfs 10.1.1.1:/export /rump/mnt
129
130	#now try a quota(8) call
131	export RUMPHIJACK='blanket=/mnt,socket=all,path=/rump,vfs=getvfsstat'
132	for q in ${expect} ; do
133		local id=$(id -${q})
134		atf_check -s exit:0 \
135-o "match:/mnt        0       10    40960               1      20   51200        " \
136-o "match:Disk quotas for .*: $" \
137		    quota -${q} -v
138	done
139
140	unset LD_PRELOAD
141	rump_quota_shutdown
142}
143