]> git.proxmox.com Git - mirror_spl-debian.git/blame - modules/splat/splat-internal.h
Add missing stub headers
[mirror_spl-debian.git] / modules / splat / splat-internal.h
CommitLineData
715f6251 1/*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
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.
16 *
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
20 * for more details.
21 *
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.
25 */
26
7c50328b 27#ifndef _SPLAT_INTERNAL_H
28#define _SPLAT_INTERNAL_H
29
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>
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>
46c685d0 65#include <linux/cdev.h>
23f28c4f 66
46c685d0 67#include "spl-device.h"
596e65b4 68#include "splat-ctl.h"
7c50328b 69
70#define SPLAT_SUBSYSTEM_INIT(type) \
8d0f1ee9 71({ splat_subsystem_t *_sub_; \
7c50328b 72 \
8d0f1ee9 73 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
7c50328b 74 if (_sub_ == NULL) { \
8d0f1ee9 75 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
7c50328b 76 } else { \
8d0f1ee9 77 spin_lock(&splat_module_lock); \
78 list_add_tail(&(_sub_->subsystem_list), \
7c50328b 79 &splat_module_list); \
8d0f1ee9 80 spin_unlock(&splat_module_lock); \
7c50328b 81 } \
82})
83
84#define SPLAT_SUBSYSTEM_FINI(type) \
8d0f1ee9 85({ splat_subsystem_t *_sub_, *_tmp_; \
7c50328b 86 int _id_, _flag_ = 0; \
87 \
8d0f1ee9 88 _id_ = splat_##type##_id(); \
89 spin_lock(&splat_module_lock); \
7c50328b 90 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
91 subsystem_list) { \
92 if (_sub_->desc.id == _id_) { \
93 list_del_init(&(_sub_->subsystem_list)); \
8d0f1ee9 94 spin_unlock(&splat_module_lock); \
95 splat_##type##_fini(_sub_); \
7c50328b 96 spin_lock(&splat_module_lock); \
97 _flag_ = 1; \
98 } \
99 } \
8d0f1ee9 100 spin_unlock(&splat_module_lock); \
7c50328b 101 \
102 if (!_flag_) \
8d0f1ee9 103 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
7c50328b 104})
105
106#define SPLAT_TEST_INIT(sub, n, d, tid, func) \
8d0f1ee9 107({ splat_test_t *_test_; \
7c50328b 108 \
8d0f1ee9 109 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
7c50328b 110 if (_test_ == NULL) { \
8d0f1ee9 111 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
7c50328b 112 } else { \
113 memset(_test_, 0, sizeof(*_test_)); \
ac569b72 114 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
115 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
7c50328b 116 _test_->desc.id = tid; \
117 _test_->test = func; \
118 INIT_LIST_HEAD(&(_test_->test_list)); \
119 spin_lock(&((sub)->test_lock)); \
120 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
121 spin_unlock(&((sub)->test_lock)); \
122 } \
123})
124
125#define SPLAT_TEST_FINI(sub, tid) \
8d0f1ee9 126({ splat_test_t *_test_, *_tmp_; \
7c50328b 127 int _flag_ = 0; \
128 \
129 spin_lock(&((sub)->test_lock)); \
130 list_for_each_entry_safe(_test_, _tmp_, \
131 &((sub)->test_list), test_list) { \
132 if (_test_->desc.id == tid) { \
133 list_del_init(&(_test_->test_list)); \
134 _flag_ = 1; \
135 } \
136 } \
137 spin_unlock(&((sub)->test_lock)); \
138 \
139 if (!_flag_) \
8d0f1ee9 140 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
7c50328b 141})
142
143typedef int (*splat_test_func_t)(struct file *, void *);
144
145typedef struct splat_test {
146 struct list_head test_list;
147 splat_user_t desc;
148 splat_test_func_t test;
149} splat_test_t;
150
151typedef struct splat_subsystem {
152 struct list_head subsystem_list;/* List had to chain entries */
153 splat_user_t desc;
154 spinlock_t test_lock;
155 struct list_head test_list;
156} splat_subsystem_t;
157
158#define SPLAT_INFO_BUFFER_SIZE 65536
159#define SPLAT_INFO_BUFFER_REDZONE 256
160
161typedef struct splat_info {
162 spinlock_t info_lock;
163 int info_size;
164 char *info_buffer;
165 char *info_head; /* Internal kernel use only */
166} splat_info_t;
167
168#define sym2str(sym) (char *)(#sym)
169
170#define splat_print(file, format, args...) \
d6a26c6a 171({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
7c50328b 172 int _rc_; \
173 \
174 ASSERT(_info_); \
175 ASSERT(_info_->info_buffer); \
176 \
177 spin_lock(&_info_->info_lock); \
178 \
179 /* Don't allow the kernel to start a write in the red zone */ \
180 if ((int)(_info_->info_head - _info_->info_buffer) > \
181 (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \
182 _rc_ = -EOVERFLOW; \
183 } else { \
184 _rc_ = sprintf(_info_->info_head, format, args); \
185 if (_rc_ >= 0) \
186 _info_->info_head += _rc_; \
187 } \
188 \
189 spin_unlock(&_info_->info_lock); \
190 _rc_; \
191})
192
d6a26c6a 193#define splat_vprint(file, test, format, args...) \
7c50328b 194 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
195
d702c04f
BB
196splat_subsystem_t *splat_condvar_init(void);
197splat_subsystem_t *splat_kmem_init(void);
198splat_subsystem_t *splat_mutex_init(void);
199splat_subsystem_t *splat_krng_init(void);
200splat_subsystem_t *splat_rwlock_init(void);
201splat_subsystem_t *splat_taskq_init(void);
202splat_subsystem_t *splat_thread_init(void);
203splat_subsystem_t *splat_time_init(void);
204splat_subsystem_t *splat_vnode_init(void);
205splat_subsystem_t *splat_kobj_init(void);
206splat_subsystem_t *splat_atomic_init(void);
207splat_subsystem_t *splat_list_init(void);
7c50328b 208
209void splat_condvar_fini(splat_subsystem_t *);
210void splat_kmem_fini(splat_subsystem_t *);
211void splat_mutex_fini(splat_subsystem_t *);
212void splat_krng_fini(splat_subsystem_t *);
213void splat_rwlock_fini(splat_subsystem_t *);
214void splat_taskq_fini(splat_subsystem_t *);
215void splat_thread_fini(splat_subsystem_t *);
216void splat_time_fini(splat_subsystem_t *);
4b171585 217void splat_vnode_fini(splat_subsystem_t *);
9490c148 218void splat_kobj_fini(splat_subsystem_t *);
9f4c835a 219void splat_atomic_fini(splat_subsystem_t *);
d702c04f 220void splat_list_fini(splat_subsystem_t *);
7c50328b 221
222int splat_condvar_id(void);
223int splat_kmem_id(void);
224int splat_mutex_id(void);
225int splat_krng_id(void);
226int splat_rwlock_id(void);
227int splat_taskq_id(void);
228int splat_thread_id(void);
229int splat_time_id(void);
4b171585 230int splat_vnode_id(void);
9490c148 231int splat_kobj_id(void);
9f4c835a 232int splat_atomic_id(void);
d702c04f 233int splat_list_id(void);
7c50328b 234
235#endif /* _SPLAT_INTERNAL_H */