misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 195
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2008 Christoph Hellwig.
4 #
5 # FS QA Test No. 195
6 #
7 # Make sure the chattr dump flag gets picked up by xfsdump without a sync
8 #
9 # http://oss.sgi.com/bugzilla/show_bug.cgi?id=340
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18
19 _cleanup()
20 {
21         rm -rf $TEST_DIR/d
22         rm -f $TEST_DIR/dumpfile
23 }
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 #
27 # Perform a level 0 dump that respects the chattr dump exclude flag,
28 # and grep the output for the inode number we expect / do not expect
29 # to be skipped
30 #
31 # Only dump a subtree so we get away with a single partition for
32 # the subtree to be dumped and the dump file.
33 #
34 _do_dump()
35 {
36         $XFSDUMP_PROG -l 0 -s d -F  \
37                 -L prova -M prova \
38                 -f $TEST_DIR/dumpfile -v excluded_files=debug $TEST_DIR \
39                 | grep "ino $inum" \
40                 | sed -e 's/.*xfsdump: pruned ino [0-9]*, owner 0, estimated size 0: skip flag set/xfsdump: pruned ino NNN, owner 0, estimated size 0: skip flag set/'
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # real QA test starts here
48 _supported_fs xfs
49
50 _require_test
51 _require_user
52 _require_command "$XFSDUMP_PROG" xfsdump
53
54 echo "Preparing subtree"
55 mkdir $TEST_DIR/d
56 touch $TEST_DIR/d/t
57 inum=`stat -c "%i" $TEST_DIR/d/t`
58
59 echo "No dump exclude flag set (should not be skipped)"
60 _do_dump
61
62 echo "Dump exclude flag set, but no sync yet (should be skipped)"
63 $CHATTR_PROG +d $TEST_DIR/d/t
64 _do_dump
65
66 echo "Dump exclude flag set, after sync (should be skipped)"
67 sync
68 _do_dump
69
70 # success, all done
71 echo "*** done"
72 rm -f $seqres.full
73 status=0