1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* db_headers.h
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _DB_HEADERS_H
#define _DB_HEADERS_H
#include <rpc/rpc.h>
#include <syslog.h>
#include <stdlib.h>
#include <setjmp.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int verbose;
#ifdef __cplusplus
}
#endif
extern jmp_buf dbenv;
#define FATAL(msg, fcode) \
{ \
syslog(LOG_ERR, "ERROR: %s", (msg)); \
__nisdb_get_tsd()->fatalcode = (int)(fcode); \
__nisdb_get_tsd()->fatalmsg = msg; \
return; \
}
#define FATAL3(msg, fcode, retval) \
{ \
syslog(LOG_ERR, "ERROR: %s", (msg)); \
__nisdb_get_tsd()->fatalcode = (int)(fcode); \
__nisdb_get_tsd()->fatalmsg = msg; \
return (retval); \
}
#ifdef NISDB_MT_DEBUG
#define LOCKVAL(lockcall, msg, lockcode) \
{ \
lockcode = lockcall(); \
if (lockcode != 0) { \
__nisdb_get_tsd()->fatalcode = lockcode; \
__nisdb_get_tsd()->fatalmsg = msg; \
abort(); \
} \
}
#else
#define LOCKVAL(lockcall, msg, lockcode) \
{ \
lockcode = lockcall(); \
if (lockcode != 0) { \
__nisdb_get_tsd()->fatalcode = lockcode; \
__nisdb_get_tsd()->fatalmsg = msg; \
} \
}
#endif /* NISDB_MT_DEBUG */
#define LOCKV(lockcall, msg) \
{ \
int lockcode; \
LOCKVAL(lockcall, msg, lockcode); \
if (lockcode != 0) \
return; \
}
#define LOCK(lockcall, retval, msg) \
{ \
int lockcode; \
LOCKVAL(lockcall, msg, lockcode); \
if (lockcode != 0) \
return (retval); \
}
/* Read lock/unlock 'this', return 'retval' is unsuccessful, and save 'msg' */
#define READLOCK(this, retval, msg) \
LOCK(this->acqnonexcl, retval, msg)
#define READUNLOCK(this, retval, msg) \
LOCK(this->relnonexcl, retval, msg)
/* Ditto, but return without a value (i.e., a "void" function */
#define READLOCKV(this, msg) \
LOCKV(this->acqnonexcl, msg)
#define READUNLOCKV(this, msg) \
LOCKV(this->relnonexcl, msg)
/* As READLOCK/READUNLOCK, but set rescode instead of returning on failure */
#define READLOCKNR(this, rescode, msg) \
LOCKVAL(this->acqnonexcl, msg, rescode)
#define READUNLOCKNR(this, rescode, msg) \
LOCKVAL(this->relnonexcl, msg, rescode)
/* As READLOCK/READUNLOCK, but use a write lock */
#define WRITELOCK(this, retval, msg) \
LOCK(this->acqexcl, retval, msg)
#define WRITEUNLOCK(this, retval, msg) \
LOCK(this->relexcl, retval, msg)
/* Non-blocking write lock */
#define TRYWRITELOCK(this, rescode, msg) \
LOCKVAL(this->tryacqexcl, msg, rescode)
/* Ditto, but return without a value */
#define WRITELOCKV(this, msg) \
LOCKV(this->acqexcl, msg)
#define WRITEUNLOCKV(this, msg) \
LOCKV(this->relexcl, msg)
/* As WRITELOCK/WRITEUNLOCK, but set rescode instead of returning on failure */
#define WRITELOCKNR(this, rescode, msg) \
LOCKVAL(this->acqexcl, msg, rescode)
#define WRITEUNLOCKNR(this, rescode, msg) \
LOCKVAL(this->relexcl, msg, rescode)
/* Apply a second write lock when already holding another write lock */
#define WRITELOCK2(this, retval, msg, that) \
if (this != 0) { \
int lockcode1, lockcode2; \
WRITELOCKNR(this, lockcode2, msg); \
if (lockcode2 != 0) { \
WRITEUNLOCKNR(that, lockcode1, msg); \
return (retval); \
} \
}
/* Release two write locks */
#define WRITEUNLOCK2(this, that, retval1, retval2, msg1, msg2) \
{ \
int lockcode1 = 0, lockcode2 = 0; \
WRITEUNLOCKNR(this, lockcode1, msg1); \
WRITEUNLOCKNR(that, lockcode2, msg2); \
if (lockcode2 != 0) { \
return (retval2); \
} else if (lockcode1 != 0) { \
return (retval1); \
} \
}
/* Apply a second read lock when already holding another read lock */
#define READLOCK2(this, retval, msg, that) \
if (this != 0) { \
int lockcode1, lockcode2; \
READLOCKNR(this, lockcode2, msg); \
if (lockcode2 != 0) { \
READUNLOCKNR(that, lockcode1, msg); \
return (retval); \
} \
}
/* Release two read locks */
#define READUNLOCK2(this, that, retval1, retval2, msg1, msg2) \
{ \
int lockcode1 = 0, lockcode2 = 0; \
READUNLOCKNR(this, lockcode1, msg1); \
READUNLOCKNR(that, lockcode2, msg2); \
if (lockcode2 != 0) { \
return (retval2); \
} else if (lockcode1 != 0) { \
return (retval1); \
} \
}
#define ASSERTWRITELOCKHELD(lvar, retval, msg) \
{ \
int lc; \
if ((lc = __nisdb_assert_wheld(&lvar ## _rwlock)) != 0) { \
__nisdb_get_tsd()->fatalcode = lc; \
__nisdb_get_tsd()->fatalmsg = msg; \
return (retval); \
} \
}
#define WARNING(x) { syslog(LOG_ERR, "WARNING: %s", (x)); }
#define WARNING_M(x) { syslog(LOG_ERR, "WARNING: %s: %m", (x)); }
enum db_status {DB_SUCCESS, DB_NOTFOUND, DB_NOTUNIQUE,
DB_BADTABLE, DB_BADQUERY, DB_BADOBJECT,
DB_MEMORY_LIMIT, DB_STORAGE_LIMIT, DB_INTERNAL_ERROR,
DB_BADDICTIONARY, DB_SYNC_FAILED, DB_LOCK_ERROR};
typedef enum db_status db_status;
enum db_action {DB_LOOKUP, DB_REMOVE, DB_ADD, DB_FIRST, DB_NEXT, DB_ALL,
DB_RESET_NEXT, DB_ADD_NOLOG,
DB_ADD_NOSYNC, DB_REMOVE_NOSYNC };
typedef enum db_action db_action;
#endif /* _DB_HEADERS_H */
|