inject_fault.sh 1.0 KB

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