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/btree.h" |
---|
17 | #include "dbinc/log.h" |
---|
18 | #include "dbinc/rep.h" |
---|
19 | #include "dbinc/txn.h" |
---|
20 | |
---|
21 | /* |
---|
22 | * PUBLIC: int __bam_split_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
23 | * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, db_pgno_t, DB_LSN *, u_int32_t, |
---|
24 | * PUBLIC: db_pgno_t, DB_LSN *, db_pgno_t, const DBT *, u_int32_t)); |
---|
25 | */ |
---|
26 | int |
---|
27 | __bam_split_log(dbp, txnid, ret_lsnp, flags, left, llsn, right, rlsn, indx, |
---|
28 | npgno, nlsn, root_pgno, pg, opflags) |
---|
29 | DB *dbp; |
---|
30 | DB_TXN *txnid; |
---|
31 | DB_LSN *ret_lsnp; |
---|
32 | u_int32_t flags; |
---|
33 | db_pgno_t left; |
---|
34 | DB_LSN * llsn; |
---|
35 | db_pgno_t right; |
---|
36 | DB_LSN * rlsn; |
---|
37 | u_int32_t indx; |
---|
38 | db_pgno_t npgno; |
---|
39 | DB_LSN * nlsn; |
---|
40 | db_pgno_t root_pgno; |
---|
41 | const DBT *pg; |
---|
42 | u_int32_t opflags; |
---|
43 | { |
---|
44 | DBT logrec; |
---|
45 | DB_ENV *dbenv; |
---|
46 | DB_LSN *lsnp, null_lsn; |
---|
47 | u_int32_t zero; |
---|
48 | u_int32_t uinttmp; |
---|
49 | u_int32_t npad, rectype, txn_num; |
---|
50 | int ret; |
---|
51 | u_int8_t *bp; |
---|
52 | |
---|
53 | dbenv = dbp->dbenv; |
---|
54 | rectype = DB___bam_split; |
---|
55 | npad = 0; |
---|
56 | |
---|
57 | if (txnid == NULL) { |
---|
58 | txn_num = 0; |
---|
59 | null_lsn.file = 0; |
---|
60 | null_lsn.offset = 0; |
---|
61 | lsnp = &null_lsn; |
---|
62 | } else { |
---|
63 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
64 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
65 | return (ret); |
---|
66 | txn_num = txnid->txnid; |
---|
67 | lsnp = &txnid->last_lsn; |
---|
68 | } |
---|
69 | |
---|
70 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
71 | + sizeof(u_int32_t) |
---|
72 | + sizeof(u_int32_t) |
---|
73 | + sizeof(*llsn) |
---|
74 | + sizeof(u_int32_t) |
---|
75 | + sizeof(*rlsn) |
---|
76 | + sizeof(u_int32_t) |
---|
77 | + sizeof(u_int32_t) |
---|
78 | + sizeof(*nlsn) |
---|
79 | + sizeof(u_int32_t) |
---|
80 | + sizeof(u_int32_t) + (pg == NULL ? 0 : pg->size) |
---|
81 | + sizeof(u_int32_t); |
---|
82 | if (CRYPTO_ON(dbenv)) { |
---|
83 | npad = |
---|
84 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
85 | logrec.size += npad; |
---|
86 | } |
---|
87 | |
---|
88 | if ((ret = __os_malloc(dbenv, |
---|
89 | logrec.size, &logrec.data)) != 0) |
---|
90 | return (ret); |
---|
91 | |
---|
92 | if (npad > 0) |
---|
93 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
94 | |
---|
95 | bp = logrec.data; |
---|
96 | |
---|
97 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
98 | bp += sizeof(rectype); |
---|
99 | |
---|
100 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
101 | bp += sizeof(txn_num); |
---|
102 | |
---|
103 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
104 | bp += sizeof(DB_LSN); |
---|
105 | |
---|
106 | DB_ASSERT(dbp->log_filename != NULL); |
---|
107 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
108 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
109 | return (ret); |
---|
110 | |
---|
111 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
112 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
113 | bp += sizeof(uinttmp); |
---|
114 | |
---|
115 | uinttmp = (u_int32_t)left; |
---|
116 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
117 | bp += sizeof(uinttmp); |
---|
118 | |
---|
119 | if (llsn != NULL) |
---|
120 | memcpy(bp, llsn, sizeof(*llsn)); |
---|
121 | else |
---|
122 | memset(bp, 0, sizeof(*llsn)); |
---|
123 | bp += sizeof(*llsn); |
---|
124 | |
---|
125 | uinttmp = (u_int32_t)right; |
---|
126 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
127 | bp += sizeof(uinttmp); |
---|
128 | |
---|
129 | if (rlsn != NULL) |
---|
130 | memcpy(bp, rlsn, sizeof(*rlsn)); |
---|
131 | else |
---|
132 | memset(bp, 0, sizeof(*rlsn)); |
---|
133 | bp += sizeof(*rlsn); |
---|
134 | |
---|
135 | uinttmp = (u_int32_t)indx; |
---|
136 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
137 | bp += sizeof(uinttmp); |
---|
138 | |
---|
139 | uinttmp = (u_int32_t)npgno; |
---|
140 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
141 | bp += sizeof(uinttmp); |
---|
142 | |
---|
143 | if (nlsn != NULL) |
---|
144 | memcpy(bp, nlsn, sizeof(*nlsn)); |
---|
145 | else |
---|
146 | memset(bp, 0, sizeof(*nlsn)); |
---|
147 | bp += sizeof(*nlsn); |
---|
148 | |
---|
149 | uinttmp = (u_int32_t)root_pgno; |
---|
150 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
151 | bp += sizeof(uinttmp); |
---|
152 | |
---|
153 | if (pg == NULL) { |
---|
154 | zero = 0; |
---|
155 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
156 | bp += sizeof(u_int32_t); |
---|
157 | } else { |
---|
158 | memcpy(bp, &pg->size, sizeof(pg->size)); |
---|
159 | bp += sizeof(pg->size); |
---|
160 | memcpy(bp, pg->data, pg->size); |
---|
161 | bp += pg->size; |
---|
162 | } |
---|
163 | |
---|
164 | uinttmp = (u_int32_t)opflags; |
---|
165 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
166 | bp += sizeof(uinttmp); |
---|
167 | |
---|
168 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
169 | ret = dbenv->log_put(dbenv, |
---|
170 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
171 | if (txnid != NULL && ret == 0) |
---|
172 | txnid->last_lsn = *ret_lsnp; |
---|
173 | #ifdef LOG_DIAGNOSTIC |
---|
174 | if (ret != 0) |
---|
175 | (void)__bam_split_print(dbenv, |
---|
176 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
177 | #endif |
---|
178 | __os_free(dbenv, logrec.data); |
---|
179 | return (ret); |
---|
180 | } |
---|
181 | |
---|
182 | /* |
---|
183 | * PUBLIC: int __bam_split_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
184 | * PUBLIC: db_recops, void *)); |
---|
185 | */ |
---|
186 | int |
---|
187 | __bam_split_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
188 | DB_ENV *dbenv; |
---|
189 | DBT *rec; |
---|
190 | DB_LSN *lsnp; |
---|
191 | db_recops notused1; |
---|
192 | void *summary; |
---|
193 | { |
---|
194 | DB *dbp; |
---|
195 | TXN_RECS *t; |
---|
196 | __bam_split_args *argp; |
---|
197 | u_int32_t ret; |
---|
198 | |
---|
199 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
200 | |
---|
201 | argp = NULL; |
---|
202 | t = (TXN_RECS *)summary; |
---|
203 | |
---|
204 | if ((ret = __bam_split_read(dbenv, rec->data, &argp)) != 0) |
---|
205 | return (ret); |
---|
206 | |
---|
207 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
208 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
209 | goto err; |
---|
210 | |
---|
211 | if ((ret = __rep_check_alloc(dbenv, t, 3)) != 0) |
---|
212 | goto err; |
---|
213 | |
---|
214 | t->array[t->npages].flags = 0; |
---|
215 | t->array[t->npages].fid = argp->fileid; |
---|
216 | t->array[t->npages].lsn = *lsnp; |
---|
217 | t->array[t->npages].pgdesc.pgno = argp->left; |
---|
218 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
219 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
220 | DB_FILE_ID_LEN); |
---|
221 | t->npages++; |
---|
222 | t->array[t->npages].flags = 0; |
---|
223 | t->array[t->npages].fid = argp->fileid; |
---|
224 | t->array[t->npages].lsn = *lsnp; |
---|
225 | t->array[t->npages].pgdesc.pgno = argp->right; |
---|
226 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
227 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
228 | DB_FILE_ID_LEN); |
---|
229 | t->npages++; |
---|
230 | if (argp->root_pgno != PGNO_INVALID) { |
---|
231 | t->array[t->npages].flags = 0; |
---|
232 | t->array[t->npages].fid = argp->fileid; |
---|
233 | t->array[t->npages].lsn = *lsnp; |
---|
234 | t->array[t->npages].pgdesc.pgno = argp->root_pgno; |
---|
235 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
236 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
237 | DB_FILE_ID_LEN); |
---|
238 | t->npages++; |
---|
239 | } |
---|
240 | |
---|
241 | err: if (argp != NULL) |
---|
242 | __os_free(dbenv, argp); |
---|
243 | return (ret); |
---|
244 | } |
---|
245 | |
---|
246 | /* |
---|
247 | * PUBLIC: int __bam_split_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
248 | * PUBLIC: db_recops, void *)); |
---|
249 | */ |
---|
250 | int |
---|
251 | __bam_split_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
252 | DB_ENV *dbenv; |
---|
253 | DBT *dbtp; |
---|
254 | DB_LSN *lsnp; |
---|
255 | db_recops notused2; |
---|
256 | void *notused3; |
---|
257 | { |
---|
258 | __bam_split_args *argp; |
---|
259 | u_int32_t i; |
---|
260 | int ch; |
---|
261 | int ret; |
---|
262 | |
---|
263 | notused2 = DB_TXN_ABORT; |
---|
264 | notused3 = NULL; |
---|
265 | |
---|
266 | if ((ret = __bam_split_read(dbenv, dbtp->data, &argp)) != 0) |
---|
267 | return (ret); |
---|
268 | (void)printf( |
---|
269 | "[%lu][%lu]__bam_split: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
270 | (u_long)lsnp->file, |
---|
271 | (u_long)lsnp->offset, |
---|
272 | (u_long)argp->type, |
---|
273 | (u_long)argp->txnid->txnid, |
---|
274 | (u_long)argp->prev_lsn.file, |
---|
275 | (u_long)argp->prev_lsn.offset); |
---|
276 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
277 | (void)printf("\tleft: %lu\n", (u_long)argp->left); |
---|
278 | (void)printf("\tllsn: [%lu][%lu]\n", |
---|
279 | (u_long)argp->llsn.file, (u_long)argp->llsn.offset); |
---|
280 | (void)printf("\tright: %lu\n", (u_long)argp->right); |
---|
281 | (void)printf("\trlsn: [%lu][%lu]\n", |
---|
282 | (u_long)argp->rlsn.file, (u_long)argp->rlsn.offset); |
---|
283 | (void)printf("\tindx: %lu\n", (u_long)argp->indx); |
---|
284 | (void)printf("\tnpgno: %lu\n", (u_long)argp->npgno); |
---|
285 | (void)printf("\tnlsn: [%lu][%lu]\n", |
---|
286 | (u_long)argp->nlsn.file, (u_long)argp->nlsn.offset); |
---|
287 | (void)printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno); |
---|
288 | (void)printf("\tpg: "); |
---|
289 | for (i = 0; i < argp->pg.size; i++) { |
---|
290 | ch = ((u_int8_t *)argp->pg.data)[i]; |
---|
291 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
292 | } |
---|
293 | (void)printf("\n"); |
---|
294 | (void)printf("\topflags: %lu\n", (u_long)argp->opflags); |
---|
295 | (void)printf("\n"); |
---|
296 | __os_free(dbenv, argp); |
---|
297 | return (0); |
---|
298 | } |
---|
299 | |
---|
300 | /* |
---|
301 | * PUBLIC: int __bam_split_read __P((DB_ENV *, void *, __bam_split_args **)); |
---|
302 | */ |
---|
303 | int |
---|
304 | __bam_split_read(dbenv, recbuf, argpp) |
---|
305 | DB_ENV *dbenv; |
---|
306 | void *recbuf; |
---|
307 | __bam_split_args **argpp; |
---|
308 | { |
---|
309 | __bam_split_args *argp; |
---|
310 | u_int32_t uinttmp; |
---|
311 | u_int8_t *bp; |
---|
312 | int ret; |
---|
313 | |
---|
314 | if ((ret = __os_malloc(dbenv, |
---|
315 | sizeof(__bam_split_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
316 | return (ret); |
---|
317 | |
---|
318 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
319 | |
---|
320 | bp = recbuf; |
---|
321 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
322 | bp += sizeof(argp->type); |
---|
323 | |
---|
324 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
325 | bp += sizeof(argp->txnid->txnid); |
---|
326 | |
---|
327 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
328 | bp += sizeof(DB_LSN); |
---|
329 | |
---|
330 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
331 | argp->fileid = (int32_t)uinttmp; |
---|
332 | bp += sizeof(uinttmp); |
---|
333 | |
---|
334 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
335 | argp->left = (db_pgno_t)uinttmp; |
---|
336 | bp += sizeof(uinttmp); |
---|
337 | |
---|
338 | memcpy(&argp->llsn, bp, sizeof(argp->llsn)); |
---|
339 | bp += sizeof(argp->llsn); |
---|
340 | |
---|
341 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
342 | argp->right = (db_pgno_t)uinttmp; |
---|
343 | bp += sizeof(uinttmp); |
---|
344 | |
---|
345 | memcpy(&argp->rlsn, bp, sizeof(argp->rlsn)); |
---|
346 | bp += sizeof(argp->rlsn); |
---|
347 | |
---|
348 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
349 | argp->indx = (u_int32_t)uinttmp; |
---|
350 | bp += sizeof(uinttmp); |
---|
351 | |
---|
352 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
353 | argp->npgno = (db_pgno_t)uinttmp; |
---|
354 | bp += sizeof(uinttmp); |
---|
355 | |
---|
356 | memcpy(&argp->nlsn, bp, sizeof(argp->nlsn)); |
---|
357 | bp += sizeof(argp->nlsn); |
---|
358 | |
---|
359 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
360 | argp->root_pgno = (db_pgno_t)uinttmp; |
---|
361 | bp += sizeof(uinttmp); |
---|
362 | |
---|
363 | memset(&argp->pg, 0, sizeof(argp->pg)); |
---|
364 | memcpy(&argp->pg.size, bp, sizeof(u_int32_t)); |
---|
365 | bp += sizeof(u_int32_t); |
---|
366 | argp->pg.data = bp; |
---|
367 | bp += argp->pg.size; |
---|
368 | |
---|
369 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
370 | argp->opflags = (u_int32_t)uinttmp; |
---|
371 | bp += sizeof(uinttmp); |
---|
372 | |
---|
373 | *argpp = argp; |
---|
374 | return (0); |
---|
375 | } |
---|
376 | |
---|
377 | /* |
---|
378 | * PUBLIC: int __bam_rsplit_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
379 | * PUBLIC: u_int32_t, db_pgno_t, const DBT *, db_pgno_t, db_pgno_t, |
---|
380 | * PUBLIC: const DBT *, DB_LSN *)); |
---|
381 | */ |
---|
382 | int |
---|
383 | __bam_rsplit_log(dbp, txnid, ret_lsnp, flags, pgno, pgdbt, root_pgno, nrec, rootent, |
---|
384 | rootlsn) |
---|
385 | DB *dbp; |
---|
386 | DB_TXN *txnid; |
---|
387 | DB_LSN *ret_lsnp; |
---|
388 | u_int32_t flags; |
---|
389 | db_pgno_t pgno; |
---|
390 | const DBT *pgdbt; |
---|
391 | db_pgno_t root_pgno; |
---|
392 | db_pgno_t nrec; |
---|
393 | const DBT *rootent; |
---|
394 | DB_LSN * rootlsn; |
---|
395 | { |
---|
396 | DBT logrec; |
---|
397 | DB_ENV *dbenv; |
---|
398 | DB_LSN *lsnp, null_lsn; |
---|
399 | u_int32_t zero; |
---|
400 | u_int32_t uinttmp; |
---|
401 | u_int32_t npad, rectype, txn_num; |
---|
402 | int ret; |
---|
403 | u_int8_t *bp; |
---|
404 | |
---|
405 | dbenv = dbp->dbenv; |
---|
406 | rectype = DB___bam_rsplit; |
---|
407 | npad = 0; |
---|
408 | |
---|
409 | if (txnid == NULL) { |
---|
410 | txn_num = 0; |
---|
411 | null_lsn.file = 0; |
---|
412 | null_lsn.offset = 0; |
---|
413 | lsnp = &null_lsn; |
---|
414 | } else { |
---|
415 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
416 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
417 | return (ret); |
---|
418 | txn_num = txnid->txnid; |
---|
419 | lsnp = &txnid->last_lsn; |
---|
420 | } |
---|
421 | |
---|
422 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
423 | + sizeof(u_int32_t) |
---|
424 | + sizeof(u_int32_t) |
---|
425 | + sizeof(u_int32_t) + (pgdbt == NULL ? 0 : pgdbt->size) |
---|
426 | + sizeof(u_int32_t) |
---|
427 | + sizeof(u_int32_t) |
---|
428 | + sizeof(u_int32_t) + (rootent == NULL ? 0 : rootent->size) |
---|
429 | + sizeof(*rootlsn); |
---|
430 | if (CRYPTO_ON(dbenv)) { |
---|
431 | npad = |
---|
432 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
433 | logrec.size += npad; |
---|
434 | } |
---|
435 | |
---|
436 | if ((ret = __os_malloc(dbenv, |
---|
437 | logrec.size, &logrec.data)) != 0) |
---|
438 | return (ret); |
---|
439 | |
---|
440 | if (npad > 0) |
---|
441 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
442 | |
---|
443 | bp = logrec.data; |
---|
444 | |
---|
445 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
446 | bp += sizeof(rectype); |
---|
447 | |
---|
448 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
449 | bp += sizeof(txn_num); |
---|
450 | |
---|
451 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
452 | bp += sizeof(DB_LSN); |
---|
453 | |
---|
454 | DB_ASSERT(dbp->log_filename != NULL); |
---|
455 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
456 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
457 | return (ret); |
---|
458 | |
---|
459 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
460 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
461 | bp += sizeof(uinttmp); |
---|
462 | |
---|
463 | uinttmp = (u_int32_t)pgno; |
---|
464 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
465 | bp += sizeof(uinttmp); |
---|
466 | |
---|
467 | if (pgdbt == NULL) { |
---|
468 | zero = 0; |
---|
469 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
470 | bp += sizeof(u_int32_t); |
---|
471 | } else { |
---|
472 | memcpy(bp, &pgdbt->size, sizeof(pgdbt->size)); |
---|
473 | bp += sizeof(pgdbt->size); |
---|
474 | memcpy(bp, pgdbt->data, pgdbt->size); |
---|
475 | bp += pgdbt->size; |
---|
476 | } |
---|
477 | |
---|
478 | uinttmp = (u_int32_t)root_pgno; |
---|
479 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
480 | bp += sizeof(uinttmp); |
---|
481 | |
---|
482 | uinttmp = (u_int32_t)nrec; |
---|
483 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
484 | bp += sizeof(uinttmp); |
---|
485 | |
---|
486 | if (rootent == NULL) { |
---|
487 | zero = 0; |
---|
488 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
489 | bp += sizeof(u_int32_t); |
---|
490 | } else { |
---|
491 | memcpy(bp, &rootent->size, sizeof(rootent->size)); |
---|
492 | bp += sizeof(rootent->size); |
---|
493 | memcpy(bp, rootent->data, rootent->size); |
---|
494 | bp += rootent->size; |
---|
495 | } |
---|
496 | |
---|
497 | if (rootlsn != NULL) |
---|
498 | memcpy(bp, rootlsn, sizeof(*rootlsn)); |
---|
499 | else |
---|
500 | memset(bp, 0, sizeof(*rootlsn)); |
---|
501 | bp += sizeof(*rootlsn); |
---|
502 | |
---|
503 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
504 | ret = dbenv->log_put(dbenv, |
---|
505 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
506 | if (txnid != NULL && ret == 0) |
---|
507 | txnid->last_lsn = *ret_lsnp; |
---|
508 | #ifdef LOG_DIAGNOSTIC |
---|
509 | if (ret != 0) |
---|
510 | (void)__bam_rsplit_print(dbenv, |
---|
511 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
512 | #endif |
---|
513 | __os_free(dbenv, logrec.data); |
---|
514 | return (ret); |
---|
515 | } |
---|
516 | |
---|
517 | /* |
---|
518 | * PUBLIC: int __bam_rsplit_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
519 | * PUBLIC: db_recops, void *)); |
---|
520 | */ |
---|
521 | int |
---|
522 | __bam_rsplit_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
523 | DB_ENV *dbenv; |
---|
524 | DBT *rec; |
---|
525 | DB_LSN *lsnp; |
---|
526 | db_recops notused1; |
---|
527 | void *summary; |
---|
528 | { |
---|
529 | DB *dbp; |
---|
530 | TXN_RECS *t; |
---|
531 | __bam_rsplit_args *argp; |
---|
532 | u_int32_t ret; |
---|
533 | |
---|
534 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
535 | |
---|
536 | argp = NULL; |
---|
537 | t = (TXN_RECS *)summary; |
---|
538 | |
---|
539 | if ((ret = __bam_rsplit_read(dbenv, rec->data, &argp)) != 0) |
---|
540 | return (ret); |
---|
541 | |
---|
542 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
543 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
544 | goto err; |
---|
545 | |
---|
546 | if ((ret = __rep_check_alloc(dbenv, t, 2)) != 0) |
---|
547 | goto err; |
---|
548 | |
---|
549 | t->array[t->npages].flags = 0; |
---|
550 | t->array[t->npages].fid = argp->fileid; |
---|
551 | t->array[t->npages].lsn = *lsnp; |
---|
552 | t->array[t->npages].pgdesc.pgno = argp->pgno; |
---|
553 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
554 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
555 | DB_FILE_ID_LEN); |
---|
556 | t->npages++; |
---|
557 | t->array[t->npages].flags = 0; |
---|
558 | t->array[t->npages].fid = argp->fileid; |
---|
559 | t->array[t->npages].lsn = *lsnp; |
---|
560 | t->array[t->npages].pgdesc.pgno = argp->root_pgno; |
---|
561 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
562 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
563 | DB_FILE_ID_LEN); |
---|
564 | t->npages++; |
---|
565 | |
---|
566 | err: if (argp != NULL) |
---|
567 | __os_free(dbenv, argp); |
---|
568 | return (ret); |
---|
569 | } |
---|
570 | |
---|
571 | /* |
---|
572 | * PUBLIC: int __bam_rsplit_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
573 | * PUBLIC: db_recops, void *)); |
---|
574 | */ |
---|
575 | int |
---|
576 | __bam_rsplit_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
577 | DB_ENV *dbenv; |
---|
578 | DBT *dbtp; |
---|
579 | DB_LSN *lsnp; |
---|
580 | db_recops notused2; |
---|
581 | void *notused3; |
---|
582 | { |
---|
583 | __bam_rsplit_args *argp; |
---|
584 | u_int32_t i; |
---|
585 | int ch; |
---|
586 | int ret; |
---|
587 | |
---|
588 | notused2 = DB_TXN_ABORT; |
---|
589 | notused3 = NULL; |
---|
590 | |
---|
591 | if ((ret = __bam_rsplit_read(dbenv, dbtp->data, &argp)) != 0) |
---|
592 | return (ret); |
---|
593 | (void)printf( |
---|
594 | "[%lu][%lu]__bam_rsplit: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
595 | (u_long)lsnp->file, |
---|
596 | (u_long)lsnp->offset, |
---|
597 | (u_long)argp->type, |
---|
598 | (u_long)argp->txnid->txnid, |
---|
599 | (u_long)argp->prev_lsn.file, |
---|
600 | (u_long)argp->prev_lsn.offset); |
---|
601 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
602 | (void)printf("\tpgno: %lu\n", (u_long)argp->pgno); |
---|
603 | (void)printf("\tpgdbt: "); |
---|
604 | for (i = 0; i < argp->pgdbt.size; i++) { |
---|
605 | ch = ((u_int8_t *)argp->pgdbt.data)[i]; |
---|
606 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
607 | } |
---|
608 | (void)printf("\n"); |
---|
609 | (void)printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno); |
---|
610 | (void)printf("\tnrec: %lu\n", (u_long)argp->nrec); |
---|
611 | (void)printf("\trootent: "); |
---|
612 | for (i = 0; i < argp->rootent.size; i++) { |
---|
613 | ch = ((u_int8_t *)argp->rootent.data)[i]; |
---|
614 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
615 | } |
---|
616 | (void)printf("\n"); |
---|
617 | (void)printf("\trootlsn: [%lu][%lu]\n", |
---|
618 | (u_long)argp->rootlsn.file, (u_long)argp->rootlsn.offset); |
---|
619 | (void)printf("\n"); |
---|
620 | __os_free(dbenv, argp); |
---|
621 | return (0); |
---|
622 | } |
---|
623 | |
---|
624 | /* |
---|
625 | * PUBLIC: int __bam_rsplit_read __P((DB_ENV *, void *, __bam_rsplit_args **)); |
---|
626 | */ |
---|
627 | int |
---|
628 | __bam_rsplit_read(dbenv, recbuf, argpp) |
---|
629 | DB_ENV *dbenv; |
---|
630 | void *recbuf; |
---|
631 | __bam_rsplit_args **argpp; |
---|
632 | { |
---|
633 | __bam_rsplit_args *argp; |
---|
634 | u_int32_t uinttmp; |
---|
635 | u_int8_t *bp; |
---|
636 | int ret; |
---|
637 | |
---|
638 | if ((ret = __os_malloc(dbenv, |
---|
639 | sizeof(__bam_rsplit_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
640 | return (ret); |
---|
641 | |
---|
642 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
643 | |
---|
644 | bp = recbuf; |
---|
645 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
646 | bp += sizeof(argp->type); |
---|
647 | |
---|
648 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
649 | bp += sizeof(argp->txnid->txnid); |
---|
650 | |
---|
651 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
652 | bp += sizeof(DB_LSN); |
---|
653 | |
---|
654 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
655 | argp->fileid = (int32_t)uinttmp; |
---|
656 | bp += sizeof(uinttmp); |
---|
657 | |
---|
658 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
659 | argp->pgno = (db_pgno_t)uinttmp; |
---|
660 | bp += sizeof(uinttmp); |
---|
661 | |
---|
662 | memset(&argp->pgdbt, 0, sizeof(argp->pgdbt)); |
---|
663 | memcpy(&argp->pgdbt.size, bp, sizeof(u_int32_t)); |
---|
664 | bp += sizeof(u_int32_t); |
---|
665 | argp->pgdbt.data = bp; |
---|
666 | bp += argp->pgdbt.size; |
---|
667 | |
---|
668 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
669 | argp->root_pgno = (db_pgno_t)uinttmp; |
---|
670 | bp += sizeof(uinttmp); |
---|
671 | |
---|
672 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
673 | argp->nrec = (db_pgno_t)uinttmp; |
---|
674 | bp += sizeof(uinttmp); |
---|
675 | |
---|
676 | memset(&argp->rootent, 0, sizeof(argp->rootent)); |
---|
677 | memcpy(&argp->rootent.size, bp, sizeof(u_int32_t)); |
---|
678 | bp += sizeof(u_int32_t); |
---|
679 | argp->rootent.data = bp; |
---|
680 | bp += argp->rootent.size; |
---|
681 | |
---|
682 | memcpy(&argp->rootlsn, bp, sizeof(argp->rootlsn)); |
---|
683 | bp += sizeof(argp->rootlsn); |
---|
684 | |
---|
685 | *argpp = argp; |
---|
686 | return (0); |
---|
687 | } |
---|
688 | |
---|
689 | /* |
---|
690 | * PUBLIC: int __bam_adj_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
691 | * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, u_int32_t, |
---|
692 | * PUBLIC: u_int32_t)); |
---|
693 | */ |
---|
694 | int |
---|
695 | __bam_adj_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, indx_copy, is_insert) |
---|
696 | DB *dbp; |
---|
697 | DB_TXN *txnid; |
---|
698 | DB_LSN *ret_lsnp; |
---|
699 | u_int32_t flags; |
---|
700 | db_pgno_t pgno; |
---|
701 | DB_LSN * lsn; |
---|
702 | u_int32_t indx; |
---|
703 | u_int32_t indx_copy; |
---|
704 | u_int32_t is_insert; |
---|
705 | { |
---|
706 | DBT logrec; |
---|
707 | DB_ENV *dbenv; |
---|
708 | DB_LSN *lsnp, null_lsn; |
---|
709 | u_int32_t uinttmp; |
---|
710 | u_int32_t npad, rectype, txn_num; |
---|
711 | int ret; |
---|
712 | u_int8_t *bp; |
---|
713 | |
---|
714 | dbenv = dbp->dbenv; |
---|
715 | rectype = DB___bam_adj; |
---|
716 | npad = 0; |
---|
717 | |
---|
718 | if (txnid == NULL) { |
---|
719 | txn_num = 0; |
---|
720 | null_lsn.file = 0; |
---|
721 | null_lsn.offset = 0; |
---|
722 | lsnp = &null_lsn; |
---|
723 | } else { |
---|
724 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
725 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
726 | return (ret); |
---|
727 | txn_num = txnid->txnid; |
---|
728 | lsnp = &txnid->last_lsn; |
---|
729 | } |
---|
730 | |
---|
731 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
732 | + sizeof(u_int32_t) |
---|
733 | + sizeof(u_int32_t) |
---|
734 | + sizeof(*lsn) |
---|
735 | + sizeof(u_int32_t) |
---|
736 | + sizeof(u_int32_t) |
---|
737 | + sizeof(u_int32_t); |
---|
738 | if (CRYPTO_ON(dbenv)) { |
---|
739 | npad = |
---|
740 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
741 | logrec.size += npad; |
---|
742 | } |
---|
743 | |
---|
744 | if ((ret = __os_malloc(dbenv, |
---|
745 | logrec.size, &logrec.data)) != 0) |
---|
746 | return (ret); |
---|
747 | |
---|
748 | if (npad > 0) |
---|
749 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
750 | |
---|
751 | bp = logrec.data; |
---|
752 | |
---|
753 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
754 | bp += sizeof(rectype); |
---|
755 | |
---|
756 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
757 | bp += sizeof(txn_num); |
---|
758 | |
---|
759 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
760 | bp += sizeof(DB_LSN); |
---|
761 | |
---|
762 | DB_ASSERT(dbp->log_filename != NULL); |
---|
763 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
764 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
765 | return (ret); |
---|
766 | |
---|
767 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
768 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
769 | bp += sizeof(uinttmp); |
---|
770 | |
---|
771 | uinttmp = (u_int32_t)pgno; |
---|
772 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
773 | bp += sizeof(uinttmp); |
---|
774 | |
---|
775 | if (lsn != NULL) |
---|
776 | memcpy(bp, lsn, sizeof(*lsn)); |
---|
777 | else |
---|
778 | memset(bp, 0, sizeof(*lsn)); |
---|
779 | bp += sizeof(*lsn); |
---|
780 | |
---|
781 | uinttmp = (u_int32_t)indx; |
---|
782 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
783 | bp += sizeof(uinttmp); |
---|
784 | |
---|
785 | uinttmp = (u_int32_t)indx_copy; |
---|
786 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
787 | bp += sizeof(uinttmp); |
---|
788 | |
---|
789 | uinttmp = (u_int32_t)is_insert; |
---|
790 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
791 | bp += sizeof(uinttmp); |
---|
792 | |
---|
793 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
794 | ret = dbenv->log_put(dbenv, |
---|
795 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
796 | if (txnid != NULL && ret == 0) |
---|
797 | txnid->last_lsn = *ret_lsnp; |
---|
798 | #ifdef LOG_DIAGNOSTIC |
---|
799 | if (ret != 0) |
---|
800 | (void)__bam_adj_print(dbenv, |
---|
801 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
802 | #endif |
---|
803 | __os_free(dbenv, logrec.data); |
---|
804 | return (ret); |
---|
805 | } |
---|
806 | |
---|
807 | /* |
---|
808 | * PUBLIC: int __bam_adj_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
809 | * PUBLIC: db_recops, void *)); |
---|
810 | */ |
---|
811 | int |
---|
812 | __bam_adj_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
813 | DB_ENV *dbenv; |
---|
814 | DBT *rec; |
---|
815 | DB_LSN *lsnp; |
---|
816 | db_recops notused1; |
---|
817 | void *summary; |
---|
818 | { |
---|
819 | DB *dbp; |
---|
820 | TXN_RECS *t; |
---|
821 | __bam_adj_args *argp; |
---|
822 | u_int32_t ret; |
---|
823 | |
---|
824 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
825 | |
---|
826 | argp = NULL; |
---|
827 | t = (TXN_RECS *)summary; |
---|
828 | |
---|
829 | if ((ret = __bam_adj_read(dbenv, rec->data, &argp)) != 0) |
---|
830 | return (ret); |
---|
831 | |
---|
832 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
833 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
834 | goto err; |
---|
835 | |
---|
836 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
837 | goto err; |
---|
838 | |
---|
839 | t->array[t->npages].flags = 0; |
---|
840 | t->array[t->npages].fid = argp->fileid; |
---|
841 | t->array[t->npages].lsn = *lsnp; |
---|
842 | t->array[t->npages].pgdesc.pgno = argp->pgno; |
---|
843 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
844 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
845 | DB_FILE_ID_LEN); |
---|
846 | t->npages++; |
---|
847 | |
---|
848 | err: if (argp != NULL) |
---|
849 | __os_free(dbenv, argp); |
---|
850 | return (ret); |
---|
851 | } |
---|
852 | |
---|
853 | /* |
---|
854 | * PUBLIC: int __bam_adj_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
855 | * PUBLIC: db_recops, void *)); |
---|
856 | */ |
---|
857 | int |
---|
858 | __bam_adj_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
859 | DB_ENV *dbenv; |
---|
860 | DBT *dbtp; |
---|
861 | DB_LSN *lsnp; |
---|
862 | db_recops notused2; |
---|
863 | void *notused3; |
---|
864 | { |
---|
865 | __bam_adj_args *argp; |
---|
866 | int ret; |
---|
867 | |
---|
868 | notused2 = DB_TXN_ABORT; |
---|
869 | notused3 = NULL; |
---|
870 | |
---|
871 | if ((ret = __bam_adj_read(dbenv, dbtp->data, &argp)) != 0) |
---|
872 | return (ret); |
---|
873 | (void)printf( |
---|
874 | "[%lu][%lu]__bam_adj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
875 | (u_long)lsnp->file, |
---|
876 | (u_long)lsnp->offset, |
---|
877 | (u_long)argp->type, |
---|
878 | (u_long)argp->txnid->txnid, |
---|
879 | (u_long)argp->prev_lsn.file, |
---|
880 | (u_long)argp->prev_lsn.offset); |
---|
881 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
882 | (void)printf("\tpgno: %lu\n", (u_long)argp->pgno); |
---|
883 | (void)printf("\tlsn: [%lu][%lu]\n", |
---|
884 | (u_long)argp->lsn.file, (u_long)argp->lsn.offset); |
---|
885 | (void)printf("\tindx: %lu\n", (u_long)argp->indx); |
---|
886 | (void)printf("\tindx_copy: %lu\n", (u_long)argp->indx_copy); |
---|
887 | (void)printf("\tis_insert: %lu\n", (u_long)argp->is_insert); |
---|
888 | (void)printf("\n"); |
---|
889 | __os_free(dbenv, argp); |
---|
890 | return (0); |
---|
891 | } |
---|
892 | |
---|
893 | /* |
---|
894 | * PUBLIC: int __bam_adj_read __P((DB_ENV *, void *, __bam_adj_args **)); |
---|
895 | */ |
---|
896 | int |
---|
897 | __bam_adj_read(dbenv, recbuf, argpp) |
---|
898 | DB_ENV *dbenv; |
---|
899 | void *recbuf; |
---|
900 | __bam_adj_args **argpp; |
---|
901 | { |
---|
902 | __bam_adj_args *argp; |
---|
903 | u_int32_t uinttmp; |
---|
904 | u_int8_t *bp; |
---|
905 | int ret; |
---|
906 | |
---|
907 | if ((ret = __os_malloc(dbenv, |
---|
908 | sizeof(__bam_adj_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
909 | return (ret); |
---|
910 | |
---|
911 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
912 | |
---|
913 | bp = recbuf; |
---|
914 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
915 | bp += sizeof(argp->type); |
---|
916 | |
---|
917 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
918 | bp += sizeof(argp->txnid->txnid); |
---|
919 | |
---|
920 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
921 | bp += sizeof(DB_LSN); |
---|
922 | |
---|
923 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
924 | argp->fileid = (int32_t)uinttmp; |
---|
925 | bp += sizeof(uinttmp); |
---|
926 | |
---|
927 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
928 | argp->pgno = (db_pgno_t)uinttmp; |
---|
929 | bp += sizeof(uinttmp); |
---|
930 | |
---|
931 | memcpy(&argp->lsn, bp, sizeof(argp->lsn)); |
---|
932 | bp += sizeof(argp->lsn); |
---|
933 | |
---|
934 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
935 | argp->indx = (u_int32_t)uinttmp; |
---|
936 | bp += sizeof(uinttmp); |
---|
937 | |
---|
938 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
939 | argp->indx_copy = (u_int32_t)uinttmp; |
---|
940 | bp += sizeof(uinttmp); |
---|
941 | |
---|
942 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
943 | argp->is_insert = (u_int32_t)uinttmp; |
---|
944 | bp += sizeof(uinttmp); |
---|
945 | |
---|
946 | *argpp = argp; |
---|
947 | return (0); |
---|
948 | } |
---|
949 | |
---|
950 | /* |
---|
951 | * PUBLIC: int __bam_cadjust_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
952 | * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, int32_t, u_int32_t)); |
---|
953 | */ |
---|
954 | int |
---|
955 | __bam_cadjust_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, adjust, opflags) |
---|
956 | DB *dbp; |
---|
957 | DB_TXN *txnid; |
---|
958 | DB_LSN *ret_lsnp; |
---|
959 | u_int32_t flags; |
---|
960 | db_pgno_t pgno; |
---|
961 | DB_LSN * lsn; |
---|
962 | u_int32_t indx; |
---|
963 | int32_t adjust; |
---|
964 | u_int32_t opflags; |
---|
965 | { |
---|
966 | DBT logrec; |
---|
967 | DB_ENV *dbenv; |
---|
968 | DB_LSN *lsnp, null_lsn; |
---|
969 | u_int32_t uinttmp; |
---|
970 | u_int32_t npad, rectype, txn_num; |
---|
971 | int ret; |
---|
972 | u_int8_t *bp; |
---|
973 | |
---|
974 | dbenv = dbp->dbenv; |
---|
975 | rectype = DB___bam_cadjust; |
---|
976 | npad = 0; |
---|
977 | |
---|
978 | if (txnid == NULL) { |
---|
979 | txn_num = 0; |
---|
980 | null_lsn.file = 0; |
---|
981 | null_lsn.offset = 0; |
---|
982 | lsnp = &null_lsn; |
---|
983 | } else { |
---|
984 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
985 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
986 | return (ret); |
---|
987 | txn_num = txnid->txnid; |
---|
988 | lsnp = &txnid->last_lsn; |
---|
989 | } |
---|
990 | |
---|
991 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
992 | + sizeof(u_int32_t) |
---|
993 | + sizeof(u_int32_t) |
---|
994 | + sizeof(*lsn) |
---|
995 | + sizeof(u_int32_t) |
---|
996 | + sizeof(u_int32_t) |
---|
997 | + sizeof(u_int32_t); |
---|
998 | if (CRYPTO_ON(dbenv)) { |
---|
999 | npad = |
---|
1000 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
1001 | logrec.size += npad; |
---|
1002 | } |
---|
1003 | |
---|
1004 | if ((ret = __os_malloc(dbenv, |
---|
1005 | logrec.size, &logrec.data)) != 0) |
---|
1006 | return (ret); |
---|
1007 | |
---|
1008 | if (npad > 0) |
---|
1009 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
1010 | |
---|
1011 | bp = logrec.data; |
---|
1012 | |
---|
1013 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
1014 | bp += sizeof(rectype); |
---|
1015 | |
---|
1016 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
1017 | bp += sizeof(txn_num); |
---|
1018 | |
---|
1019 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
1020 | bp += sizeof(DB_LSN); |
---|
1021 | |
---|
1022 | DB_ASSERT(dbp->log_filename != NULL); |
---|
1023 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
1024 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
1025 | return (ret); |
---|
1026 | |
---|
1027 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
1028 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1029 | bp += sizeof(uinttmp); |
---|
1030 | |
---|
1031 | uinttmp = (u_int32_t)pgno; |
---|
1032 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1033 | bp += sizeof(uinttmp); |
---|
1034 | |
---|
1035 | if (lsn != NULL) |
---|
1036 | memcpy(bp, lsn, sizeof(*lsn)); |
---|
1037 | else |
---|
1038 | memset(bp, 0, sizeof(*lsn)); |
---|
1039 | bp += sizeof(*lsn); |
---|
1040 | |
---|
1041 | uinttmp = (u_int32_t)indx; |
---|
1042 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1043 | bp += sizeof(uinttmp); |
---|
1044 | |
---|
1045 | uinttmp = (u_int32_t)adjust; |
---|
1046 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1047 | bp += sizeof(uinttmp); |
---|
1048 | |
---|
1049 | uinttmp = (u_int32_t)opflags; |
---|
1050 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1051 | bp += sizeof(uinttmp); |
---|
1052 | |
---|
1053 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
1054 | ret = dbenv->log_put(dbenv, |
---|
1055 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
1056 | if (txnid != NULL && ret == 0) |
---|
1057 | txnid->last_lsn = *ret_lsnp; |
---|
1058 | #ifdef LOG_DIAGNOSTIC |
---|
1059 | if (ret != 0) |
---|
1060 | (void)__bam_cadjust_print(dbenv, |
---|
1061 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
1062 | #endif |
---|
1063 | __os_free(dbenv, logrec.data); |
---|
1064 | return (ret); |
---|
1065 | } |
---|
1066 | |
---|
1067 | /* |
---|
1068 | * PUBLIC: int __bam_cadjust_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1069 | * PUBLIC: db_recops, void *)); |
---|
1070 | */ |
---|
1071 | int |
---|
1072 | __bam_cadjust_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
1073 | DB_ENV *dbenv; |
---|
1074 | DBT *rec; |
---|
1075 | DB_LSN *lsnp; |
---|
1076 | db_recops notused1; |
---|
1077 | void *summary; |
---|
1078 | { |
---|
1079 | DB *dbp; |
---|
1080 | TXN_RECS *t; |
---|
1081 | __bam_cadjust_args *argp; |
---|
1082 | u_int32_t ret; |
---|
1083 | |
---|
1084 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
1085 | |
---|
1086 | argp = NULL; |
---|
1087 | t = (TXN_RECS *)summary; |
---|
1088 | |
---|
1089 | if ((ret = __bam_cadjust_read(dbenv, rec->data, &argp)) != 0) |
---|
1090 | return (ret); |
---|
1091 | |
---|
1092 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
1093 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
1094 | goto err; |
---|
1095 | |
---|
1096 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
1097 | goto err; |
---|
1098 | |
---|
1099 | t->array[t->npages].flags = 0; |
---|
1100 | t->array[t->npages].fid = argp->fileid; |
---|
1101 | t->array[t->npages].lsn = *lsnp; |
---|
1102 | t->array[t->npages].pgdesc.pgno = argp->pgno; |
---|
1103 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
1104 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
1105 | DB_FILE_ID_LEN); |
---|
1106 | t->npages++; |
---|
1107 | |
---|
1108 | err: if (argp != NULL) |
---|
1109 | __os_free(dbenv, argp); |
---|
1110 | return (ret); |
---|
1111 | } |
---|
1112 | |
---|
1113 | /* |
---|
1114 | * PUBLIC: int __bam_cadjust_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1115 | * PUBLIC: db_recops, void *)); |
---|
1116 | */ |
---|
1117 | int |
---|
1118 | __bam_cadjust_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
1119 | DB_ENV *dbenv; |
---|
1120 | DBT *dbtp; |
---|
1121 | DB_LSN *lsnp; |
---|
1122 | db_recops notused2; |
---|
1123 | void *notused3; |
---|
1124 | { |
---|
1125 | __bam_cadjust_args *argp; |
---|
1126 | int ret; |
---|
1127 | |
---|
1128 | notused2 = DB_TXN_ABORT; |
---|
1129 | notused3 = NULL; |
---|
1130 | |
---|
1131 | if ((ret = __bam_cadjust_read(dbenv, dbtp->data, &argp)) != 0) |
---|
1132 | return (ret); |
---|
1133 | (void)printf( |
---|
1134 | "[%lu][%lu]__bam_cadjust: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
1135 | (u_long)lsnp->file, |
---|
1136 | (u_long)lsnp->offset, |
---|
1137 | (u_long)argp->type, |
---|
1138 | (u_long)argp->txnid->txnid, |
---|
1139 | (u_long)argp->prev_lsn.file, |
---|
1140 | (u_long)argp->prev_lsn.offset); |
---|
1141 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
1142 | (void)printf("\tpgno: %lu\n", (u_long)argp->pgno); |
---|
1143 | (void)printf("\tlsn: [%lu][%lu]\n", |
---|
1144 | (u_long)argp->lsn.file, (u_long)argp->lsn.offset); |
---|
1145 | (void)printf("\tindx: %lu\n", (u_long)argp->indx); |
---|
1146 | (void)printf("\tadjust: %ld\n", (long)argp->adjust); |
---|
1147 | (void)printf("\topflags: %lu\n", (u_long)argp->opflags); |
---|
1148 | (void)printf("\n"); |
---|
1149 | __os_free(dbenv, argp); |
---|
1150 | return (0); |
---|
1151 | } |
---|
1152 | |
---|
1153 | /* |
---|
1154 | * PUBLIC: int __bam_cadjust_read __P((DB_ENV *, void *, |
---|
1155 | * PUBLIC: __bam_cadjust_args **)); |
---|
1156 | */ |
---|
1157 | int |
---|
1158 | __bam_cadjust_read(dbenv, recbuf, argpp) |
---|
1159 | DB_ENV *dbenv; |
---|
1160 | void *recbuf; |
---|
1161 | __bam_cadjust_args **argpp; |
---|
1162 | { |
---|
1163 | __bam_cadjust_args *argp; |
---|
1164 | u_int32_t uinttmp; |
---|
1165 | u_int8_t *bp; |
---|
1166 | int ret; |
---|
1167 | |
---|
1168 | if ((ret = __os_malloc(dbenv, |
---|
1169 | sizeof(__bam_cadjust_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
1170 | return (ret); |
---|
1171 | |
---|
1172 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
1173 | |
---|
1174 | bp = recbuf; |
---|
1175 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
1176 | bp += sizeof(argp->type); |
---|
1177 | |
---|
1178 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
1179 | bp += sizeof(argp->txnid->txnid); |
---|
1180 | |
---|
1181 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
1182 | bp += sizeof(DB_LSN); |
---|
1183 | |
---|
1184 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1185 | argp->fileid = (int32_t)uinttmp; |
---|
1186 | bp += sizeof(uinttmp); |
---|
1187 | |
---|
1188 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1189 | argp->pgno = (db_pgno_t)uinttmp; |
---|
1190 | bp += sizeof(uinttmp); |
---|
1191 | |
---|
1192 | memcpy(&argp->lsn, bp, sizeof(argp->lsn)); |
---|
1193 | bp += sizeof(argp->lsn); |
---|
1194 | |
---|
1195 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1196 | argp->indx = (u_int32_t)uinttmp; |
---|
1197 | bp += sizeof(uinttmp); |
---|
1198 | |
---|
1199 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1200 | argp->adjust = (int32_t)uinttmp; |
---|
1201 | bp += sizeof(uinttmp); |
---|
1202 | |
---|
1203 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1204 | argp->opflags = (u_int32_t)uinttmp; |
---|
1205 | bp += sizeof(uinttmp); |
---|
1206 | |
---|
1207 | *argpp = argp; |
---|
1208 | return (0); |
---|
1209 | } |
---|
1210 | |
---|
1211 | /* |
---|
1212 | * PUBLIC: int __bam_cdel_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
1213 | * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, u_int32_t)); |
---|
1214 | */ |
---|
1215 | int |
---|
1216 | __bam_cdel_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx) |
---|
1217 | DB *dbp; |
---|
1218 | DB_TXN *txnid; |
---|
1219 | DB_LSN *ret_lsnp; |
---|
1220 | u_int32_t flags; |
---|
1221 | db_pgno_t pgno; |
---|
1222 | DB_LSN * lsn; |
---|
1223 | u_int32_t indx; |
---|
1224 | { |
---|
1225 | DBT logrec; |
---|
1226 | DB_ENV *dbenv; |
---|
1227 | DB_LSN *lsnp, null_lsn; |
---|
1228 | u_int32_t uinttmp; |
---|
1229 | u_int32_t npad, rectype, txn_num; |
---|
1230 | int ret; |
---|
1231 | u_int8_t *bp; |
---|
1232 | |
---|
1233 | dbenv = dbp->dbenv; |
---|
1234 | rectype = DB___bam_cdel; |
---|
1235 | npad = 0; |
---|
1236 | |
---|
1237 | if (txnid == NULL) { |
---|
1238 | txn_num = 0; |
---|
1239 | null_lsn.file = 0; |
---|
1240 | null_lsn.offset = 0; |
---|
1241 | lsnp = &null_lsn; |
---|
1242 | } else { |
---|
1243 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
1244 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
1245 | return (ret); |
---|
1246 | txn_num = txnid->txnid; |
---|
1247 | lsnp = &txnid->last_lsn; |
---|
1248 | } |
---|
1249 | |
---|
1250 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
1251 | + sizeof(u_int32_t) |
---|
1252 | + sizeof(u_int32_t) |
---|
1253 | + sizeof(*lsn) |
---|
1254 | + sizeof(u_int32_t); |
---|
1255 | if (CRYPTO_ON(dbenv)) { |
---|
1256 | npad = |
---|
1257 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
1258 | logrec.size += npad; |
---|
1259 | } |
---|
1260 | |
---|
1261 | if ((ret = __os_malloc(dbenv, |
---|
1262 | logrec.size, &logrec.data)) != 0) |
---|
1263 | return (ret); |
---|
1264 | |
---|
1265 | if (npad > 0) |
---|
1266 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
1267 | |
---|
1268 | bp = logrec.data; |
---|
1269 | |
---|
1270 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
1271 | bp += sizeof(rectype); |
---|
1272 | |
---|
1273 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
1274 | bp += sizeof(txn_num); |
---|
1275 | |
---|
1276 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
1277 | bp += sizeof(DB_LSN); |
---|
1278 | |
---|
1279 | DB_ASSERT(dbp->log_filename != NULL); |
---|
1280 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
1281 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
1282 | return (ret); |
---|
1283 | |
---|
1284 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
1285 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1286 | bp += sizeof(uinttmp); |
---|
1287 | |
---|
1288 | uinttmp = (u_int32_t)pgno; |
---|
1289 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1290 | bp += sizeof(uinttmp); |
---|
1291 | |
---|
1292 | if (lsn != NULL) |
---|
1293 | memcpy(bp, lsn, sizeof(*lsn)); |
---|
1294 | else |
---|
1295 | memset(bp, 0, sizeof(*lsn)); |
---|
1296 | bp += sizeof(*lsn); |
---|
1297 | |
---|
1298 | uinttmp = (u_int32_t)indx; |
---|
1299 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1300 | bp += sizeof(uinttmp); |
---|
1301 | |
---|
1302 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
1303 | ret = dbenv->log_put(dbenv, |
---|
1304 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
1305 | if (txnid != NULL && ret == 0) |
---|
1306 | txnid->last_lsn = *ret_lsnp; |
---|
1307 | #ifdef LOG_DIAGNOSTIC |
---|
1308 | if (ret != 0) |
---|
1309 | (void)__bam_cdel_print(dbenv, |
---|
1310 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
1311 | #endif |
---|
1312 | __os_free(dbenv, logrec.data); |
---|
1313 | return (ret); |
---|
1314 | } |
---|
1315 | |
---|
1316 | /* |
---|
1317 | * PUBLIC: int __bam_cdel_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1318 | * PUBLIC: db_recops, void *)); |
---|
1319 | */ |
---|
1320 | int |
---|
1321 | __bam_cdel_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
1322 | DB_ENV *dbenv; |
---|
1323 | DBT *rec; |
---|
1324 | DB_LSN *lsnp; |
---|
1325 | db_recops notused1; |
---|
1326 | void *summary; |
---|
1327 | { |
---|
1328 | DB *dbp; |
---|
1329 | TXN_RECS *t; |
---|
1330 | __bam_cdel_args *argp; |
---|
1331 | u_int32_t ret; |
---|
1332 | |
---|
1333 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
1334 | |
---|
1335 | argp = NULL; |
---|
1336 | t = (TXN_RECS *)summary; |
---|
1337 | |
---|
1338 | if ((ret = __bam_cdel_read(dbenv, rec->data, &argp)) != 0) |
---|
1339 | return (ret); |
---|
1340 | |
---|
1341 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
1342 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
1343 | goto err; |
---|
1344 | |
---|
1345 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
1346 | goto err; |
---|
1347 | |
---|
1348 | t->array[t->npages].flags = 0; |
---|
1349 | t->array[t->npages].fid = argp->fileid; |
---|
1350 | t->array[t->npages].lsn = *lsnp; |
---|
1351 | t->array[t->npages].pgdesc.pgno = argp->pgno; |
---|
1352 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
1353 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
1354 | DB_FILE_ID_LEN); |
---|
1355 | t->npages++; |
---|
1356 | |
---|
1357 | err: if (argp != NULL) |
---|
1358 | __os_free(dbenv, argp); |
---|
1359 | return (ret); |
---|
1360 | } |
---|
1361 | |
---|
1362 | /* |
---|
1363 | * PUBLIC: int __bam_cdel_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1364 | * PUBLIC: db_recops, void *)); |
---|
1365 | */ |
---|
1366 | int |
---|
1367 | __bam_cdel_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
1368 | DB_ENV *dbenv; |
---|
1369 | DBT *dbtp; |
---|
1370 | DB_LSN *lsnp; |
---|
1371 | db_recops notused2; |
---|
1372 | void *notused3; |
---|
1373 | { |
---|
1374 | __bam_cdel_args *argp; |
---|
1375 | int ret; |
---|
1376 | |
---|
1377 | notused2 = DB_TXN_ABORT; |
---|
1378 | notused3 = NULL; |
---|
1379 | |
---|
1380 | if ((ret = __bam_cdel_read(dbenv, dbtp->data, &argp)) != 0) |
---|
1381 | return (ret); |
---|
1382 | (void)printf( |
---|
1383 | "[%lu][%lu]__bam_cdel: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
1384 | (u_long)lsnp->file, |
---|
1385 | (u_long)lsnp->offset, |
---|
1386 | (u_long)argp->type, |
---|
1387 | (u_long)argp->txnid->txnid, |
---|
1388 | (u_long)argp->prev_lsn.file, |
---|
1389 | (u_long)argp->prev_lsn.offset); |
---|
1390 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
1391 | (void)printf("\tpgno: %lu\n", (u_long)argp->pgno); |
---|
1392 | (void)printf("\tlsn: [%lu][%lu]\n", |
---|
1393 | (u_long)argp->lsn.file, (u_long)argp->lsn.offset); |
---|
1394 | (void)printf("\tindx: %lu\n", (u_long)argp->indx); |
---|
1395 | (void)printf("\n"); |
---|
1396 | __os_free(dbenv, argp); |
---|
1397 | return (0); |
---|
1398 | } |
---|
1399 | |
---|
1400 | /* |
---|
1401 | * PUBLIC: int __bam_cdel_read __P((DB_ENV *, void *, __bam_cdel_args **)); |
---|
1402 | */ |
---|
1403 | int |
---|
1404 | __bam_cdel_read(dbenv, recbuf, argpp) |
---|
1405 | DB_ENV *dbenv; |
---|
1406 | void *recbuf; |
---|
1407 | __bam_cdel_args **argpp; |
---|
1408 | { |
---|
1409 | __bam_cdel_args *argp; |
---|
1410 | u_int32_t uinttmp; |
---|
1411 | u_int8_t *bp; |
---|
1412 | int ret; |
---|
1413 | |
---|
1414 | if ((ret = __os_malloc(dbenv, |
---|
1415 | sizeof(__bam_cdel_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
1416 | return (ret); |
---|
1417 | |
---|
1418 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
1419 | |
---|
1420 | bp = recbuf; |
---|
1421 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
1422 | bp += sizeof(argp->type); |
---|
1423 | |
---|
1424 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
1425 | bp += sizeof(argp->txnid->txnid); |
---|
1426 | |
---|
1427 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
1428 | bp += sizeof(DB_LSN); |
---|
1429 | |
---|
1430 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1431 | argp->fileid = (int32_t)uinttmp; |
---|
1432 | bp += sizeof(uinttmp); |
---|
1433 | |
---|
1434 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1435 | argp->pgno = (db_pgno_t)uinttmp; |
---|
1436 | bp += sizeof(uinttmp); |
---|
1437 | |
---|
1438 | memcpy(&argp->lsn, bp, sizeof(argp->lsn)); |
---|
1439 | bp += sizeof(argp->lsn); |
---|
1440 | |
---|
1441 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1442 | argp->indx = (u_int32_t)uinttmp; |
---|
1443 | bp += sizeof(uinttmp); |
---|
1444 | |
---|
1445 | *argpp = argp; |
---|
1446 | return (0); |
---|
1447 | } |
---|
1448 | |
---|
1449 | /* |
---|
1450 | * PUBLIC: int __bam_repl_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
1451 | * PUBLIC: u_int32_t, db_pgno_t, DB_LSN *, u_int32_t, u_int32_t, |
---|
1452 | * PUBLIC: const DBT *, const DBT *, u_int32_t, u_int32_t)); |
---|
1453 | */ |
---|
1454 | int |
---|
1455 | __bam_repl_log(dbp, txnid, ret_lsnp, flags, pgno, lsn, indx, isdeleted, orig, |
---|
1456 | repl, prefix, suffix) |
---|
1457 | DB *dbp; |
---|
1458 | DB_TXN *txnid; |
---|
1459 | DB_LSN *ret_lsnp; |
---|
1460 | u_int32_t flags; |
---|
1461 | db_pgno_t pgno; |
---|
1462 | DB_LSN * lsn; |
---|
1463 | u_int32_t indx; |
---|
1464 | u_int32_t isdeleted; |
---|
1465 | const DBT *orig; |
---|
1466 | const DBT *repl; |
---|
1467 | u_int32_t prefix; |
---|
1468 | u_int32_t suffix; |
---|
1469 | { |
---|
1470 | DBT logrec; |
---|
1471 | DB_ENV *dbenv; |
---|
1472 | DB_LSN *lsnp, null_lsn; |
---|
1473 | u_int32_t zero; |
---|
1474 | u_int32_t uinttmp; |
---|
1475 | u_int32_t npad, rectype, txn_num; |
---|
1476 | int ret; |
---|
1477 | u_int8_t *bp; |
---|
1478 | |
---|
1479 | dbenv = dbp->dbenv; |
---|
1480 | rectype = DB___bam_repl; |
---|
1481 | npad = 0; |
---|
1482 | |
---|
1483 | if (txnid == NULL) { |
---|
1484 | txn_num = 0; |
---|
1485 | null_lsn.file = 0; |
---|
1486 | null_lsn.offset = 0; |
---|
1487 | lsnp = &null_lsn; |
---|
1488 | } else { |
---|
1489 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
1490 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
1491 | return (ret); |
---|
1492 | txn_num = txnid->txnid; |
---|
1493 | lsnp = &txnid->last_lsn; |
---|
1494 | } |
---|
1495 | |
---|
1496 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
1497 | + sizeof(u_int32_t) |
---|
1498 | + sizeof(u_int32_t) |
---|
1499 | + sizeof(*lsn) |
---|
1500 | + sizeof(u_int32_t) |
---|
1501 | + sizeof(u_int32_t) |
---|
1502 | + sizeof(u_int32_t) + (orig == NULL ? 0 : orig->size) |
---|
1503 | + sizeof(u_int32_t) + (repl == NULL ? 0 : repl->size) |
---|
1504 | + sizeof(u_int32_t) |
---|
1505 | + sizeof(u_int32_t); |
---|
1506 | if (CRYPTO_ON(dbenv)) { |
---|
1507 | npad = |
---|
1508 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
1509 | logrec.size += npad; |
---|
1510 | } |
---|
1511 | |
---|
1512 | if ((ret = __os_malloc(dbenv, |
---|
1513 | logrec.size, &logrec.data)) != 0) |
---|
1514 | return (ret); |
---|
1515 | |
---|
1516 | if (npad > 0) |
---|
1517 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
1518 | |
---|
1519 | bp = logrec.data; |
---|
1520 | |
---|
1521 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
1522 | bp += sizeof(rectype); |
---|
1523 | |
---|
1524 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
1525 | bp += sizeof(txn_num); |
---|
1526 | |
---|
1527 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
1528 | bp += sizeof(DB_LSN); |
---|
1529 | |
---|
1530 | DB_ASSERT(dbp->log_filename != NULL); |
---|
1531 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
1532 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
1533 | return (ret); |
---|
1534 | |
---|
1535 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
1536 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1537 | bp += sizeof(uinttmp); |
---|
1538 | |
---|
1539 | uinttmp = (u_int32_t)pgno; |
---|
1540 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1541 | bp += sizeof(uinttmp); |
---|
1542 | |
---|
1543 | if (lsn != NULL) |
---|
1544 | memcpy(bp, lsn, sizeof(*lsn)); |
---|
1545 | else |
---|
1546 | memset(bp, 0, sizeof(*lsn)); |
---|
1547 | bp += sizeof(*lsn); |
---|
1548 | |
---|
1549 | uinttmp = (u_int32_t)indx; |
---|
1550 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1551 | bp += sizeof(uinttmp); |
---|
1552 | |
---|
1553 | uinttmp = (u_int32_t)isdeleted; |
---|
1554 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1555 | bp += sizeof(uinttmp); |
---|
1556 | |
---|
1557 | if (orig == NULL) { |
---|
1558 | zero = 0; |
---|
1559 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
1560 | bp += sizeof(u_int32_t); |
---|
1561 | } else { |
---|
1562 | memcpy(bp, &orig->size, sizeof(orig->size)); |
---|
1563 | bp += sizeof(orig->size); |
---|
1564 | memcpy(bp, orig->data, orig->size); |
---|
1565 | bp += orig->size; |
---|
1566 | } |
---|
1567 | |
---|
1568 | if (repl == NULL) { |
---|
1569 | zero = 0; |
---|
1570 | memcpy(bp, &zero, sizeof(u_int32_t)); |
---|
1571 | bp += sizeof(u_int32_t); |
---|
1572 | } else { |
---|
1573 | memcpy(bp, &repl->size, sizeof(repl->size)); |
---|
1574 | bp += sizeof(repl->size); |
---|
1575 | memcpy(bp, repl->data, repl->size); |
---|
1576 | bp += repl->size; |
---|
1577 | } |
---|
1578 | |
---|
1579 | uinttmp = (u_int32_t)prefix; |
---|
1580 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1581 | bp += sizeof(uinttmp); |
---|
1582 | |
---|
1583 | uinttmp = (u_int32_t)suffix; |
---|
1584 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1585 | bp += sizeof(uinttmp); |
---|
1586 | |
---|
1587 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
1588 | ret = dbenv->log_put(dbenv, |
---|
1589 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
1590 | if (txnid != NULL && ret == 0) |
---|
1591 | txnid->last_lsn = *ret_lsnp; |
---|
1592 | #ifdef LOG_DIAGNOSTIC |
---|
1593 | if (ret != 0) |
---|
1594 | (void)__bam_repl_print(dbenv, |
---|
1595 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
1596 | #endif |
---|
1597 | __os_free(dbenv, logrec.data); |
---|
1598 | return (ret); |
---|
1599 | } |
---|
1600 | |
---|
1601 | /* |
---|
1602 | * PUBLIC: int __bam_repl_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1603 | * PUBLIC: db_recops, void *)); |
---|
1604 | */ |
---|
1605 | int |
---|
1606 | __bam_repl_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
1607 | DB_ENV *dbenv; |
---|
1608 | DBT *rec; |
---|
1609 | DB_LSN *lsnp; |
---|
1610 | db_recops notused1; |
---|
1611 | void *summary; |
---|
1612 | { |
---|
1613 | DB *dbp; |
---|
1614 | TXN_RECS *t; |
---|
1615 | __bam_repl_args *argp; |
---|
1616 | u_int32_t ret; |
---|
1617 | |
---|
1618 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
1619 | |
---|
1620 | argp = NULL; |
---|
1621 | t = (TXN_RECS *)summary; |
---|
1622 | |
---|
1623 | if ((ret = __bam_repl_read(dbenv, rec->data, &argp)) != 0) |
---|
1624 | return (ret); |
---|
1625 | |
---|
1626 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
1627 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
1628 | goto err; |
---|
1629 | |
---|
1630 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
1631 | goto err; |
---|
1632 | |
---|
1633 | t->array[t->npages].flags = 0; |
---|
1634 | t->array[t->npages].fid = argp->fileid; |
---|
1635 | t->array[t->npages].lsn = *lsnp; |
---|
1636 | t->array[t->npages].pgdesc.pgno = argp->pgno; |
---|
1637 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
1638 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
1639 | DB_FILE_ID_LEN); |
---|
1640 | t->npages++; |
---|
1641 | |
---|
1642 | err: if (argp != NULL) |
---|
1643 | __os_free(dbenv, argp); |
---|
1644 | return (ret); |
---|
1645 | } |
---|
1646 | |
---|
1647 | /* |
---|
1648 | * PUBLIC: int __bam_repl_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1649 | * PUBLIC: db_recops, void *)); |
---|
1650 | */ |
---|
1651 | int |
---|
1652 | __bam_repl_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
1653 | DB_ENV *dbenv; |
---|
1654 | DBT *dbtp; |
---|
1655 | DB_LSN *lsnp; |
---|
1656 | db_recops notused2; |
---|
1657 | void *notused3; |
---|
1658 | { |
---|
1659 | __bam_repl_args *argp; |
---|
1660 | u_int32_t i; |
---|
1661 | int ch; |
---|
1662 | int ret; |
---|
1663 | |
---|
1664 | notused2 = DB_TXN_ABORT; |
---|
1665 | notused3 = NULL; |
---|
1666 | |
---|
1667 | if ((ret = __bam_repl_read(dbenv, dbtp->data, &argp)) != 0) |
---|
1668 | return (ret); |
---|
1669 | (void)printf( |
---|
1670 | "[%lu][%lu]__bam_repl: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
1671 | (u_long)lsnp->file, |
---|
1672 | (u_long)lsnp->offset, |
---|
1673 | (u_long)argp->type, |
---|
1674 | (u_long)argp->txnid->txnid, |
---|
1675 | (u_long)argp->prev_lsn.file, |
---|
1676 | (u_long)argp->prev_lsn.offset); |
---|
1677 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
1678 | (void)printf("\tpgno: %lu\n", (u_long)argp->pgno); |
---|
1679 | (void)printf("\tlsn: [%lu][%lu]\n", |
---|
1680 | (u_long)argp->lsn.file, (u_long)argp->lsn.offset); |
---|
1681 | (void)printf("\tindx: %lu\n", (u_long)argp->indx); |
---|
1682 | (void)printf("\tisdeleted: %lu\n", (u_long)argp->isdeleted); |
---|
1683 | (void)printf("\torig: "); |
---|
1684 | for (i = 0; i < argp->orig.size; i++) { |
---|
1685 | ch = ((u_int8_t *)argp->orig.data)[i]; |
---|
1686 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
1687 | } |
---|
1688 | (void)printf("\n"); |
---|
1689 | (void)printf("\trepl: "); |
---|
1690 | for (i = 0; i < argp->repl.size; i++) { |
---|
1691 | ch = ((u_int8_t *)argp->repl.data)[i]; |
---|
1692 | printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch); |
---|
1693 | } |
---|
1694 | (void)printf("\n"); |
---|
1695 | (void)printf("\tprefix: %lu\n", (u_long)argp->prefix); |
---|
1696 | (void)printf("\tsuffix: %lu\n", (u_long)argp->suffix); |
---|
1697 | (void)printf("\n"); |
---|
1698 | __os_free(dbenv, argp); |
---|
1699 | return (0); |
---|
1700 | } |
---|
1701 | |
---|
1702 | /* |
---|
1703 | * PUBLIC: int __bam_repl_read __P((DB_ENV *, void *, __bam_repl_args **)); |
---|
1704 | */ |
---|
1705 | int |
---|
1706 | __bam_repl_read(dbenv, recbuf, argpp) |
---|
1707 | DB_ENV *dbenv; |
---|
1708 | void *recbuf; |
---|
1709 | __bam_repl_args **argpp; |
---|
1710 | { |
---|
1711 | __bam_repl_args *argp; |
---|
1712 | u_int32_t uinttmp; |
---|
1713 | u_int8_t *bp; |
---|
1714 | int ret; |
---|
1715 | |
---|
1716 | if ((ret = __os_malloc(dbenv, |
---|
1717 | sizeof(__bam_repl_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
1718 | return (ret); |
---|
1719 | |
---|
1720 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
1721 | |
---|
1722 | bp = recbuf; |
---|
1723 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
1724 | bp += sizeof(argp->type); |
---|
1725 | |
---|
1726 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
1727 | bp += sizeof(argp->txnid->txnid); |
---|
1728 | |
---|
1729 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
1730 | bp += sizeof(DB_LSN); |
---|
1731 | |
---|
1732 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1733 | argp->fileid = (int32_t)uinttmp; |
---|
1734 | bp += sizeof(uinttmp); |
---|
1735 | |
---|
1736 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1737 | argp->pgno = (db_pgno_t)uinttmp; |
---|
1738 | bp += sizeof(uinttmp); |
---|
1739 | |
---|
1740 | memcpy(&argp->lsn, bp, sizeof(argp->lsn)); |
---|
1741 | bp += sizeof(argp->lsn); |
---|
1742 | |
---|
1743 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1744 | argp->indx = (u_int32_t)uinttmp; |
---|
1745 | bp += sizeof(uinttmp); |
---|
1746 | |
---|
1747 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1748 | argp->isdeleted = (u_int32_t)uinttmp; |
---|
1749 | bp += sizeof(uinttmp); |
---|
1750 | |
---|
1751 | memset(&argp->orig, 0, sizeof(argp->orig)); |
---|
1752 | memcpy(&argp->orig.size, bp, sizeof(u_int32_t)); |
---|
1753 | bp += sizeof(u_int32_t); |
---|
1754 | argp->orig.data = bp; |
---|
1755 | bp += argp->orig.size; |
---|
1756 | |
---|
1757 | memset(&argp->repl, 0, sizeof(argp->repl)); |
---|
1758 | memcpy(&argp->repl.size, bp, sizeof(u_int32_t)); |
---|
1759 | bp += sizeof(u_int32_t); |
---|
1760 | argp->repl.data = bp; |
---|
1761 | bp += argp->repl.size; |
---|
1762 | |
---|
1763 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1764 | argp->prefix = (u_int32_t)uinttmp; |
---|
1765 | bp += sizeof(uinttmp); |
---|
1766 | |
---|
1767 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
1768 | argp->suffix = (u_int32_t)uinttmp; |
---|
1769 | bp += sizeof(uinttmp); |
---|
1770 | |
---|
1771 | *argpp = argp; |
---|
1772 | return (0); |
---|
1773 | } |
---|
1774 | |
---|
1775 | /* |
---|
1776 | * PUBLIC: int __bam_root_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
1777 | * PUBLIC: u_int32_t, db_pgno_t, db_pgno_t, DB_LSN *)); |
---|
1778 | */ |
---|
1779 | int |
---|
1780 | __bam_root_log(dbp, txnid, ret_lsnp, flags, meta_pgno, root_pgno, meta_lsn) |
---|
1781 | DB *dbp; |
---|
1782 | DB_TXN *txnid; |
---|
1783 | DB_LSN *ret_lsnp; |
---|
1784 | u_int32_t flags; |
---|
1785 | db_pgno_t meta_pgno; |
---|
1786 | db_pgno_t root_pgno; |
---|
1787 | DB_LSN * meta_lsn; |
---|
1788 | { |
---|
1789 | DBT logrec; |
---|
1790 | DB_ENV *dbenv; |
---|
1791 | DB_LSN *lsnp, null_lsn; |
---|
1792 | u_int32_t uinttmp; |
---|
1793 | u_int32_t npad, rectype, txn_num; |
---|
1794 | int ret; |
---|
1795 | u_int8_t *bp; |
---|
1796 | |
---|
1797 | dbenv = dbp->dbenv; |
---|
1798 | rectype = DB___bam_root; |
---|
1799 | npad = 0; |
---|
1800 | |
---|
1801 | if (txnid == NULL) { |
---|
1802 | txn_num = 0; |
---|
1803 | null_lsn.file = 0; |
---|
1804 | null_lsn.offset = 0; |
---|
1805 | lsnp = &null_lsn; |
---|
1806 | } else { |
---|
1807 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
1808 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
1809 | return (ret); |
---|
1810 | txn_num = txnid->txnid; |
---|
1811 | lsnp = &txnid->last_lsn; |
---|
1812 | } |
---|
1813 | |
---|
1814 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
1815 | + sizeof(u_int32_t) |
---|
1816 | + sizeof(u_int32_t) |
---|
1817 | + sizeof(u_int32_t) |
---|
1818 | + sizeof(*meta_lsn); |
---|
1819 | if (CRYPTO_ON(dbenv)) { |
---|
1820 | npad = |
---|
1821 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
1822 | logrec.size += npad; |
---|
1823 | } |
---|
1824 | |
---|
1825 | if ((ret = __os_malloc(dbenv, |
---|
1826 | logrec.size, &logrec.data)) != 0) |
---|
1827 | return (ret); |
---|
1828 | |
---|
1829 | if (npad > 0) |
---|
1830 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
1831 | |
---|
1832 | bp = logrec.data; |
---|
1833 | |
---|
1834 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
1835 | bp += sizeof(rectype); |
---|
1836 | |
---|
1837 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
1838 | bp += sizeof(txn_num); |
---|
1839 | |
---|
1840 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
1841 | bp += sizeof(DB_LSN); |
---|
1842 | |
---|
1843 | DB_ASSERT(dbp->log_filename != NULL); |
---|
1844 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
1845 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
1846 | return (ret); |
---|
1847 | |
---|
1848 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
1849 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1850 | bp += sizeof(uinttmp); |
---|
1851 | |
---|
1852 | uinttmp = (u_int32_t)meta_pgno; |
---|
1853 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1854 | bp += sizeof(uinttmp); |
---|
1855 | |
---|
1856 | uinttmp = (u_int32_t)root_pgno; |
---|
1857 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
1858 | bp += sizeof(uinttmp); |
---|
1859 | |
---|
1860 | if (meta_lsn != NULL) |
---|
1861 | memcpy(bp, meta_lsn, sizeof(*meta_lsn)); |
---|
1862 | else |
---|
1863 | memset(bp, 0, sizeof(*meta_lsn)); |
---|
1864 | bp += sizeof(*meta_lsn); |
---|
1865 | |
---|
1866 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
1867 | ret = dbenv->log_put(dbenv, |
---|
1868 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
1869 | if (txnid != NULL && ret == 0) |
---|
1870 | txnid->last_lsn = *ret_lsnp; |
---|
1871 | #ifdef LOG_DIAGNOSTIC |
---|
1872 | if (ret != 0) |
---|
1873 | (void)__bam_root_print(dbenv, |
---|
1874 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
1875 | #endif |
---|
1876 | __os_free(dbenv, logrec.data); |
---|
1877 | return (ret); |
---|
1878 | } |
---|
1879 | |
---|
1880 | /* |
---|
1881 | * PUBLIC: int __bam_root_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1882 | * PUBLIC: db_recops, void *)); |
---|
1883 | */ |
---|
1884 | int |
---|
1885 | __bam_root_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
1886 | DB_ENV *dbenv; |
---|
1887 | DBT *rec; |
---|
1888 | DB_LSN *lsnp; |
---|
1889 | db_recops notused1; |
---|
1890 | void *summary; |
---|
1891 | { |
---|
1892 | DB *dbp; |
---|
1893 | TXN_RECS *t; |
---|
1894 | __bam_root_args *argp; |
---|
1895 | u_int32_t ret; |
---|
1896 | |
---|
1897 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
1898 | |
---|
1899 | argp = NULL; |
---|
1900 | t = (TXN_RECS *)summary; |
---|
1901 | |
---|
1902 | if ((ret = __bam_root_read(dbenv, rec->data, &argp)) != 0) |
---|
1903 | return (ret); |
---|
1904 | |
---|
1905 | if ((ret = __dbreg_id_to_db(dbenv, |
---|
1906 | argp->txnid, &dbp, argp->fileid, 0)) != 0) |
---|
1907 | goto err; |
---|
1908 | |
---|
1909 | if ((ret = __rep_check_alloc(dbenv, t, 2)) != 0) |
---|
1910 | goto err; |
---|
1911 | |
---|
1912 | t->array[t->npages].flags = 0; |
---|
1913 | t->array[t->npages].fid = argp->fileid; |
---|
1914 | t->array[t->npages].lsn = *lsnp; |
---|
1915 | t->array[t->npages].pgdesc.pgno = argp->meta_pgno; |
---|
1916 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
1917 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
1918 | DB_FILE_ID_LEN); |
---|
1919 | t->npages++; |
---|
1920 | t->array[t->npages].flags = 0; |
---|
1921 | t->array[t->npages].fid = argp->fileid; |
---|
1922 | t->array[t->npages].lsn = *lsnp; |
---|
1923 | t->array[t->npages].pgdesc.pgno = argp->root_pgno; |
---|
1924 | t->array[t->npages].pgdesc.type = DB_PAGE_LOCK; |
---|
1925 | memcpy(t->array[t->npages].pgdesc.fileid, dbp->fileid, |
---|
1926 | DB_FILE_ID_LEN); |
---|
1927 | t->npages++; |
---|
1928 | |
---|
1929 | err: if (argp != NULL) |
---|
1930 | __os_free(dbenv, argp); |
---|
1931 | return (ret); |
---|
1932 | } |
---|
1933 | |
---|
1934 | /* |
---|
1935 | * PUBLIC: int __bam_root_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
1936 | * PUBLIC: db_recops, void *)); |
---|
1937 | */ |
---|
1938 | int |
---|
1939 | __bam_root_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
1940 | DB_ENV *dbenv; |
---|
1941 | DBT *dbtp; |
---|
1942 | DB_LSN *lsnp; |
---|
1943 | db_recops notused2; |
---|
1944 | void *notused3; |
---|
1945 | { |
---|
1946 | __bam_root_args *argp; |
---|
1947 | int ret; |
---|
1948 | |
---|
1949 | notused2 = DB_TXN_ABORT; |
---|
1950 | notused3 = NULL; |
---|
1951 | |
---|
1952 | if ((ret = __bam_root_read(dbenv, dbtp->data, &argp)) != 0) |
---|
1953 | return (ret); |
---|
1954 | (void)printf( |
---|
1955 | "[%lu][%lu]__bam_root: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
1956 | (u_long)lsnp->file, |
---|
1957 | (u_long)lsnp->offset, |
---|
1958 | (u_long)argp->type, |
---|
1959 | (u_long)argp->txnid->txnid, |
---|
1960 | (u_long)argp->prev_lsn.file, |
---|
1961 | (u_long)argp->prev_lsn.offset); |
---|
1962 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
1963 | (void)printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno); |
---|
1964 | (void)printf("\troot_pgno: %lu\n", (u_long)argp->root_pgno); |
---|
1965 | (void)printf("\tmeta_lsn: [%lu][%lu]\n", |
---|
1966 | (u_long)argp->meta_lsn.file, (u_long)argp->meta_lsn.offset); |
---|
1967 | (void)printf("\n"); |
---|
1968 | __os_free(dbenv, argp); |
---|
1969 | return (0); |
---|
1970 | } |
---|
1971 | |
---|
1972 | /* |
---|
1973 | * PUBLIC: int __bam_root_read __P((DB_ENV *, void *, __bam_root_args **)); |
---|
1974 | */ |
---|
1975 | int |
---|
1976 | __bam_root_read(dbenv, recbuf, argpp) |
---|
1977 | DB_ENV *dbenv; |
---|
1978 | void *recbuf; |
---|
1979 | __bam_root_args **argpp; |
---|
1980 | { |
---|
1981 | __bam_root_args *argp; |
---|
1982 | u_int32_t uinttmp; |
---|
1983 | u_int8_t *bp; |
---|
1984 | int ret; |
---|
1985 | |
---|
1986 | if ((ret = __os_malloc(dbenv, |
---|
1987 | sizeof(__bam_root_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
1988 | return (ret); |
---|
1989 | |
---|
1990 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
1991 | |
---|
1992 | bp = recbuf; |
---|
1993 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
1994 | bp += sizeof(argp->type); |
---|
1995 | |
---|
1996 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
1997 | bp += sizeof(argp->txnid->txnid); |
---|
1998 | |
---|
1999 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
2000 | bp += sizeof(DB_LSN); |
---|
2001 | |
---|
2002 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2003 | argp->fileid = (int32_t)uinttmp; |
---|
2004 | bp += sizeof(uinttmp); |
---|
2005 | |
---|
2006 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2007 | argp->meta_pgno = (db_pgno_t)uinttmp; |
---|
2008 | bp += sizeof(uinttmp); |
---|
2009 | |
---|
2010 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2011 | argp->root_pgno = (db_pgno_t)uinttmp; |
---|
2012 | bp += sizeof(uinttmp); |
---|
2013 | |
---|
2014 | memcpy(&argp->meta_lsn, bp, sizeof(argp->meta_lsn)); |
---|
2015 | bp += sizeof(argp->meta_lsn); |
---|
2016 | |
---|
2017 | *argpp = argp; |
---|
2018 | return (0); |
---|
2019 | } |
---|
2020 | |
---|
2021 | /* |
---|
2022 | * PUBLIC: int __bam_curadj_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
2023 | * PUBLIC: u_int32_t, db_ca_mode, db_pgno_t, db_pgno_t, db_pgno_t, |
---|
2024 | * PUBLIC: u_int32_t, u_int32_t, u_int32_t)); |
---|
2025 | */ |
---|
2026 | int |
---|
2027 | __bam_curadj_log(dbp, txnid, ret_lsnp, flags, mode, from_pgno, to_pgno, left_pgno, first_indx, |
---|
2028 | from_indx, to_indx) |
---|
2029 | DB *dbp; |
---|
2030 | DB_TXN *txnid; |
---|
2031 | DB_LSN *ret_lsnp; |
---|
2032 | u_int32_t flags; |
---|
2033 | db_ca_mode mode; |
---|
2034 | db_pgno_t from_pgno; |
---|
2035 | db_pgno_t to_pgno; |
---|
2036 | db_pgno_t left_pgno; |
---|
2037 | u_int32_t first_indx; |
---|
2038 | u_int32_t from_indx; |
---|
2039 | u_int32_t to_indx; |
---|
2040 | { |
---|
2041 | DBT logrec; |
---|
2042 | DB_ENV *dbenv; |
---|
2043 | DB_LSN *lsnp, null_lsn; |
---|
2044 | u_int32_t uinttmp; |
---|
2045 | u_int32_t npad, rectype, txn_num; |
---|
2046 | int ret; |
---|
2047 | u_int8_t *bp; |
---|
2048 | |
---|
2049 | dbenv = dbp->dbenv; |
---|
2050 | rectype = DB___bam_curadj; |
---|
2051 | npad = 0; |
---|
2052 | |
---|
2053 | if (txnid == NULL) { |
---|
2054 | txn_num = 0; |
---|
2055 | null_lsn.file = 0; |
---|
2056 | null_lsn.offset = 0; |
---|
2057 | lsnp = &null_lsn; |
---|
2058 | } else { |
---|
2059 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
2060 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
2061 | return (ret); |
---|
2062 | txn_num = txnid->txnid; |
---|
2063 | lsnp = &txnid->last_lsn; |
---|
2064 | } |
---|
2065 | |
---|
2066 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
2067 | + sizeof(u_int32_t) |
---|
2068 | + sizeof(u_int32_t) |
---|
2069 | + sizeof(u_int32_t) |
---|
2070 | + sizeof(u_int32_t) |
---|
2071 | + sizeof(u_int32_t) |
---|
2072 | + sizeof(u_int32_t) |
---|
2073 | + sizeof(u_int32_t) |
---|
2074 | + sizeof(u_int32_t); |
---|
2075 | if (CRYPTO_ON(dbenv)) { |
---|
2076 | npad = |
---|
2077 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
2078 | logrec.size += npad; |
---|
2079 | } |
---|
2080 | |
---|
2081 | if ((ret = __os_malloc(dbenv, |
---|
2082 | logrec.size, &logrec.data)) != 0) |
---|
2083 | return (ret); |
---|
2084 | |
---|
2085 | if (npad > 0) |
---|
2086 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
2087 | |
---|
2088 | bp = logrec.data; |
---|
2089 | |
---|
2090 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
2091 | bp += sizeof(rectype); |
---|
2092 | |
---|
2093 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
2094 | bp += sizeof(txn_num); |
---|
2095 | |
---|
2096 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
2097 | bp += sizeof(DB_LSN); |
---|
2098 | |
---|
2099 | DB_ASSERT(dbp->log_filename != NULL); |
---|
2100 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
2101 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
2102 | return (ret); |
---|
2103 | |
---|
2104 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
2105 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2106 | bp += sizeof(uinttmp); |
---|
2107 | |
---|
2108 | uinttmp = (u_int32_t)mode; |
---|
2109 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2110 | bp += sizeof(uinttmp); |
---|
2111 | |
---|
2112 | uinttmp = (u_int32_t)from_pgno; |
---|
2113 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2114 | bp += sizeof(uinttmp); |
---|
2115 | |
---|
2116 | uinttmp = (u_int32_t)to_pgno; |
---|
2117 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2118 | bp += sizeof(uinttmp); |
---|
2119 | |
---|
2120 | uinttmp = (u_int32_t)left_pgno; |
---|
2121 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2122 | bp += sizeof(uinttmp); |
---|
2123 | |
---|
2124 | uinttmp = (u_int32_t)first_indx; |
---|
2125 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2126 | bp += sizeof(uinttmp); |
---|
2127 | |
---|
2128 | uinttmp = (u_int32_t)from_indx; |
---|
2129 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2130 | bp += sizeof(uinttmp); |
---|
2131 | |
---|
2132 | uinttmp = (u_int32_t)to_indx; |
---|
2133 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2134 | bp += sizeof(uinttmp); |
---|
2135 | |
---|
2136 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
2137 | ret = dbenv->log_put(dbenv, |
---|
2138 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
2139 | if (txnid != NULL && ret == 0) |
---|
2140 | txnid->last_lsn = *ret_lsnp; |
---|
2141 | #ifdef LOG_DIAGNOSTIC |
---|
2142 | if (ret != 0) |
---|
2143 | (void)__bam_curadj_print(dbenv, |
---|
2144 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
2145 | #endif |
---|
2146 | __os_free(dbenv, logrec.data); |
---|
2147 | return (ret); |
---|
2148 | } |
---|
2149 | |
---|
2150 | /* |
---|
2151 | * PUBLIC: int __bam_curadj_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
2152 | * PUBLIC: db_recops, void *)); |
---|
2153 | */ |
---|
2154 | int |
---|
2155 | __bam_curadj_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
2156 | DB_ENV *dbenv; |
---|
2157 | DBT *rec; |
---|
2158 | DB_LSN *lsnp; |
---|
2159 | db_recops notused1; |
---|
2160 | void *summary; |
---|
2161 | { |
---|
2162 | TXN_RECS *t; |
---|
2163 | int ret; |
---|
2164 | COMPQUIET(rec, NULL); |
---|
2165 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
2166 | |
---|
2167 | t = (TXN_RECS *)summary; |
---|
2168 | |
---|
2169 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
2170 | return (ret); |
---|
2171 | |
---|
2172 | t->array[t->npages].flags = LSN_PAGE_NOLOCK; |
---|
2173 | t->array[t->npages].lsn = *lsnp; |
---|
2174 | t->array[t->npages].fid = DB_LOGFILEID_INVALID; |
---|
2175 | memset(&t->array[t->npages].pgdesc, 0, |
---|
2176 | sizeof(t->array[t->npages].pgdesc)); |
---|
2177 | |
---|
2178 | t->npages++; |
---|
2179 | |
---|
2180 | return (0); |
---|
2181 | } |
---|
2182 | |
---|
2183 | /* |
---|
2184 | * PUBLIC: int __bam_curadj_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
2185 | * PUBLIC: db_recops, void *)); |
---|
2186 | */ |
---|
2187 | int |
---|
2188 | __bam_curadj_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
2189 | DB_ENV *dbenv; |
---|
2190 | DBT *dbtp; |
---|
2191 | DB_LSN *lsnp; |
---|
2192 | db_recops notused2; |
---|
2193 | void *notused3; |
---|
2194 | { |
---|
2195 | __bam_curadj_args *argp; |
---|
2196 | int ret; |
---|
2197 | |
---|
2198 | notused2 = DB_TXN_ABORT; |
---|
2199 | notused3 = NULL; |
---|
2200 | |
---|
2201 | if ((ret = __bam_curadj_read(dbenv, dbtp->data, &argp)) != 0) |
---|
2202 | return (ret); |
---|
2203 | (void)printf( |
---|
2204 | "[%lu][%lu]__bam_curadj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
2205 | (u_long)lsnp->file, |
---|
2206 | (u_long)lsnp->offset, |
---|
2207 | (u_long)argp->type, |
---|
2208 | (u_long)argp->txnid->txnid, |
---|
2209 | (u_long)argp->prev_lsn.file, |
---|
2210 | (u_long)argp->prev_lsn.offset); |
---|
2211 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
2212 | (void)printf("\tmode: %ld\n", (long)argp->mode); |
---|
2213 | (void)printf("\tfrom_pgno: %lu\n", (u_long)argp->from_pgno); |
---|
2214 | (void)printf("\tto_pgno: %lu\n", (u_long)argp->to_pgno); |
---|
2215 | (void)printf("\tleft_pgno: %lu\n", (u_long)argp->left_pgno); |
---|
2216 | (void)printf("\tfirst_indx: %lu\n", (u_long)argp->first_indx); |
---|
2217 | (void)printf("\tfrom_indx: %lu\n", (u_long)argp->from_indx); |
---|
2218 | (void)printf("\tto_indx: %lu\n", (u_long)argp->to_indx); |
---|
2219 | (void)printf("\n"); |
---|
2220 | __os_free(dbenv, argp); |
---|
2221 | return (0); |
---|
2222 | } |
---|
2223 | |
---|
2224 | /* |
---|
2225 | * PUBLIC: int __bam_curadj_read __P((DB_ENV *, void *, __bam_curadj_args **)); |
---|
2226 | */ |
---|
2227 | int |
---|
2228 | __bam_curadj_read(dbenv, recbuf, argpp) |
---|
2229 | DB_ENV *dbenv; |
---|
2230 | void *recbuf; |
---|
2231 | __bam_curadj_args **argpp; |
---|
2232 | { |
---|
2233 | __bam_curadj_args *argp; |
---|
2234 | u_int32_t uinttmp; |
---|
2235 | u_int8_t *bp; |
---|
2236 | int ret; |
---|
2237 | |
---|
2238 | if ((ret = __os_malloc(dbenv, |
---|
2239 | sizeof(__bam_curadj_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
2240 | return (ret); |
---|
2241 | |
---|
2242 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
2243 | |
---|
2244 | bp = recbuf; |
---|
2245 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
2246 | bp += sizeof(argp->type); |
---|
2247 | |
---|
2248 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
2249 | bp += sizeof(argp->txnid->txnid); |
---|
2250 | |
---|
2251 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
2252 | bp += sizeof(DB_LSN); |
---|
2253 | |
---|
2254 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2255 | argp->fileid = (int32_t)uinttmp; |
---|
2256 | bp += sizeof(uinttmp); |
---|
2257 | |
---|
2258 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2259 | argp->mode = (db_ca_mode)uinttmp; |
---|
2260 | bp += sizeof(uinttmp); |
---|
2261 | |
---|
2262 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2263 | argp->from_pgno = (db_pgno_t)uinttmp; |
---|
2264 | bp += sizeof(uinttmp); |
---|
2265 | |
---|
2266 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2267 | argp->to_pgno = (db_pgno_t)uinttmp; |
---|
2268 | bp += sizeof(uinttmp); |
---|
2269 | |
---|
2270 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2271 | argp->left_pgno = (db_pgno_t)uinttmp; |
---|
2272 | bp += sizeof(uinttmp); |
---|
2273 | |
---|
2274 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2275 | argp->first_indx = (u_int32_t)uinttmp; |
---|
2276 | bp += sizeof(uinttmp); |
---|
2277 | |
---|
2278 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2279 | argp->from_indx = (u_int32_t)uinttmp; |
---|
2280 | bp += sizeof(uinttmp); |
---|
2281 | |
---|
2282 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2283 | argp->to_indx = (u_int32_t)uinttmp; |
---|
2284 | bp += sizeof(uinttmp); |
---|
2285 | |
---|
2286 | *argpp = argp; |
---|
2287 | return (0); |
---|
2288 | } |
---|
2289 | |
---|
2290 | /* |
---|
2291 | * PUBLIC: int __bam_rcuradj_log __P((DB *, DB_TXN *, DB_LSN *, |
---|
2292 | * PUBLIC: u_int32_t, ca_recno_arg, db_pgno_t, db_recno_t, u_int32_t)); |
---|
2293 | */ |
---|
2294 | int |
---|
2295 | __bam_rcuradj_log(dbp, txnid, ret_lsnp, flags, mode, root, recno, order) |
---|
2296 | DB *dbp; |
---|
2297 | DB_TXN *txnid; |
---|
2298 | DB_LSN *ret_lsnp; |
---|
2299 | u_int32_t flags; |
---|
2300 | ca_recno_arg mode; |
---|
2301 | db_pgno_t root; |
---|
2302 | db_recno_t recno; |
---|
2303 | u_int32_t order; |
---|
2304 | { |
---|
2305 | DBT logrec; |
---|
2306 | DB_ENV *dbenv; |
---|
2307 | DB_LSN *lsnp, null_lsn; |
---|
2308 | u_int32_t uinttmp; |
---|
2309 | u_int32_t npad, rectype, txn_num; |
---|
2310 | int ret; |
---|
2311 | u_int8_t *bp; |
---|
2312 | |
---|
2313 | dbenv = dbp->dbenv; |
---|
2314 | rectype = DB___bam_rcuradj; |
---|
2315 | npad = 0; |
---|
2316 | |
---|
2317 | if (txnid == NULL) { |
---|
2318 | txn_num = 0; |
---|
2319 | null_lsn.file = 0; |
---|
2320 | null_lsn.offset = 0; |
---|
2321 | lsnp = &null_lsn; |
---|
2322 | } else { |
---|
2323 | if (TAILQ_FIRST(&txnid->kids) != NULL && |
---|
2324 | (ret = __txn_activekids(dbenv, rectype, txnid)) != 0) |
---|
2325 | return (ret); |
---|
2326 | txn_num = txnid->txnid; |
---|
2327 | lsnp = &txnid->last_lsn; |
---|
2328 | } |
---|
2329 | |
---|
2330 | logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) |
---|
2331 | + sizeof(u_int32_t) |
---|
2332 | + sizeof(u_int32_t) |
---|
2333 | + sizeof(u_int32_t) |
---|
2334 | + sizeof(u_int32_t) |
---|
2335 | + sizeof(u_int32_t); |
---|
2336 | if (CRYPTO_ON(dbenv)) { |
---|
2337 | npad = |
---|
2338 | ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size); |
---|
2339 | logrec.size += npad; |
---|
2340 | } |
---|
2341 | |
---|
2342 | if ((ret = __os_malloc(dbenv, |
---|
2343 | logrec.size, &logrec.data)) != 0) |
---|
2344 | return (ret); |
---|
2345 | |
---|
2346 | if (npad > 0) |
---|
2347 | memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); |
---|
2348 | |
---|
2349 | bp = logrec.data; |
---|
2350 | |
---|
2351 | memcpy(bp, &rectype, sizeof(rectype)); |
---|
2352 | bp += sizeof(rectype); |
---|
2353 | |
---|
2354 | memcpy(bp, &txn_num, sizeof(txn_num)); |
---|
2355 | bp += sizeof(txn_num); |
---|
2356 | |
---|
2357 | memcpy(bp, lsnp, sizeof(DB_LSN)); |
---|
2358 | bp += sizeof(DB_LSN); |
---|
2359 | |
---|
2360 | DB_ASSERT(dbp->log_filename != NULL); |
---|
2361 | if (dbp->log_filename->id == DB_LOGFILEID_INVALID && |
---|
2362 | (ret = __dbreg_lazy_id(dbp)) != 0) |
---|
2363 | return (ret); |
---|
2364 | |
---|
2365 | uinttmp = (u_int32_t)dbp->log_filename->id; |
---|
2366 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2367 | bp += sizeof(uinttmp); |
---|
2368 | |
---|
2369 | uinttmp = (u_int32_t)mode; |
---|
2370 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2371 | bp += sizeof(uinttmp); |
---|
2372 | |
---|
2373 | uinttmp = (u_int32_t)root; |
---|
2374 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2375 | bp += sizeof(uinttmp); |
---|
2376 | |
---|
2377 | uinttmp = (u_int32_t)recno; |
---|
2378 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2379 | bp += sizeof(uinttmp); |
---|
2380 | |
---|
2381 | uinttmp = (u_int32_t)order; |
---|
2382 | memcpy(bp, &uinttmp, sizeof(uinttmp)); |
---|
2383 | bp += sizeof(uinttmp); |
---|
2384 | |
---|
2385 | DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); |
---|
2386 | ret = dbenv->log_put(dbenv, |
---|
2387 | ret_lsnp, (DBT *)&logrec, flags | DB_NOCOPY); |
---|
2388 | if (txnid != NULL && ret == 0) |
---|
2389 | txnid->last_lsn = *ret_lsnp; |
---|
2390 | #ifdef LOG_DIAGNOSTIC |
---|
2391 | if (ret != 0) |
---|
2392 | (void)__bam_rcuradj_print(dbenv, |
---|
2393 | (DBT *)&logrec, ret_lsnp, NULL, NULL); |
---|
2394 | #endif |
---|
2395 | __os_free(dbenv, logrec.data); |
---|
2396 | return (ret); |
---|
2397 | } |
---|
2398 | |
---|
2399 | /* |
---|
2400 | * PUBLIC: int __bam_rcuradj_getpgnos __P((DB_ENV *, DBT *, DB_LSN *, |
---|
2401 | * PUBLIC: db_recops, void *)); |
---|
2402 | */ |
---|
2403 | int |
---|
2404 | __bam_rcuradj_getpgnos(dbenv, rec, lsnp, notused1, summary) |
---|
2405 | DB_ENV *dbenv; |
---|
2406 | DBT *rec; |
---|
2407 | DB_LSN *lsnp; |
---|
2408 | db_recops notused1; |
---|
2409 | void *summary; |
---|
2410 | { |
---|
2411 | TXN_RECS *t; |
---|
2412 | int ret; |
---|
2413 | COMPQUIET(rec, NULL); |
---|
2414 | COMPQUIET(notused1, DB_TXN_ABORT); |
---|
2415 | |
---|
2416 | t = (TXN_RECS *)summary; |
---|
2417 | |
---|
2418 | if ((ret = __rep_check_alloc(dbenv, t, 1)) != 0) |
---|
2419 | return (ret); |
---|
2420 | |
---|
2421 | t->array[t->npages].flags = LSN_PAGE_NOLOCK; |
---|
2422 | t->array[t->npages].lsn = *lsnp; |
---|
2423 | t->array[t->npages].fid = DB_LOGFILEID_INVALID; |
---|
2424 | memset(&t->array[t->npages].pgdesc, 0, |
---|
2425 | sizeof(t->array[t->npages].pgdesc)); |
---|
2426 | |
---|
2427 | t->npages++; |
---|
2428 | |
---|
2429 | return (0); |
---|
2430 | } |
---|
2431 | |
---|
2432 | /* |
---|
2433 | * PUBLIC: int __bam_rcuradj_print __P((DB_ENV *, DBT *, DB_LSN *, |
---|
2434 | * PUBLIC: db_recops, void *)); |
---|
2435 | */ |
---|
2436 | int |
---|
2437 | __bam_rcuradj_print(dbenv, dbtp, lsnp, notused2, notused3) |
---|
2438 | DB_ENV *dbenv; |
---|
2439 | DBT *dbtp; |
---|
2440 | DB_LSN *lsnp; |
---|
2441 | db_recops notused2; |
---|
2442 | void *notused3; |
---|
2443 | { |
---|
2444 | __bam_rcuradj_args *argp; |
---|
2445 | int ret; |
---|
2446 | |
---|
2447 | notused2 = DB_TXN_ABORT; |
---|
2448 | notused3 = NULL; |
---|
2449 | |
---|
2450 | if ((ret = __bam_rcuradj_read(dbenv, dbtp->data, &argp)) != 0) |
---|
2451 | return (ret); |
---|
2452 | (void)printf( |
---|
2453 | "[%lu][%lu]__bam_rcuradj: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", |
---|
2454 | (u_long)lsnp->file, |
---|
2455 | (u_long)lsnp->offset, |
---|
2456 | (u_long)argp->type, |
---|
2457 | (u_long)argp->txnid->txnid, |
---|
2458 | (u_long)argp->prev_lsn.file, |
---|
2459 | (u_long)argp->prev_lsn.offset); |
---|
2460 | (void)printf("\tfileid: %ld\n", (long)argp->fileid); |
---|
2461 | (void)printf("\tmode: %ld\n", (long)argp->mode); |
---|
2462 | (void)printf("\troot: %ld\n", (long)argp->root); |
---|
2463 | (void)printf("\trecno: %ld\n", (long)argp->recno); |
---|
2464 | (void)printf("\torder: %ld\n", (long)argp->order); |
---|
2465 | (void)printf("\n"); |
---|
2466 | __os_free(dbenv, argp); |
---|
2467 | return (0); |
---|
2468 | } |
---|
2469 | |
---|
2470 | /* |
---|
2471 | * PUBLIC: int __bam_rcuradj_read __P((DB_ENV *, void *, |
---|
2472 | * PUBLIC: __bam_rcuradj_args **)); |
---|
2473 | */ |
---|
2474 | int |
---|
2475 | __bam_rcuradj_read(dbenv, recbuf, argpp) |
---|
2476 | DB_ENV *dbenv; |
---|
2477 | void *recbuf; |
---|
2478 | __bam_rcuradj_args **argpp; |
---|
2479 | { |
---|
2480 | __bam_rcuradj_args *argp; |
---|
2481 | u_int32_t uinttmp; |
---|
2482 | u_int8_t *bp; |
---|
2483 | int ret; |
---|
2484 | |
---|
2485 | if ((ret = __os_malloc(dbenv, |
---|
2486 | sizeof(__bam_rcuradj_args) + sizeof(DB_TXN), &argp)) != 0) |
---|
2487 | return (ret); |
---|
2488 | |
---|
2489 | argp->txnid = (DB_TXN *)&argp[1]; |
---|
2490 | |
---|
2491 | bp = recbuf; |
---|
2492 | memcpy(&argp->type, bp, sizeof(argp->type)); |
---|
2493 | bp += sizeof(argp->type); |
---|
2494 | |
---|
2495 | memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); |
---|
2496 | bp += sizeof(argp->txnid->txnid); |
---|
2497 | |
---|
2498 | memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); |
---|
2499 | bp += sizeof(DB_LSN); |
---|
2500 | |
---|
2501 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2502 | argp->fileid = (int32_t)uinttmp; |
---|
2503 | bp += sizeof(uinttmp); |
---|
2504 | |
---|
2505 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2506 | argp->mode = (ca_recno_arg)uinttmp; |
---|
2507 | bp += sizeof(uinttmp); |
---|
2508 | |
---|
2509 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2510 | argp->root = (db_pgno_t)uinttmp; |
---|
2511 | bp += sizeof(uinttmp); |
---|
2512 | |
---|
2513 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2514 | argp->recno = (db_recno_t)uinttmp; |
---|
2515 | bp += sizeof(uinttmp); |
---|
2516 | |
---|
2517 | memcpy(&uinttmp, bp, sizeof(uinttmp)); |
---|
2518 | argp->order = (u_int32_t)uinttmp; |
---|
2519 | bp += sizeof(uinttmp); |
---|
2520 | |
---|
2521 | *argpp = argp; |
---|
2522 | return (0); |
---|
2523 | } |
---|
2524 | |
---|
2525 | /* |
---|
2526 | * PUBLIC: int __bam_init_print __P((DB_ENV *, int (***)(DB_ENV *, |
---|
2527 | * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *)); |
---|
2528 | */ |
---|
2529 | int |
---|
2530 | __bam_init_print(dbenv, dtabp, dtabsizep) |
---|
2531 | DB_ENV *dbenv; |
---|
2532 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
2533 | size_t *dtabsizep; |
---|
2534 | { |
---|
2535 | int ret; |
---|
2536 | |
---|
2537 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2538 | __bam_split_print, DB___bam_split)) != 0) |
---|
2539 | return (ret); |
---|
2540 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2541 | __bam_rsplit_print, DB___bam_rsplit)) != 0) |
---|
2542 | return (ret); |
---|
2543 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2544 | __bam_adj_print, DB___bam_adj)) != 0) |
---|
2545 | return (ret); |
---|
2546 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2547 | __bam_cadjust_print, DB___bam_cadjust)) != 0) |
---|
2548 | return (ret); |
---|
2549 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2550 | __bam_cdel_print, DB___bam_cdel)) != 0) |
---|
2551 | return (ret); |
---|
2552 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2553 | __bam_repl_print, DB___bam_repl)) != 0) |
---|
2554 | return (ret); |
---|
2555 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2556 | __bam_root_print, DB___bam_root)) != 0) |
---|
2557 | return (ret); |
---|
2558 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2559 | __bam_curadj_print, DB___bam_curadj)) != 0) |
---|
2560 | return (ret); |
---|
2561 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2562 | __bam_rcuradj_print, DB___bam_rcuradj)) != 0) |
---|
2563 | return (ret); |
---|
2564 | return (0); |
---|
2565 | } |
---|
2566 | |
---|
2567 | /* |
---|
2568 | * PUBLIC: int __bam_init_getpgnos __P((DB_ENV *, int (***)(DB_ENV *, |
---|
2569 | * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *)); |
---|
2570 | */ |
---|
2571 | int |
---|
2572 | __bam_init_getpgnos(dbenv, dtabp, dtabsizep) |
---|
2573 | DB_ENV *dbenv; |
---|
2574 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
2575 | size_t *dtabsizep; |
---|
2576 | { |
---|
2577 | int ret; |
---|
2578 | |
---|
2579 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2580 | __bam_split_getpgnos, DB___bam_split)) != 0) |
---|
2581 | return (ret); |
---|
2582 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2583 | __bam_rsplit_getpgnos, DB___bam_rsplit)) != 0) |
---|
2584 | return (ret); |
---|
2585 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2586 | __bam_adj_getpgnos, DB___bam_adj)) != 0) |
---|
2587 | return (ret); |
---|
2588 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2589 | __bam_cadjust_getpgnos, DB___bam_cadjust)) != 0) |
---|
2590 | return (ret); |
---|
2591 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2592 | __bam_cdel_getpgnos, DB___bam_cdel)) != 0) |
---|
2593 | return (ret); |
---|
2594 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2595 | __bam_repl_getpgnos, DB___bam_repl)) != 0) |
---|
2596 | return (ret); |
---|
2597 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2598 | __bam_root_getpgnos, DB___bam_root)) != 0) |
---|
2599 | return (ret); |
---|
2600 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2601 | __bam_curadj_getpgnos, DB___bam_curadj)) != 0) |
---|
2602 | return (ret); |
---|
2603 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2604 | __bam_rcuradj_getpgnos, DB___bam_rcuradj)) != 0) |
---|
2605 | return (ret); |
---|
2606 | return (0); |
---|
2607 | } |
---|
2608 | |
---|
2609 | /* |
---|
2610 | * PUBLIC: int __bam_init_recover __P((DB_ENV *, int (***)(DB_ENV *, |
---|
2611 | * PUBLIC: DBT *, DB_LSN *, db_recops, void *), size_t *)); |
---|
2612 | */ |
---|
2613 | int |
---|
2614 | __bam_init_recover(dbenv, dtabp, dtabsizep) |
---|
2615 | DB_ENV *dbenv; |
---|
2616 | int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *)); |
---|
2617 | size_t *dtabsizep; |
---|
2618 | { |
---|
2619 | int ret; |
---|
2620 | |
---|
2621 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2622 | __bam_split_recover, DB___bam_split)) != 0) |
---|
2623 | return (ret); |
---|
2624 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2625 | __bam_rsplit_recover, DB___bam_rsplit)) != 0) |
---|
2626 | return (ret); |
---|
2627 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2628 | __bam_adj_recover, DB___bam_adj)) != 0) |
---|
2629 | return (ret); |
---|
2630 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2631 | __bam_cadjust_recover, DB___bam_cadjust)) != 0) |
---|
2632 | return (ret); |
---|
2633 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2634 | __bam_cdel_recover, DB___bam_cdel)) != 0) |
---|
2635 | return (ret); |
---|
2636 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2637 | __bam_repl_recover, DB___bam_repl)) != 0) |
---|
2638 | return (ret); |
---|
2639 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2640 | __bam_root_recover, DB___bam_root)) != 0) |
---|
2641 | return (ret); |
---|
2642 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2643 | __bam_curadj_recover, DB___bam_curadj)) != 0) |
---|
2644 | return (ret); |
---|
2645 | if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep, |
---|
2646 | __bam_rcuradj_recover, DB___bam_rcuradj)) != 0) |
---|
2647 | return (ret); |
---|
2648 | return (0); |
---|
2649 | } |
---|