RAS: Export helper to get ras_debugfs_dir
[linux-2.6-block.git] / drivers / ras / debugfs.c
CommitLineData
457c8996 1// SPDX-License-Identifier: GPL-2.0-only
d963cd95 2#include <linux/debugfs.h>
0a54b809
VK
3#include <linux/ras.h>
4#include "debugfs.h"
d963cd95 5
9d2b6fa0 6static struct dentry *ras_debugfs_dir;
d963cd95
CG
7
8static atomic_t trace_count = ATOMIC_INIT(0);
9
9d2b6fa0
BPA
10struct dentry *ras_get_debugfs_root(void)
11{
12 return ras_debugfs_dir;
13}
14EXPORT_SYMBOL_GPL(ras_get_debugfs_root);
15
d963cd95
CG
16int ras_userspace_consumers(void)
17{
18 return atomic_read(&trace_count);
19}
20EXPORT_SYMBOL_GPL(ras_userspace_consumers);
21
22static int trace_show(struct seq_file *m, void *v)
23{
50865c14 24 return 0;
d963cd95
CG
25}
26
27static int trace_open(struct inode *inode, struct file *file)
28{
29 atomic_inc(&trace_count);
30 return single_open(file, trace_show, NULL);
31}
32
33static int trace_release(struct inode *inode, struct file *file)
34{
35 atomic_dec(&trace_count);
36 return single_release(inode, file);
37}
38
39static const struct file_operations trace_fops = {
40 .open = trace_open,
41 .read = seq_read,
42 .llseek = seq_lseek,
43 .release = trace_release,
44};
45
46int __init ras_add_daemon_trace(void)
47{
48 struct dentry *fentry;
49
50 if (!ras_debugfs_dir)
51 return -ENOENT;
52
53 fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
54 NULL, &trace_fops);
2a1d18a5 55 if (IS_ERR(fentry))
d963cd95
CG
56 return -ENODEV;
57
58 return 0;
59
60}
61
62void __init ras_debugfs_init(void)
63{
64 ras_debugfs_dir = debugfs_create_dir("ras", NULL);
65}