summaryrefslogtreecommitdiff
path: root/tools/nfsd/inject_fault.sh
blob: 10ceee64a09a8c2ad0b3153f6bd96155ce423ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
#
# Script for easier NFSD fault injection

# Check that debugfs has been mounted
DEBUGFS=`cat /proc/mounts | grep debugfs`
if [ "$DEBUGFS" == "" ]; then
	echo "debugfs does not appear to be mounted!"
	echo "Please mount debugfs and try again"
	exit 1
fi

# Check that the fault injection directory exists
DEBUGDIR=`echo $DEBUGFS | awk '{print $2}'`/nfsd
if [ ! -d "$DEBUGDIR" ]; then
	echo "$DEBUGDIR does not exist"
	echo "Check that your .config selects CONFIG_NFSD_FAULT_INJECTION"
	exit 1
fi

function help()
{
	echo "Usage $0 injection_type [count]"
	echo ""
	echo "Injection types are:"
	ls $DEBUGDIR
	exit 1
}

if [ $# == 0 ]; then
	help
elif [ ! -f $DEBUGDIR/$1 ]; then
	help
elif [ $# != 2 ]; then
	COUNT=0
else
	COUNT=$2
fi

BEFORE=`mktemp`
AFTER=`mktemp`
dmesg > $BEFORE
echo $COUNT > $DEBUGDIR/$1
dmesg > $AFTER
# Capture lines that only exist in the $AFTER file
diff $BEFORE $AFTER | grep ">"
rm -f $BEFORE $AFTER