generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 504
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 RedHat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 504
6 #
7 # Regression test case for kernel patch:
8 # fs/lock: skip lock owner pid translation in case we are in init_pid_ns
9 #
10 # Open new fd by exec shell built-in, then require exclusive lock
11 # by flock(1) command. Checking /proc/locks for the lock info.
12 #
13 . ./common/preamble
14 _begin_fstest auto quick locks
15
16 # Override the default cleanup function.
17 _cleanup()
18 {
19         exec {test_fd}<&-
20         cd /
21         rm -f $tmp.*
22 }
23
24 # Import common functions.
25 . ./common/filter
26
27 # real QA test starts here
28 _supported_fs generic
29 _require_test
30 _require_command "$FLOCK_PROG" "flock"
31
32 # Create test file and find its inode NO.
33 testfile=$TEST_DIR/flock_testfile_$seq
34 touch $testfile
35 tf_inode=$(stat -c %i $testfile)
36 echo inode $tf_inode >> $seqres.full
37
38 # Create new fd by exec
39 exec {test_fd}> $testfile
40 # flock locks the fd then exits, we should see the lock info even the owner is dead
41 flock -x $test_fd
42 cat /proc/locks >> $seqres.full
43
44 # Checking
45 grep -q ":$tf_inode " /proc/locks || echo "lock info not found"
46
47 # success, all done
48 status=0
49 echo "Silence is golden"
50 exit