common/rc: add _scratch_{u}mount_idmapped() helpers
[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 _require_scratch_encryption
35 _require_command "$KEYCTL_PROG" keyctl
36
37 _new_session_keyring
38
39 #
40 # Create an encrypted file whose size is not a multiple of the filesystem block
41 # size, then add it to the orphan list.
42 #
43 # We create the encrypted file normally, rather than use debugfs to force the
44 # inode flags to ENCRYPT|EXTENTS as done in the example listed in the commit
45 # message of the kernel fix, because forcing the inode flags is incompatible
46 # with some MKFS_OPTIONS such as inline_data or ^extents.
47 #
48 # This choice does, however, have the disadvantage that this test won't detect
49 # the bug in as many situations, such as in kernels configured without
50 # encryption support.
51 #
52 _scratch_mkfs_encrypted &>>$seqres.full
53 _scratch_mount
54 mkdir $SCRATCH_MNT/edir
55 keydesc=$(_generate_session_encryption_key)
56 _set_encpolicy $SCRATCH_MNT/edir $keydesc
57 echo foo > $SCRATCH_MNT/edir/file
58 inum=$(stat -c '%i' $SCRATCH_MNT/edir/file)
59 _scratch_unmount
60 debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full
61
62 # Try to mount the filesystem.  This would hit a BUG() in fs/ext4/inode.c.
63 _try_scratch_mount
64
65 # success, all done
66 echo "Didn't crash!"
67 status=0
68 exit