]> git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-internal.h
14303a1057de151e76a63993e2cbfb36c5badb03
[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 "spl-device.h"
29 #include "spl-debug.h"
30 #include "splat-ctl.h"
31
32 #define SPLAT_SUBSYSTEM_INIT(type) \
33 ({ splat_subsystem_t *_sub_; \
34 \
35 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
36 if (_sub_ == NULL) { \
37 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
38 } else { \
39 spin_lock(&splat_module_lock); \
40 list_add_tail(&(_sub_->subsystem_list), \
41 &splat_module_list); \
42 spin_unlock(&splat_module_lock); \
43 } \
44 })
45
46 #define SPLAT_SUBSYSTEM_FINI(type) \
47 ({ splat_subsystem_t *_sub_, *_tmp_; \
48 int _id_, _flag_ = 0; \
49 \
50 _id_ = splat_##type##_id(); \
51 spin_lock(&splat_module_lock); \
52 list_for_each_entry_safe(_sub_, _tmp_, &splat_module_list, \
53 subsystem_list) { \
54 if (_sub_->desc.id == _id_) { \
55 list_del_init(&(_sub_->subsystem_list)); \
56 spin_unlock(&splat_module_lock); \
57 splat_##type##_fini(_sub_); \
58 spin_lock(&splat_module_lock); \
59 _flag_ = 1; \
60 } \
61 } \
62 spin_unlock(&splat_module_lock); \
63 \
64 if (!_flag_) \
65 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
66 })
67
68 #define SPLAT_TEST_INIT(sub, n, d, tid, func) \
69 ({ splat_test_t *_test_; \
70 \
71 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
72 if (_test_ == NULL) { \
73 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
74 } else { \
75 memset(_test_, 0, sizeof(*_test_)); \
76 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
77 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
78 _test_->desc.id = tid; \
79 _test_->test = func; \
80 INIT_LIST_HEAD(&(_test_->test_list)); \
81 spin_lock(&((sub)->test_lock)); \
82 list_add_tail(&(_test_->test_list),&((sub)->test_list));\
83 spin_unlock(&((sub)->test_lock)); \
84 } \
85 })
86
87 #define SPLAT_TEST_FINI(sub, tid) \
88 ({ splat_test_t *_test_, *_tmp_; \
89 int _flag_ = 0; \
90 \
91 spin_lock(&((sub)->test_lock)); \
92 list_for_each_entry_safe(_test_, _tmp_, \
93 &((sub)->test_list), test_list) { \
94 if (_test_->desc.id == tid) { \
95 list_del_init(&(_test_->test_list)); \
96 _flag_ = 1; \
97 } \
98 } \
99 spin_unlock(&((sub)->test_lock)); \
100 \
101 if (!_flag_) \
102 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
103 })
104
105 typedef int (*splat_test_func_t)(struct file *, void *);
106
107 typedef struct splat_test {
108 struct list_head test_list;
109 splat_user_t desc;
110 splat_test_func_t test;
111 } splat_test_t;
112
113 typedef struct splat_subsystem {
114 struct list_head subsystem_list;/* List had to chain entries */
115 splat_user_t desc;
116 spinlock_t test_lock;
117 struct list_head test_list;
118 } splat_subsystem_t;
119
120 #define SPLAT_INFO_BUFFER_SIZE 65536
121 #define SPLAT_INFO_BUFFER_REDZONE 256
122
123 typedef struct splat_info {
124 struct mutex info_lock;
125 int info_size;
126 char *info_buffer;
127 char *info_head; /* Internal kernel use only */
128 } splat_info_t;
129
130 #define sym2str(sym) (char *)(#sym)
131
132 #define splat_print(file, format, args...) \
133 ({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
134 int _rc_; \
135 \
136 ASSERT(_info_); \
137 ASSERT(_info_->info_buffer); \
138 \
139 mutex_lock(&_info_->info_lock); \
140 \
141 /* Don't allow the kernel to start a write in the red zone */ \
142 if ((int)(_info_->info_head - _info_->info_buffer) > \
143 (SPLAT_INFO_BUFFER_SIZE - SPLAT_INFO_BUFFER_REDZONE)) { \
144 _rc_ = -EOVERFLOW; \
145 } else { \
146 _rc_ = sprintf(_info_->info_head, format, args); \
147 if (_rc_ >= 0) \
148 _info_->info_head += _rc_; \
149 } \
150 \
151 mutex_unlock(&_info_->info_lock); \
152 _rc_; \
153 })
154
155 #define splat_vprint(file, test, format, args...) \
156 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
157
158 #define splat_locked_test(lock, test) \
159 ({ \
160 int _rc_; \
161 spin_lock(lock); \
162 _rc_ = (test) ? 1 : 0; \
163 spin_unlock(lock); \
164 _rc_; \
165 })
166
167 splat_subsystem_t *splat_condvar_init(void);
168 splat_subsystem_t *splat_kmem_init(void);
169 splat_subsystem_t *splat_mutex_init(void);
170 splat_subsystem_t *splat_krng_init(void);
171 splat_subsystem_t *splat_rwlock_init(void);
172 splat_subsystem_t *splat_taskq_init(void);
173 splat_subsystem_t *splat_thread_init(void);
174 splat_subsystem_t *splat_time_init(void);
175 splat_subsystem_t *splat_vnode_init(void);
176 splat_subsystem_t *splat_kobj_init(void);
177 splat_subsystem_t *splat_atomic_init(void);
178 splat_subsystem_t *splat_list_init(void);
179 splat_subsystem_t *splat_generic_init(void);
180 splat_subsystem_t *splat_cred_init(void);
181 splat_subsystem_t *splat_zlib_init(void);
182 splat_subsystem_t *splat_linux_init(void);
183
184 void splat_condvar_fini(splat_subsystem_t *);
185 void splat_kmem_fini(splat_subsystem_t *);
186 void splat_mutex_fini(splat_subsystem_t *);
187 void splat_krng_fini(splat_subsystem_t *);
188 void splat_rwlock_fini(splat_subsystem_t *);
189 void splat_taskq_fini(splat_subsystem_t *);
190 void splat_thread_fini(splat_subsystem_t *);
191 void splat_time_fini(splat_subsystem_t *);
192 void splat_vnode_fini(splat_subsystem_t *);
193 void splat_kobj_fini(splat_subsystem_t *);
194 void splat_atomic_fini(splat_subsystem_t *);
195 void splat_list_fini(splat_subsystem_t *);
196 void splat_generic_fini(splat_subsystem_t *);
197 void splat_cred_fini(splat_subsystem_t *);
198 void splat_zlib_fini(splat_subsystem_t *);
199 void splat_linux_fini(splat_subsystem_t *);
200
201 int splat_condvar_id(void);
202 int splat_kmem_id(void);
203 int splat_mutex_id(void);
204 int splat_krng_id(void);
205 int splat_rwlock_id(void);
206 int splat_taskq_id(void);
207 int splat_thread_id(void);
208 int splat_time_id(void);
209 int splat_vnode_id(void);
210 int splat_kobj_id(void);
211 int splat_atomic_id(void);
212 int splat_list_id(void);
213 int splat_generic_id(void);
214 int splat_cred_id(void);
215 int splat_zlib_id(void);
216 int splat_linux_id(void);
217
218 #endif /* _SPLAT_INTERNAL_H */