]>
Commit | Line | Data |
---|---|---|
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 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
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 | ||
596e65b4 | 28 | #include "splat-ctl.h" |
10946b02 AX |
29 | #include <sys/mutex.h> |
30 | #include <linux/file_compat.h> | |
f6188ddd | 31 | #include <linux/version.h> |
7c50328b | 32 | |
33 | #define SPLAT_SUBSYSTEM_INIT(type) \ | |
8d0f1ee9 | 34 | ({ splat_subsystem_t *_sub_; \ |
7c50328b | 35 | \ |
8d0f1ee9 | 36 | _sub_ = (splat_subsystem_t *)splat_##type##_init(); \ |
7c50328b | 37 | if (_sub_ == NULL) { \ |
8d0f1ee9 | 38 | printk(KERN_ERR "splat: Error initializing: " #type "\n"); \ |
7c50328b | 39 | } else { \ |
8d0f1ee9 | 40 | spin_lock(&splat_module_lock); \ |
41 | list_add_tail(&(_sub_->subsystem_list), \ | |
7c50328b | 42 | &splat_module_list); \ |
8d0f1ee9 | 43 | spin_unlock(&splat_module_lock); \ |
7c50328b | 44 | } \ |
45 | }) | |
46 | ||
47 | #define SPLAT_SUBSYSTEM_FINI(type) \ | |
8d0f1ee9 | 48 | ({ splat_subsystem_t *_sub_, *_tmp_; \ |
7c50328b | 49 | int _id_, _flag_ = 0; \ |
50 | \ | |
8d0f1ee9 | 51 | _id_ = splat_##type##_id(); \ |
52 | spin_lock(&splat_module_lock); \ | |
7c50328b | 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)); \ | |
8d0f1ee9 | 57 | spin_unlock(&splat_module_lock); \ |
58 | splat_##type##_fini(_sub_); \ | |
7c50328b | 59 | spin_lock(&splat_module_lock); \ |
60 | _flag_ = 1; \ | |
61 | } \ | |
62 | } \ | |
8d0f1ee9 | 63 | spin_unlock(&splat_module_lock); \ |
7c50328b | 64 | \ |
65 | if (!_flag_) \ | |
8d0f1ee9 | 66 | printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \ |
7c50328b | 67 | }) |
68 | ||
69 | #define SPLAT_TEST_INIT(sub, n, d, tid, func) \ | |
8d0f1ee9 | 70 | ({ splat_test_t *_test_; \ |
7c50328b | 71 | \ |
8d0f1ee9 | 72 | _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \ |
7c50328b | 73 | if (_test_ == NULL) { \ |
8d0f1ee9 | 74 | printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\ |
7c50328b | 75 | } else { \ |
76 | memset(_test_, 0, sizeof(*_test_)); \ | |
ac569b72 | 77 | strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \ |
78 | strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \ | |
7c50328b | 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) \ | |
8d0f1ee9 | 89 | ({ splat_test_t *_test_, *_tmp_; \ |
7c50328b | 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)); \ | |
ac9cc135 | 97 | kfree(_test_); \ |
7c50328b | 98 | _flag_ = 1; \ |
99 | } \ | |
100 | } \ | |
101 | spin_unlock(&((sub)->test_lock)); \ | |
102 | \ | |
103 | if (!_flag_) \ | |
8d0f1ee9 | 104 | printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \ |
7c50328b | 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 { | |
10946b02 | 126 | kmutex_t info_lock; |
7c50328b | 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...) \ | |
d6a26c6a | 135 | ({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \ |
7c50328b | 136 | int _rc_; \ |
137 | \ | |
138 | ASSERT(_info_); \ | |
139 | ASSERT(_info_->info_buffer); \ | |
140 | \ | |
10946b02 | 141 | mutex_enter(&_info_->info_lock); \ |
7c50328b | 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 | \ | |
10946b02 | 153 | mutex_exit(&_info_->info_lock); \ |
7c50328b | 154 | _rc_; \ |
155 | }) | |
156 | ||
d6a26c6a | 157 | #define splat_vprint(file, test, format, args...) \ |
7c50328b | 158 | splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args) |
159 | ||
e811949a BB |
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 | ||
d702c04f BB |
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); | |
b871b8cd | 181 | splat_subsystem_t *splat_generic_init(void); |
ec7d53e9 | 182 | splat_subsystem_t *splat_cred_init(void); |
19c1eb82 | 183 | splat_subsystem_t *splat_zlib_init(void); |
bf0c60c0 | 184 | splat_subsystem_t *splat_linux_init(void); |
7c50328b | 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 *); | |
4b171585 | 194 | void splat_vnode_fini(splat_subsystem_t *); |
9490c148 | 195 | void splat_kobj_fini(splat_subsystem_t *); |
9f4c835a | 196 | void splat_atomic_fini(splat_subsystem_t *); |
d702c04f | 197 | void splat_list_fini(splat_subsystem_t *); |
b871b8cd | 198 | void splat_generic_fini(splat_subsystem_t *); |
ec7d53e9 | 199 | void splat_cred_fini(splat_subsystem_t *); |
19c1eb82 | 200 | void splat_zlib_fini(splat_subsystem_t *); |
bf0c60c0 | 201 | void splat_linux_fini(splat_subsystem_t *); |
7c50328b | 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); | |
4b171585 | 211 | int splat_vnode_id(void); |
9490c148 | 212 | int splat_kobj_id(void); |
9f4c835a | 213 | int splat_atomic_id(void); |
d702c04f | 214 | int splat_list_id(void); |
b871b8cd | 215 | int splat_generic_id(void); |
ec7d53e9 | 216 | int splat_cred_id(void); |
19c1eb82 | 217 | int splat_zlib_id(void); |
bf0c60c0 | 218 | int splat_linux_id(void); |
7c50328b | 219 | |
220 | #endif /* _SPLAT_INTERNAL_H */ |