misc: move exit status into trap handler
[xfstests-dev.git] / tests / xfs / 441
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 441
6 #
7 # Regression test for a quota accounting bug when reflinking across EOF
8 # of a file in which we forgot dq_attach.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/reflink
28 . ./common/quota
29 . ./common/filter
30
31 # Modify as appropriate.
32 _supported_fs xfs
33
34 _require_quota
35 _require_scratch_reflink
36 _require_cp_reflink
37 _require_user
38
39 rm -f $seqres.full
40
41 check_quota() {
42         du_total="$(du -ksc $SCRATCH_MNT/a $SCRATCH_MNT/b | tail -n 1 | awk '{print $1}')"
43         qu_total="$(_report_quota_blocks "-u $SCRATCH_MNT" | grep $qa_user | awk '{print $2}')"
44         echo "du: $du_total; quota: $qu_total"
45 }
46
47 echo "Format and mount (noquota)"
48 _scratch_mkfs > "$seqres.full" 2>&1
49 _scratch_mount "-o noquota" >> $seqres.full 2>&1
50
51 echo "Create files"
52 _pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
53 _pwrite_byte 0x58 0 1m $SCRATCH_MNT/b >> $seqres.full
54 chown $qa_user $SCRATCH_MNT/a $SCRATCH_MNT/b
55 check_quota 2>&1 | _filter_scratch
56
57 echo "Mount (usrquota) and check quota"
58 _scratch_unmount
59 _scratch_mount "-o usrquota,grpquota" >> "$seqres.full" 2>&1
60 check_quota
61
62 echo "Reflink and check quota again"
63 _reflink_range $SCRATCH_MNT/a 256k $SCRATCH_MNT/b 384k 128k >> $seqres.full
64 _reflink_range $SCRATCH_MNT/a 256k $SCRATCH_MNT/b 960k 128k >> $seqres.full
65 check_quota
66
67 echo "Force quotacheck"
68 _check_quota_usage
69
70 # success, all done
71 status=0
72 exit