Skip to contentSkip to conversation

NFSD: Added fault injection

PATCH In review [email protected] 2 participants 6 messages Oct 7, 2011 – Oct 18, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 NFSD: Added fault injection

From: Bryan Schumaker <[email protected]>

Fault injection on the NFS server makes it easier to test the client's state manager and recovery threads. Simulating errors on the server is easier than finding the right conditions that cause them naturally.

This patch uses debugfs to add a simple framework for fault injection to the server. This framework is a config option, and can be enabled through CONFIG_NFSD_FAULT_INJECTION. Assuming you have debugfs mounted to /sys/debug, a set of files will be created in /sys/debug/nfsd/. Writing to any of these files will cause the corresponding action and write a log entry to dmesg.

Changes in v4:
- Move fault injection function declarations to a new .h file
- Use the Makefile to selectively compile fault_injection.c
- Add copyright notices to top of files

Changes in v3:
- Code cleanup and better use of generic functions
- Allow the user to input the number of state objects to delete
- Remove "forget_everything()" since forgetting a client is basically the same thing

Changes in v2:
- Replaced "forget all state owners" with "forget all open owners"
- Include fs/nfsd/fault_inject.c in the patch

---
 fs/nfsd/Kconfig        |   10 ++++
 fs/nfsd/Makefile       |    1 +
 fs/nfsd/fault_inject.c |   94 +++++++++++++++++++++++++++++++++++++++
 fs/nfsd/fault_inject.h |   28 ++++++++++++
 fs/nfsd/nfs4state.c    |  115 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/nfsctl.c       |    7 +++
 6 files changed, 255 insertions(+), 0 deletions(-)
 create mode 100644 fs/nfsd/fault_inject.c
 create mode 100644 fs/nfsd/fault_inject.h
fs/nfsd/Kconfig +10 -0
index 10e6366..52fdd1c 100644
@@ -80,3 +80,13 @@ config NFSD_V4
 	  available from http://linux-nfs.org/.
 
 	  If unsure, say N.
+
+config NFSD_FAULT_INJECTION
+	bool "NFS server manual fault injection"
+	depends on NFSD_V4 && DEBUG_KERNEL
+	help
+	  This option enables support for manually injectiong faults
+	  into the NFS server.  This is intended to be used for
+	  testing error recovery on the NFS client.
+
+	  If unsure, say N.
fs/nfsd/Makefile +1 -0
index 9b118ee..af32ef0 100644
@@ -6,6 +6,7 @@ obj-$(CONFIG_NFSD)	+= nfsd.o
 
 nfsd-y 			:= nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
 			   export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
+nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
 nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
 nfsd-$(CONFIG_NFSD_V3)	+= nfs3proc.o nfs3xdr.o
 nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o
fs/nfsd/fault_inject.c new file +94 -0

94 lines not on this page · raw message

fs/nfsd/fault_inject.h new file +28 -0
new file mode 100644
index 0000000..90bd057
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011 Bryan Schumaker <[email protected]>
+ *
+ * Function definitions for fault injection
+ */
+
+#ifndef LINUX_NFSD_FAULT_INJECT_H
+#define LINUX_NFSD_FAULT_INJECT_H
+
+#ifdef CONFIG_NFSD_FAULT_INJECTION
+int nfsd_fault_inject_init(void);
+void nfsd_fault_inject_cleanup(void);
+void nfsd_forget_clients(u64);
+void nfsd_forget_locks(u64);
+void nfsd_forget_openowners(u64);
+void nfsd_forget_delegations(u64);
+void nfsd_recall_delegations(u64);
+#else /* CONFIG_NFSD_FAULT_INJECTION */
+static inline int nfsd_fault_inject_init(void) { return 0; }
+static inline void nfsd_fault_inject_cleanup(void) {}
+static inline void nfsd_forget_clients(u64 num) {}
+static inline void nfsd_forget_locks(u64 num) {}
+static inline void nfsd_forget_openowners(u64 num) {}
+static inline void nfsd_forget_delegations(u64 num) {}
+static inline void nfsd_recall_delegations(u64 num) {}
+#endif /* CONFIG_NFSD_FAULT_INJECTION */
+
+#endif /* LINUX_NFSD_FAULT_INJECT_H */
fs/nfsd/nfs4state.c +115 -0

121 lines not on this page · raw message

fs/nfsd/nfsctl.c +7 -0
index db34a58..e67f30c 100644
@@ -17,6 +17,7 @@
 #include "idmap.h"
 #include "nfsd.h"
 #include "cache.h"
