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 # filter out known changes to xfs type sizes
21 _type_size_filter()
22 {
23         # lazy SB adds __be32 agf_btreeblks - pv960372
24         if [ "$($MKFS_XFS_PROG 2>&1 | grep -c lazy-count )" == "0" ]; then
25                 perl -ne '
26 s/sizeof\( xfs_agf_t \) = 60/sizeof( xfs_agf_t ) = <SIZE>/;
27                 print;'
28         else
29                 perl -ne '
30 s/sizeof\( xfs_agf_t \) = 64/sizeof( xfs_agf_t ) = <SIZE>/;
31                 print;'
32         fi
33 }
34
35 # filter out known changes to xfs type names
36 _type_name_filter()
37 {
38         sed -e 's/xfs_bmbt_rec_64_t/xfs_bmbt_rec_t/'
39 }
40
41 _attribute_filter()
42 {
43         sed -e 's/__attribute__ *[(][(]packed[)][)]//' \
44             -e 's/__arch_pack//'
45 }
46
47 cprog=$tmp.get_structs.c
48 oprog=$tmp.get_structs
49 progout=$tmp.output
50 keyfile=$tmp.keys
51
52 cat >$cprog <<EOF
53 #define _GNU_SOURCE
54 #include <stdio.h>
55 EOF
56 # Certain headers must be included in a certain order...
57 for hdr in xfs.h xfs_types.h xfs_fs.h xfs_arch.h xfs_format.h; do
58         test -e "/usr/include/xfs/$hdr" && echo "#include <xfs/$hdr>" >> $cprog
59 done
60 # ...but be sure to pull in any new headers that might show up.
61 for hdr in /usr/include/xfs/xfs*.h; do
62         echo "#include <$(echo "$hdr" | sed -e 's|/usr/include/||g')>" >> $cprog
63 done
64
65 # missing:
66 # xfs_trans_header_t
67
68 cat >$tmp.ignore <<EOF
69 xfs_buf_log_format_t
70 xfs_attr3_icleaf_hdr
71 xfs_da3_icnode_hdr
72 xfs_dir3_icfree_hdr
73 xfs_dir3_icleaf_hdr
74 xfs_name
75 xfs_owner_info
76 xfs_refcount_irec
77 xfs_rmap_irec
78 xfs_alloctype_t
79 xfs_buf_cancel_t
80 xfs_bmbt_rec_32_t
81 xfs_swapext_t
82 xfs_dirops_t
83 xfs_efi_log_item_t
84 xfs_efd_log_item_t
85 xfs_iocore_t
86 xfs_ihash_t
87 xfs_chashlist_t
88 xfs_chash_t
89 xfs_iptr_t
90 xfs_dmops_t
91 xfs_qmops_t
92 xfs_ioops_t
93 xfs_mod_sb_t
94 xfs_dqtrx_t
95 xfs_dqtrxops_t
96 xfs_ail_t
97 xfs_ail_entry_t
98 xfs_item_ops_t
99 xfs_log_busy_slot_t
100 xfs_log_busy_chunk_t
101 xfs_inode_log_format_t
102 xfs_efi_log_format_t
103 xfs_efd_log_format_t
104 xfs_perag_busy_t
105 xfs_perag_t
106 xfs_alloc_arg_t
107 xfs_attr_list_context_t
108 xfs_attr_sf_sort_t
109 xfs_bmbt_irec_t
110 xfs_bmbt_rec_host_t
111 xfs_bmap_free_item_t
112 xfs_bmap_free_t
113 xfs_bmalloca_t
114 xfs_btree_cur_t
115 xfs_buf_log_item_t
116 xfs_buf_log_format_v1_t
117 xfs_da_args_t
118 xfs_dabuf_t
119 xfs_da_state_blk_t
120 xfs_da_state_path_t
121 xfs_da_state_t
122 xfs_dinode_t
123 xfs_dircook_t
124 xfs_dir2_block_t
125 xfs_dir2_data_entry_t
126 xfs_dir2_data_union_t
127 xfs_dir2_data_t
128 xfs_dir2_put_args_t
129 xfs_dir_put_args_t
130 xfs_dir_sf_sort_t
131 xfs_extent_t
132 xfs_ext_irec_t
133 xfs_extdelta_t
134 xfs_flock64_t
135 xfs_fsop_geom_v1_t
136 xfs_growfs_data_t
137 xfs_growfs_rt_t
138 xfs_bstime_t
139 xfs_bstat_t
140 struct xfs_bstat
141 xfs_fsop_bulkreq_t
142 struct xfs_fsop_bulkreq
143 xfs_icsb_cnts_t
144 xfs_icdinode_t
145 xfs_ictimestamp_t
146 xfs_inobt_rec_incore_t
147 xfs_inogrp_t
148 struct xfs_inogrp
149 xfs_fid2_t
150 xfs_fsop_handlereq_t
151 xfs_fsop_setdm_handlereq_t
152 xfs_fsop_attrlist_handlereq_t
153 xfs_attr_multiop_t
154 xfs_fsop_attrmulti_handlereq_t
155 xfs_imap_t
156 xfs_ifork_t
157 xfs_inode_t
158 xfs_inode_log_item_t
159 xfs_log_iovec_t
160 xfs_log_callback_t
161 xfs_metablock_t
162 xfs_mount_t
163 xfs_sb_t
164 xfs_log_item_t
165 xfs_log_item_desc_t
166 xfs_log_item_chunk_t
167 xfs_trans_t
168 xfs_dirent_t
169 xfs_fsop_getparents_handlereq_t
170 xfs_dinode_core_t
171 struct xfs_iext_cursor
172 struct xfs_ino_geometry
173 struct xfs_attrlist
174 struct xfs_attrlist_ent
175 struct xfs_legacy_ictimestamp
176 EOF
177
178 echo 'int main(int argc, char *argv[]) {' >>$cprog
179
180 #
181 # Printfs of typedef sizes
182 #
183 cat /usr/include/xfs/xfs*.h | indent |\
184 _attribute_filter |\
185 egrep '(} *xfs_.*_t|^struct xfs_[a-z0-9_]*$)' |\
186 egrep -v -f $tmp.ignore |\
187 sed -e 's/^.*}[[:space:]]*//g' -e 's/;.*$//g' -e 's/_t, /_t\n/g' |\
188 sort | uniq |\
189 awk '{printf("printf(\"sizeof(%s) = %%zu\\n\", sizeof(%s));\n", $0, $0);}' |\
190 cat >> $cprog
191
192 #
193 # Look at offsets of key ones which differ in lengths
194 #
195
196 # xfs_sb_t
197 cat /usr/include/xfs/xfs*.h | indent |\
198 awk '
199    /typedef struct xfs_sb/ { structon = 1; next }
200    structon && $2 ~ /^sb_/ { sub(/[;,]/,"",$2)
201                              sub(/XFSLABEL_MAX/,"12",$2)
202                              printf("printf(\"offsetof(xfs_sb_t, %s) = %%zu\\n\", offsetof(xfs_sb_t, %s));", $2, $2); next}
203    structon && /}/ { structon = 0; next}
204 '>>$cprog
205
206 echo 'return 0; }' >>$cprog
207
208 # create and run program
209 cc -o $oprog $cprog >> $seqres.full 2>&1 || \
210   _notrun "Could not compile test program (see end of $seqres.full)"
211 $oprog | _type_size_filter | _type_name_filter > $progout
212
213 # Find all the items that only exist in the golden output
214 comm -23 <(grep '=' $0.out | sed -e 's/ =.*$//g' | LC_COLLATE=POSIX sort) \
215          <(sed -e 's/ =.*$//g' < $progout | LC_COLLATE=POSIX sort) > $keyfile
216
217 # Copy those items to the program output
218 grep -F -f $keyfile $0.out >> $progout
219
220 LC_COLLATE=POSIX sort $progout
221
222 status=0