debugfs.c 1.1 KB

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