summaryrefslogtreecommitdiff
path: root/tests/xfs/122
blob: ba927c77c46a41016a97bdc7dde2df4dc88ebed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
#
# FS QA Test No. 122
#
# pv#952498
# Keep an eye on some of the xfs type sizes
# Motivation from differing ondisk types for 32 and 64 bit word versions.
#
. ./common/preamble
_begin_fstest other auto quick clone realtime

# get standard environment

# real QA test starts here
_supported_fs xfs
_require_command "$INDENT_PROG" indent

# Starting in Linux 6.1, the EFI log formats were adjusted away from using
# single-element arrays as flex arrays.
_wants_kernel_commit 03a7485cd701 \
	"xfs: fix memcpy fortify errors in EFI log format copying"

# filter out known changes to xfs type sizes
_type_size_filter()
{
	# lazy SB adds __be32 agf_btreeblks - pv960372
	# flexarray conversion of the attr structures in Linux 6.5 changed
	# the sizeof output
	if [ "$($MKFS_XFS_PROG 2>&1 | grep -c lazy-count )" == "0" ]; then
		perl -ne '
s/sizeof\( xfs_agf_t \) = 60/sizeof( xfs_agf_t ) = <SIZE>/;
s/sizeof\(struct xfs_attr3_leafblock\) = 80/sizeof(struct xfs_attr3_leafblock) = 88/;
s/sizeof\(struct xfs_attr_shortform\) = 4/sizeof(struct xfs_attr_shortform) = 8/;
s/sizeof\(xfs_attr_leafblock_t\) = 32/sizeof(xfs_attr_leafblock_t) = 40/;
		print;'
	else
		perl -ne '
s/sizeof\( xfs_agf_t \) = 64/sizeof( xfs_agf_t ) = <SIZE>/;
s/sizeof\(struct xfs_attr3_leafblock\) = 80/sizeof(struct xfs_attr3_leafblock) = 88/;
s/sizeof\(struct xfs_attr_shortform\) = 4/sizeof(struct xfs_attr_shortform) = 8/;
s/sizeof\(xfs_attr_leafblock_t\) = 32/sizeof(xfs_attr_leafblock_t) = 40/;
		print;'
	fi
}

# filter out known changes to xfs type names
_type_name_filter()
{
	sed -e 's/xfs_bmbt_rec_64_t/xfs_bmbt_rec_t/'
}

_attribute_filter()
{
	sed -e 's/__attribute__ *[(][(]packed[)][)]//' \
	    -e 's/__arch_pack//'
}

cprog=$tmp.get_structs.c
oprog=$tmp.get_structs
progout=$tmp.output
keyfile=$tmp.keys

cat >$cprog <<EOF
#define _GNU_SOURCE
#include <stdio.h>
EOF
# Certain headers must be included in a certain order...
for hdr in xfs.h xfs_types.h xfs_fs.h xfs_arch.h xfs_format.h; do
	test -e "/usr/include/xfs/$hdr" && echo "#include <xfs/$hdr>" >> $cprog
done
# ...but be sure to pull in any new headers that might show up.
for hdr in /usr/include/xfs/xfs*.h; do
	echo "#include <$(echo "$hdr" | sed -e 's|/usr/include/||g')>" >> $cprog
done

# missing:
# xfs_trans_header_t

