#!/bin/bash # # Copyright (c) 2011 Bryan Schumaker # # Script for easier NFSD fault injection # Check that debugfs has been mounted global DEBUGFS := $[cat /proc/mounts | grep debugfs] if test $DEBUGFS == "" { echo "debugfs does not appear to be mounted!" echo "Please mount debugfs and try again" exit 1 } # Check that the fault injection directory exists global DEBUGDIR := "$[echo $DEBUGFS | awk '{print $2}]/nfsd" if test ! -d $DEBUGDIR { echo "$DEBUGDIR does not exist" echo "Check that your .config selects CONFIG_NFSD_FAULT_INJECTION" exit 1 } proc help { echo "Usage $0 injection_type [count]" echo "" echo "Injection types are:" ls $DEBUGDIR exit 1 } if test $Argc == 0 { help } elif test ! -f $DEBUGDIR/$1 { help } elif test $Argc != 2 { global COUNT := '0' } else { global COUNT := $2 } global BEFORE := $[mktemp] global 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 (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DEBUGFS) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(cat)} {(/proc/mounts)}) (C {(grep)} {(debugfs)})] negated: False ) ] ) left_token: spids: [20 30] ) } spids: [19] ) ] spids: [19] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$DEBUGFS"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ )} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("debugfs does not appear to be mounted!"))}) (C {(echo)} {(DQ ("Please mount debugfs and try again"))}) (C {(exit)} {(1)}) ] spids: [-1 49] ) ] spids: [-1 70] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DEBUGDIR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {($ VSub_Name "$DEBUGFS")}) (C {(awk)} {(SQ <"{print $2}">)}) ] negated: False ) ] ) left_token: spids: [77 89] ) (/nfsd) } spids: [76] ) ] spids: [76] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-d)} {(DQ ($ VSub_Name "$DEBUGDIR"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ($ VSub_Name "$DEBUGDIR") (" does not exist"))}) (C {(echo)} {(DQ ("Check that your .config selects CONFIG_NFSD_FAULT_INJECTION"))}) (C {(exit)} {(1)}) ] spids: [-1 107] ) ] spids: [-1 129] ) (FuncDef name: help body: (BraceGroup children: [ (C {(echo)} {(DQ ("Usage ") ($ VSub_Number "$0") (" injection_type [count]"))}) (C {(echo)} {(DQ )}) (C {(echo)} {(DQ ("Injection types are:"))}) (C {(ls)} {($ VSub_Name "$DEBUGDIR")}) (C {(exit)} {(1)}) ] spids: [138] ) spids: [132 137] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(Lit_Other "=") (Lit_Other "=")} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(help)})] spids: [-1 189] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-f)} {($ VSub_Name "$DEBUGDIR") (/) ($ VSub_Number "$1")} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(help)})] spids: [194 209] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Pound "$#")} {(KW_Bang "!") (Lit_Other "=")} {(2)} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:COUNT) op:Equal rhs:{(0)} spids:[231])] spids: [231] ) ] spids: [214 228] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COUNT) op: Equal rhs: {($ VSub_Number "$2")} spids: [237] ) ] spids: [237] ) ] spids: [234 240] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BEFORE) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)})]) left_token: spids: [244 246] ) } spids: [243] ) ] spids: [243] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:AFTER) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(mktemp)})]) left_token: spids: [249 251] ) } spids: [248] ) ] spids: [248] ) (SimpleCommand words: [{(dmesg)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Name "$BEFORE")} spids:[255])] ) (SimpleCommand words: [{(echo)} {($ VSub_Name "$COUNT")}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$DEBUGDIR") (/) ($ VSub_Number "$1")} spids: [263] ) ] ) (SimpleCommand words: [{(dmesg)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{($ VSub_Name "$AFTER")} spids:[271])] ) (Pipeline children: [ (C {(diff)} {($ VSub_Name "$BEFORE")} {($ VSub_Name "$AFTER")}) (C {(grep)} {(DQ (">"))}) ] negated: False ) (C {(rm)} {(-f)} {($ VSub_Name "$BEFORE")} {($ VSub_Name "$AFTER")}) ] )