]> git.proxmox.com Git - mirror_spl-debian.git/blame - module/splat/splat-internal.h
Fix zlib compression
[mirror_spl-debian.git] / module / splat / splat-internal.h
CommitLineData
716154c5
BB
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>.
715f6251 6 * UCRL-CODE-235197
7 *
716154c5
BB
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.
715f6251 15 *
716154c5 16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
715f6251 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
716154c5
BB
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23\*****************************************************************************/
715f6251 24
7c50328b 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>
ea3e6ca9 41#include <linux/swap.h>
e811949a 42#include <linux/delay.h>
86de8532 43
7c50328b 44#include <asm/ioctls.h>
45#include <asm/uaccess.h>
46#include <stdarg.h>
47
23f28c4f 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>
9490c148 62#include <sys/kobj.h>
9f4c835a 63#include <sys/atomic.h>
d702c04f 64#include <sys/list.h>
b871b8cd 65#include <sys/sunddi.h>
46c685d0 66#include <linux/cdev.h>
23f28c4f 67
46c685d0 68#include "spl-device.h"
55abb092 69#include "spl-debug.h"
596e65b4 70#include "splat-ctl.h"
7c50328b 71
72#define SPLAT_SUBSYSTEM_INIT(type) \
8d0f1ee9 73({ splat_subsystem_t *_sub_; \
7c50328b 74 \
8d0f1ee9 75 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
7c50328b 76 if (_sub_ == NULL) { \
8d0f1ee9 77 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
7c50328b 78 } else { \
8d0f1ee9 79 spin_lock(&splat_module_lock); \
80 list_add_tail(&(_sub_->subsystem_list), \
7c50328b 81 &splat_module_list); \
8d0f1ee9 82 spin_unlock(&splat_module_lock); \
7c50328b 83 } \
84})
85
86#define SPLAT_SUBSYSTEM_FINI(type) \
8d0f1ee9 87({ splat_subsystem_t *_sub_, *_tmp_; \
7c50328b 88 int _id_, _flag_ = 0; \
89 \
8d0f1ee9 90 _id_ = splat_##type##_id(); \
91 spin_lock(&splat_module_lock); \
7c50328b 92 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
93 subsystem_list) { \
94 if (_sub_->desc.id == _id_) { \
95 list_del_init(&(_sub_->subsystem_list)); \
8d0f1ee9 96 spin_unlock(&splat_module_lock); \
97 splat_##type##_fini(_sub_); \
7c50328b 98 spin_lock(&splat_module_lock); \
99 _flag_ = 1; \
100 } \
101 } \
8d0f1ee9 102 spin_unlock(&splat_module_lock); \
7c50328b 103 \
104 if (!_flag_) \
8d0f1ee9 105 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
7c50328b 106})
107
108#define SPLAT_TEST_INIT(sub, n, d, tid, func) \
8d0f1ee9 109({ splat_test_t *_test_; \
7c50328b 110 \
8d0f1ee9 111 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
7c50328b 112 if (_test_ == NULL) { \
8d0f1ee9 113 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
7c50328b 114 } else { \
115 memset(_test_, 0, sizeof(*_test_)); \
ac569b72 116 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
117 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
7c50328b 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)); \
124 } \
125})
126
127#define SPLAT_TEST_FINI(sub, tid) \
8d0f1ee9 128({ splat_test_t *_test_, *_tmp_; \
7c50328b 129 int _flag_ = 0; \
130 \
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)); \
136 _flag_ = 1; \
137 } \
138 } \
139 spin_unlock(&((sub)->test_lock)); \
140 \
141 if (!_flag_) \
8d0f1ee9 142 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
7c50328b 143})
144
145typedef int (*splat_test_func_t)(struct file *, void *);
146
147typedef struct splat_test {
148 struct list_head test_list;
149 splat_user_t desc;
150 splat_test_func_t test;
151} splat_test_t;
152
153typedef struct splat_subsystem {
154 struct list_head subsystem_list;/* List had to chain entries */
155 splat_user_t desc;
156 spinlock_t test_lock;
157 struct list_head test_list;
158} splat_subsystem_t;
159
160#define SPLAT_INFO_BUFFER_SIZE 65536
161#define SPLAT_INFO_BUFFER_REDZONE 256
162
163typedef struct splat_info {
164 spinlock_t info_lock;
165 int info_size;
166 char *info_buffer;
167 char *info_head; /* Internal kernel use only */
168} splat_info_t;
169
170#define sym2str(sym) (char *)(#sym)
171
172#define splat_print(file, format, args...) \
d6a26c6a 173({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
7c50328b 174 int _rc_; \
175 \
176 ASSERT(_info_); \
177 ASSERT(_info_->info_buffer); \
178 \
179 spin_lock(&_info_->info_lock); \
180 \
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)) { \
184 _rc_ = -EOVERFLOW; \
185 } else { \
186 _rc_ = sprintf(_info_->info_head, format, args); \
187 if (_rc_ >= 0) \
188 _info_->info_head += _rc_; \
189 } \
190 \
191 spin_unlock(&_info_->info_lock); \
192 _rc_; \
193})
194
d6a26c6a 195#define splat_vprint(file, test, format, args...) \
7c50328b 196 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
197
e811949a
BB
198#define splat_locked_test(lock, test) \
199({ \
200 int _rc_; \
201 spin_lock(lock); \
202 _rc_ = (test) ? 1 : 0; \
203 spin_unlock(lock); \
204 _rc_; \
205})
206
d702c04f
BB
207splat_subsystem_t *splat_condvar_init(void);
208splat_subsystem_t *splat_kmem_init(void);
209splat_subsystem_t *splat_mutex_init(void);
210splat_subsystem_t *splat_krng_init(void);
211splat_subsystem_t *splat_rwlock_init(void);
212splat_subsystem_t *splat_taskq_init(void);
213splat_subsystem_t *splat_thread_init(void);
214splat_subsystem_t *splat_time_init(void);
215splat_subsystem_t *splat_vnode_init(void);
216splat_subsystem_t *splat_kobj_init(void);
217splat_subsystem_t *splat_atomic_init(void);
218splat_subsystem_t *splat_list_init(void);
b871b8cd 219splat_subsystem_t *splat_generic_init(void);
ec7d53e9 220splat_subsystem_t *splat_cred_init(void);
7c50328b 221
222void splat_condvar_fini(splat_subsystem_t *);
223void splat_kmem_fini(splat_subsystem_t *);
224void splat_mutex_fini(splat_subsystem_t *);
225void splat_krng_fini(splat_subsystem_t *);
226void splat_rwlock_fini(splat_subsystem_t *);
227void splat_taskq_fini(splat_subsystem_t *);
228void splat_thread_fini(splat_subsystem_t *);
229void splat_time_fini(splat_subsystem_t *);
4b171585 230void splat_vnode_fini(splat_subsystem_t *);
9490c148 231void splat_kobj_fini(splat_subsystem_t *);
9f4c835a 232void splat_atomic_fini(splat_subsystem_t *);
d702c04f 233void splat_list_fini(splat_subsystem_t *);
b871b8cd 234void splat_generic_fini(splat_subsystem_t *);
ec7d53e9 235void splat_cred_fini(splat_subsystem_t *);
7c50328b 236
237int splat_condvar_id(void);
238int splat_kmem_id(void);
239int splat_mutex_id(void);
240int splat_krng_id(void);
241int splat_rwlock_id(void);
242int splat_taskq_id(void);
243int splat_thread_id(void);
244int splat_time_id(void);
4b171585 245int splat_vnode_id(void);
9490c148 246int splat_kobj_id(void);
9f4c835a 247int splat_atomic_id(void);
d702c04f 248int splat_list_id(void);
b871b8cd 249int splat_generic_id(void);
ec7d53e9 250int splat_cred_id(void);
7c50328b 251
252#endif /* _SPLAT_INTERNAL_H */