1 | /* Do not edit: automatically built by gen_rec.awk. */ |
---|
2 | #include "db_config.h" |
---|
3 | |
---|
4 | #ifndef NO_SYSTEM_INCLUDES |
---|
5 | #include <sys/types.h> |
---|
6 | |
---|
7 | #include <ctype.h> |
---|
8 | #include <string.h> |
---|
9 | #endif |
---|
10 | |
---|
11 | #include "db_int.h" |
---|
12 | #include "dbinc/crypto.h" |
---|
13 | #include "dbinc/db_page.h" |
---|
14 | #include "dbinc/db_dispatch.h" |
---|
15 | #include "dbinc/db_am.h" |
---|
16 | #include "dbinc/log.h" |
---|
17 | #include "dbinc/rep.h" |
---|
18 | #include "dbinc/txn.h" |
---|
19 | |
---|
20 | /* |
---|
21 | * PUBLIC: int __dbreg_register_log __P((DB_ENV *, DB_TXN *, |
---|
22 | * PUBLIC: DB_LSN *, u_int32_t, u_int32_t, const DBT *, const DBT *, |
---|
23 | * PUBLIC: int32_t, DBTYPE, db_pgno_t, u_int32_t)); |
---|
24 | */ |
---|
25 | int |
---|
26 | __dbreg_register_log(dbenv, txnid, ret_lsnp, flags, |
---|
27 | opcode, name, uid, fileid, ftype, meta_pgno, |
---|
28 | id) |
---|
29 | DB_ENV *dbenv; |
---|
30 | DB_TXN *txnid; |
---|
31 | DB_LSN *ret_lsnp; |
---|
32 | u_int32_t flags; |
---|
33 | u_int32_t opcode; |
---|
34 | const DBT *name; |
---|
35 | const DBT *uid; |
---|
36 | int32_t fileid; |
---|
37 | DBTYPE ftype; |
---|
38 | db_pgno_t meta_pgno; |
---|
39 | u_int32_t id; |
---|
40 | { |
---|
41 | DBT logrec; |
---|
42 | DB_LSN *lsnp, null_lsn; |
---|
43 | u_int32_t zero; |
---|
44 | u_int32_t uinttmp; |
---|
45 | u_int32_t npad, rectype, txn_num; |
---|
46 | int ret; |
---|
47 | u_int8_t *bp; |
---|
48 | |
---|
49 | rectype = DB___dbreg_register; |
---|
50 | npad = 0; |
---|
51 | |
---|
52 | if (txnid == NULL) { |
---|
53 | txn_num = 0; |
---|
54 | null_lsn.file = 0; |
---|
55 | null_lsn.offset = 0; |
---|
56 | lsnp = &null_lsn; |
---|
57 | } else { |
---|
58 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
59 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
60 | return (ret); |
---|
61 | txn_num = txnid->txnid; |
---|
62 | lsnp = &txnid->last_lsn; |
---|
63 | } |
---|
64 | |
---|
65 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
66 | + sizeof(u_int32_t) |
---|
67 | + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) |
---|
68 | + sizeof(u_int32_t) + (uid == NULL ? 0 : uid->size) |
---|
69 | + sizeof(u_int32_t) |
---|
70 | + sizeof(u_int32_t) |
---|
71 | + sizeof(u_int32_t) |
---|
72 | + sizeof(u_int32_t); |
---|
73 | if (CRYPTO_ON(dbenv)) { |
---|
74 | npad = |
---|
75 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
76 | logrec.size += npad; |
---|
77 | } |
---|
78 | |
---|
79 | if ((ret = __os_malloc(dbenv, |
---|
80 | logrec.size, &logrec.data)) != 0) |
---|
81 | return (ret); |
---|
82 | |
---|
83 | if (npad > 0) |
---|
84 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
85 | |
---|
86 | bp = logrec.data; |
---|
87 | |
---|
88 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
89 | bp += sizeof(rectype); |
---|
90 | |
---|
91 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
92 | bp += sizeof(txn_num); |
---|
93 | |
---|
94 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
95 | bp += sizeof(DB_LSN); |
---|
96 | |
---|
97 | uinttmp = (u_int32_t)opcode; |
---|
98 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
99 | bp += sizeof(uinttmp); |
---|
100 | |
---|
101 | if (name == NULL) { |
---|
102 | zero = 0; |
---|
103 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
104 | bp += sizeof(u_int32_t); |
---|
105 | } else { |
---|
106 | memcpy(bp, &name->size, sizeof(name->size)); |
---|
107 | bp += sizeof(name->size); |
---|
108 | memcpy(bp, name->data, name->size); |
---|
109 | bp += name->size; |
---|
110 | } |
---|
111 | |
---|
112 | if (uid == NULL) { |
---|
113 | zero = 0; |
---|
114 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
115 | bp += sizeof(u_int32_t); |
---|
116 | } else { |
---|
117 | memcpy(bp, &uid->size, sizeof(uid->size)); |
---|
118 | bp += sizeof(uid->size); |
---|
119 | memcpy(bp, uid->data, uid->size); |
---|
120 | bp += uid->size; |
---|
121 | } |
---|
122 | |
---|
123 | uinttmp = (u_int32_t)fileid; |
---|
124 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
125 | bp += sizeof(uinttmp); |
---|
126 | |
---|
127 | uinttmp = (u_int32_t)ftype; |
---|
128 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
129 | bp += sizeof(uinttmp); |
---|
130 | |
---|
131 | uinttmp = (u_int32_t)meta_pgno; |
---|
132 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
133 | bp += sizeof(uinttmp); |
---|
134 | |
---|
135 | uinttmp = (u_int32_t)id; |
---|
136 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
137 | bp += sizeof(uinttmp); |
---|
138 | |
---|
139 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
140 | ret = dbenv->log_put(dbenv, |
---|
141 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
142 | if (txnid != NULL && ret == 0) |
---|
143 | txnid->last_lsn = *ret_lsnp; |
---|
144 | #ifdef LOG_DIAGNOSTIC |
---|
145 | if (ret != 0) |
---|
146 | (void)__dbreg_register_print(dbenv, |
---|
147 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
148 | #endif |
---|
149 | __os_free(dbenv, logrec.data); |
---|
150 | return (ret); |
---|
151 | } |
---|
152 | |
---|
153 | /* |
---|
154 | * PUBLIC: int __dbreg_register_getpgnos __P((DB_ENV *, DBT *, |
---|
155 | * PUBLIC: DB_LSN *, db_recops, void *)); |
---|
156 | */ |
---|
157 | int |
---|
158 | __dbreg_register_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
159 | DB_ENV *dbenv; |
---|
160 | DBT *rec; |
---|
161 | DB_LSN *lsnp; |
---|
162 | db_recops notused1; |
---|
163 | void *summary; |
---|
164 | { |
---|
165 | TXN_RECS *t; |
---|
166 | int ret; |
---|
167 | COMPQUIET(rec, NULL); |
---|
168 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
169 | |
---|
170 | t = (TXN_RECS *)summary; |
---|
171 | |
---|
172 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
173 | return (ret); |
---|
174 | |
---|
175 | t->array[t->npages].flags = LSN_PAGE_NOLOCK; |
---|
176 | t->array[t->npages].lsn = *lsnp; |
---|
177 | t->array[t->npages].fid = DB_LOGFILEID_INVALID; |
---|
178 | memset(&t->array[t->npages].pgdesc, 0, |
---|
179 | sizeof(t->array[t->npages].pgdesc)); |
---|
180 | |
---|
181 | t->npages++; |
---|
182 | |
---|
183 | return (0); |
---|
184 | } |
---|
185 | |
---|
186 | /* |
---|
187 | * PUBLIC: int __dbreg_register_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
188 | * PUBLIC: db_recops, void *)); |
---|
189 | */ |
---|
190 | int |
---|
191 | __dbreg_register_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
192 | DB_ENV *dbenv; |
---|
193 | DBT *dbtp; |
---|
194 | DB_LSN *lsnp; |
---|
195 | db_recops notused2; |
---|
196 | void *notused3; |
---|
197 | { |
---|
198 | __dbreg_register_args *argp; |
---|
199 | u_int32_t i; |
---|
200 | int ch; |
---|
201 | int ret; |
---|
202 | |
---|
203 | notused2 = DB_TXN_ABORT; |
---|
204 | notused3 = NULL; |
---|
205 | |
---|
206 | if ((ret = __dbreg_register_read(dbenv, dbtp->data, &argp)) != 0) |
---|
207 | return (ret); |
---|
208 | (void)printf( |
---|
209 | "[%lu][%lu]__dbreg_register: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
210 | (u_long)lsnp->file, |
---|
211 | (u_long)lsnp->offset, |
---|
212 | (u_long)argp->type, |
---|
213 | (u_long)argp->txnid->txnid, |
---|
214 | (u_long)argp->prev_lsn.file, |
---|
215 | (u_long)argp->prev_lsn.offset); |
---|
216 | (void)printf("\topcode: %lu\n", (u_long)argp->opcode); |
---|
217 | (void)printf("\tname: "); |
---|
218 | for (i = 0; i < argp->name.size; i++) { |
---|
219 | ch = ((u_int8_t *)argp->name.data)[i]; |
---|
220 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
221 | } |
---|
222 | (void)printf("\n"); |
---|
223 | (void)printf("\tuid: "); |
---|
224 | for (i = 0; i < argp->uid.size; i++) { |
---|
225 | ch = ((u_int8_t *)argp->uid.data)[i]; |
---|
226 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
227 | } |
---|
228 | (void)printf("\n"); |
---|
229 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
230 | (void)printf("\tftype: 0x%lx\n", (u_long)argp->ftype); |
---|
231 | (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno); |
---|
232 | (void)printf("\tid: 0x%lx\n", (u_long)argp->id); |
---|
233 | (void)printf("\n"); |
---|
234 | __os_free(dbenv, argp); |
---|
235 | return (0); |
---|
236 | } |
---|
237 | |
---|
238 | /* |
---|
239 | * PUBLIC: int __dbreg_register_read __P((DB_ENV *, void *, |
---|
240 | * PUBLIC: __dbreg_register_args **)); |
---|
241 | */ |
---|
242 | int |
---|
243 | __dbreg_register_read(dbenv, recbuf, argpp) |
---|
244 | DB_ENV *dbenv; |
---|
245 | void *recbuf; |
---|
246 | __dbreg_register_args **argpp; |
---|
247 | { |
---|
248 | __dbreg_register_args *argp; |
---|
249 | u_int32_t uinttmp; |
---|
250 | u_int8_t *bp; |
---|
251 | int ret; |
---|
252 | |
---|
253 | if ((ret = __os_malloc(dbenv, |
---|
254 | sizeof(__dbreg_register_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
255 | return (ret); |
---|
256 | |
---|
257 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
258 | |
---|
259 | bp = recbuf; |
---|
260 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
261 | bp += sizeof(argp->type); |
---|
262 | |
---|
263 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
264 | bp += sizeof(argp->txnid->txnid); |
---|
265 | |
---|
266 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
267 | bp += sizeof(DB_LSN); |
---|
268 | |
---|
269 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
270 | argp->opcode = (u_int32_t)uinttmp; |
---|
271 | bp += sizeof(uinttmp); |
---|
272 | |
---|
273 | memset(&argp->name, 0, sizeof(argp->name)); |
---|
274 | memcpy(&argp->name.size, bp, sizeof(u_int32_t)); |
---|
275 | bp += sizeof(u_int32_t); |
---|
276 | argp->name.data = bp; |
---|
277 | bp += argp->name.size; |
---|
278 | |
---|
279 | memset(&argp->uid, 0, sizeof(argp->uid)); |
---|
280 | memcpy(&argp->uid.size, bp, sizeof(u_int32_t)); |
---|
281 | bp += sizeof(u_int32_t); |
---|
282 | argp->uid.data = bp; |
---|
283 | bp += argp->uid.size; |
---|
284 | |
---|
285 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
286 | argp->fileid = (int32_t)uinttmp; |
---|
287 | bp += sizeof(uinttmp); |
---|
288 | |
---|
289 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
290 | argp->ftype = (DBTYPE)uinttmp; |
---|
291 | bp += sizeof(uinttmp); |
---|
292 | |
---|
293 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
294 | argp->meta_pgno = (db_pgno_t)uinttmp; |
---|
295 | bp += sizeof(uinttmp); |
---|
296 | |
---|
297 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
298 | argp->id = (u_int32_t)uinttmp; |
---|
299 | bp += sizeof(uinttmp); |
---|
300 | |
---|
301 | *argpp = argp; |
---|
302 | return (0); |
---|
303 | } |
---|
304 | |
---|
305 | /* |
---|
306 | * PUBLIC: int __dbreg_init_print __P((DB_ENV *, int (***)(DB_ENV *, |
---|
307 | * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *)); |
---|
308 | */ |
---|
309 | int |
---|
310 | __dbreg_init_print(dbenv, dtabp, dtabsizep) |
---|
311 | DB_ENV *dbenv; |
---|
312 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
313 | size_t *dtabsizep; |
---|
314 | { |
---|
315 | int ret; |
---|
316 | |
---|
317 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
318 | __dbreg_register_print, DB___dbreg_register)) != 0) |
---|
319 | return (ret); |
---|
320 | return (0); |
---|
321 | } |
---|
322 | |
---|
323 | /* |
---|
324 | * PUBLIC: int __dbreg_init_getpgnos __P((DB_ENV *, |
---|
325 | * PUBLIC: int (***)(DB_ENV *, DBT *, DB_LSN *, db_recops, void *), |
---|
326 | * PUBLIC: size_t *)); |
---|
327 | */ |
---|
328 | int |
---|
329 | __dbreg_init_getpgnos(dbenv, dtabp, dtabsizep) |
---|
330 | DB_ENV *dbenv; |
---|
331 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
332 | size_t *dtabsizep; |
---|
333 | { |
---|
334 | int ret; |
---|
335 | |
---|
336 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
337 | __dbreg_register_getpgnos, DB___dbreg_register)) != 0) |
---|
338 | return (ret); |
---|
339 | return (0); |
---|
340 | } |
---|
341 | |
---|
342 | /* |
---|
343 | * PUBLIC: int __dbreg_init_recover __P((DB_ENV *, int (***)(DB_ENV *, |
---|
344 | * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *)); |
---|
345 | */ |
---|
346 | int |
---|
347 | __dbreg_init_recover(dbenv, dtabp, dtabsizep) |
---|
348 | DB_ENV *dbenv; |
---|
349 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
350 | size_t *dtabsizep; |
---|
351 | { |
---|
352 | int ret; |
---|
353 | |
---|
354 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
355 | __dbreg_register_recover, DB___dbreg_register)) != 0) |
---|
356 | return (ret); |
---|
357 | return (0); |
---|
358 | } |
---|