]>
git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-internal.h
2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifndef _SPLAT_INTERNAL_H
28 #define _SPLAT_INTERNAL_H
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/string.h>
33 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/sched.h>
36 #include <linux/elf.h>
37 #include <linux/limits.h>
38 #include <linux/version.h>
39 #include <linux/vmalloc.h>
40 #include <linux/module.h>
41 #include <linux/device.h>
42 #include <linux/list.h>
43 #include <linux/swap.h>
45 #include <asm/ioctls.h>
46 #include <asm/uaccess.h>
49 #include <sys/callb.h>
50 #include <sys/condvar.h>
52 #include <sys/sysmacros.h>
54 #include <sys/kstat.h>
55 #include <sys/mutex.h>
56 #include <sys/random.h>
57 #include <sys/rwlock.h>
58 #include <sys/taskq.h>
59 #include <sys/thread.h>
61 #include <sys/timer.h>
62 #include <sys/types.h>
64 #include <sys/atomic.h>
66 #include <sys/sunddi.h>
67 #include <linux/cdev.h>
69 #include "spl-device.h"
70 #include "splat-ctl.h"
72 #define SPLAT_SUBSYSTEM_INIT(type) \
73 ({ splat_subsystem_t *_sub_; \
75 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
76 if (_sub_ == NULL) { \
77 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
79 spin_lock(&splat_module_lock); \
80 list_add_tail(&(_sub_->subsystem_list), \
81 &splat_module_list); \
82 spin_unlock(&splat_module_lock); \
86 #define SPLAT_SUBSYSTEM_FINI(type) \
87 ({ splat_subsystem_t *_sub_, *_tmp_; \
88 int _id_, _flag_ = 0; \
90 _id_ = splat_##type##_id(); \
91 spin_lock(&splat_module_lock); \
92 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
94 if (_sub_->desc.id == _id_) { \
95 list_del_init(&(_sub_->subsystem_list)); \
96 spin_unlock(&splat_module_lock); \
97 splat_##type##_fini(_sub_); \
98 spin_lock(&splat_module_lock); \
102 spin_unlock(&splat_module_lock); \
105 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
108 #define SPLAT_TEST_INIT(sub, n, d, tid, func) \
109 ({ splat_test_t *_test_; \
111 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
112 if (_test_ == NULL) { \
113 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
115 memset(_test_, 0, sizeof(*_test_)); \
116 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
117 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
118 _test_->desc.id = tid; \
119 _test_->test = func; \
120 INIT_LIST_HEAD(&(_test_->test_list)); \
121 spin_lock(&((sub)->test_lock)); \
122 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
123 spin_unlock(&((sub)->test_lock)); \
127 #define SPLAT_TEST_FINI(sub, tid) \
128 ({ splat_test_t *_test_, *_tmp_; \
131 spin_lock(&((sub)->test_lock)); \
132 list_for_each_entry_safe(_test_, _tmp_, \
133 &((sub)->test_list), test_list) { \
134 if (_test_->desc.id == tid) { \
135 list_del_init(&(_test_->test_list)); \
139 spin_unlock(&((sub)->test_lock)); \
142 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
145 typedef int (*splat_test_func_t
)(struct file
*, void *);
147 typedef struct splat_test
{
148 struct list_head test_list
;
150 splat_test_func_t test
;
153 typedef struct splat_subsystem
{
154 struct list_head subsystem_list
;/* List had to chain entries */
156 spinlock_t test_lock
;
157 struct list_head test_list
;
160 #define SPLAT_INFO_BUFFER_SIZE 65536
161 #define SPLAT_INFO_BUFFER_REDZONE 256
163 typedef struct splat_info
{
164 spinlock_t info_lock
;
167 char *info_head
; /* Internal kernel use only */
170 #define sym2str(sym) (char *)(#sym)
172 #define splat_print(file, format, args...) \
173 ({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
177 ASSERT(_info_->info_buffer); \
179 spin_lock(&_info_->info_lock); \
181 /* Don't allow the kernel to start a write in the red zone */ \
182 if ((int)(_info_->info_head - _info_->info_buffer) > \
183 (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \
186 _rc_ = sprintf(_info_->info_head, format, args); \
188 _info_->info_head += _rc_; \
191 spin_unlock(&_info_->info_lock); \
195 #define splat_vprint(file, test, format, args...) \
196 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
198 splat_subsystem_t
*splat_condvar_init(void);
199 splat_subsystem_t
*splat_kmem_init(void);
200 splat_subsystem_t
*splat_mutex_init(void);
201 splat_subsystem_t
*splat_krng_init(void);
202 splat_subsystem_t
*splat_rwlock_init(void);
203 splat_subsystem_t
*splat_taskq_init(void);
204 splat_subsystem_t
*splat_thread_init(void);
205 splat_subsystem_t
*splat_time_init(void);
206 splat_subsystem_t
*splat_vnode_init(void);
207 splat_subsystem_t
*splat_kobj_init(void);
208 splat_subsystem_t
*splat_atomic_init(void);
209 splat_subsystem_t
*splat_list_init(void);
210 splat_subsystem_t
*splat_generic_init(void);
211 splat_subsystem_t
*splat_cred_init(void);
213 void splat_condvar_fini(splat_subsystem_t
*);
214 void splat_kmem_fini(splat_subsystem_t
*);
215 void splat_mutex_fini(splat_subsystem_t
*);
216 void splat_krng_fini(splat_subsystem_t
*);
217 void splat_rwlock_fini(splat_subsystem_t
*);
218 void splat_taskq_fini(splat_subsystem_t
*);
219 void splat_thread_fini(splat_subsystem_t
*);
220 void splat_time_fini(splat_subsystem_t
*);
221 void splat_vnode_fini(splat_subsystem_t
*);
222 void splat_kobj_fini(splat_subsystem_t
*);
223 void splat_atomic_fini(splat_subsystem_t
*);
224 void splat_list_fini(splat_subsystem_t
*);
225 void splat_generic_fini(splat_subsystem_t
*);
226 void splat_cred_fini(splat_subsystem_t
*);
228 int splat_condvar_id(void);
229 int splat_kmem_id(void);
230 int splat_mutex_id(void);
231 int splat_krng_id(void);
232 int splat_rwlock_id(void);
233 int splat_taskq_id(void);
234 int splat_thread_id(void);
235 int splat_time_id(void);
236 int splat_vnode_id(void);
237 int splat_kobj_id(void);
238 int splat_atomic_id(void);
239 int splat_list_id(void);
240 int splat_generic_id(void);
241 int splat_cred_id(void);
243 #endif /* _SPLAT_INTERNAL_H */