debugfs.c 1.1 KB

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