xref: /aosp_15_r20/external/ltp/testcases/network/nfs/nfs_stress/nfs09.sh (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (C) 2024 SUSE LLC <[email protected]>
4#
5# DESCRIPTION: Check that stale NFS client cache does not prevent file
6# truncation.
7#
8# 1. Through NFS, access metadata of a file that does not exist
9# 2. Create the file on the remote end (bypassing NFS)
10# 3. Through NFS, try to overwrite the file with shorter data
11
12TST_TESTFUNC="do_test"
13
14do_test()
15{
16	local local_file="testfile"
17	local remote_file="$(nfs_get_remote_path)/$local_file"
18	local testmsg='File truncated'
19	local data
20
21	EXPECT_FAIL "ls -l '$local_file'"
22	tst_rhost_run -c "echo -n 'File rewritten not' >'$remote_file'"
23	echo -n "$testmsg" >"$local_file"
24	data=$(tst_rhost_run -c "cat '$remote_file'")
25
26	if [ "$data" != "$testmsg" ]; then
27		tst_res TFAIL "Wrong file contents, expected '$testmsg', got '$data'"
28	else
29		tst_res TPASS "File was truncated correctly"
30	fi
31}
32
33. nfs_lib.sh
34tst_run
35