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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef _LINUX_REF_TRACKER_H
#define _LINUX_REF_TRACKER_H
#include <linux/refcount.h>
#include <linux/types.h>
#include <linux/spinlock.h>
#include <linux/stackdepot.h>
#define __ostream_printf __printf(2, 3)
struct ref_tracker;
struct ref_tracker_dir {
#ifdef CONFIG_REF_TRACKER
spinlock_t lock;
unsigned int quarantine_avail;
refcount_t untracked;
refcount_t no_tracker;
bool dead;
struct list_head list; /* List of active trackers */
struct list_head quarantine; /* List of dead trackers */
const char *class; /* object classname */
#endif
};
#ifdef CONFIG_REF_TRACKER
#ifdef CONFIG_DEBUG_FS
void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir);
void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...);
#else /* CONFIG_DEBUG_FS */
static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
{
}
static inline __ostream_printf
void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
{
}
#endif /* CONFIG_DEBUG_FS */
/**
* ref_tracker_dir_init - initialize a ref_tracker dir
* @dir: ref_tracker_dir to be initialized
* @quarantine_count: max number of entries to be tracked
* @class: pointer to static string that describes object type
*
* Initialize a ref_tracker_dir. If debugfs is configured, then a file
* will also be created for it under the top-level ref_tracker debugfs
* directory.
*
* Note that @class must point to a static string.
*/
static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
unsigned int quarantine_count,
const char *class)
{
INIT_LIST_HEAD(&dir->list);
INIT_LIST_HEAD(&dir->quarantine);
spin_lock_init(&dir->lock);
dir->quarantine_avail = quarantine_count;
dir->dead = false;
refcount_set(&dir->untracked, 1);
refcount_set(&dir->no_tracker, 1);
dir->class = class;
ref_tracker_dir_debugfs(dir);
stack_depot_init();
}
void ref_tracker_dir_exit(struct ref_tracker_dir *dir);
void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
unsigned int display_limit);
void ref_tracker_dir_print(struct ref_tracker_dir *dir,
unsigned int display_limit);
int ref_tracker_dir_snprint(struct ref_tracker_dir *dir, char *buf, size_t size);
int ref_tracker_alloc(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp, gfp_t gfp);
int ref_tracker_free(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp);
#else /* CONFIG_REF_TRACKER */
static inline void ref_tracker_dir_init(struct ref_tracker_dir *dir,
unsigned int quarantine_count,
const char *class)
{
}
static inline void ref_tracker_dir_debugfs(struct ref_tracker_dir *dir)
{
}
static inline __ostream_printf
void ref_tracker_dir_symlink(struct ref_tracker_dir *dir, const char *fmt, ...)
{
}
static inline void ref_tracker_dir_exit(struct ref_tracker_dir *dir)
{
}
static inline void ref_tracker_dir_print_locked(struct ref_tracker_dir *dir,
unsigned int display_limit)
{
}
static inline void ref_tracker_dir_print(struct ref_tracker_dir *dir,
unsigned int display_limit)
{
}
static inline int ref_tracker_dir_snprint(struct ref_tracker_dir *dir,
char *buf, size_t size)
{
return 0;
}
static inline int ref_tracker_alloc(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp,
gfp_t gfp)
{
return 0;
}
static inline int ref_tracker_free(struct ref_tracker_dir *dir,
struct ref_tracker **trackerp)
{
return 0;
}
#endif
#endif /* _LINUX_REF_TRACKER_H */
|