]> git.proxmox.com Git - mirror_spl-debian.git/blame - module/splat/splat-internal.h
Merge branch 'splat'
[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
46c685d0 28#include "spl-device.h"
55abb092 29#include "spl-debug.h"
596e65b4 30#include "splat-ctl.h"
7c50328b 31
32#define SPLAT_SUBSYSTEM_INIT(type) \
8d0f1ee9 33({ splat_subsystem_t *_sub_; \
7c50328b 34 \
8d0f1ee9 35 _sub_ = (splat_subsystem_t *)splat_##type##_init(); \
7c50328b 36 if (_sub_ == NULL) { \
8d0f1ee9 37 printk(KERN_ERR "splat: Error initializing: " #type "\n"); \
7c50328b 38 } else { \
8d0f1ee9 39 spin_lock(&splat_module_lock); \
40 list_add_tail(&(_sub_->subsystem_list), \
7c50328b 41 &splat_module_list); \
8d0f1ee9 42 spin_unlock(&splat_module_lock); \
7c50328b 43 } \
44})
45
46#define SPLAT_SUBSYSTEM_FINI(type) \
8d0f1ee9 47({ splat_subsystem_t *_sub_, *_tmp_; \
7c50328b 48 int _id_, _flag_ = 0; \
49 \
8d0f1ee9 50 _id_ = splat_##type##_id(); \
51 spin_lock(&splat_module_lock); \
7c50328b 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)); \
8d0f1ee9 56 spin_unlock(&splat_module_lock); \
57 splat_##type##_fini(_sub_); \
7c50328b 58 spin_lock(&splat_module_lock); \
59 _flag_ = 1; \
60 } \
61 } \
8d0f1ee9 62 spin_unlock(&splat_module_lock); \
7c50328b 63 \
64 if (!_flag_) \
8d0f1ee9 65 printk(KERN_ERR "splat: Error finalizing: " #type "\n"); \
7c50328b 66})
67
68#define SPLAT_TEST_INIT(sub, n, d, tid, func) \
8d0f1ee9 69({ splat_test_t *_test_; \
7c50328b 70 \
8d0f1ee9 71 _test_ = (splat_test_t *)kmalloc(sizeof(*_test_), GFP_KERNEL); \
7c50328b 72 if (_test_ == NULL) { \
8d0f1ee9 73 printk(KERN_ERR "splat: Error initializing: " n "/" #tid" \n");\
7c50328b 74 } else { \
75 memset(_test_, 0, sizeof(*_test_)); \
ac569b72 76 strncpy(_test_->desc.name, n, SPLAT_NAME_SIZE-1); \
77 strncpy(_test_->desc.desc, d, SPLAT_DESC_SIZE-1); \
7c50328b 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) \
8d0f1ee9 88({ splat_test_t *_test_, *_tmp_; \
7c50328b 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_) \
8d0f1ee9 102 printk(KERN_ERR "splat: Error finalizing: " #tid "\n"); \
7c50328b 103})
104
105typedef int (*splat_test_func_t)(struct file *, void *);
106
107typedef 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
113typedef 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
123typedef struct splat_info {
0e149d42 124 struct mutex info_lock;
7c50328b 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...) \
d6a26c6a 133({ splat_info_t *_info_ = (splat_info_t *)file->private_data; \
7c50328b 134 int _rc_; \
135 \
136 ASSERT(_info_); \
137 ASSERT(_info_->info_buffer); \
138 \
0e149d42 139 mutex_lock(&_info_->info_lock); \
7c50328b 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 \
0e149d42 151 mutex_unlock(&_info_->info_lock); \
7c50328b 152 _rc_; \
153})
154
d6a26c6a 155#define splat_vprint(file, test, format, args...) \
7c50328b 156 splat_print(file, "%*s: " format, SPLAT_NAME_SIZE, test, args)
157
e811949a
BB
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
d702c04f
BB
167splat_subsystem_t *splat_condvar_init(void);
168splat_subsystem_t *splat_kmem_init(void);
169splat_subsystem_t *splat_mutex_init(void);
170splat_subsystem_t *splat_krng_init(void);
171splat_subsystem_t *splat_rwlock_init(void);
172splat_subsystem_t *splat_taskq_init(void);
173splat_subsystem_t *splat_thread_init(void);
174splat_subsystem_t *splat_time_init(void);
175splat_subsystem_t *splat_vnode_init(void);
176splat_subsystem_t *splat_kobj_init(void);
177splat_subsystem_t *splat_atomic_init(void);
178splat_subsystem_t *splat_list_init(void);
b871b8cd 179splat_subsystem_t *splat_generic_init(void);
ec7d53e9 180splat_subsystem_t *splat_cred_init(void);
19c1eb82 181splat_subsystem_t *splat_zlib_init(void);
bf0c60c0 182splat_subsystem_t *splat_linux_init(void);
7c50328b 183
184void splat_condvar_fini(splat_subsystem_t *);
185void splat_kmem_fini(splat_subsystem_t *);
186void splat_mutex_fini(splat_subsystem_t *);
187void splat_krng_fini(splat_subsystem_t *);
188void splat_rwlock_fini(splat_subsystem_t *);
189void splat_taskq_fini(splat_subsystem_t *);
190void splat_thread_fini(splat_subsystem_t *);
191void splat_time_fini(splat_subsystem_t *);
4b171585 192void splat_vnode_fini(splat_subsystem_t *);
9490c148 193void splat_kobj_fini(splat_subsystem_t *);
9f4c835a 194void splat_atomic_fini(splat_subsystem_t *);
d702c04f 195void splat_list_fini(splat_subsystem_t *);
b871b8cd 196void splat_generic_fini(splat_subsystem_t *);
ec7d53e9 197void splat_cred_fini(splat_subsystem_t *);
19c1eb82 198void splat_zlib_fini(splat_subsystem_t *);
bf0c60c0 199void splat_linux_fini(splat_subsystem_t *);
7c50328b 200
201int splat_condvar_id(void);
202int splat_kmem_id(void);
203int splat_mutex_id(void);
204int splat_krng_id(void);
205int splat_rwlock_id(void);
206int splat_taskq_id(void);
207int splat_thread_id(void);
208int splat_time_id(void);
4b171585 209int splat_vnode_id(void);
9490c148 210int splat_kobj_id(void);
9f4c835a 211int splat_atomic_id(void);
d702c04f 212int splat_list_id(void);
b871b8cd 213int splat_generic_id(void);
ec7d53e9 214int splat_cred_id(void);
19c1eb82 215int splat_zlib_id(void);
bf0c60c0 216int splat_linux_id(void);
7c50328b 217
218#endif /* _SPLAT_INTERNAL_H */