generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 674
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 674
6 #
7 # Functional test for dropping suid and sgid bits as part of a deduplication.
8 #
9 . ./common/preamble
10 _begin_fstest auto clone quick
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/reflink
15
16 # real QA test starts here
17
18 # Modify as appropriate.
19 _supported_fs generic
20 _require_user
21 _require_scratch_dedupe
22 _require_xfs_io_command dedupe
23
24 _scratch_mkfs >> $seqres.full
25 _scratch_mount
26 chmod a+rw $SCRATCH_MNT/
27
28 setup_testfile() {
29         rm -f $SCRATCH_MNT/a $SCRATCH_MNT/b
30         _pwrite_byte 0x58 0 1m $SCRATCH_MNT/a >> $seqres.full
31         _pwrite_byte 0x58 0 1m $SCRATCH_MNT/b >> $seqres.full
32         chmod a+r $SCRATCH_MNT/b
33         sync
34 }
35
36 commit_and_check() {
37         local user="$1"
38
39         md5sum $SCRATCH_MNT/a | _filter_scratch
40         stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
41
42         local before_freesp=$(_get_available_space $SCRATCH_MNT)
43
44         local cmd="$XFS_IO_PROG -c 'dedupe $SCRATCH_MNT/b 0 0 1m' $SCRATCH_MNT/a"
45         if [ -n "$user" ]; then
46                 su - "$user" -c "$cmd" >> $seqres.full
47         else
48                 $SHELL -c "$cmd" >> $seqres.full
49         fi
50
51         _scratch_cycle_mount
52         md5sum $SCRATCH_MNT/a | _filter_scratch
53         stat -c '%a %A %n' $SCRATCH_MNT/a | _filter_scratch
54
55         local after_freesp=$(_get_available_space $SCRATCH_MNT)
56
57         echo "before: $before_freesp; after: $after_freesp" >> $seqres.full
58         if [ $after_freesp -le $before_freesp ]; then
59                 echo "expected more free space after dedupe"
60         fi
61
62         # Blank line in output
63         echo
64 }
65
66 # Commit to a non-exec file by an unprivileged user clears suid but leaves
67 # sgid.
68 echo "Test 1 - qa_user, non-exec file"
69 setup_testfile
70 chmod a+rws $SCRATCH_MNT/a
71 commit_and_check "$qa_user"
72
73 # Commit to a group-exec file by an unprivileged user clears suid and sgid.
74 echo "Test 2 - qa_user, group-exec file"
75 setup_testfile
76 chmod g+x,a+rws $SCRATCH_MNT/a
77 commit_and_check "$qa_user"
78
79 # Commit to a user-exec file by an unprivileged user clears suid but not sgid.
80 echo "Test 3 - qa_user, user-exec file"
81 setup_testfile
82 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
83 commit_and_check "$qa_user"
84
85 # Commit to a all-exec file by an unprivileged user clears suid and sgid.
86 echo "Test 4 - qa_user, all-exec file"
87 setup_testfile
88 chmod a+rwxs $SCRATCH_MNT/a
89 commit_and_check "$qa_user"
90
91 # Commit to a non-exec file by root clears suid but leaves sgid.
92 echo "Test 5 - root, non-exec file"
93 setup_testfile
94 chmod a+rws $SCRATCH_MNT/a
95 commit_and_check
96
97 # Commit to a group-exec file by root clears suid and sgid.
98 echo "Test 6 - root, group-exec file"
99 setup_testfile
100 chmod g+x,a+rws $SCRATCH_MNT/a
101 commit_and_check
102
103 # Commit to a user-exec file by root clears suid but not sgid.
104 echo "Test 7 - root, user-exec file"
105 setup_testfile
106 chmod u+x,a+rws,g-x $SCRATCH_MNT/a
107 commit_and_check
108
109 # Commit to a all-exec file by root clears suid and sgid.
110 echo "Test 8 - root, all-exec file"
111 setup_testfile
112 chmod a+rwxs $SCRATCH_MNT/a
113 commit_and_check
114
115 # success, all done
116 status=0
117 exit