1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2016-2018 Oracle and/or its affiliates. All Rights Reserved.
4# Copyright (c) International Business Machines  Corp., 2001
5
6TST_TESTFUNC="do_test"
7TST_NEEDS_CMDS="nfsstat"
8
9. nfs_lib.sh
10
11get_calls()
12{
13	local name=$1
14	local field=$2
15	local nfs_f=$3
16	local calls=
17	local opt=
18	[ "$name" = "rpc" ] && opt="r" || opt="n"
19
20	if tst_net_use_netns || [ "$nfs_f" = "nfs" ]; then
21		calls="$(grep $name /proc/net/rpc/$nfs_f | cut -d' ' -f$field)"
22		ROD nfsstat -c$opt | grep -q "$calls"
23		echo "$calls"
24		return
25	fi
26
27	calls=$(tst_rhost_run -c "grep $name /proc/net/rpc/$nfs_f" | \
28		cut -d' ' -f$field)
29	tst_rhost_run -s -c "nfsstat -s$opt" | grep -q "$calls"
30	echo "$calls"
31}
32
33# PURPOSE:  Performs simple copies and removes to verify statistic
34#           tracking using the 'nfsstat' command and /proc/net/rpc
35do_test()
36{
37	tst_res TINFO "checking RPC calls for server/client"
38
39	local server_calls="$(get_calls rpc 2 nfsd)"
40	local client_calls="$(get_calls rpc 2 nfs)"
41
42	tst_res TINFO "calls $server_calls/$client_calls"
43
44	tst_res TINFO "Checking for tracking of RPC calls for server/client"
45	cat /proc/cpuinfo > nfsstat01.tmp
46
47	local new_server_calls="$(get_calls rpc 2 nfsd)"
48	local new_client_calls="$(get_calls rpc 2 nfs)"
49	tst_res TINFO "new calls $new_server_calls/$new_client_calls"
50
51	if [ "$new_server_calls" -le "$server_calls" ]; then
52		tst_res TFAIL "server RPC calls not increased"
53	else
54		tst_res TPASS "server RPC calls increased"
55	fi
56
57	if [ "$new_client_calls" -le "$client_calls" ]; then
58		tst_res TFAIL "client RPC calls not increased"
59	else
60		tst_res TPASS "client RPC calls increased"
61	fi
62
63	tst_res TINFO "checking NFS calls for server/client"
64	local field=
65	case $VERSION in
66	2) field=13
67	;;
68	*) field=15
69	;;
70	esac
71
72	server_calls="$(get_calls proc$VERSION $field nfsd)"
73	client_calls="$(get_calls proc$VERSION $field nfs)"
74	tst_res TINFO "calls $server_calls/$client_calls"
75
76	tst_res TINFO "Checking for tracking of NFS calls for server/client"
77	rm -f nfsstat01.tmp
78
79	new_server_calls="$(get_calls proc$VERSION $field nfsd)"
80	new_client_calls="$(get_calls proc$VERSION $field nfs)"
81	tst_res TINFO "new calls $new_server_calls/$new_client_calls"
82
83	if [ "$new_server_calls" -le "$server_calls" ]; then
84		tst_res TFAIL "server NFS calls not increased"
85	else
86		tst_res TPASS "server NFS calls increased"
87	fi
88
89	if [ "$new_client_calls" -le "$client_calls" ]; then
90		tst_res TFAIL "client NFS calls not increased"
91	else
92		tst_res TPASS "client NFS calls increased"
93	fi
94}
95
96tst_run
97