generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 067
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 067
6 #
7 # Some random mount/umount corner case tests
8 #
9 # - mount at a nonexistent mount point
10 # - mount a free loop device
11 # - mount with a wrong fs type specified
12 # - umount an symlink to device which is not mounted
13 # - umount a path with too long name
14 # - lazy umount a symlink
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 tmp=/tmp/$$
22 status=1        # failure is the default!
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs generic
39 _supported_os Linux
40 _require_test_symlinks
41 _require_test
42 _require_scratch
43 _require_loop
44 _require_block_device $SCRATCH_DEV
45
46 rm -f $seqres.full
47
48 _scratch_mkfs >>$seqres.full 2>&1
49
50 # kernel should not hang nor oops when mounting fs to nonexistent mount point
51 mount_nonexistent_mnt()
52 {
53         echo "# mount to nonexistent mount point" >>$seqres.full
54         rm -rf $TEST_DIR/nosuchdir
55         $MOUNT_PROG $SCRATCH_DEV $TEST_DIR/nosuchdir >>$seqres.full 2>&1
56 }
57
58 # fs driver should be able to handle mounting a free loop device gracefully
59 # xfs ever hung, "ec53d1d xfs: don't block on buffer read errors" fixed it
60 mount_free_loopdev()
61 {
62         echo "# mount a free loop device" >>$seqres.full
63         loopdev=`losetup -f`
64         $MOUNT_PROG -t $FSTYP $loopdev $SCRATCH_MNT >>$seqres.full 2>&1
65 }
66
67 # mount with wrong fs type specified.
68 # This should fail gracefully, no hang no oops are expected
69 mount_wrong_fstype()
70 {
71         local fs=ext4
72         if [ "$FSTYP" == "ext4" ]; then
73                 fs=xfs
74         fi
75         echo "# mount with wrong fs type" >>$seqres.full
76         $MOUNT_PROG -t $fs $SCRATCH_DEV $SCRATCH_MNT >>$seqres.full 2>&1
77 }
78
79 # umount a symlink to device, which is not mounted.
80 # This should fail gracefully, no hang no oops are expected
81 umount_symlink_device()
82 {
83         local symlink=$TEST_DIR/$seq.scratch_dev_symlink
84         rm -f $symlink
85         echo "# umount symlink to device, which is not mounted" >>$seqres.full
86         ln -s $SCRATCH_DEV $symlink
87         $UMOUNT_PROG $symlink >>$seqres.full 2>&1
88 }
89
90 # umount a path name that is 256 bytes long, this should fail gracefully,
91 # and the following umount should not hang nor oops
92 umount_toolong_name()
93 {
94         local longname=$SCRATCH_MNT/`$PERL_PROG -e 'print "a"x256;'`
95
96         _scratch_mount 2>&1 | tee -a $seqres.full
97
98         echo "# umount a too-long name" >>$seqres.full
99         $UMOUNT_PROG $longname >>$seqres.full 2>&1
100         _scratch_unmount 2>&1 | tee -a $seqres.full
101 }
102
103 # lazy umount a symlink should not block following umount.
104 # This is the test case described in https://lkml.org/lkml/2014/7/21/98
105 lazy_umount_symlink()
106 {
107         local symlink=$SCRATCH_MNT/$seq.testdir_symlink
108         echo "# lazy umount a symlink" >>$seqres.full
109         _scratch_mount 2>&1 | tee -a $seqres.full
110         mkdir -p $SCRATCH_MNT/testdir
111         rm -f $symlink
112         ln -s $SCRATCH_MNT/testdir $symlink
113
114         $UMOUNT_PROG -l $symlink >>$seqres.full 2>&1
115         # _scratch_unmount should not be blocked
116         _scratch_unmount 2>&1 | tee -a $seqres.full
117 }
118
119 echo "Silence is golden"
120
121 mount_nonexistent_mnt
122 mount_free_loopdev
123 mount_wrong_fstype
124
125 umount_symlink_device
126 umount_toolong_name
127 lazy_umount_symlink
128
129 status=0
130 exit