+#include "fault_inject.h"
 
 /*
  *	We have a single directory with several nodes in it.
@@ -1130,6 +1131,9 @@ static int __init init_nfsd(void)
 	retval = nfs4_state_init(); /* nfs4 locking state */
 	if (retval)
 		return retval;
+	retval = nfsd_fault_inject_init(); /* nfsd fault injection controls */
+	if (retval)
+		goto out_cleanup_fault_injection;
 	nfsd_stat_init();	/* Statistics */
 	retval = nfsd_reply_cache_init();
 	if (retval)
@@ -1161,6 +1165,8 @@ out_free_cache:
 out_free_stat:
 	nfsd_stat_shutdown();
 	nfsd4_free_slabs();
+out_cleanup_fault_injection:
+	nfsd_fault_inject_cleanup();
 	return retval;
 }
 
@@ -1174,6 +1180,7 @@ static void __exit exit_nfsd(void)
 	nfsd_lockd_shutdown();
 	nfsd_idmap_shutdown();
 	nfsd4_free_slabs();
+	nfsd_fault_inject_cleanup();
 	unregister_filesystem(&nfsd_fs_type);
 }
 
Signature · 1 line
1.7.7
#1 lore raw

PATCH 2/3 NFSD: Added fault injection script

From: Bryan Schumaker <[email protected]>

This script provides a convenient way to use the NFSD fault injection framework. Fault injection writes to dmesg using the KERN_INFO flag, so this script will compare the before and after output of dmesg to show the user what happened

---
 tools/nfsd/inject_fault.sh |   49 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100755 tools/nfsd/inject_fault.sh
tools/nfsd/inject_fault.sh new file +49 -0
new file mode 100755
index 0000000..06a399a
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Copyright (c) 2011 Bryan Schumaker <[email protected]>
+#
+# 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
Signature · 1 line
1.7.7
#2 lore raw

PATCH 3/3 NFSD: Added fault injection documentation

In reply to [email protected]

From: Bryan Schumaker <[email protected]>

---
 Documentation/filesystems/nfs/00-INDEX            |    2 +
 Documentation/filesystems/nfs/fault_injection.txt |   69 +++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/fault_injection.txt
Documentation/filesystems/nfs/00-INDEX +2 -0
index a57e124..1716874 100644
@@ -2,6 +2,8 @@
 	- this file (nfs-related documentation).
 Exporting
 	- explanation of how to make filesystems exportable.
+fault_injection.txt
+	- information for using fault injection on the server
 knfsd-stats.txt
 	- statistics which the NFS server makes available to user space.
 nfs.txt
Documentation/filesystems/nfs/fault_injection.txt new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
1.7.7
#3 lore raw
In reply to [email protected]
Quoted 5 lines · On Fri, Oct 07, 2011 at 01:44:26PM -0400, [email protected] wrote:
fs/nfsd/Kconfig +0 -0
index 10e6366..52fdd1c 100644

fs/nfsd/Kconfig config NFSD_V4 · line 88

Quoted 9 lines
fs/nfsd/Kconfig +6 -0
@@ -80,3 +80,13 @@ config NFSD_V4
 	  available from http://linux-nfs.org/.
 
 	  If unsure, say N.
+
+config NFSD_FAULT_INJECTION
+	bool "NFS server manual fault injection"
+	depends on NFSD_V4 && DEBUG_KERNEL
+	help
+	  This option enables support for manually injectiong faults
						   ^^^^^^^^^^
