3 # This script parses /proc/locks and finds the processes that are holding
4 # locks on CTDB databases. For all those processes the script dumps a
7 # This script can be used only if Samba is configured to use fcntl locks
8 # rather than mutex locks.
10 [ -n "$CTDB_BASE" ] || \
11 export CTDB_BASE
=$
(cd -P $
(dirname "$0") ; echo "$PWD")
13 .
"$CTDB_BASE/functions"
15 # Default fallback location for database directories.
16 # These can be overwritten from CTDB configuration
17 CTDB_DBDIR
="${CTDB_VARDIR}"
18 CTDB_DBDIR_PERSISTENT
="${CTDB_VARDIR}/persistent"
25 echo "===== Start of debug locks PID=$$ ====="
27 # Create sed expression to convert inodes to names
28 sed_cmd
=$
( ls -li "$CTDB_DBDIR"/*.tdb.
* "$CTDB_DBDIR_PERSISTENT"/*.tdb.
* |
29 sed -e "s#${CTDB_DBDIR}/\(.*\)#\1#" \
30 -e "s#${CTDB_DBDIR_PERSISTENT}/\(.*\)#\1#" |
31 awk '{printf "s#[0-9a-f]*:[0-9a-f]*:%s #%s #\n", $1, $10}' )
33 # Parse /proc/locks and extract following information
34 # pid process_name tdb_name offsets [W]
35 out
=$
( cat /proc
/locks |
36 grep -F "POSIX ADVISORY WRITE" |
37 awk '{ if($2 == "->") { print $6, $7, $8, $9, "W" } else { print $5, $6, $7, $8 } }' |
38 while read pid rest
; do
39 pname
=$
(readlink
/proc
/$pid/exe
)
40 echo $pid $pname $rest
41 done |
sed -e "$sed_cmd" |
grep "\.tdb" )
43 if [ -n "$out" ]; then
44 # Log information about locks
47 # Find processes that are waiting for locks
48 dbs
=$
(echo "$out" |
grep "W$" |
awk '{print $3}')
51 pids
=$
(echo "$out" |
grep -v "W$" |
grep "$db" |
grep -v ctdbd |
awk '{print $1}')
52 all_pids
="$all_pids $pids"
54 pids
=$
(echo $all_pids |
tr " " "\n" |
sort -u)
56 # For each process waiting, log stack trace
58 echo "----- Stack trace for PID=$pid -----"
59 read x x state x
</proc
/$pid/stat
60 if [ "$state" = "D" ] ; then
61 # Don't run gstack on a process in D state since
62 # gstack will hang until the process exits D state.
63 # Although it is possible for a process to transition
64 # to D state after this check, it is unlikely because
65 # if a process is stuck in D state then it is probably
66 # the reason why this script was called. Note that a
67 # kernel stack almost certainly won't help diagnose a
68 # deadlock... but it will probably give us someone to
70 echo "----- Process in D state, printing kernel stack only"
74 # gcore -o /var/log/core-deadlock-ctdb $pid
79 echo "===== End of debug locks PID=$$ ====="
80 )9>"${CTDB_SCRIPT_VARDIR}/debug_locks.lock" | script_log
"ctdbd-lock"