1 /* Do not edit: automatically built by dist/db_gen.sh. */ 2 #include "config.h" 3 4 #ifndef NO_SYSTEM_INCLUDES 5 #include <ctype.h> 6 #include <errno.h> 7 #include <stddef.h> 8 #include <stdlib.h> 9 #include <string.h> 10 #endif 11 12 #include "db_int.h" 13 #include "db_page.h" 14 #include "db_dispatch.h" 15 #include "txn.h" 16 #include "db_am.h" 17 /* 18 * PUBLIC: int __txn_regop_log 19 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, 20 * PUBLIC: u_int32_t)); 21 */ 22 int __txn_regop_log(logp, txnid, ret_lsnp, flags, 23 opcode) 24 DB_LOG *logp; 25 DB_TXN *txnid; 26 DB_LSN *ret_lsnp; 27 u_int32_t flags; 28 u_int32_t opcode; 29 { 30 DBT logrec; 31 DB_LSN *lsnp, null_lsn; 32 u_int32_t rectype, txn_num; 33 int ret; 34 u_int8_t *bp; 35 36 rectype = DB_txn_regop; 37 txn_num = txnid == NULL ? 0 : txnid->txnid; 38 if (txnid == NULL) { 39 ZERO_LSN(null_lsn); 40 lsnp = &null_lsn; 41 } else 42 lsnp = &txnid->last_lsn; 43 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 44 + sizeof(opcode); 45 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) 46 return (ret); 47 48 bp = logrec.data; 49 memcpy(bp, &rectype, sizeof(rectype)); 50 bp += sizeof(rectype); 51 memcpy(bp, &txn_num, sizeof(txn_num)); 52 bp += sizeof(txn_num); 53 memcpy(bp, lsnp, sizeof(DB_LSN)); 54 bp += sizeof(DB_LSN); 55 memcpy(bp, &opcode, sizeof(opcode)); 56 bp += sizeof(opcode); 57 #ifdef DIAGNOSTIC 58 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) 59 fprintf(stderr, "Error in log record length"); 60 #endif 61 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); 62 if (txnid != NULL) 63 txnid->last_lsn = *ret_lsnp; 64 __os_free(logrec.data, 0); 65 return (ret); 66 } 67 68 /* 69 * PUBLIC: int __txn_regop_print 70 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 71 */ 72 int 73 __txn_regop_print(notused1, dbtp, lsnp, notused2, notused3) 74 DB_LOG *notused1; 75 DBT *dbtp; 76 DB_LSN *lsnp; 77 int notused2; 78 void *notused3; 79 { 80 __txn_regop_args *argp; 81 u_int32_t i; 82 u_int ch; 83 int ret; 84 85 i = 0; 86 ch = 0; 87 notused1 = NULL; 88 notused2 = 0; 89 notused3 = NULL; 90 91 if ((ret = __txn_regop_read(dbtp->data, &argp)) != 0) 92 return (ret); 93 printf("[%lu][%lu]txn_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 94 (u_long)lsnp->file, 95 (u_long)lsnp->offset, 96 (u_long)argp->type, 97 (u_long)argp->txnid->txnid, 98 (u_long)argp->prev_lsn.file, 99 (u_long)argp->prev_lsn.offset); 100 printf("\topcode: %lu\n", (u_long)argp->opcode); 101 printf("\n"); 102 __os_free(argp, 0); 103 return (0); 104 } 105 106 /* 107 * PUBLIC: int __txn_regop_read __P((void *, __txn_regop_args **)); 108 */ 109 int 110 __txn_regop_read(recbuf, argpp) 111 void *recbuf; 112 __txn_regop_args **argpp; 113 { 114 __txn_regop_args *argp; 115 u_int8_t *bp; 116 int ret; 117 118 ret = __os_malloc(sizeof(__txn_regop_args) + 119 sizeof(DB_TXN), NULL, &argp); 120 if (ret != 0) 121 return (ret); 122 argp->txnid = (DB_TXN *)&argp[1]; 123 bp = recbuf; 124 memcpy(&argp->type, bp, sizeof(argp->type)); 125 bp += sizeof(argp->type); 126 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 127 bp += sizeof(argp->txnid->txnid); 128 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 129 bp += sizeof(DB_LSN); 130 memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 131 bp += sizeof(argp->opcode); 132 *argpp = argp; 133 return (0); 134 } 135 136 /* 137 * PUBLIC: int __txn_ckp_log 138 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, 139 * PUBLIC: DB_LSN *, DB_LSN *)); 140 */ 141 int __txn_ckp_log(logp, txnid, ret_lsnp, flags, 142 ckp_lsn, last_ckp) 143 DB_LOG *logp; 144 DB_TXN *txnid; 145 DB_LSN *ret_lsnp; 146 u_int32_t flags; 147 DB_LSN * ckp_lsn; 148 DB_LSN * last_ckp; 149 { 150 DBT logrec; 151 DB_LSN *lsnp, null_lsn; 152 u_int32_t rectype, txn_num; 153 int ret; 154 u_int8_t *bp; 155 156 rectype = DB_txn_ckp; 157 txn_num = txnid == NULL ? 0 : txnid->txnid; 158 if (txnid == NULL) { 159 ZERO_LSN(null_lsn); 160 lsnp = &null_lsn; 161 } else 162 lsnp = &txnid->last_lsn; 163 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 164 + sizeof(*ckp_lsn) 165 + sizeof(*last_ckp); 166 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) 167 return (ret); 168 169 bp = logrec.data; 170 memcpy(bp, &rectype, sizeof(rectype)); 171 bp += sizeof(rectype); 172 memcpy(bp, &txn_num, sizeof(txn_num)); 173 bp += sizeof(txn_num); 174 memcpy(bp, lsnp, sizeof(DB_LSN)); 175 bp += sizeof(DB_LSN); 176 if (ckp_lsn != NULL) 177 memcpy(bp, ckp_lsn, sizeof(*ckp_lsn)); 178 else 179 memset(bp, 0, sizeof(*ckp_lsn)); 180 bp += sizeof(*ckp_lsn); 181 if (last_ckp != NULL) 182 memcpy(bp, last_ckp, sizeof(*last_ckp)); 183 else 184 memset(bp, 0, sizeof(*last_ckp)); 185 bp += sizeof(*last_ckp); 186 #ifdef DIAGNOSTIC 187 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) 188 fprintf(stderr, "Error in log record length"); 189 #endif 190 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); 191 if (txnid != NULL) 192 txnid->last_lsn = *ret_lsnp; 193 __os_free(logrec.data, 0); 194 return (ret); 195 } 196 197 /* 198 * PUBLIC: int __txn_ckp_print 199 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 200 */ 201 int 202 __txn_ckp_print(notused1, dbtp, lsnp, notused2, notused3) 203 DB_LOG *notused1; 204 DBT *dbtp; 205 DB_LSN *lsnp; 206 int notused2; 207 void *notused3; 208 { 209 __txn_ckp_args *argp; 210 u_int32_t i; 211 u_int ch; 212 int ret; 213 214 i = 0; 215 ch = 0; 216 notused1 = NULL; 217 notused2 = 0; 218 notused3 = NULL; 219 220 if ((ret = __txn_ckp_read(dbtp->data, &argp)) != 0) 221 return (ret); 222 printf("[%lu][%lu]txn_ckp: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 223 (u_long)lsnp->file, 224 (u_long)lsnp->offset, 225 (u_long)argp->type, 226 (u_long)argp->txnid->txnid, 227 (u_long)argp->prev_lsn.file, 228 (u_long)argp->prev_lsn.offset); 229 printf("\tckp_lsn: [%lu][%lu]\n", 230 (u_long)argp->ckp_lsn.file, (u_long)argp->ckp_lsn.offset); 231 printf("\tlast_ckp: [%lu][%lu]\n", 232 (u_long)argp->last_ckp.file, (u_long)argp->last_ckp.offset); 233 printf("\n"); 234 __os_free(argp, 0); 235 return (0); 236 } 237 238 /* 239 * PUBLIC: int __txn_ckp_read __P((void *, __txn_ckp_args **)); 240 */ 241 int 242 __txn_ckp_read(recbuf, argpp) 243 void *recbuf; 244 __txn_ckp_args **argpp; 245 { 246 __txn_ckp_args *argp; 247 u_int8_t *bp; 248 int ret; 249 250 ret = __os_malloc(sizeof(__txn_ckp_args) + 251 sizeof(DB_TXN), NULL, &argp); 252 if (ret != 0) 253 return (ret); 254 argp->txnid = (DB_TXN *)&argp[1]; 255 bp = recbuf; 256 memcpy(&argp->type, bp, sizeof(argp->type)); 257 bp += sizeof(argp->type); 258 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 259 bp += sizeof(argp->txnid->txnid); 260 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 261 bp += sizeof(DB_LSN); 262 memcpy(&argp->ckp_lsn, bp, sizeof(argp->ckp_lsn)); 263 bp += sizeof(argp->ckp_lsn); 264 memcpy(&argp->last_ckp, bp, sizeof(argp->last_ckp)); 265 bp += sizeof(argp->last_ckp); 266 *argpp = argp; 267 return (0); 268 } 269 270 /* 271 * PUBLIC: int __txn_xa_regop_log 272 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, 273 * PUBLIC: u_int32_t, const DBT *, int32_t, u_int32_t, 274 * PUBLIC: u_int32_t, DB_LSN *)); 275 */ 276 int __txn_xa_regop_log(logp, txnid, ret_lsnp, flags, 277 opcode, xid, formatID, gtrid, bqual, begin_lsn) 278 DB_LOG *logp; 279 DB_TXN *txnid; 280 DB_LSN *ret_lsnp; 281 u_int32_t flags; 282 u_int32_t opcode; 283 const DBT *xid; 284 int32_t formatID; 285 u_int32_t gtrid; 286 u_int32_t bqual; 287 DB_LSN * begin_lsn; 288 { 289 DBT logrec; 290 DB_LSN *lsnp, null_lsn; 291 u_int32_t zero; 292 u_int32_t rectype, txn_num; 293 int ret; 294 u_int8_t *bp; 295 296 rectype = DB_txn_xa_regop; 297 txn_num = txnid == NULL ? 0 : txnid->txnid; 298 if (txnid == NULL) { 299 ZERO_LSN(null_lsn); 300 lsnp = &null_lsn; 301 } else 302 lsnp = &txnid->last_lsn; 303 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 304 + sizeof(opcode) 305 + sizeof(u_int32_t) + (xid == NULL ? 0 : xid->size) 306 + sizeof(formatID) 307 + sizeof(gtrid) 308 + sizeof(bqual) 309 + sizeof(*begin_lsn); 310 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) 311 return (ret); 312 313 bp = logrec.data; 314 memcpy(bp, &rectype, sizeof(rectype)); 315 bp += sizeof(rectype); 316 memcpy(bp, &txn_num, sizeof(txn_num)); 317 bp += sizeof(txn_num); 318 memcpy(bp, lsnp, sizeof(DB_LSN)); 319 bp += sizeof(DB_LSN); 320 memcpy(bp, &opcode, sizeof(opcode)); 321 bp += sizeof(opcode); 322 if (xid == NULL) { 323 zero = 0; 324 memcpy(bp, &zero, sizeof(u_int32_t)); 325 bp += sizeof(u_int32_t); 326 } else { 327 memcpy(bp, &xid->size, sizeof(xid->size)); 328 bp += sizeof(xid->size); 329 memcpy(bp, xid->data, xid->size); 330 bp += xid->size; 331 } 332 memcpy(bp, &formatID, sizeof(formatID)); 333 bp += sizeof(formatID); 334 memcpy(bp, >rid, sizeof(gtrid)); 335 bp += sizeof(gtrid); 336 memcpy(bp, &bqual, sizeof(bqual)); 337 bp += sizeof(bqual); 338 if (begin_lsn != NULL) 339 memcpy(bp, begin_lsn, sizeof(*begin_lsn)); 340 else 341 memset(bp, 0, sizeof(*begin_lsn)); 342 bp += sizeof(*begin_lsn); 343 #ifdef DIAGNOSTIC 344 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) 345 fprintf(stderr, "Error in log record length"); 346 #endif 347 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); 348 if (txnid != NULL) 349 txnid->last_lsn = *ret_lsnp; 350 __os_free(logrec.data, 0); 351 return (ret); 352 } 353 354 /* 355 * PUBLIC: int __txn_xa_regop_print 356 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 357 */ 358 int 359 __txn_xa_regop_print(notused1, dbtp, lsnp, notused2, notused3) 360 DB_LOG *notused1; 361 DBT *dbtp; 362 DB_LSN *lsnp; 363 int notused2; 364 void *notused3; 365 { 366 __txn_xa_regop_args *argp; 367 u_int32_t i; 368 u_int ch; 369 int ret; 370 371 i = 0; 372 ch = 0; 373 notused1 = NULL; 374 notused2 = 0; 375 notused3 = NULL; 376 377 if ((ret = __txn_xa_regop_read(dbtp->data, &argp)) != 0) 378 return (ret); 379 printf("[%lu][%lu]txn_xa_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 380 (u_long)lsnp->file, 381 (u_long)lsnp->offset, 382 (u_long)argp->type, 383 (u_long)argp->txnid->txnid, 384 (u_long)argp->prev_lsn.file, 385 (u_long)argp->prev_lsn.offset); 386 printf("\topcode: %lu\n", (u_long)argp->opcode); 387 printf("\txid: "); 388 for (i = 0; i < argp->xid.size; i++) { 389 ch = ((u_int8_t *)argp->xid.data)[i]; 390 if (isprint(ch) || ch == 0xa) 391 putchar(ch); 392 else 393 printf("%#x ", ch); 394 } 395 printf("\n"); 396 printf("\tformatID: %ld\n", (long)argp->formatID); 397 printf("\tgtrid: %u\n", argp->gtrid); 398 printf("\tbqual: %u\n", argp->bqual); 399 printf("\tbegin_lsn: [%lu][%lu]\n", 400 (u_long)argp->begin_lsn.file, (u_long)argp->begin_lsn.offset); 401 printf("\n"); 402 __os_free(argp, 0); 403 return (0); 404 } 405 406 /* 407 * PUBLIC: int __txn_xa_regop_read __P((void *, __txn_xa_regop_args **)); 408 */ 409 int 410 __txn_xa_regop_read(recbuf, argpp) 411 void *recbuf; 412 __txn_xa_regop_args **argpp; 413 { 414 __txn_xa_regop_args *argp; 415 u_int8_t *bp; 416 int ret; 417 418 ret = __os_malloc(sizeof(__txn_xa_regop_args) + 419 sizeof(DB_TXN), NULL, &argp); 420 if (ret != 0) 421 return (ret); 422 argp->txnid = (DB_TXN *)&argp[1]; 423 bp = recbuf; 424 memcpy(&argp->type, bp, sizeof(argp->type)); 425 bp += sizeof(argp->type); 426 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 427 bp += sizeof(argp->txnid->txnid); 428 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 429 bp += sizeof(DB_LSN); 430 memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 431 bp += sizeof(argp->opcode); 432 memcpy(&argp->xid.size, bp, sizeof(u_int32_t)); 433 bp += sizeof(u_int32_t); 434 argp->xid.data = bp; 435 bp += argp->xid.size; 436 memcpy(&argp->formatID, bp, sizeof(argp->formatID)); 437 bp += sizeof(argp->formatID); 438 memcpy(&argp->gtrid, bp, sizeof(argp->gtrid)); 439 bp += sizeof(argp->gtrid); 440 memcpy(&argp->bqual, bp, sizeof(argp->bqual)); 441 bp += sizeof(argp->bqual); 442 memcpy(&argp->begin_lsn, bp, sizeof(argp->begin_lsn)); 443 bp += sizeof(argp->begin_lsn); 444 *argpp = argp; 445 return (0); 446 } 447 448 /* 449 * PUBLIC: int __txn_child_log 450 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t, 451 * PUBLIC: u_int32_t, u_int32_t)); 452 */ 453 int __txn_child_log(logp, txnid, ret_lsnp, flags, 454 opcode, parent) 455 DB_LOG *logp; 456 DB_TXN *txnid; 457 DB_LSN *ret_lsnp; 458 u_int32_t flags; 459 u_int32_t opcode; 460 u_int32_t parent; 461 { 462 DBT logrec; 463 DB_LSN *lsnp, null_lsn; 464 u_int32_t rectype, txn_num; 465 int ret; 466 u_int8_t *bp; 467 468 rectype = DB_txn_child; 469 txn_num = txnid == NULL ? 0 : txnid->txnid; 470 if (txnid == NULL) { 471 ZERO_LSN(null_lsn); 472 lsnp = &null_lsn; 473 } else 474 lsnp = &txnid->last_lsn; 475 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 476 + sizeof(opcode) 477 + sizeof(parent); 478 if ((ret = __os_malloc(logrec.size, NULL, &logrec.data)) != 0) 479 return (ret); 480 481 bp = logrec.data; 482 memcpy(bp, &rectype, sizeof(rectype)); 483 bp += sizeof(rectype); 484 memcpy(bp, &txn_num, sizeof(txn_num)); 485 bp += sizeof(txn_num); 486 memcpy(bp, lsnp, sizeof(DB_LSN)); 487 bp += sizeof(DB_LSN); 488 memcpy(bp, &opcode, sizeof(opcode)); 489 bp += sizeof(opcode); 490 memcpy(bp, &parent, sizeof(parent)); 491 bp += sizeof(parent); 492 #ifdef DIAGNOSTIC 493 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size) 494 fprintf(stderr, "Error in log record length"); 495 #endif 496 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags); 497 if (txnid != NULL) 498 txnid->last_lsn = *ret_lsnp; 499 __os_free(logrec.data, 0); 500 return (ret); 501 } 502 503 /* 504 * PUBLIC: int __txn_child_print 505 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *)); 506 */ 507 int 508 __txn_child_print(notused1, dbtp, lsnp, notused2, notused3) 509 DB_LOG *notused1; 510 DBT *dbtp; 511 DB_LSN *lsnp; 512 int notused2; 513 void *notused3; 514 { 515 __txn_child_args *argp; 516 u_int32_t i; 517 u_int ch; 518 int ret; 519 520 i = 0; 521 ch = 0; 522 notused1 = NULL; 523 notused2 = 0; 524 notused3 = NULL; 525 526 if ((ret = __txn_child_read(dbtp->data, &argp)) != 0) 527 return (ret); 528 printf("[%lu][%lu]txn_child: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 529 (u_long)lsnp->file, 530 (u_long)lsnp->offset, 531 (u_long)argp->type, 532 (u_long)argp->txnid->txnid, 533 (u_long)argp->prev_lsn.file, 534 (u_long)argp->prev_lsn.offset); 535 printf("\topcode: %lu\n", (u_long)argp->opcode); 536 printf("\tparent: %lu\n", (u_long)argp->parent); 537 printf("\n"); 538 __os_free(argp, 0); 539 return (0); 540 } 541 542 /* 543 * PUBLIC: int __txn_child_read __P((void *, __txn_child_args **)); 544 */ 545 int 546 __txn_child_read(recbuf, argpp) 547 void *recbuf; 548 __txn_child_args **argpp; 549 { 550 __txn_child_args *argp; 551 u_int8_t *bp; 552 int ret; 553 554 ret = __os_malloc(sizeof(__txn_child_args) + 555 sizeof(DB_TXN), NULL, &argp); 556 if (ret != 0) 557 return (ret); 558 argp->txnid = (DB_TXN *)&argp[1]; 559 bp = recbuf; 560 memcpy(&argp->type, bp, sizeof(argp->type)); 561 bp += sizeof(argp->type); 562 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 563 bp += sizeof(argp->txnid->txnid); 564 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 565 bp += sizeof(DB_LSN); 566 memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 567 bp += sizeof(argp->opcode); 568 memcpy(&argp->parent, bp, sizeof(argp->parent)); 569 bp += sizeof(argp->parent); 570 *argpp = argp; 571 return (0); 572 } 573 574 /* 575 * PUBLIC: int __txn_init_print __P((DB_ENV *)); 576 */ 577 int 578 __txn_init_print(dbenv) 579 DB_ENV *dbenv; 580 { 581 int ret; 582 583 if ((ret = __db_add_recovery(dbenv, 584 __txn_regop_print, DB_txn_regop)) != 0) 585 return (ret); 586 if ((ret = __db_add_recovery(dbenv, 587 __txn_ckp_print, DB_txn_ckp)) != 0) 588 return (ret); 589 if ((ret = __db_add_recovery(dbenv, 590 __txn_xa_regop_print, DB_txn_xa_regop)) != 0) 591 return (ret); 592 if ((ret = __db_add_recovery(dbenv, 593 __txn_child_print, DB_txn_child)) != 0) 594 return (ret); 595 return (0); 596 } 597 598 /* 599 * PUBLIC: int __txn_init_recover __P((DB_ENV *)); 600 */ 601 int 602 __txn_init_recover(dbenv) 603 DB_ENV *dbenv; 604 { 605 int ret; 606 607 if ((ret = __db_add_recovery(dbenv, 608 __txn_regop_recover, DB_txn_regop)) != 0) 609 return (ret); 610 if ((ret = __db_add_recovery(dbenv, 611 __txn_ckp_recover, DB_txn_ckp)) != 0) 612 return (ret); 613 if ((ret = __db_add_recovery(dbenv, 614 __txn_xa_regop_recover, DB_txn_xa_regop)) != 0) 615 return (ret); 616 if ((ret = __db_add_recovery(dbenv, 617 __txn_child_recover, DB_txn_child)) != 0) 618 return (ret); 619 return (0); 620 } 621 622