Skip to content

Commit 4c175ff

Browse files
amotinrobn
authored andcommitted
Cleanup VERIFY() macros (openzfs#17163)
- Fix VERIFY3B() when given non-boolean values. - Map EQUIV() into VERIFY3B(,==,) as equivalent. - Tune messages for better readability and to closer match source code for easier search. Unify user-space messages with kernel. - Tune printed types and remove %px outside of Linux kernel. Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc. Reviewed-by: @ImAwsumm Reviewed-by: Rob Norris <[email protected]> Reviewed-by: Tony Hutter <[email protected]> (cherry picked from commit 4866c2f)
1 parent 0f295ca commit 4c175ff

File tree

3 files changed

+89
-114
lines changed

3 files changed

+89
-114
lines changed

include/os/freebsd/spl/sys/debug.h

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,21 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
112112
} while (0)
113113

114114
#define VERIFY3B(LEFT, OP, RIGHT) do { \
115-
const boolean_t _verify3_left = (boolean_t)(LEFT); \
116-
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
115+
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
116+
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
117117
if (unlikely(!(_verify3_left OP _verify3_right))) \
118118
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
119-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
119+
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
120120
"failed (%d " #OP " %d)\n", \
121-
(boolean_t)_verify3_left, \
122-
(boolean_t)_verify3_right); \
121+
_verify3_left, _verify3_right); \
123122
} while (0)
124123

125124
#define VERIFY3S(LEFT, OP, RIGHT) do { \
126125
const int64_t _verify3_left = (int64_t)(LEFT); \
127126
const int64_t _verify3_right = (int64_t)(RIGHT); \
128127
if (unlikely(!(_verify3_left OP _verify3_right))) \
129128
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
130-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
129+
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
131130
"failed (%lld " #OP " %lld)\n", \
132131
(long long)_verify3_left, \
133132
(long long)_verify3_right); \
@@ -138,7 +137,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
138137
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
139138
if (unlikely(!(_verify3_left OP _verify3_right))) \
140139
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
141-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
140+
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
142141
"failed (%llu " #OP " %llu)\n", \
143142
(unsigned long long)_verify3_left, \
144143
(unsigned long long)_verify3_right); \
@@ -149,8 +148,8 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
149148
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
150149
if (unlikely(!(_verify3_left OP _verify3_right))) \
151150
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
152-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
153-
"failed (%px " #OP " %px)\n", \
151+
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
152+
"failed (%p " #OP " %p)\n", \
154153
(void *)_verify3_left, \
155154
(void *)_verify3_right); \
156155
} while (0)
@@ -159,17 +158,15 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
159158
const int64_t _verify0_right = (int64_t)(RIGHT); \
160159
if (unlikely(!(0 == _verify0_right))) \
161160
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
162-
"VERIFY0(" #RIGHT ") " \
163-
"failed (0 == %lld)\n", \
161+
"VERIFY0(" #RIGHT ") failed (%lld)\n", \
164162
(long long)_verify0_right); \
165163
} while (0)
166164

167165
#define VERIFY0P(RIGHT) do { \
168166
const uintptr_t _verify0_right = (uintptr_t)(RIGHT); \
169167
if (unlikely(!(0 == _verify0_right))) \
170168
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
171-
"VERIFY0P(" #RIGHT ") " \
172-
"failed (NULL == %px)\n", \
169+
"VERIFY0P(" #RIGHT ") failed (%p)\n", \
173170
(void *)_verify0_right); \
174171
} while (0)
175172

@@ -182,14 +179,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
182179
*/
183180

184181
#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) do { \
185-
const boolean_t _verify3_left = (boolean_t)(LEFT); \
186-
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
182+
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
183+
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
187184
if (unlikely(!(_verify3_left OP _verify3_right))) \
188185
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
189-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
186+
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
190187
"failed (%d " #OP " %d) " STR "\n", \
191-
(boolean_t)(_verify3_left), \
192-
(boolean_t)(_verify3_right), \
188+
_verify3_left, _verify3_right, \
193189
__VA_ARGS__); \
194190
} while (0)
195191

@@ -198,10 +194,9 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
198194
const int64_t _verify3_right = (int64_t)(RIGHT); \
199195
if (unlikely(!(_verify3_left OP _verify3_right))) \
200196
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
201-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
197+
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
202198
"failed (%lld " #OP " %lld) " STR "\n", \
203-
(long long)(_verify3_left), \
204-
(long long)(_verify3_right), \
199+
(long long)_verify3_left, (long long)_verify3_right,\
205200
__VA_ARGS__); \
206201
} while (0)
207202

