From: Jeffrey Hutzelman Date: Sun, 16 Jun 2013 23:16:05 +0000 (-0400) Subject: Add a tool to find lock ID numbers X-Git-Tag: openafs-stable-1_8_0pre1~1085 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=e4ce2a544f8fcec7355f296a456ddcb6b84b7d93 Add a tool to find lock ID numbers This adds a Perl program, src/afs/findlocks, which grovels through the kernel module source tree, finds every location where a lock is obtained, and produces an index of lock site ID numbers. This can be used to find a lock when debugging, or when picking a new number. Run it as ./src/afs/findlocks src/afs Change-Id: I7fdcfb807a92dbb1938a0c37637e9122b52addd7 Reviewed-on: http://gerrit.openafs.org/9982 Tested-by: BuildBot Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear --- diff --git a/src/afs/findlocks b/src/afs/findlocks new file mode 100755 index 0000000..85f6f59 --- /dev/null +++ b/src/afs/findlocks @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use File::Find; +use IO::File; + +use strict; +use vars qw($Pat @Locks $DupOnly); + +# This pattern matches the function names we are looking for +$Pat = qr/(?:NB)?Obtain(?:Write|Shared|)Lock|UpgradeSToWLock/; + +if (@ARGV[0] eq '-d') { + $DupOnly = 1; + shift @ARGV; +} + +find( + sub { + return unless -f $_; + + my $path = $File::Find::name; + my $F = new IO::File($_, O_RDONLY) or die "$path: $!\n"; + while (<$F>) { + next unless /\b(?:$Pat)\(.*,\s*(\d+)\)/o; + $Locks[$1] ||= []; + push(@{$Locks[$1]}, sprintf("%s:%d", $path, $.)); + } + $F->close; + }, @ARGV); + +foreach my $id (0 .. @Locks) { + next unless defined $Locks[$id]; + next if $DupOnly && @{$Locks[$id]} < 2; + printf("%5d %s", $id, join(" ", map("$_\n", @{$Locks[$id]}))) +}