From 2ebc305be64cd59ad8cb4ccb6beb6ec6e66bf07a Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 14 Nov 2014 13:31:03 +1100 Subject: 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 Reviewed-by: Amitay Isaacs --- ctdb/config/functions | 40 +++++++++++++++++++------------- 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 @@ -210,6 +210,27 @@ get_proc () cat "/proc/$1" } +###################################################### +# 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 @@ -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}[] fake_stack_trace_for_pid_${_pid}/stack+0x0/0xff" done fi -- cgit