@@ -210,10 +205,10 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
210205
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
211206
if (unlikely(!(_verify3_left OP _verify3_right))) \
212207
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
213-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
208+
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
214209
"failed (%llu " #OP " %llu) " STR "\n", \
215-
(unsigned long long)(_verify3_left), \
216-
(unsigned long long)(_verify3_right), \
210+
(unsigned long long)_verify3_left, \
211+
(unsigned long long)_verify3_right, \
217212
__VA_ARGS__); \
218213
} while (0)
219214

@@ -222,32 +217,27 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
222217
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
223218
if (unlikely(!(_verify3_left OP _verify3_right))) \
224219
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
225-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
226-
"failed (%px " #OP " %px) " STR "\n", \
227-
(void *) (_verify3_left), \
228-
(void *) (_verify3_right), \
220+
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
221+
"failed (%p " #OP " %p) " STR "\n", \
222+
(void *)_verify3_left, (void *)_verify3_right, \
229223
__VA_ARGS__); \
230224
} while (0)
231225

232226
#define VERIFY0PF(RIGHT, STR, ...) do { \
233-
const uintptr_t _verify3_left = (uintptr_t)(0); \
234227
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
235-
if (unlikely(!(_verify3_left == _verify3_right))) \
228+
if (unlikely(!(0 == _verify3_right))) \
236229
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
237-
"VERIFY0(0 == " #RIGHT ") " \
238-
"failed (0 == %px) " STR "\n", \
239-
(long long) (_verify3_right), \
230+
"VERIFY0P(" #RIGHT ") failed (%p) " STR "\n", \
231+
(void *)_verify3_right, \
240232
__VA_ARGS__); \
241233
} while (0)
242234

243235
#define VERIFY0F(RIGHT, STR, ...) do { \
244-
const int64_t _verify3_left = (int64_t)(0); \
245236
const int64_t _verify3_right = (int64_t)(RIGHT); \
246-
if (unlikely(!(_verify3_left == _verify3_right))) \
237+
if (unlikely(!(0 == _verify3_right))) \
247238
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
248-
"VERIFY0(0 == " #RIGHT ") " \
249-
"failed (0 == %lld) " STR "\n", \
250-
(long long) (_verify3_right), \
239+
"VERIFY0(" #RIGHT ") failed (%lld) " STR "\n", \
240+
(long long)_verify3_right, \
251241
__VA_ARGS__); \
252242
} while (0)
253243

@@ -256,10 +246,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
256246
spl_assert("(" #A ") implies (" #B ")", \
257247
__FILE__, __FUNCTION__, __LINE__)))
258248

259-
#define VERIFY_EQUIV(A, B) \
260-
((void)(likely(!!(A) == !!(B)) || \
261-
spl_assert("(" #A ") is equivalent to (" #B ")", \
262-
__FILE__, __FUNCTION__, __LINE__)))
249+
#define VERIFY_EQUIV(A, B) VERIFY3B(A, ==, B)
263250

264251
/*
265252
* Debugging disabled (--disable-debug)

include/os/linux/spl/sys/debug.h

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,21 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
116116
} while (0)
117117

118118
#define VERIFY3B(LEFT, OP, RIGHT) do { \
119-
const boolean_t _verify3_left = (boolean_t)(LEFT); \
120-
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
119+
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
120+
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
121121
if (unlikely(!(_verify3_left OP _verify3_right))) \
122122
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
123-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
123+
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
124124
"failed (%d " #OP " %d)\n", \
125-
(boolean_t)_verify3_left, \
126-
(boolean_t)_verify3_right); \
125+
_verify3_left, _verify3_right); \
127126
} while (0)
128127

129128
#define VERIFY3S(LEFT, OP, RIGHT) do { \
130129
const int64_t _verify3_left = (int64_t)(LEFT); \
131130
const int64_t _verify3_right = (int64_t)(RIGHT); \
132131
if (unlikely(!(_verify3_left OP _verify3_right))) \
133132
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
134-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
133+
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
135134
"failed (%lld " #OP " %lld)\n", \
136135
(long long)_verify3_left, \
137136
(long long)_verify3_right); \
@@ -142,7 +141,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
142141
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
143142
if (unlikely(!(_verify3_left OP _verify3_right))) \
144143
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
145-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
144+
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
146145
"failed (%llu " #OP " %llu)\n", \
147146
(unsigned long long)_verify3_left, \
148147
(unsigned long long)_verify3_right); \
@@ -153,7 +152,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
153152
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
154153
if (unlikely(!(_verify3_left OP _verify3_right))) \
155154
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
156-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
155+
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
157156
"failed (%px " #OP " %px)\n", \
158157
(void *)_verify3_left, \
159158
(void *)_verify3_right); \
@@ -163,17 +162,15 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
163162
const int64_t _verify0_right = (int64_t)(RIGHT); \
164163
if (unlikely(!(0 == _verify0_right))) \
165164
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
166-
"VERIFY0(" #RIGHT ") " \
167-
"failed (0 == %lld)\n", \
165+
"VERIFY0(" #RIGHT ") failed (%lld)\n", \
168166
(long long)_verify0_right); \
169167
} while (0)
170168

171169
#define VERIFY0P(RIGHT) do { \
172170
const uintptr_t _verify0_right = (uintptr_t)(RIGHT); \
173171
if (unlikely(!(0 == _verify0_right))) \
174172
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
175-
"VERIFY0P(" #RIGHT ") " \
176-
"failed (NULL == %px)\n", \
173+
"VERIFY0P(" #RIGHT ") failed (%px)\n", \
177174
(void *)_verify0_right); \
178175
} while (0)
179176

@@ -186,14 +183,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
186183
*/
187184

