diff options
author | Martin Schwenke <martin@meltin.net> | 2014-11-14 13:31:03 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2014-11-18 04:17:10 +0100 |
commit | 2ebc305be64cd59ad8cb4ccb6beb6ec6e66bf07a (patch) | |
tree | d1afb9cfe6dbbaf740f1fb4f2448561f04fd736f | |
parent | 0062a2f5fb464b7c0991ccefd2f9d146fca54a0e (diff) | |
download | samba-2ebc305be64cd59ad8cb4ccb6beb6ec6e66bf07a.tar.gz samba-2ebc305be64cd59ad8cb4ccb6beb6ec6e66bf07a.tar.xz samba-2ebc305be64cd59ad8cb4ccb6beb6ec6e66bf07a.zip |
ctdb-scripts: Factor out new function program_stack_traces()
In the process, fix a bug where an extra trace would be printed.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
-rwxr-xr-x | ctdb/config/functions | 40 | ||||
-rw-r--r-- | ctdb/tests/eventscripts/scripts/local.sh | 2 |
2 files changed, 25 insertions, 17 deletions
diff --git a/ctdb/config/functions b/ctdb/config/functions index 53a36dc335..49553c7355 100755 --- a/ctdb/config/functions +++ b/ctdb/config/functions @@ -211,6 +211,27 @@ get_proc () } ###################################################### +# Print up to $_max kernel stack traces for processes named $_program +program_stack_traces () +{ + _prog="$1" + _max="${2:-1}" + + _count=1 + for _pid in $(pidof "$_prog") ; do + [ $_count -le $_max ] || break + + # Do this first to avoid racing with process exit + _stack=$(get_proc "${_pid}/stack" 2>/dev/null) + if [ -n "$_stack" ] ; then + echo "Stack trace for ${_prog}[${_pid}]:" + echo "$_stack" + _count=$(($_count + 1)) + fi + done +} + +###################################################### # Check that an RPC service is healthy - # this includes allowing a certain number of failures # before marking the NFS service unhealthy. @@ -745,23 +766,10 @@ startstop_nfs() { # Dump up to the configured number of nfsd thread backtraces. nfs_dump_some_threads () { - [ -n "$CTDB_NFS_DUMP_STUCK_THREADS" ] || CTDB_NFS_DUMP_STUCK_THREADS=5 - - # Optimisation to avoid running an unnecessary pidof - [ $CTDB_NFS_DUMP_STUCK_THREADS -gt 0 ] || return 0 + _num="${CTDB_NFS_DUMP_STUCK_THREADS:-5}" + [ $_num -gt 0 ] || return 0 - _count=0 - for _pid in $(pidof nfsd) ; do - [ $_count -le $CTDB_NFS_DUMP_STUCK_THREADS ] || break - - # Do this first to avoid racing with thread exit - _stack=$(get_proc "${_pid}/stack" 2>/dev/null) - if [ -n "$_stack" ] ; then - echo "Stack trace for stuck nfsd thread [${_pid}]:" - echo "$_stack" - _count=$(($_count + 1)) - fi - done + program_stack_traces "nfsd" $_num } ######################################################## diff --git a/ctdb/tests/eventscripts/scripts/local.sh b/ctdb/tests/eventscripts/scripts/local.sh index d14e42ec84..2c5738eefa 100644 --- a/ctdb/tests/eventscripts/scripts/local.sh +++ b/ctdb/tests/eventscripts/scripts/local.sh @@ -861,7 +861,7 @@ Trying to restart NFS service" for _pid in $FAKE_NFSD_THREAD_PIDS ; do _t="\ $_t -${_bg}Stack trace for stuck nfsd thread [${_pid}]: +${_bg}Stack trace for nfsd[${_pid}]: ${_bg}[<ffffffff87654321>] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff" done fi |