btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 287
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2012 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 287
6 #
7 # Test to verify project quota xfs_admin, xfsdump/xfsrestore and
8 # xfs_db functionality
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 here=`pwd`
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17 rm -f $seqres.full
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/quota
22 . ./common/dump
23
24 _cleanup()
25 {
26         _cleanup_dump
27         cd /
28         rm -rf $tmp.*
29 }
30
31 _print_projid()
32 {
33         _scratch_xfs_db -r -c "inode $1" \
34                 -c "print core.projid_lo" \
35                 -c "print core.projid_hi"
36 }
37
38 # real QA test starts here
39 _supported_fs xfs
40 _require_xfs_quota
41 _require_scratch
42 _require_projid32bit
43 _require_projid16bit
44
45 # create xfs fs without projid32bit ability, will be gained by xfs_admin
46 _scratch_mkfs_xfs -i projid32bit=0 -d size=200m >> $seqres.full \
47                 || _fail "mkfs failed"
48 _qmount_option "pquota"
49 _qmount
50 # require project quotas
51 _require_prjquota $SCRATCH_DEV
52
53 dir=$SCRATCH_MNT/pquota
54
55 status=1
56
57 mkdir -p $dir
58 touch $dir/{16,32}bit
59 inode16a=$(ls -i $dir/16bit | cut -d ' ' -f 1)
60 inode32a=$(ls -i $dir/32bit | cut -d ' ' -f 1)
61 $XFS_QUOTA_PROG -x -c "project -s -p $dir/16bit 1234" $SCRATCH_DEV \
62                 >> $seqres.full
63 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
64                 >> $seqres.full 2>&1
65
66 echo "No 32bit project quotas:"
67 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
68 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
69
70 _scratch_unmount
71
72 # Now, enable projid32bit support by xfs_admin
73 _scratch_xfs_admin -p >> $seqres.full 2>&1 || _fail "xfs_admin failed"
74
75 # Now mount the fs, 32bit project quotas shall be supported, now
76 _qmount_option "pquota"
77 _qmount
78 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
79                 >> $seqres.full
80
81 # These will be checked by $seq.out
82 echo "With 32bit project quota support:"
83 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
84 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
85
86 # Dump the fs to a temporary file
87 rm -f $tmp.dump.img
88 $XFSDUMP_PROG -f $tmp.dump -L label -M media -l 0 $SCRATCH_MNT >> $seqres.full \
89                 || _fail "dump failed"
90
91 # Prepare the device to restore the dumped file system
92 restore_dir=$SCRATCH_MNT/restore/pquota
93
94 # Just make the restore dir, the pquota dir will be created by xfsrestore
95 mkdir -p $SCRATCH_MNT/restore
96
97 # Restore
98 $XFSRESTORE_PROG -f $tmp.dump $SCRATCH_MNT/restore >> $seqres.full 2>&1 \
99                 || _fail "xfsrestore failed"
100
101 # Check that they are the same
102 diff -urpN $SCRATCH_MNT/{,restore}/pquota || _fail "diff failed"
103
104 touch $restore_dir/32bitv2
105 inode16b=$(ls -i $restore_dir/16bit | cut -d ' ' -f 1)
106 inode32b=$(ls -i $restore_dir/32bit | cut -d ' ' -f 1)
107 inode32v2=$(ls -i $restore_dir/32bitv2 | cut -d ' ' -f 1)
108 $XFS_QUOTA_PROG -x -c "project -s -p $restore_dir/32bitv2 2123456789" \
109                 $SCRATCH_MNT >> $seqres.full
110 echo "The restored file system + one additional file:"
111 $XFS_IO_PROG -r -c "lsproj" $restore_dir/16bit
112 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bit
113 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bitv2
114
115 _scratch_unmount
116
117 # Now, we can examine the file systems with xfs_db
118 echo "These two values of 16bit project quota ids shall be the same"
119 _print_projid $inode16a
120 _print_projid $inode16b
121
122 echo "These three values of 32bit project quota ids shall be the same"
123 _print_projid $inode32b
124 _print_projid $inode32a
125 _print_projid $inode32v2
126
127 status=0
128 exit