68ff169f6c81625c1e7ff0e21a6bb89946abc169
[xfstests-dev.git] / tests / generic / 426
1 #! /bin/bash
2 # FS QA Test No. 426
3 #
4 # Check stale handles pointing to unlinked files
5 # and non-stale handles pointing to linked files
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2017 CTERA Networks. All Rights Reserved.
9 # Author: Amir Goldstein <amir73il@gmail.com>
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # real QA test starts here
46
47 # Modify as appropriate.
48 _supported_fs generic
49 _supported_os Linux
50 _require_test
51 # _require_exportfs already requires open_by_handle, but let's not count on it
52 _require_test_program "open_by_handle"
53 _require_exportfs
54
55 NUMFILES=1024
56 testdir=$TEST_DIR/$seq-dir
57 mkdir -p $testdir
58
59 # Create empty test files in test dir
60 create_test_files()
61 {
62         local dir=$1
63         local opt=$2
64
65         mkdir -p $dir
66         rm -f $dir/*
67         src/open_by_handle -c $dir $NUMFILES
68 }
69
70 # Test encode/decode file handles
71 test_file_handles()
72 {
73         local dir=$1
74         local opt=$2
75
76         echo test_file_handles $* | _filter_test_dir
77         src/open_by_handle $opt $dir $NUMFILES
78 }
79
80 # Check stale handles to deleted files
81 create_test_files $testdir
82 test_file_handles $testdir -d
83
84 # Check non-stale handles to linked files
85 create_test_files $testdir
86 test_file_handles $testdir
87
88 # Check non-stale handles to files that were hardlinked and original deleted
89 create_test_files $testdir
90 test_file_handles $testdir -l
91 test_file_handles $testdir -u
92
93 echo "Silence is golden"
94 status=0
95 exit