common/rc: Add _require_{chown,chmod}()
[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 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         exec {test_fd}<&-
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37 _supported_fs generic
38 _require_test
39 _require_command "$FLOCK_PROG" "flock"
40
41 # Create test file and find its inode NO.
42 testfile=$TEST_DIR/flock_testfile_$seq
43 touch $testfile
44 tf_inode=$(stat -c %i $testfile)
45 echo inode $tf_inode >> $seqres.full
46
47 # Create new fd by exec
48 exec {test_fd}> $testfile
49 # flock locks the fd then exits, we should see the lock info even the owner is dead
50 flock -x $test_fd
51 cat /proc/locks >> $seqres.full
52
53 # Checking
54 grep -q ":$tf_inode " /proc/locks || echo "lock info not found"
55
56 # success, all done
57 status=0
58 echo "Silence is golden"
59 exit