cat >$tmp.ignore <<EOF
xfs_buf_log_format_t
xfs_attr3_icleaf_hdr
xfs_da3_icnode_hdr
xfs_dir3_icfree_hdr
xfs_dir3_icleaf_hdr
xfs_name
xfs_owner_info
xfs_refcount_irec
xfs_rmap_irec
xfs_alloctype_t
xfs_buf_cancel_t
xfs_bmbt_rec_32_t
xfs_swapext_t
xfs_dirops_t
xfs_efi_log_item_t
xfs_efd_log_item_t
xfs_iocore_t
xfs_ihash_t
xfs_chashlist_t
xfs_chash_t
xfs_iptr_t
xfs_dmops_t
xfs_qmops_t
xfs_ioops_t
xfs_mod_sb_t
xfs_dqtrx_t
xfs_dqtrxops_t
xfs_ail_t
xfs_ail_entry_t
xfs_item_ops_t
xfs_log_busy_slot_t
xfs_log_busy_chunk_t
xfs_inode_log_format_t
xfs_efi_log_format_t
xfs_efd_log_format_t
xfs_perag_busy_t
xfs_perag_t
xfs_alloc_arg_t
xfs_attr_list_context_t
xfs_attr_sf_sort_t
xfs_bmbt_irec_t
xfs_bmbt_rec_host_t
xfs_bmap_free_item_t
xfs_bmap_free_t
xfs_bmalloca_t
xfs_btree_cur_t
xfs_buf_log_item_t
xfs_buf_log_format_v1_t
xfs_da_args_t
xfs_dabuf_t
xfs_da_state_blk_t
xfs_da_state_path_t
xfs_da_state_t
xfs_dinode_t
xfs_dircook_t
xfs_dir2_block_t
xfs_dir2_data_entry_t
xfs_dir2_data_union_t
xfs_dir2_data_t
xfs_dir2_put_args_t
xfs_dir_put_args_t
xfs_dir_sf_sort_t
xfs_extent_t
xfs_ext_irec_t
xfs_extdelta_t
xfs_flock64_t
xfs_fsop_geom_v1_t
xfs_growfs_data_t
xfs_growfs_rt_t
xfs_bstime_t
xfs_bstat_t
struct xfs_bstat
xfs_fsop_bulkreq_t
struct xfs_fsop_bulkreq
xfs_icsb_cnts_t
xfs_icdinode_t
xfs_ictimestamp_t
xfs_inobt_rec_incore_t
xfs_inogrp_t
struct xfs_inogrp
xfs_fid2_t
xfs_fsop_handlereq_t
xfs_fsop_setdm_handlereq_t
xfs_fsop_attrlist_handlereq_t
xfs_attr_multiop_t
xfs_fsop_attrmulti_handlereq_t
xfs_imap_t
xfs_ifork_t
xfs_inode_t
xfs_inode_log_item_t
xfs_log_iovec_t
xfs_log_callback_t
xfs_metablock_t
xfs_mount_t
xfs_sb_t
xfs_log_item_t
xfs_log_item_desc_t
xfs_log_item_chunk_t
xfs_trans_t
xfs_dirent_t
xfs_fsop_getparents_handlereq_t
xfs_dinode_core_t
struct xfs_iext_cursor
struct xfs_ino_geometry
struct xfs_attrlist
struct xfs_attrlist_ent
struct xfs_legacy_ictimestamp
EOF

echo 'int main(int argc, char *argv[]) {' >>$cprog

#
# Printfs of typedef sizes
#
cat /usr/include/xfs/xfs*.h | indent |\
_attribute_filter |\
grep -E '(} *xfs_.*_t|^struct xfs_[a-z0-9_]*$)' |\
grep -E -v -f $tmp.ignore |\
sed -e 's/^.*}[[:space:]]*//g' -e 's/;.*$//g' -e 's/_t, /_t\n/g' |\
sort | uniq |\
awk '{printf("printf(\"sizeof(%s) = %%zu\\n\", sizeof(%s));\n", $0, $0);}' |\
cat >> $cprog

#
# Look at offsets of key ones which differ in lengths
#

# xfs_sb_t
cat /usr/include/xfs/xfs*.h | indent |\
awk '
   /typedef struct xfs_sb/ { structon = 1; next }
   structon && $2 ~ /^sb_/ { sub(/[;,]/,"",$2)
                             sub(/XFSLABEL_MAX/,"12",$2)
                             printf("printf(\"offsetof(xfs_sb_t, %s) = %%zu\\n\", offsetof(xfs_sb_t, %s));", $2, $2); next}
   structon && /}/ { structon = 0; next}
'>>$cprog

echo 'return 0; }' >>$cprog

# create and run program
cc -o $oprog $cprog >> $seqres.full 2>&1 || \
  _notrun "Could not compile test program (see end of $seqres.full)"
$oprog | _type_size_filter | _type_name_filter > $progout

# Find all the items that only exist in the golden output
comm -23 <(grep '=' $0.out | sed -e 's/ =.*$//g' | LC_COLLATE=POSIX sort) \
	 <(sed -e 's/ =.*$//g' < $progout | LC_COLLATE=POSIX sort) > $keyfile

# Copy those items to the program output
grep -F -f $keyfile $0.out >> $progout

LC_COLLATE=POSIX sort $progout

status=0