2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Google, Inc. All Rights Reserved.
7 # Regression test for 0d06863f903a ("ext4: don't BUG when truncating encrypted
8 # inodes on the orphan list").
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment and checks
29 # remove previous $seqres.full before test
32 # real QA test starts here
35 _require_scratch_encryption
36 _require_xfs_io_command "set_encpolicy"
37 _require_command "$KEYCTL_PROG" keyctl
42 # Create an encrypted file whose size is not a multiple of the filesystem block
43 # size, then add it to the orphan list.
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.
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
54 _scratch_mkfs_encrypted &>>$seqres.full
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)
62 debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full
64 # Try to mount the filesystem. This would hit a BUG() in fs/ext4/inode.c.