debugfs.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/debugfs.h>
  3. #include <linux/ras.h>
  4. #include "debugfs.h"
  5. static struct dentry *ras_debugfs_dir;
  6. static atomic_t trace_count = ATOMIC_INIT(0);
  7. struct dentry *ras_get_debugfs_root(void)
  8. {
  9. return ras_debugfs_dir;
  10. }
  11. EXPORT_SYMBOL_GPL(ras_get_debugfs_root);
  12. int ras_userspace_consumers(void)
  13. {
  14. return atomic_read(&trace_count);
  15. }
  16. EXPORT_SYMBOL_GPL(ras_userspace_consumers);
  17. static int trace_show(struct seq_file *m, void *v)
  18. {
  19. return 0;
  20. }
  21. static int trace_open(struct inode *inode, struct file *file)
  22. {
  23. atomic_inc(&trace_count);
  24. return single_open(file, trace_show, NULL);
  25. }
  26. static int trace_release(struct inode *inode, struct file *file)
  27. {
  28. atomic_dec(&trace_count);
  29. return single_release(inode, file);
  30. }
  31. static const struct file_operations trace_fops = {
  32. .open = trace_open,
  33. .read = seq_read,
  34. .llseek = seq_lseek,
  35. .release = trace_release,
  36. };
  37. int __init ras_add_daemon_trace(void)
  38. {
  39. struct dentry *fentry;
  40. if (!ras_debugfs_dir)
  41. return -ENOENT;
  42. fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
  43. NULL, &trace_fops);
  44. if (IS_ERR(fentry))
  45. return -ENODEV;
  46. return 0;
  47. }
  48. void __init ras_debugfs_init(void)
  49. {
  50. ras_debugfs_dir = debugfs_create_dir("ras", NULL);
  51. }