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