lib/: spdx license conversion
[xfstests-dev.git] / tests / ext4 / 024
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test ext4/024
6 #
7 # Regression test for 0d06863f903a ("ext4: don't BUG when truncating encrypted
8 # inodes on the orphan list").
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 and checks
26 . ./common/rc
27 . ./common/encrypt
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs ext4
34 _supported_os Linux
35 _require_scratch_encryption
36 _require_xfs_io_command "set_encpolicy"
37 _require_command "$KEYCTL_PROG" keyctl
38
39 _new_session_keyring
40
41 #
42 # Create an encrypted file whose size is not a multiple of the filesystem block
43 # size, then add it to the orphan list.
44 #
45 # We create the encrypted file normally, rather than use debugfs to force the
46 # inode flags to ENCRYPT|EXTENTS as done in the example listed in the commit
47 # message of the kernel fix, because forcing the inode flags is incompatible
48 # with some MKFS_OPTIONS such as inline_data or ^extents.
49 #
50 # This choice does, however, have the disadvantage that this test won't detect
51 # the bug in as many situations, such as in kernels configured without
52 # encryption support.
53 #
54 _scratch_mkfs_encrypted &>>$seqres.full
55 _scratch_mount
56 mkdir $SCRATCH_MNT/edir
57 keydesc=$(_generate_encryption_key)
58 $XFS_IO_PROG -c "set_encpolicy $keydesc" $SCRATCH_MNT/edir
59 echo foo > $SCRATCH_MNT/edir/file
60 inum=$(stat -c '%i' $SCRATCH_MNT/edir/file)
61 _scratch_unmount
62 debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full
63
64 # Try to mount the filesystem.  This would hit a BUG() in fs/ext4/inode.c.
65 _try_scratch_mount
66
67 # success, all done
68 echo "Didn't crash!"
69 status=0
70 exit