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