188185
#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) do { \
189-
const boolean_t _verify3_left = (boolean_t)(LEFT); \
190-
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
186+
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
187+
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
191188
if (unlikely(!(_verify3_left OP _verify3_right))) \
192189
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
193-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
190+
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
194191
"failed (%d " #OP " %d) " STR "\n", \
195-
(boolean_t)(_verify3_left), \
196-
(boolean_t)(_verify3_right), \
192+
_verify3_left, _verify3_right, \
197193
__VA_ARGS__); \
198194
} while (0)
199195

@@ -202,10 +198,9 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
202198
const int64_t _verify3_right = (int64_t)(RIGHT); \
203199
if (unlikely(!(_verify3_left OP _verify3_right))) \
204200
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
205-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
201+
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
206202
"failed (%lld " #OP " %lld) " STR "\n", \
207-
(long long)(_verify3_left), \
208-
(long long)(_verify3_right), \
203+
(long long)_verify3_left, (long long)_verify3_right,\
209204
__VA_ARGS__); \
210205
} while (0)
211206

@@ -214,10 +209,10 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
214209
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
215210
if (unlikely(!(_verify3_left OP _verify3_right))) \
216211
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
217-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
212+
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
218213
"failed (%llu " #OP " %llu) " STR "\n", \
219-
(unsigned long long)(_verify3_left), \
220-
(unsigned long long)(_verify3_right), \
214+
(unsigned long long)_verify3_left, \
215+
(unsigned long long)_verify3_right, \
221216
__VA_ARGS__); \
222217
} while (0)
223218

@@ -226,32 +221,27 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
226221
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
227222
if (unlikely(!(_verify3_left OP _verify3_right))) \
228223
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
229-
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
224+
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
230225
"failed (%px " #OP " %px) " STR "\n", \
231-
(void *) (_verify3_left), \
232-
(void *) (_verify3_right), \
226+
(void *)_verify3_left, (void *)_verify3_right, \
233227
__VA_ARGS__); \
234228
} while (0)
235229

236230
#define VERIFY0PF(RIGHT, STR, ...) do { \
237-
const uintptr_t _verify3_left = (uintptr_t)(0); \
238231
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
239-
if (unlikely(!(_verify3_left == _verify3_right))) \
232+
if (unlikely(!(0 == _verify3_right))) \
240233
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
241-
"VERIFY0(0 == " #RIGHT ") " \
242-
"failed (0 == %px) " STR "\n", \
243-
(long long) (_verify3_right), \
234+
"VERIFY0P(" #RIGHT ") failed (%px) " STR "\n", \
235+
(void *)_verify3_right, \
244236
__VA_ARGS__); \
245237
} while (0)
246238

247239
#define VERIFY0F(RIGHT, STR, ...) do { \
248-
const int64_t _verify3_left = (int64_t)(0); \
249240
const int64_t _verify3_right = (int64_t)(RIGHT); \
250-
if (unlikely(!(_verify3_left == _verify3_right))) \
241+
if (unlikely(!(0 == _verify3_right))) \
251242
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
252-
"VERIFY0(0 == " #RIGHT ") " \
253-
"failed (0 == %lld) " STR "\n", \
254-
(long long) (_verify3_right), \
243+
"VERIFY0(" #RIGHT ") failed (%lld) " STR "\n", \
244+
(long long)_verify3_right, \
255245
__VA_ARGS__); \
256246
} while (0)
257247

@@ -260,10 +250,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
260250
spl_assert("(" #A ") implies (" #B ")", \
261251
__FILE__, __FUNCTION__, __LINE__)))
262252

263-
#define VERIFY_EQUIV(A, B) \
264-
((void)(likely(!!(A) == !!(B)) || \
265-
spl_assert("(" #A ") is equivalent to (" #B ")", \
266-
__FILE__, __FUNCTION__, __LINE__)))
253+
#define VERIFY_EQUIV(A, B) VERIFY3B(A, ==, B)
267254

268255
/*
269256
* Debugging disabled (--disable-debug)

0 commit comments

Comments
 (0)