]> git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-internal.h
Add linux compatibility tests
[mirror_spl-debian.git] / module / splat / splat-internal.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 #ifndef _SPLAT_INTERNAL_H
26 #define _SPLAT_INTERNAL_H
27
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/string.h>
31 #include <linux/errno.h>
32 #include <linux/slab.h>
33 #include <linux/sched.h>
34 #include <linux/elf.h>
35 #include <linux/limits.h>
36 #include <linux/version.h>
37 #include <linux/vmalloc.h>
38 #include <linux/module.h>
39 #include <linux/device.h>
40 #include <linux/list.h>
41 #include <linux/swap.h>
42 #include <linux/delay.h>
43
44 #include <asm/ioctls.h>
45 #include <asm/uaccess.h>
46 #include <stdarg.h>
47
48 #include <sys/callb.h>
49 #include <sys/condvar.h>
50 #include <sys/cred.h>
51 #include <sys/sysmacros.h>
52 #include <sys/kmem.h>
53 #include <sys/kstat.h>
54 #include <sys/mutex.h>
55 #include <sys/random.h>
56 #include <sys/rwlock.h>
57 #include <sys/taskq.h>
58 #include <sys/thread.h>
59 #include <sys/time.h>
60 #include <sys/timer.h>
61 #include <sys/types.h>
62 #include <sys/kobj.h>
63 #include <sys/atomic.h>
64 #include <sys/list.h>
65 #include <sys/sunddi.h>
66 #include <sys/zmod.h>
67 #include <linux/cdev.h>
68
69 #include "spl-device.h"
70 #include "spl-debug.h"
71 #include "splat-ctl.h"
72
73 #define SPLAT_SUBSYSTEM_INIT(type) \
74 ({ splat_subsystem_t *_sub_; \
75 \
76 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
77 if (_sub_ == NULL) { \
78 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
79 } else { \
80 spin_lock(&splat_module_lock); \
81 list_add_tail(&(_sub_->subsystem_list), \
82 &splat_module_list); \
83 spin_unlock(&splat_module_lock); \
84 } \
85 })
86
87 #define SPLAT_SUBSYSTEM_FINI(type) \
88 ({ splat_subsystem_t *_sub_, *_tmp_; \
89 int _id_, _flag_ = 0; \
90 \
91 _id_ = splat_##type##_id(); \
92 spin_lock(&splat_module_lock); \
93 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
94 subsystem_list) { \
95 if (_sub_->desc.id == _id_) { \
96 list_del_init(&(_sub_->subsystem_list)); \
97 spin_unlock(&splat_module_lock); \
98 splat_##type##_fini(_sub_); \
99 spin_lock(&splat_module_lock); \
100 _flag_ = 1; \
101 } \
102 } \
103 spin_unlock(&splat_module_lock); \
104 \
105 if (!_flag_) \
106 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
107 })
108
109 #define SPLAT_TEST_INIT(sub, n, d, tid, func) \
110 ({ splat_test_t *_test_; \
111 \
112 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
113 if (_test_ == NULL) { \
114 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
115 } else { \
116 memset(_test_, 0, sizeof(*_test_)); \
117 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
118 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
119 _test_->desc.id = tid; \
120 _test_->test = func; \
121 INIT_LIST_HEAD(&(_test_->test_list)); \
122 spin_lock(&((sub)->test_lock)); \
123 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
124 spin_unlock(&((sub)->test_lock)); \
125 } \
126 })
127
128 #define SPLAT_TEST_FINI(sub, tid) \
129 ({ splat_test_t *_test_, *_tmp_; \
130 int _flag_ = 0; \
131 \
132 spin_lock(&((sub)->test_lock)); \
133 list_for_each_entry_safe(_test_, _tmp_, \
134 &((sub)->test_list), test_list) { \
135 if (_test_->desc.id == tid) { \
136 list_del_init(&(_test_->test_list)); \
137 _flag_ = 1; \
138 } \
139 } \
140 spin_unlock(&((sub)->test_lock)); \
141 \
142 if (!_flag_) \
143 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
144 })
145
146 typedef int (*splat_test_func_t)(struct file *, void *);
147
148 typedef struct splat_test {
149 struct list_head test_list;
150 splat_user_t desc;
151 splat_test_func_t test;
152 } splat_test_t;
153
154 typedef struct splat_subsystem {
155 struct list_head subsystem_list;/* List had to chain entries */
156 splat_user_t desc;
157 spinlock_t test_lock;
158 struct list_head test_list;
159 } splat_subsystem_t;
160
161 #define SPLAT_INFO_BUFFER_SIZE 65536
162 #define SPLAT_INFO_BUFFER_REDZONE 256
163
164 typedef struct splat_info {
165 spinlock_t info_lock;
166 int info_size;
167 char *info_buffer;
168 char *info_head; /* Internal kernel use only */
169 } splat_info_t;
170
171 #define sym2str(sym) (char *)(#sym)
172
173 #define splat_print(file, format, args...) \
174 ({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
175 int _rc_; \
176 \
177 ASSERT(_info_); \
178 ASSERT(_info_->info_buffer); \
179 \
180 spin_lock(&_info_->info_lock); \
181 \
182 /* Don't allow the kernel to start a write in the red zone */ \
183 if ((int)(_info_->info_head - _info_->info_buffer) > \
184 (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \
185 _rc_ = -EOVERFLOW; \
186 } else { \
187 _rc_ = sprintf(_info_->info_head, format, args); \
188 if (_rc_ >= 0) \
189 _info_->info_head += _rc_; \
190 } \
191 \
192 spin_unlock(&_info_->info_lock); \
193 _rc_; \
194 })
195
196 #define splat_vprint(file, test, format, args...) \
197 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
198
199 #define splat_locked_test(lock, test) \
200 ({ \
201 int _rc_; \
202 spin_lock(lock); \
203 _rc_ = (test) ? 1 : 0; \
204 spin_unlock(lock); \
205 _rc_; \
206 })
207
208 splat_subsystem_t *splat_condvar_init(void);
209 splat_subsystem_t *splat_kmem_init(void);
210 splat_subsystem_t *splat_mutex_init(void);
211 splat_subsystem_t *splat_krng_init(void);
212 splat_subsystem_t *splat_rwlock_init(void);
213 splat_subsystem_t *splat_taskq_init(void);
214 splat_subsystem_t *splat_thread_init(void);
215 splat_subsystem_t *splat_time_init(void);
216 splat_subsystem_t *splat_vnode_init(void);
217 splat_subsystem_t *splat_kobj_init(void);
218 splat_subsystem_t *splat_atomic_init(void);
219 splat_subsystem_t *splat_list_init(void);
220 splat_subsystem_t *splat_generic_init(void);
221 splat_subsystem_t *splat_cred_init(void);
222 splat_subsystem_t *splat_zlib_init(void);
223 splat_subsystem_t *splat_linux_init(void);
224
225 void splat_condvar_fini(splat_subsystem_t *);
226 void splat_kmem_fini(splat_subsystem_t *);
227 void splat_mutex_fini(splat_subsystem_t *);
228 void splat_krng_fini(splat_subsystem_t *);
229 void splat_rwlock_fini(splat_subsystem_t *);
230 void splat_taskq_fini(splat_subsystem_t *);
231 void splat_thread_fini(splat_subsystem_t *);
232 void splat_time_fini(splat_subsystem_t *);
233 void splat_vnode_fini(splat_subsystem_t *);
234 void splat_kobj_fini(splat_subsystem_t *);
235 void splat_atomic_fini(splat_subsystem_t *);
236 void splat_list_fini(splat_subsystem_t *);
237 void splat_generic_fini(splat_subsystem_t *);
238 void splat_cred_fini(splat_subsystem_t *);
239 void splat_zlib_fini(splat_subsystem_t *);
240 void splat_linux_fini(splat_subsystem_t *);
241
242 int splat_condvar_id(void);
243 int splat_kmem_id(void);
244 int splat_mutex_id(void);
245 int splat_krng_id(void);
246 int splat_rwlock_id(void);
247 int splat_taskq_id(void);
248 int splat_thread_id(void);
249 int splat_time_id(void);
250 int splat_vnode_id(void);
251 int splat_kobj_id(void);
252 int splat_atomic_id(void);
253 int splat_list_id(void);
254 int splat_generic_id(void);
255 int splat_cred_id(void);
256 int splat_zlib_id(void);
257 int splat_linux_id(void);
258
259 #endif /* _SPLAT_INTERNAL_H */