btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / generic / 395
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Google, Inc.  All Rights Reserved.
4 #
5 # FS QA Test generic/395
6 #
7 # Test setting and getting encryption policies.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
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 generic
34 _require_scratch_encryption
35 _require_xfs_io_command "get_encpolicy"
36 _require_user
37
38 _scratch_mkfs_encrypted &>> $seqres.full
39 _scratch_mount
40
41 # Should be able to set an encryption policy on an empty directory
42 empty_dir=$SCRATCH_MNT/empty_dir
43 echo -e "\n*** Setting encryption policy on empty directory ***"
44 mkdir $empty_dir
45 _get_encpolicy $empty_dir |& _filter_scratch
46 _set_encpolicy $empty_dir 0000111122223333
47 _get_encpolicy $empty_dir | _filter_scratch
48
49 # Should be able to set the same policy again, but not a different one.
50 echo -e "\n*** Setting encryption policy again ***"
51 _set_encpolicy $empty_dir 0000111122223333
52 _get_encpolicy $empty_dir | _filter_scratch
53 _set_encpolicy $empty_dir 4444555566667777 |& _filter_scratch
54 _get_encpolicy $empty_dir | _filter_scratch
55
56 # Should *not* be able to set an encryption policy on a nonempty directory
57 nonempty_dir=$SCRATCH_MNT/nonempty_dir
58 echo -e "\n*** Setting encryption policy on nonempty directory ***"
59 mkdir $nonempty_dir
60 touch $nonempty_dir/file
61 _set_encpolicy $nonempty_dir |& _filter_scratch
62 _get_encpolicy $nonempty_dir |& _filter_scratch
63
64 # Should *not* be able to set an encryption policy on a nondirectory file, even
65 # an empty one.  Regression test for 002ced4be642: "fscrypto: only allow setting
66 # encryption policy on directories".
67 nondirectory=$SCRATCH_MNT/nondirectory
68 echo -e "\n*** Setting encryption policy on nondirectory ***"
69 touch $nondirectory
70 _set_encpolicy $nondirectory |& _filter_scratch
71 _get_encpolicy $nondirectory |& _filter_scratch
72
73 # Should *not* be able to set an encryption policy on another user's directory.
74 # Regression test for 163ae1c6ad62: "fscrypto: add authorization check for
75 # setting encryption policy".
76 unauthorized_dir=$SCRATCH_MNT/unauthorized_dir
77 echo -e "\n*** Setting encryption policy on another user's directory ***"
78 mkdir $unauthorized_dir
79 _user_do_set_encpolicy $unauthorized_dir |& _filter_scratch
80 _get_encpolicy $unauthorized_dir |& _filter_scratch
81
82 # Should *not* be able to set an encryption policy on a directory on a
83 # filesystem mounted readonly.  Regression test for ba63f23d69a3: "fscrypto:
84 # require write access to mount to set encryption policy".  Test both a regular
85 # readonly filesystem and a readonly bind mount of a read-write filesystem.
86 echo -e "\n*** Setting encryption policy on readonly filesystem ***"
87 mkdir $SCRATCH_MNT/ro_dir $SCRATCH_MNT/ro_bind_mnt
88 _scratch_remount ro
89 _set_encpolicy $SCRATCH_MNT/ro_dir |& _filter_scratch
90 _get_encpolicy $SCRATCH_MNT/ro_dir |& _filter_scratch
91 _scratch_remount rw
92 mount --bind $SCRATCH_MNT $SCRATCH_MNT/ro_bind_mnt
93 mount -o remount,ro,bind $SCRATCH_MNT/ro_bind_mnt
94 _set_encpolicy $SCRATCH_MNT/ro_bind_mnt/ro_dir |& _filter_scratch
95 _get_encpolicy $SCRATCH_MNT/ro_bind_mnt/ro_dir |& _filter_scratch
96 umount $SCRATCH_MNT/ro_bind_mnt
97
98 # success, all done
99 status=0
100 exit