File: debugfs.c

package info (click to toggle)
linux 4.19.20-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 954,852 kB
  • sloc: ansic: 16,749,828; asm: 271,286; makefile: 38,257; sh: 32,808; perl: 27,671; python: 21,022; cpp: 5,063; yacc: 4,648; lex: 2,585; awk: 1,385; ruby: 25; sed: 5
file content (56 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <linux/debugfs.h>

struct dentry *ras_debugfs_dir;

static atomic_t trace_count = ATOMIC_INIT(0);

int ras_userspace_consumers(void)
{
	return atomic_read(&trace_count);
}
EXPORT_SYMBOL_GPL(ras_userspace_consumers);

static int trace_show(struct seq_file *m, void *v)
{
	return atomic_read(&trace_count);
}

static int trace_open(struct inode *inode, struct file *file)
{
	atomic_inc(&trace_count);
	return single_open(file, trace_show, NULL);
}

static int trace_release(struct inode *inode, struct file *file)
{
	atomic_dec(&trace_count);
	return single_release(inode, file);
}

static const struct file_operations trace_fops = {
	.open    = trace_open,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = trace_release,
};

int __init ras_add_daemon_trace(void)
{
	struct dentry *fentry;

	if (!ras_debugfs_dir)
		return -ENOENT;

	fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
				     NULL, &trace_fops);
	if (!fentry)
		return -ENODEV;

	return 0;

}

void __init ras_debugfs_init(void)
{
	ras_debugfs_dir = debugfs_create_dir("ras", NULL);
}