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