lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 467
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
4 #
5 # FS QA Test No. 467
6 #
7 # Check open by file handle.
8 # This is a variant of test generic/426 that tests with less
9 # files and more use cases:
10 # - open directory by file handle
11 # - verify content integrity of file after opening by file handle
12 # - open by file handle of unlinked open files
13 # - open by file handle of renamed files
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35
36 # Modify as appropriate.
37 _supported_fs generic
38 _supported_os Linux
39 _require_test
40 # _require_exportfs already requires open_by_handle, but let's not count on it
41 _require_test_program "open_by_handle"
42 _require_exportfs
43
44 NUMFILES=10
45 testdir=$TEST_DIR/$seq-dir
46
47 # Create test dir and non-empty test files
48 create_test_files()
49 {
50         local dir=$1
51         local opt=$2
52
53         rm -rf $dir
54         $here/src/open_by_handle -cwp $dir $NUMFILES
55 }
56
57 # Test encode/decode file handles
58 test_file_handles()
59 {
60         local dir=$1
61         local opt=$2
62
63         echo test_file_handles $* | _filter_test_dir
64         $here/src/open_by_handle $opt $dir $NUMFILES
65 }
66
67 # Check stale handles to deleted files/dir
68 create_test_files $testdir
69 test_file_handles $testdir -dp
70
71 # Check non-stale handles to linked files/dir
72 create_test_files $testdir
73 test_file_handles $testdir -rp
74
75 # Check non-stale handles to unlinked open files
76 create_test_files $testdir
77 test_file_handles $testdir -dkr
78
79 # Check non-stale handles to files that were hardlinked and original deleted
80 create_test_files $testdir
81 test_file_handles $testdir -lr
82 test_file_handles $testdir -ur
83
84 # Check non-stale file handles of renamed files
85 create_test_files $testdir
86 test_file_handles $testdir -mr
87
88 # Check non-stale file handles after rename of parent
89 create_test_files $testdir
90 rm -rf $testdir.renamed
91 mv $testdir $testdir.renamed/
92 test_file_handles $testdir.renamed -rp
93
94 # Check non-stale file handles after move to new parent
95 create_test_files $testdir
96 rm -rf $testdir.new
97 mkdir -p $testdir.new
98 mv $testdir/* $testdir.new/
99 test_file_handles $testdir.new -rp
100
101 status=0
102 exit