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