generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 122
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 122
6 #
7 # pv#952498
8 # Keep an eye on some of the xfs type sizes
9 # Motivation from differing ondisk types for 32 and 64 bit word versions.
10 #
11 . ./common/preamble
12 _begin_fstest other auto quick clone realtime
13
14 # get standard environment
15
16 # real QA test starts here
17 _supported_fs xfs
18 _require_command "$INDENT_PROG" indent
19
20 # Starting in Linux 6.1, the EFI log formats were adjusted away from using
21 # single-element arrays as flex arrays.
22 _wants_kernel_commit 03a7485cd701 \
23         "xfs: fix memcpy fortify errors in EFI log format copying"
24
25 # filter out known changes to xfs type sizes
26 _type_size_filter()
27 {
28         # lazy SB adds __be32 agf_btreeblks - pv960372
29         # flexarray conversion of the attr structures in Linux 6.5 changed
30         # the sizeof output
31         if [ "$($MKFS_XFS_PROG 2>&1 | grep -c lazy-count )" == "0" ]; then
32                 perl -ne '
33 s/sizeof\( xfs_agf_t \) = 60/sizeof( xfs_agf_t ) = <SIZE>/;
34 s/sizeof\(struct xfs_attr3_leafblock\) = 80/sizeof(struct xfs_attr3_leafblock) = 88/;
35 s/sizeof\(struct xfs_attr_shortform\) = 4/sizeof(struct xfs_attr_shortform) = 8/;
36 s/sizeof\(xfs_attr_leafblock_t\) = 32/sizeof(xfs_attr_leafblock_t) = 40/;
37                 print;'
38         else
39                 perl -ne '
40 s/sizeof\( xfs_agf_t \) = 64/sizeof( xfs_agf_t ) = <SIZE>/;
41 s/sizeof\(struct xfs_attr3_leafblock\) = 80/sizeof(struct xfs_attr3_leafblock) = 88/;
42 s/sizeof\(struct xfs_attr_shortform\) = 4/sizeof(struct xfs_attr_shortform) = 8/;
43 s/sizeof\(xfs_attr_leafblock_t\) = 32/sizeof(xfs_attr_leafblock_t) = 40/;
44                 print;'
45         fi
46 }
47
48 # filter out known changes to xfs type names
49 _type_name_filter()
50 {
51         sed -e 's/xfs_bmbt_rec_64_t/xfs_bmbt_rec_t/'
52 }
53
54 _attribute_filter()
55 {
56         sed -e 's/__attribute__ *[(][(]packed[)][)]//' \
57             -e 's/__arch_pack//'
58 }
59
60 cprog=$tmp.get_structs.c
61 oprog=$tmp.get_structs
62 progout=$tmp.output
63 keyfile=$tmp.keys
64
65 cat >$cprog <<EOF
66 #define _GNU_SOURCE
67 #include <stdio.h>
68 EOF
69 # Certain headers must be included in a certain order...
70 for hdr in xfs.h xfs_types.h xfs_fs.h xfs_arch.h xfs_format.h; do
71         test -e "/usr/include/xfs/$hdr" && echo "#include <xfs/$hdr>" >> $cprog
72 done
73 # ...but be sure to pull in any new headers that might show up.
74 for hdr in /usr/include/xfs/xfs*.h; do
75         echo "#include <$(echo "$hdr" | sed -e 's|/usr/include/||g')>" >> $cprog
76 done
77
78 # missing:
79 # xfs_trans_header_t
80
81 cat >$tmp.ignore <<EOF
82 xfs_buf_log_format_t
83 xfs_attr3_icleaf_hdr
84 xfs_da3_icnode_hdr
85 xfs_dir3_icfree_hdr
86 xfs_dir3_icleaf_hdr
87 xfs_name
88 xfs_owner_info
89 xfs_refcount_irec
90 xfs_rmap_irec
91 xfs_alloctype_t
92 xfs_buf_cancel_t
93 xfs_bmbt_rec_32_t
94 xfs_swapext_t
95 xfs_dirops_t
96 xfs_efi_log_item_t
97 xfs_efd_log_item_t
98 xfs_iocore_t
99 xfs_ihash_t
100 xfs_chashlist_t
101 xfs_chash_t
102 xfs_iptr_t
103 xfs_dmops_t
104 xfs_qmops_t
105 xfs_ioops_t
106 xfs_mod_sb_t
107 xfs_dqtrx_t
108 xfs_dqtrxops_t
109 xfs_ail_t
110 xfs_ail_entry_t
111 xfs_item_ops_t
112 xfs_log_busy_slot_t
113 xfs_log_busy_chunk_t
114 xfs_inode_log_format_t
115 xfs_efi_log_format_t
116 xfs_efd_log_format_t
117 xfs_perag_busy_t
118 xfs_perag_t
119 xfs_alloc_arg_t
120 xfs_attr_list_context_t
121 xfs_attr_sf_sort_t
122 xfs_bmbt_irec_t
123 xfs_bmbt_rec_host_t
124 xfs_bmap_free_item_t
125 xfs_bmap_free_t
126 xfs_bmalloca_t
127 xfs_btree_cur_t
128 xfs_buf_log_item_t
129 xfs_buf_log_format_v1_t
130 xfs_da_args_t
131 xfs_dabuf_t
132 xfs_da_state_blk_t
133 xfs_da_state_path_t
134 xfs_da_state_t
135 xfs_dinode_t
136 xfs_dircook_t
137 xfs_dir2_block_t
138 xfs_dir2_data_entry_t
139 xfs_dir2_data_union_t
140 xfs_dir2_data_t
141 xfs_dir2_put_args_t
142 xfs_dir_put_args_t
143 xfs_dir_sf_sort_t
144 xfs_extent_t
145 xfs_ext_irec_t
146 xfs_extdelta_t
147 xfs_flock64_t
148 xfs_fsop_geom_v1_t
149 xfs_growfs_data_t
150 xfs_growfs_rt_t
151 xfs_bstime_t
152 xfs_bstat_t
153 struct xfs_bstat
154 xfs_fsop_bulkreq_t
155 struct xfs_fsop_bulkreq
156 xfs_icsb_cnts_t
157 xfs_icdinode_t
158 xfs_ictimestamp_t
159 xfs_inobt_rec_incore_t
160 xfs_inogrp_t
161 struct xfs_inogrp
162 xfs_fid2_t
163 xfs_fsop_handlereq_t
164 xfs_fsop_setdm_handlereq_t
165 xfs_fsop_attrlist_handlereq_t
166 xfs_attr_multiop_t
167 xfs_fsop_attrmulti_handlereq_t
168 xfs_imap_t
169 xfs_ifork_t
170 xfs_inode_t
171 xfs_inode_log_item_t
172 xfs_log_iovec_t
173 xfs_log_callback_t
174 xfs_metablock_t
175 xfs_mount_t
176 xfs_sb_t
177 xfs_log_item_t
178 xfs_log_item_desc_t
179 xfs_log_item_chunk_t
180 xfs_trans_t
181 xfs_dirent_t
182 xfs_fsop_getparents_handlereq_t
183 xfs_dinode_core_t
184 struct xfs_iext_cursor
185 struct xfs_ino_geometry
186 struct xfs_attrlist
187 struct xfs_attrlist_ent
188 struct xfs_legacy_ictimestamp
189 EOF
190
191 echo 'int main(int argc, char *argv[]) {' >>$cprog
192
193 #
194 # Printfs of typedef sizes
195 #
196 cat /usr/include/xfs/xfs*.h | indent |\
197 _attribute_filter |\
198 grep -E '(} *xfs_.*_t|^(union|struct) xfs_[a-z0-9_]*$)' |\
199 grep -E -v -f $tmp.ignore |\
200 sed -e 's/^.*}[[:space:]]*//g' -e 's/;.*$//g' -e 's/_t, /_t\n/g' |\
201 sort | uniq |\
202 awk '{printf("printf(\"sizeof(%s) = %%zu\\n\", sizeof(%s));\n", $0, $0);}' |\
203 cat >> $cprog
204
205 #
206 # Look at offsets of key ones which differ in lengths
207 #
208
209 # xfs_sb_t
210 cat /usr/include/xfs/xfs*.h | indent |\
211 awk '
212    /typedef struct xfs_sb/ { structon = 1; next }
213    structon && $2 ~ /^sb_/ { sub(/[;,]/,"",$2)
214                              sub(/XFSLABEL_MAX/,"12",$2)
215                              printf("printf(\"offsetof(xfs_sb_t, %s) = %%zu\\n\", offsetof(xfs_sb_t, %s));", $2, $2); next}
216    structon && /}/ { structon = 0; next}
217 '>>$cprog
218
219 echo 'return 0; }' >>$cprog
220
221 # create and run program
222 cc -o $oprog $cprog >> $seqres.full 2>&1 || \
223   _notrun "Could not compile test program (see end of $seqres.full)"
224 $oprog | _type_size_filter | _type_name_filter > $progout
225
226 # Find all the items that only exist in the golden output
227 comm -23 <(grep '=' $0.out | sed -e 's/ =.*$//g' | LC_COLLATE=POSIX sort) \
228          <(sed -e 's/ =.*$//g' < $progout | LC_COLLATE=POSIX sort) > $keyfile
229
230 # Copy those items to the program output
231 grep -F -f $keyfile $0.out >> $progout
232
233 LC_COLLATE=POSIX sort $progout
234
235 status=0