4 # srcdiff is used to compare current user level code with the current
5 # kernel code and advise of any differences between files which are
6 # sharing some or all of their content.
8 # There are two classes of sharing which we will check - header files
9 # in the include directory, which must be exactly the same (use diff)
10 # and source files which contain routines which must be exactly the
11 # same (but the userland file is always a subset of the kernel file,
12 # and hence a more flexible mechanism to "diff" is required).
14 # NB: to cross check that srcdiff is finding all the functions in the
15 # user source file, providing you have "mkproto" installed, you
16 # can "cd xfsprogs/libxfs" and cut&paste this in a bourne shell:
17 # $ for file in xfs_*.c; do
18 # > mkproto -nps < $file | perl -ne '
19 # > END { print " $count\t- " }
20 # > s/^.* (xfs\w+|\*xfs\w+|xlog\w+|\*xlog\w+) \(.*/\1/ && { $count++ }'
23 # (compare this to "srcdiff | fgrep Total:")
26 die "WORKAREA not set" unless defined $ENV{'WORKAREA'};
27 die "KWORKAREA not set" unless defined $ENV{'KWORKAREA'};
28 chdir $ENV{'WORKAREA'};
29 my $kworkarea = $ENV{'KWORKAREA'};
30 my $xdiff = $ENV{'XDIFF'};
34 if ( ! -f "$kworkarea/xfs_fs.h" ) {
35 $kworkarea .= '/fs/xfs';
36 die "Cannot find XFS in KWORKAREA" unless -f "$kworkarea/xfs_fs.h";
43 print STDERR "Illegal option $_\n";
49 print STDERR "Usage: $0 [-q]\n";
53 my @pkglist = qw( xfstests attr acl dmapi xfsdump xfsprogs );
55 xfs_ag.h xfs_alloc.h xfs_alloc_btree.h xfs_arch.h
56 xfs_attr_leaf.h xfs_attr_sf.h xfs_bit.h xfs_bmap.h
57 xfs_bmap_btree.h xfs_btree.h xfs_buf_item.h
58 xfs_da_btree.h xfs_dfrag.h xfs_dinode.h xfs_dir.h
59 xfs_dir2.h xfs_dir2_block.h xfs_dir2_data.h
60 xfs_dir2_leaf.h xfs_dir2_node.h xfs_dir2_sf.h
61 xfs_dir_leaf.h xfs_dir_sf.h xfs_extfree_item.h xfs_ialloc.h
62 xfs_imap.h xfs_ialloc_btree.h xfs_inode.h xfs_inode_item.h
63 xfs_inum.h xfs_log.h xfs_log_priv.h xfs_log_recover.h
64 xfs_mount.h xfs_quota.h xfs_rtalloc.h
65 xfs_sb.h xfs_trans.h xfs_trans_space.h xfs_types.h xfs_fs.h
69 my ( $file, $prefix1, $prefix2 ) = @_;
71 `diff $prefix1/$file $prefix2/$file >/dev/null 2>&1`;
73 print sprintf("\t%-35s ... ", $file);
74 if ($? != 0) { printf("FAILED\n(%s/%s differs to %s/%s)\n",
75 $prefix1, $file, $prefix2, $file); }
76 else { print "ok\n"; }
79 printf("\t%-35s ... FAILED\n(%s/%s differs to %s/%s)\n",
80 $file, $prefix1, $file, $prefix2, $file);
85 # xfstests directory m4 directory is a repository of all of the
86 # custom m4 macros used in the packages we look after.
91 foreach (`ls $package/m4/*.m4`) {
92 my $m4 = `basename $_`;
94 straightdiff $m4, "$package/m4", "xfstests/m4";
98 my $first = shift @pkglist;
100 print "\n=== Checking $_ package ===\n";
102 straightdiff 'buildrules', "$first/include", "$_/include";
103 straightdiff 'buildmacros', "$first/include", "$_/include";
104 straightdiff 'Makefile', "$first/build", "$_/build";
105 straightdiff 'Makefile', "$first/build/rpm", "$_/build/rpm";
106 straightdiff 'Makefile', "$first/build/tar", "$_/build/tar";
108 print "\n=== Checking headers ===\n";
109 foreach (@difflist) {
110 straightdiff $_, 'xfsprogs/include', "$kworkarea";
112 straightdiff 'dmapi_kern.h', 'dmapi/include', "$kworkarea/dmapi";
113 straightdiff 'dmapi.h', 'dmapi/include', "$kworkarea/dmapi";
117 # Implements a tri-state FSA, see comments for state transitions
118 # (knows about the way the XFS kernel code is written, & makes
119 # some assumptions so as to not need to parse generic C code).
120 # Accepts one line at a time from a source file, picking out the
121 # function bodies so they can be subsequently compared.
124 my $line; # line number in current source file
125 my $state; # current FSA state
126 my $funcbody; # current function body (contents)
129 my ( $newline ) = @_;
133 # if line looks like start of a function, transition to 1
134 # & squirrel line away as line 1 of current function
136 if ($newline =~ m/^[xfs|xlog]/) {
138 $funcbody = $newline;
143 # if line looks like start of a function, stay here
144 # & squirrel line away as line 1 of current function
145 # otherwise if line isn't start of function body,
146 # squirrel line away as next line of current function
147 # (args/..., but not sure this is a real function yet)
148 # otherwise (start of function)
149 # squirrel line away as next line of current function
150 # transition to state 2
151 elsif ($state == 1) {
152 if ($newline =~ m/^[xfs|xlog]/) {
153 $funcbody = $newline;
155 elsif ($newline =~ m/^\{/) {
157 $funcbody .= $newline;
162 # if line looks like end of function body,
163 # squirrel line away as last line of current function
164 # tell someone we have a complete function ready
165 # transition to state 0
167 # squirrel line away as next line of current function
168 elsif ($state == 2) {
169 $funcbody .= $newline;
170 if ($newline =~ m/^\}/) {
177 die "unknown state transition";
179 return undef; # i.e. not at end of a function
189 open(USER, "$file") || die "cannot open $file";
191 my $func = setstate($_);
192 push @funcs, $func if (defined($func)); # store function away
205 open(KERN, "$file") || die "cannot open $file";
207 my $func = setstate($_);
208 if (defined($func)) {
209 $func =~ m/^([xfs|xlog]\w+)\s*\(/;
210 next unless defined($1);
212 if (defined($func)) {
213 $funcs{$name} = $func; # store function away
222 my ( $sa, $sb ) = @_;
224 return unless defined($xdiff);
226 open(FILEA, "> /tmp/diff.user.$$") || die "cannot write to /tmp/diff.user.$$";
227 open(FILEB, "> /tmp/diff.kern.$$") || die "cannot write to /tmp/diff.kern.$$";
232 `$xdiff /tmp/diff.user.$$ /tmp/diff.kern.$$`;
233 unlink ("/tmp/diff.user.$$","/tmp/diff.kern.$$");
237 my ( $file, $prefix1, $prefix2 ) = @_;
243 print "\n=== Checking $file routines ===\n" unless ($quiet);
245 # iterate over user funcs, match up to kernel funcs
247 my @user = listfuncs "$prefix1/$file";
248 my %kern = hashfuncs "$prefix2/$file";
250 foreach my $userfunc (@user) {
252 $userfunc =~ m/^([xfs|xlog]\w+)\s*\(/;
253 next unless (defined($1));
257 if (exists($kern{$name})) {
258 if ($userfunc ne $kern{$name}) {
259 print "\n=== $file routines ===\n"
260 if (!$found++ && $quiet);
262 printf("\t%-35s ... ", $name);
264 diffme $userfunc, $kern{$name};
267 printf("\t%-35s ... ", $name);
272 print "Cannot find kernel function $userfunc";
273 print " in file $prefix2/$file\n";
276 ($count != 1) && ( $plural = 's' );
277 print "( Total: $count routine$plural checked in $file )\n" unless ($quiet);
280 # xfsprogs/{libxfs,libxlog}/* fs/xfs/*
282 xfs_alloc.c xfs_alloc_btree.c xfs_attr_leaf.c
283 xfs_bmap.c xfs_bmap_btree.c xfs_btree.c xfs_da_btree.c
284 xfs_dir.c xfs_dir2.c xfs_dir2_block.c xfs_dir2_data.c
285 xfs_dir2_leaf.c xfs_dir2_node.c xfs_dir2_sf.c
286 xfs_dir_leaf.c xfs_ialloc.c xfs_ialloc_btree.c
287 xfs_inode.c xfs_rtalloc.c xfs_mount.c xfs_trans.c
290 print "\n=== Checking libxfs code ===\n";
291 foreach (@funclist) {
292 functiondiff $_, 'xfsprogs/libxfs', "$kworkarea";
294 print "\n=== Checking libxlog code ===\n";
295 functiondiff 'xfs_log_recover.c', 'xfsprogs/libxlog', "$kworkarea";