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