Quoted 32 lines
fs/nfsd/fault_inject.c new file +26 -0
new file mode 100644
index 0000000..9f6815b
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2011 Bryan Schumaker <[email protected]>
+ *
+ * Uses debugfs to create fault injection points for client testing
+ */
+
+#include <linux/types.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <linux/module.h>
+
+#include "state.h"
+#include "fault_inject.h"
+
+struct nfsd_fault_inject_op {
+	char *action;
+	char *item;
+	char *file;
+	int file_data;
+	void (*func)(u64);
+};
+
+#define INJECTION_OP(op_action, op_item, op_func)	\
+{							\
+	.action = op_action,				\
+	.item   = op_item,				\

fs/nfsd/fault_inject.c line 36

Quoted 10 lines
fs/nfsd/fault_inject.c new file +10 -0
+	.file   = op_action"_"op_item,			\
+	.func   = op_func,				\
+}
+
+static struct nfsd_fault_inject_op inject_ops[] = {
+	INJECTION_OP("forget", "clients",     nfsd_forget_clients),
+	INJECTION_OP("forget", "locks",       nfsd_forget_locks),
+	INJECTION_OP("forget", "openowners",  nfsd_forget_openowners),
+	INJECTION_OP("forget", "delegations", nfsd_forget_delegations),
+	INJECTION_OP("recall", "delegations", nfsd_recall_delegations),

This is a little clever for my taste.... Could we just do

	static struct nfsd_fault_inject_op inject_ops[] = {
		{
			.file = "forget_client",
			.op = nfsd_forget_clients,
		},
		...
	}

and do away with the separate item and action fields?

I'd rather be sort of obvious and boring even if it's slightly less compact.

fs/nfsd/fault_inject.c line 49

Quoted 13 lines
fs/nfsd/fault_inject.c new file +13 -0
+};
+
+static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);
+static struct dentry *debug_dir;
+
+static int nfsd_inject_set(void *data, u64 val)
+{
+	int i;
+	struct nfsd_fault_inject_op *op;
+
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		if (&op->file_data == data) {

Huh, OK, so if I understand right, the contents of file_data doesn't matter, you're just using a pointer to that field as a way to identify the op array.

But then couldn't you just pass in a pointer to the op itself:

fs/nfsd/fault_inject.c line 87

Quoted 3 lines
fs/nfsd/fault_inject.c new file +3 -0
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		debugfs_create_file(op->file, mode, debug_dir, &op->file_data, &fops_nfsd);

like:

		debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd);

and eliminate the file_data field?

Patches look OK otherwise on a quick skim, thanks.

--b.

Quoted 2 lines
fs/nfsd/fault_inject.c new file +2 -0
+	}
+	return 0;
#4 lore raw
Quoted 8 lines · J. Bruce Fields
Quoted 7 lines · On Fri, Oct 07, 2011 at 01:44:26PM -0400, [email protected] wrote:
fs/nfsd/Kconfig +0 -0
index 10e6366..52fdd1c 100644
@@ -80,3 +80,13 @@ config NFSD_V4
 	  available from http://linux-nfs.org/.
 
Quoted 8 lines

fs/nfsd/Kconfig config NFSD_V4 · line 88

Quoted 7 lines
fs/nfsd/Kconfig +6 -0
 	  If unsure, say N.
+
+config NFSD_FAULT_INJECTION
+	bool "NFS server manual fault injection"
+	depends on NFSD_V4 && DEBUG_KERNEL
+	help
+	  This option enables support for manually injectiong faults
						   ^^^^^^^^^^

Good catch, this is a weird cross between "injection" and "injecting"

