inject_fault.sh 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
  4. #
  5. # Script for easier NFSD fault injection
  6. # Check that debugfs has been mounted
  7. DEBUGFS=`cat /proc/mounts | grep debugfs`
  8. if [ "$DEBUGFS" == "" ]; then
  9. echo "debugfs does not appear to be mounted!"
  10. echo "Please mount debugfs and try again"
  11. exit 1
  12. fi
  13. # Check that the fault injection directory exists
  14. DEBUGDIR=`echo $DEBUGFS | awk '{print $2}'`/nfsd
  15. if [ ! -d "$DEBUGDIR" ]; then
  16. echo "$DEBUGDIR does not exist"
  17. echo "Check that your .config selects CONFIG_NFSD_FAULT_INJECTION"
  18. exit 1
  19. fi
  20. function help()
  21. {
  22. echo "Usage $0 injection_type [count]"
  23. echo ""
  24. echo "Injection types are:"
  25. ls $DEBUGDIR
  26. exit 1
  27. }
  28. if [ $# == 0 ]; then
  29. help
  30. elif [ ! -f $DEBUGDIR/$1 ]; then
  31. help
  32. elif [ $# != 2 ]; then
  33. COUNT=0
  34. else
  35. COUNT=$2
  36. fi
  37. BEFORE=`mktemp`
  38. AFTER=`mktemp`
  39. dmesg > $BEFORE
  40. echo $COUNT > $DEBUGDIR/$1
  41. dmesg > $AFTER
  42. # Capture lines that only exist in the $AFTER file
  43. diff $BEFORE $AFTER | grep ">"
  44. rm -f $BEFORE $AFTER