]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/splat/splat-internal.h
Prep for for 0.3.0 tag, this is the tag which was used for all
[mirror_spl-debian.git] / modules / splat / splat-internal.h
CommitLineData
7c50328b 1#ifndef _SPLAT_INTERNAL_H
2#define _SPLAT_INTERNAL_H
3
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/string.h>
7#include <linux/errno.h>
8#include <linux/slab.h>
9#include <linux/sched.h>
10#include <linux/elf.h>
11#include <linux/limits.h>
12#include <linux/version.h>
13#include <linux/vmalloc.h>
14#include <linux/module.h>
15#include <linux/device.h>
16#include <linux/list.h>
17#include <asm/ioctls.h>
18#include <asm/uaccess.h>
19#include <stdarg.h>
20
23f28c4f 21#include <sys/callb.h>
22#include <sys/condvar.h>
23#include <sys/cred.h>
24#include <sys/sysmacros.h>
25#include <sys/kmem.h>
26#include <sys/kstat.h>
27#include <sys/mutex.h>
28#include <sys/random.h>
29#include <sys/rwlock.h>
30#include <sys/taskq.h>
31#include <sys/thread.h>
32#include <sys/time.h>
33#include <sys/timer.h>
34#include <sys/types.h>
9490c148 35#include <sys/kobj.h>
9f4c835a 36#include <sys/atomic.h>
23f28c4f 37
596e65b4 38#include "splat-ctl.h"
7c50328b 39
40#define SPLAT_SUBSYSTEM_INIT(type) \
8d0f1ee9 41({ splat_subsystem_t *_sub_; \
7c50328b 42 \
8d0f1ee9 43 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
7c50328b 44 if (_sub_ == NULL) { \
8d0f1ee9 45 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
7c50328b 46 } else { \
8d0f1ee9 47 spin_lock(&splat_module_lock); \
48 list_add_tail(&(_sub_->subsystem_list), \
7c50328b 49 &splat_module_list); \
8d0f1ee9 50 spin_unlock(&splat_module_lock); \
7c50328b 51 } \
52})
53
54#define SPLAT_SUBSYSTEM_FINI(type) \
8d0f1ee9 55({ splat_subsystem_t *_sub_, *_tmp_; \
7c50328b 56 int _id_, _flag_ = 0; \
57 \
8d0f1ee9 58 _id_ = splat_##type##_id(); \
59 spin_lock(&splat_module_lock); \
7c50328b 60 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
61 subsystem_list) { \
62 if (_sub_->desc.id == _id_) { \
63 list_del_init(&(_sub_->subsystem_list)); \
8d0f1ee9 64 spin_unlock(&splat_module_lock); \
65 splat_##type##_fini(_sub_); \
7c50328b 66 spin_lock(&splat_module_lock); \
67 _flag_ = 1; \
68 } \
69 } \
8d0f1ee9 70 spin_unlock(&splat_module_lock); \
7c50328b 71 \
72 if (!_flag_) \
8d0f1ee9 73 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
7c50328b 74})
75
76#define SPLAT_TEST_INIT(sub, n, d, tid, func) \
8d0f1ee9 77({ splat_test_t *_test_; \
7c50328b 78 \
8d0f1ee9 79 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
7c50328b 80 if (_test_ == NULL) { \
8d0f1ee9 81 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
7c50328b 82 } else { \
83 memset(_test_, 0, sizeof(*_test_)); \
84 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE); \
85 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE); \
86 _test_->desc.id = tid; \
87 _test_->test = func; \
88 INIT_LIST_HEAD(&(_test_->test_list)); \
89 spin_lock(&((sub)->test_lock)); \
90 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
91 spin_unlock(&((sub)->test_lock)); \
92 } \
93})
94
95#define SPLAT_TEST_FINI(sub, tid) \
8d0f1ee9 96({ splat_test_t *_test_, *_tmp_; \
7c50328b 97 int _flag_ = 0; \
98 \
99 spin_lock(&((sub)->test_lock)); \
100 list_for_each_entry_safe(_test_, _tmp_, \
101 &((sub)->test_list), test_list) { \
102 if (_test_->desc.id == tid) { \
103 list_del_init(&(_test_->test_list)); \
104 _flag_ = 1; \
105 } \
106 } \
107 spin_unlock(&((sub)->test_lock)); \
108 \
109 if (!_flag_) \
8d0f1ee9 110 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
7c50328b 111})
112
113typedef int (*splat_test_func_t)(struct file *, void *);
114
115typedef struct splat_test {
116 struct list_head test_list;
117 splat_user_t desc;
118 splat_test_func_t test;
119} splat_test_t;
120
121typedef struct splat_subsystem {
122 struct list_head subsystem_list;/* List had to chain entries */
123 splat_user_t desc;
124 spinlock_t test_lock;
125 struct list_head test_list;
126} splat_subsystem_t;
127
128#define SPLAT_INFO_BUFFER_SIZE 65536
129#define SPLAT_INFO_BUFFER_REDZONE 256
130
131typedef struct splat_info {
132 spinlock_t info_lock;
133 int info_size;
134 char *info_buffer;
135 char *info_head; /* Internal kernel use only */
136} splat_info_t;
137
138#define sym2str(sym) (char *)(#sym)
139
140#define splat_print(file, format, args...) \
d6a26c6a 141({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
7c50328b 142 int _rc_; \
143 \
144 ASSERT(_info_); \
145 ASSERT(_info_->info_buffer); \
146 \
147 spin_lock(&_info_->info_lock); \
148 \
149 /* Don't allow the kernel to start a write in the red zone */ \
150 if ((int)(_info_->info_head - _info_->info_buffer) > \
151 (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \
152 _rc_ = -EOVERFLOW; \
153 } else { \
154 _rc_ = sprintf(_info_->info_head, format, args); \
155 if (_rc_ >= 0) \
156 _info_->info_head += _rc_; \
157 } \
158 \
159 spin_unlock(&_info_->info_lock); \
160 _rc_; \
161})
162
d6a26c6a 163#define splat_vprint(file, test, format, args...) \
7c50328b 164 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
165
166splat_subsystem_t * splat_condvar_init(void);
167splat_subsystem_t * splat_kmem_init(void);
168splat_subsystem_t * splat_mutex_init(void);
169splat_subsystem_t * splat_krng_init(void);
170splat_subsystem_t * splat_rwlock_init(void);
171splat_subsystem_t * splat_taskq_init(void);
172splat_subsystem_t * splat_thread_init(void);
173splat_subsystem_t * splat_time_init(void);
4b171585 174splat_subsystem_t * splat_vnode_init(void);
9490c148 175splat_subsystem_t * splat_kobj_init(void);
9f4c835a 176splat_subsystem_t * splat_atomic_init(void);
7c50328b 177
178void splat_condvar_fini(splat_subsystem_t *);
179void splat_kmem_fini(splat_subsystem_t *);
180void splat_mutex_fini(splat_subsystem_t *);
181void splat_krng_fini(splat_subsystem_t *);
182void splat_rwlock_fini(splat_subsystem_t *);
183void splat_taskq_fini(splat_subsystem_t *);
184void splat_thread_fini(splat_subsystem_t *);
185void splat_time_fini(splat_subsystem_t *);
4b171585 186void splat_vnode_fini(splat_subsystem_t *);
9490c148 187void splat_kobj_fini(splat_subsystem_t *);
9f4c835a 188void splat_atomic_fini(splat_subsystem_t *);
7c50328b 189
190int splat_condvar_id(void);
191int splat_kmem_id(void);
192int splat_mutex_id(void);
193int splat_krng_id(void);
194int splat_rwlock_id(void);
195int splat_taskq_id(void);
196int splat_thread_id(void);
197int splat_time_id(void);
4b171585 198int splat_vnode_id(void);
9490c148 199int splat_kobj_id(void);
9f4c835a 200int splat_atomic_id(void);
7c50328b 201
202#endif /* _SPLAT_INTERNAL_H */