fault_inject.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2011 Bryan Schumaker <bjschuma@netapp.com>
  3. *
  4. * Uses debugfs to create fault injection points for client testing
  5. */
  6. #include <linux/types.h>
  7. #include <linux/fs.h>
  8. #include <linux/debugfs.h>
  9. #include <linux/module.h>
  10. #include "state.h"
  11. #include "fault_inject.h"
  12. struct nfsd_fault_inject_op {
  13. char *file;
  14. void (*func)(u64);
  15. };
  16. static struct nfsd_fault_inject_op inject_ops[] = {
  17. {
  18. .file = "forget_clients",
  19. .func = nfsd_forget_clients,
  20. },
  21. {
  22. .file = "forget_locks",
  23. .func = nfsd_forget_locks,
  24. },
  25. {
  26. .file = "forget_openowners",
  27. .func = nfsd_forget_openowners,
  28. },
  29. {
  30. .file = "forget_delegations",
  31. .func = nfsd_forget_delegations,
  32. },
  33. {
  34. .file = "recall_delegations",
  35. .func = nfsd_recall_delegations,
  36. },
  37. };
  38. static long int NUM_INJECT_OPS = sizeof(inject_ops) / sizeof(struct nfsd_fault_inject_op);
  39. static struct dentry *debug_dir;
  40. static int nfsd_inject_set(void *op_ptr, u64 val)
  41. {
  42. struct nfsd_fault_inject_op *op = op_ptr;
  43. if (val == 0)
  44. printk(KERN_INFO "NFSD Fault Injection: %s (all)", op->file);
  45. else
  46. printk(KERN_INFO "NFSD Fault Injection: %s (n = %llu)", op->file, val);
  47. op->func(val);
  48. return 0;
  49. }
  50. static int nfsd_inject_get(void *data, u64 *val)
  51. {
  52. return 0;
  53. }
  54. DEFINE_SIMPLE_ATTRIBUTE(fops_nfsd, nfsd_inject_get, nfsd_inject_set, "%llu\n");
  55. void nfsd_fault_inject_cleanup(void)
  56. {
  57. debugfs_remove_recursive(debug_dir);
  58. }
  59. int nfsd_fault_inject_init(void)
  60. {
  61. unsigned int i;
  62. struct nfsd_fault_inject_op *op;
  63. umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
  64. debug_dir = debugfs_create_dir("nfsd", NULL);
  65. if (!debug_dir)
  66. goto fail;
  67. for (i = 0; i < NUM_INJECT_OPS; i++) {
  68. op = &inject_ops[i];
  69. if (!debugfs_create_file(op->file, mode, debug_dir, op, &fops_nfsd))
  70. goto fail;
  71. }
  72. return 0;
  73. fail:
  74. nfsd_fault_inject_cleanup();
  75. return -ENOMEM;
  76. }