Quoted 54 lines
Quoted 33 lines
fs/nfsd/fault_inject.c new file +26 -0
new file mode 100644
index 0000000..9f6815b
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2011 Bryan Schumaker <[email protected]>
+ *
+ * Uses debugfs to create fault injection points for client testing
+ */
+
+#include <linux/types.h>
+#include <linux/fs.h>
+#include <linux/debugfs.h>
+#include <linux/module.h>
+
+#include "state.h"
+#include "fault_inject.h"
+
+struct nfsd_fault_inject_op {
+	char *action;
+	char *item;
+	char *file;
+	int file_data;
+	void (*func)(u64);
+};
+
+#define INJECTION_OP(op_action, op_item, op_func)	\
+{							\
+	.action = op_action,				\
+	.item   = op_item,				\

fs/nfsd/fault_inject.c line 36

Quoted 10 lines
fs/nfsd/fault_inject.c new file +10 -0
+	.file   = op_action"_"op_item,			\
+	.func   = op_func,				\
+}
+
+static struct nfsd_fault_inject_op inject_ops[] = {
+	INJECTION_OP("forget", "clients",     nfsd_forget_clients),
+	INJECTION_OP("forget", "locks",       nfsd_forget_locks),
+	INJECTION_OP("forget", "openowners",  nfsd_forget_openowners),
+	INJECTION_OP("forget", "delegations", nfsd_forget_delegations),
+	INJECTION_OP("recall", "delegations", nfsd_recall_delegations),

This is a little clever for my taste.... Could we just do

	static struct nfsd_fault_inject_op inject_ops[] = {
		{
			.file = "forget_client",
			.op = nfsd_forget_clients,
		},
		...
	}
Quoted 5 lines

and do away with the separate item and action fields?

I'd rather be sort of obvious and boring even if it's slightly less compact.

I was going for compact when I initially wrote this, but I can change it. I have them as separate fields so I can print out slightly different messages based on what is going on. Such as: "NFSD: Server forgetting all clients" or "NFSD: Server recalling at most 4 delegations".

Quoted 26 lines

fs/nfsd/fault_inject.c line 49

Quoted 13 lines
fs/nfsd/fault_inject.c new file +13 -0
+};
+
+static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);
+static struct dentry *debug_dir;
+
+static int nfsd_inject_set(void *data, u64 val)
+{
+	int i;
+	struct nfsd_fault_inject_op *op;
+
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		if (&op->file_data == data) {

Huh, OK, so if I understand right, the contents of file_data doesn't matter, you're just using a pointer to that field as a way to identify the op array.

But then couldn't you just pass in a pointer to the op itself:

fs/nfsd/fault_inject.c line 87

Quoted 3 lines
fs/nfsd/fault_inject.c new file +3 -0
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		debugfs_create_file(op->file, mode, debug_dir, &op->file_data, &fops_nfsd);

like:

Quoted 3 lines
		debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd);

and eliminate the file_data field?

I've never thought about trying it that way, but it seems fairly straightforward. I'll try it that way and see if it works!

Quoted 8 lines

Patches look OK otherwise on a quick skim, thanks.

--b.

Quoted 2 lines
fs/nfsd/fault_inject.c new file +2 -0
+	}
+	return 0;
#5 lore raw
Quoted 27 lines · Bryan Schumaker
Quoted 26 lines · J. Bruce Fields
Quoted 4 lines · On Fri, Oct 07, 2011 at 01:44:26PM -0400, [email protected] wrote:
fs/nfsd/fault_inject.c new file +4 -0
+#define INJECTION_OP(op_action, op_item, op_func)	\
+{							\
+	.action = op_action,				\
+	.item   = op_item,				\

fs/nfsd/fault_inject.c line 36

Quoted 10 lines
fs/nfsd/fault_inject.c new file +10 -0
+	.file   = op_action"_"op_item,			\
+	.func   = op_func,				\
+}
+
+static struct nfsd_fault_inject_op inject_ops[] = {
+	INJECTION_OP("forget", "clients",     nfsd_forget_clients),
+	INJECTION_OP("forget", "locks",       nfsd_forget_locks),
+	INJECTION_OP("forget", "openowners",  nfsd_forget_openowners),
+	INJECTION_OP("forget", "delegations", nfsd_forget_delegations),
+	INJECTION_OP("recall", "delegations", nfsd_recall_delegations),

This is a little clever for my taste.... Could we just do

	static struct nfsd_fault_inject_op inject_ops[] = {
		{
			.file = "forget_client",
			.op = nfsd_forget_clients,
		},
		...
	}
Quoted 6 lines
Quoted 5 lines

and do away with the separate item and action fields?

I'd rather be sort of obvious and boring even if it's slightly less compact.

I was going for compact when I initially wrote this, but I can change it. I have them as separate fields so I can print out slightly different messages based on what is going on. Such as: "NFSD: Server forgetting all clients" or "NFSD: Server recalling at most 4 delegations".

Even

	{ .file = "forget_client", .op=nfsd_forget_clients },
	{ ... }

would be fine by me and still pretty compact.

And log messages are probably a good idea but I don't think they have to be beautiful--"NFSD: recall_delegations(4)" would do fine.

--b.

Quoted 45 lines
Quoted 27 lines
Quoted 4 lines
fs/nfsd/fault_inject.c new file +3 -0
+};
+
+static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);

fs/nfsd/fault_inject.c line 49

Quoted 10 lines
fs/nfsd/fault_inject.c new file +10 -0
+static struct dentry *debug_dir;
+
+static int nfsd_inject_set(void *data, u64 val)
+{
+	int i;
+	struct nfsd_fault_inject_op *op;
+
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		if (&op->file_data == data) {

Huh, OK, so if I understand right, the contents of file_data doesn't matter, you're just using a pointer to that field as a way to identify the op array.

But then couldn't you just pass in a pointer to the op itself:

fs/nfsd/fault_inject.c line 87

Quoted 3 lines
fs/nfsd/fault_inject.c new file +3 -0
+	for (i = 0; i < NUM_INJECT_OPS; i++) {
+		op = &inject_ops[i];
+		debugfs_create_file(op->file, mode, debug_dir, &op->file_data, &fops_nfsd);

like:

Quoted 3 lines
		debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd);

and eliminate the file_data field?

I've never thought about trying it that way, but it seems fairly straightforward. I'll try it that way and see if it works!

Quoted 8 lines

Patches look OK otherwise on a quick skim, thanks.

--b.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	}
+	return 0;

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html