a9ce24d406d443299e93fb908a2d9d261fdddb42
[xfstests-dev.git] / tests / ext4 / 024
1 #! /bin/bash
2 # FS QA Test ext4/024
3 #
4 # Regression test for 0d06863f903a ("ext4: don't BUG when truncating encrypted
5 # inodes on the orphan list").
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
9 #
10 # Author: Eric Biggers <ebiggers@google.com>
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -f $tmp.*
40 }
41
42 # get standard environment and checks
43 . ./common/rc
44 . ./common/encrypt
45
46 # remove previous $seqres.full before test
47 rm -f $seqres.full
48
49 # real QA test starts here
50 _supported_fs ext4
51 _supported_os Linux
52 _require_scratch_encryption
53 _require_xfs_io_command "set_encpolicy"
54 _require_command "$KEYCTL_PROG" keyctl
55
56 _new_session_keyring
57
58 #
59 # Create an encrypted file whose size is not a multiple of the filesystem block
60 # size, then add it to the orphan list.
61 #
62 # We create the encrypted file normally, rather than use debugfs to force the
63 # inode flags to ENCRYPT|EXTENTS as done in the example listed in the commit
64 # message of the kernel fix, because forcing the inode flags is incompatible
65 # with some MKFS_OPTIONS such as inline_data or ^extents.
66 #
67 # This choice does, however, have the disadvantage that this test won't detect
68 # the bug in as many situations, such as in kernels configured without
69 # encryption support.
70 #
71 _scratch_mkfs_encrypted &>>$seqres.full
72 _scratch_mount
73 mkdir $SCRATCH_MNT/edir
74 keydesc=$(_generate_encryption_key)
75 $XFS_IO_PROG -c "set_encpolicy $keydesc" $SCRATCH_MNT/edir
76 echo foo > $SCRATCH_MNT/edir/file
77 inum=$(stat -c '%i' $SCRATCH_MNT/edir/file)
78 _scratch_unmount
79 debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full
80
81 # Try to mount the filesystem.  This would hit a BUG() in fs/ext4/inode.c.
82 _try_scratch_mount
83
84 # success, all done
85 echo "Didn't crash!"
86 status=0
87 exit