1/* Do not edit: automatically built by gen_rec.awk. */ 2 3#include "db_config.h" 4#include "db_int.h" 5#include "dbinc/crypto.h" 6#include "dbinc/db_page.h" 7#include "dbinc/db_am.h" 8#include "dbinc/log.h" 9#include "dbinc/txn.h" 10#include "dbinc/fop.h" 11 12/* 13 * PUBLIC: int __fop_create_read __P((ENV *, void *, __fop_create_args **)); 14 */ 15int 16__fop_create_read(env, recbuf, argpp) 17 ENV *env; 18 void *recbuf; 19 __fop_create_args **argpp; 20{ 21 __fop_create_args *argp; 22 u_int8_t *bp; 23 int ret; 24 25 if ((ret = __os_malloc(env, 26 sizeof(__fop_create_args) + sizeof(DB_TXN), &argp)) != 0) 27 return (ret); 28 bp = recbuf; 29 argp->txnp = (DB_TXN *)&argp[1]; 30 memset(argp->txnp, 0, sizeof(DB_TXN)); 31 32 LOGCOPY_32(env, &argp->type, bp); 33 bp += sizeof(argp->type); 34 35 LOGCOPY_32(env, &argp->txnp->txnid, bp); 36 bp += sizeof(argp->txnp->txnid); 37 38 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 39 bp += sizeof(DB_LSN); 40 41 memset(&argp->name, 0, sizeof(argp->name)); 42 LOGCOPY_32(env,&argp->name.size, bp); 43 bp += sizeof(u_int32_t); 44 argp->name.data = bp; 45 bp += argp->name.size; 46 47 LOGCOPY_32(env, &argp->appname, bp); 48 bp += sizeof(argp->appname); 49 50 LOGCOPY_32(env, &argp->mode, bp); 51 bp += sizeof(argp->mode); 52 53 *argpp = argp; 54 return (ret); 55} 56 57/* 58 * PUBLIC: int __fop_create_log __P((ENV *, DB_TXN *, DB_LSN *, 59 * PUBLIC: u_int32_t, const DBT *, u_int32_t, u_int32_t)); 60 */ 61int 62__fop_create_log(env, txnp, ret_lsnp, flags, 63 name, appname, mode) 64 ENV *env; 65 DB_TXN *txnp; 66 DB_LSN *ret_lsnp; 67 u_int32_t flags; 68 const DBT *name; 69 u_int32_t appname; 70 u_int32_t mode; 71{ 72 DBT logrec; 73 DB_LSN *lsnp, null_lsn, *rlsnp; 74 DB_TXNLOGREC *lr; 75 u_int32_t zero, rectype, txn_num; 76 u_int npad; 77 u_int8_t *bp; 78 int is_durable, ret; 79 80 COMPQUIET(lr, NULL); 81 82 rlsnp = ret_lsnp; 83 rectype = DB___fop_create; 84 npad = 0; 85 ret = 0; 86 87 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 88 if (txnp == NULL) 89 return (0); 90 if (txnp == NULL) 91 return (0); 92 is_durable = 0; 93 } else 94 is_durable = 1; 95 96 if (txnp == NULL) { 97 txn_num = 0; 98 lsnp = &null_lsn; 99 null_lsn.file = null_lsn.offset = 0; 100 } else { 101 if (TAILQ_FIRST(&txnp->kids) != NULL && 102 (ret = __txn_activekids(env, rectype, txnp)) != 0) 103 return (ret); 104 /* 105 * We need to assign begin_lsn while holding region mutex. 106 * That assignment is done inside the DbEnv->log_put call, 107 * so pass in the appropriate memory location to be filled 108 * in by the log_put code. 109 */ 110 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 111 txn_num = txnp->txnid; 112 } 113 114 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 115 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 116 + sizeof(u_int32_t) 117 + sizeof(u_int32_t); 118 if (CRYPTO_ON(env)) { 119 npad = env->crypto_handle->adj_size(logrec.size); 120 logrec.size += npad; 121 } 122 123 if (is_durable || txnp == NULL) { 124 if ((ret = 125 __os_malloc(env, logrec.size, &logrec.data)) != 0) 126 return (ret); 127 } else { 128 if ((ret = __os_malloc(env, 129 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 130 return (ret); 131#ifdef DIAGNOSTIC 132 if ((ret = 133 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 134 __os_free(env, lr); 135 return (ret); 136 } 137#else 138 logrec.data = lr->data; 139#endif 140 } 141 if (npad > 0) 142 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 143 144 bp = logrec.data; 145 146 LOGCOPY_32(env, bp, &rectype); 147 bp += sizeof(rectype); 148 149 LOGCOPY_32(env, bp, &txn_num); 150 bp += sizeof(txn_num); 151 152 LOGCOPY_FROMLSN(env, bp, lsnp); 153 bp += sizeof(DB_LSN); 154 155 if (name == NULL) { 156 zero = 0; 157 LOGCOPY_32(env, bp, &zero); 158 bp += sizeof(u_int32_t); 159 } else { 160 LOGCOPY_32(env, bp, &name->size); 161 bp += sizeof(name->size); 162 memcpy(bp, name->data, name->size); 163 bp += name->size; 164 } 165 166 LOGCOPY_32(env, bp, &appname); 167 bp += sizeof(appname); 168 169 LOGCOPY_32(env, bp, &mode); 170 bp += sizeof(mode); 171 172 DB_ASSERT(env, 173 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 174 175 if (is_durable || txnp == NULL) { 176 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 177 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 178 *lsnp = *rlsnp; 179 if (rlsnp != ret_lsnp) 180 *ret_lsnp = *rlsnp; 181 } 182 } else { 183 ret = 0; 184#ifdef DIAGNOSTIC 185 /* 186 * Set the debug bit if we are going to log non-durable 187 * transactions so they will be ignored by recovery. 188 */ 189 memcpy(lr->data, logrec.data, logrec.size); 190 rectype |= DB_debug_FLAG; 191 LOGCOPY_32(env, logrec.data, &rectype); 192 193 if (!IS_REP_CLIENT(env)) 194 ret = __log_put(env, 195 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 196#endif 197 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 198 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 199 LSN_NOT_LOGGED(*ret_lsnp); 200 } 201 202#ifdef LOG_DIAGNOSTIC 203 if (ret != 0) 204 (void)__fop_create_print(env, 205 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 206#endif 207 208#ifdef DIAGNOSTIC 209 __os_free(env, logrec.data); 210#else 211 if (is_durable || txnp == NULL) 212 __os_free(env, logrec.data); 213#endif 214 return (ret); 215} 216 217/* 218 * PUBLIC: int __fop_remove_read __P((ENV *, void *, __fop_remove_args **)); 219 */ 220int 221__fop_remove_read(env, recbuf, argpp) 222 ENV *env; 223 void *recbuf; 224 __fop_remove_args **argpp; 225{ 226 __fop_remove_args *argp; 227 u_int8_t *bp; 228 int ret; 229 230 if ((ret = __os_malloc(env, 231 sizeof(__fop_remove_args) + sizeof(DB_TXN), &argp)) != 0) 232 return (ret); 233 bp = recbuf; 234 argp->txnp = (DB_TXN *)&argp[1]; 235 memset(argp->txnp, 0, sizeof(DB_TXN)); 236 237 LOGCOPY_32(env, &argp->type, bp); 238 bp += sizeof(argp->type); 239 240 LOGCOPY_32(env, &argp->txnp->txnid, bp); 241 bp += sizeof(argp->txnp->txnid); 242 243 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 244 bp += sizeof(DB_LSN); 245 246 memset(&argp->name, 0, sizeof(argp->name)); 247 LOGCOPY_32(env,&argp->name.size, bp); 248 bp += sizeof(u_int32_t); 249 argp->name.data = bp; 250 bp += argp->name.size; 251 252 memset(&argp->fid, 0, sizeof(argp->fid)); 253 LOGCOPY_32(env,&argp->fid.size, bp); 254 bp += sizeof(u_int32_t); 255 argp->fid.data = bp; 256 bp += argp->fid.size; 257 258 LOGCOPY_32(env, &argp->appname, bp); 259 bp += sizeof(argp->appname); 260 261 *argpp = argp; 262 return (ret); 263} 264 265/* 266 * PUBLIC: int __fop_remove_log __P((ENV *, DB_TXN *, DB_LSN *, 267 * PUBLIC: u_int32_t, const DBT *, const DBT *, u_int32_t)); 268 */ 269int 270__fop_remove_log(env, txnp, ret_lsnp, flags, 271 name, fid, appname) 272 ENV *env; 273 DB_TXN *txnp; 274 DB_LSN *ret_lsnp; 275 u_int32_t flags; 276 const DBT *name; 277 const DBT *fid; 278 u_int32_t appname; 279{ 280 DBT logrec; 281 DB_LSN *lsnp, null_lsn, *rlsnp; 282 DB_TXNLOGREC *lr; 283 u_int32_t zero, rectype, txn_num; 284 u_int npad; 285 u_int8_t *bp; 286 int is_durable, ret; 287 288 COMPQUIET(lr, NULL); 289 290 rlsnp = ret_lsnp; 291 rectype = DB___fop_remove; 292 npad = 0; 293 ret = 0; 294 295 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 296 if (txnp == NULL) 297 return (0); 298 if (txnp == NULL) 299 return (0); 300 is_durable = 0; 301 } else 302 is_durable = 1; 303 304 if (txnp == NULL) { 305 txn_num = 0; 306 lsnp = &null_lsn; 307 null_lsn.file = null_lsn.offset = 0; 308 } else { 309 if (TAILQ_FIRST(&txnp->kids) != NULL && 310 (ret = __txn_activekids(env, rectype, txnp)) != 0) 311 return (ret); 312 /* 313 * We need to assign begin_lsn while holding region mutex. 314 * That assignment is done inside the DbEnv->log_put call, 315 * so pass in the appropriate memory location to be filled 316 * in by the log_put code. 317 */ 318 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 319 txn_num = txnp->txnid; 320 } 321 322 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 323 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 324 + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size) 325 + sizeof(u_int32_t); 326 if (CRYPTO_ON(env)) { 327 npad = env->crypto_handle->adj_size(logrec.size); 328 logrec.size += npad; 329 } 330 331 if (is_durable || txnp == NULL) { 332 if ((ret = 333 __os_malloc(env, logrec.size, &logrec.data)) != 0) 334 return (ret); 335 } else { 336 if ((ret = __os_malloc(env, 337 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 338 return (ret); 339#ifdef DIAGNOSTIC 340 if ((ret = 341 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 342 __os_free(env, lr); 343 return (ret); 344 } 345#else 346 logrec.data = lr->data; 347#endif 348 } 349 if (npad > 0) 350 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 351 352 bp = logrec.data; 353 354 LOGCOPY_32(env, bp, &rectype); 355 bp += sizeof(rectype); 356 357 LOGCOPY_32(env, bp, &txn_num); 358 bp += sizeof(txn_num); 359 360 LOGCOPY_FROMLSN(env, bp, lsnp); 361 bp += sizeof(DB_LSN); 362 363 if (name == NULL) { 364 zero = 0; 365 LOGCOPY_32(env, bp, &zero); 366 bp += sizeof(u_int32_t); 367 } else { 368 LOGCOPY_32(env, bp, &name->size); 369 bp += sizeof(name->size); 370 memcpy(bp, name->data, name->size); 371 bp += name->size; 372 } 373 374 if (fid == NULL) { 375 zero = 0; 376 LOGCOPY_32(env, bp, &zero); 377 bp += sizeof(u_int32_t); 378 } else { 379 LOGCOPY_32(env, bp, &fid->size); 380 bp += sizeof(fid->size); 381 memcpy(bp, fid->data, fid->size); 382 bp += fid->size; 383 } 384 385 LOGCOPY_32(env, bp, &appname); 386 bp += sizeof(appname); 387 388 DB_ASSERT(env, 389 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 390 391 if (is_durable || txnp == NULL) { 392 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 393 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 394 *lsnp = *rlsnp; 395 if (rlsnp != ret_lsnp) 396 *ret_lsnp = *rlsnp; 397 } 398 } else { 399 ret = 0; 400#ifdef DIAGNOSTIC 401 /* 402 * Set the debug bit if we are going to log non-durable 403 * transactions so they will be ignored by recovery. 404 */ 405 memcpy(lr->data, logrec.data, logrec.size); 406 rectype |= DB_debug_FLAG; 407 LOGCOPY_32(env, logrec.data, &rectype); 408 409 if (!IS_REP_CLIENT(env)) 410 ret = __log_put(env, 411 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 412#endif 413 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 414 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 415 LSN_NOT_LOGGED(*ret_lsnp); 416 } 417 418#ifdef LOG_DIAGNOSTIC 419 if (ret != 0) 420 (void)__fop_remove_print(env, 421 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 422#endif 423 424#ifdef DIAGNOSTIC 425 __os_free(env, logrec.data); 426#else 427 if (is_durable || txnp == NULL) 428 __os_free(env, logrec.data); 429#endif 430 return (ret); 431} 432 433/* 434 * PUBLIC: int __fop_write_read __P((ENV *, void *, __fop_write_args **)); 435 */ 436int 437__fop_write_read(env, recbuf, argpp) 438 ENV *env; 439 void *recbuf; 440 __fop_write_args **argpp; 441{ 442 __fop_write_args *argp; 443 u_int32_t uinttmp; 444 u_int8_t *bp; 445 int ret; 446 447 if ((ret = __os_malloc(env, 448 sizeof(__fop_write_args) + sizeof(DB_TXN), &argp)) != 0) 449 return (ret); 450 bp = recbuf; 451 argp->txnp = (DB_TXN *)&argp[1]; 452 memset(argp->txnp, 0, sizeof(DB_TXN)); 453 454 LOGCOPY_32(env, &argp->type, bp); 455 bp += sizeof(argp->type); 456 457 LOGCOPY_32(env, &argp->txnp->txnid, bp); 458 bp += sizeof(argp->txnp->txnid); 459 460 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 461 bp += sizeof(DB_LSN); 462 463 memset(&argp->name, 0, sizeof(argp->name)); 464 LOGCOPY_32(env,&argp->name.size, bp); 465 bp += sizeof(u_int32_t); 466 argp->name.data = bp; 467 bp += argp->name.size; 468 469 LOGCOPY_32(env, &argp->appname, bp); 470 bp += sizeof(argp->appname); 471 472 LOGCOPY_32(env, &argp->pgsize, bp); 473 bp += sizeof(argp->pgsize); 474 475 LOGCOPY_32(env, &uinttmp, bp); 476 argp->pageno = (db_pgno_t)uinttmp; 477 bp += sizeof(uinttmp); 478 479 LOGCOPY_32(env, &argp->offset, bp); 480 bp += sizeof(argp->offset); 481 482 memset(&argp->page, 0, sizeof(argp->page)); 483 LOGCOPY_32(env,&argp->page.size, bp); 484 bp += sizeof(u_int32_t); 485 argp->page.data = bp; 486 bp += argp->page.size; 487 488 LOGCOPY_32(env, &argp->flag, bp); 489 bp += sizeof(argp->flag); 490 491 *argpp = argp; 492 return (ret); 493} 494 495/* 496 * PUBLIC: int __fop_write_log __P((ENV *, DB_TXN *, DB_LSN *, 497 * PUBLIC: u_int32_t, const DBT *, u_int32_t, u_int32_t, db_pgno_t, 498 * PUBLIC: u_int32_t, const DBT *, u_int32_t)); 499 */ 500int 501__fop_write_log(env, txnp, ret_lsnp, flags, 502 name, appname, pgsize, pageno, offset, page, 503 flag) 504 ENV *env; 505 DB_TXN *txnp; 506 DB_LSN *ret_lsnp; 507 u_int32_t flags; 508 const DBT *name; 509 u_int32_t appname; 510 u_int32_t pgsize; 511 db_pgno_t pageno; 512 u_int32_t offset; 513 const DBT *page; 514 u_int32_t flag; 515{ 516 DBT logrec; 517 DB_LSN *lsnp, null_lsn, *rlsnp; 518 DB_TXNLOGREC *lr; 519 u_int32_t zero, uinttmp, rectype, txn_num; 520 u_int npad; 521 u_int8_t *bp; 522 int is_durable, ret; 523 524 COMPQUIET(lr, NULL); 525 526 rlsnp = ret_lsnp; 527 rectype = DB___fop_write; 528 npad = 0; 529 ret = 0; 530 531 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 532 if (txnp == NULL) 533 return (0); 534 if (txnp == NULL) 535 return (0); 536 is_durable = 0; 537 } else 538 is_durable = 1; 539 540 if (txnp == NULL) { 541 txn_num = 0; 542 lsnp = &null_lsn; 543 null_lsn.file = null_lsn.offset = 0; 544 } else { 545 if (TAILQ_FIRST(&txnp->kids) != NULL && 546 (ret = __txn_activekids(env, rectype, txnp)) != 0) 547 return (ret); 548 /* 549 * We need to assign begin_lsn while holding region mutex. 550 * That assignment is done inside the DbEnv->log_put call, 551 * so pass in the appropriate memory location to be filled 552 * in by the log_put code. 553 */ 554 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 555 txn_num = txnp->txnid; 556 } 557 558 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 559 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 560 + sizeof(u_int32_t) 561 + sizeof(u_int32_t) 562 + sizeof(u_int32_t) 563 + sizeof(u_int32_t) 564 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size) 565 + sizeof(u_int32_t); 566 if (CRYPTO_ON(env)) { 567 npad = env->crypto_handle->adj_size(logrec.size); 568 logrec.size += npad; 569 } 570 571 if (is_durable || txnp == NULL) { 572 if ((ret = 573 __os_malloc(env, logrec.size, &logrec.data)) != 0) 574 return (ret); 575 } else { 576 if ((ret = __os_malloc(env, 577 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 578 return (ret); 579#ifdef DIAGNOSTIC 580 if ((ret = 581 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 582 __os_free(env, lr); 583 return (ret); 584 } 585#else 586 logrec.data = lr->data; 587#endif 588 } 589 if (npad > 0) 590 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 591 592 bp = logrec.data; 593 594 LOGCOPY_32(env, bp, &rectype); 595 bp += sizeof(rectype); 596 597 LOGCOPY_32(env, bp, &txn_num); 598 bp += sizeof(txn_num); 599 600 LOGCOPY_FROMLSN(env, bp, lsnp); 601 bp += sizeof(DB_LSN); 602 603 if (name == NULL) { 604 zero = 0; 605 LOGCOPY_32(env, bp, &zero); 606 bp += sizeof(u_int32_t); 607 } else { 608 LOGCOPY_32(env, bp, &name->size); 609 bp += sizeof(name->size); 610 memcpy(bp, name->data, name->size); 611 bp += name->size; 612 } 613 614 LOGCOPY_32(env, bp, &appname); 615 bp += sizeof(appname); 616 617 LOGCOPY_32(env, bp, &pgsize); 618 bp += sizeof(pgsize); 619 620 uinttmp = (u_int32_t)pageno; 621 LOGCOPY_32(env,bp, &uinttmp); 622 bp += sizeof(uinttmp); 623 624 LOGCOPY_32(env, bp, &offset); 625 bp += sizeof(offset); 626 627 if (page == NULL) { 628 zero = 0; 629 LOGCOPY_32(env, bp, &zero); 630 bp += sizeof(u_int32_t); 631 } else { 632 LOGCOPY_32(env, bp, &page->size); 633 bp += sizeof(page->size); 634 memcpy(bp, page->data, page->size); 635 bp += page->size; 636 } 637 638 LOGCOPY_32(env, bp, &flag); 639 bp += sizeof(flag); 640 641 DB_ASSERT(env, 642 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 643 644 if (is_durable || txnp == NULL) { 645 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 646 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 647 *lsnp = *rlsnp; 648 if (rlsnp != ret_lsnp) 649 *ret_lsnp = *rlsnp; 650 } 651 } else { 652 ret = 0; 653#ifdef DIAGNOSTIC 654 /* 655 * Set the debug bit if we are going to log non-durable 656 * transactions so they will be ignored by recovery. 657 */ 658 memcpy(lr->data, logrec.data, logrec.size); 659 rectype |= DB_debug_FLAG; 660 LOGCOPY_32(env, logrec.data, &rectype); 661 662 if (!IS_REP_CLIENT(env)) 663 ret = __log_put(env, 664 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 665#endif 666 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 667 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 668 LSN_NOT_LOGGED(*ret_lsnp); 669 } 670 671#ifdef LOG_DIAGNOSTIC 672 if (ret != 0) 673 (void)__fop_write_print(env, 674 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 675#endif 676 677#ifdef DIAGNOSTIC 678 __os_free(env, logrec.data); 679#else 680 if (is_durable || txnp == NULL) 681 __os_free(env, logrec.data); 682#endif 683 return (ret); 684} 685 686/* 687 * PUBLIC: int __fop_rename_read __P((ENV *, void *, __fop_rename_args **)); 688 */ 689int 690__fop_rename_read(env, recbuf, argpp) 691 ENV *env; 692 void *recbuf; 693 __fop_rename_args **argpp; 694{ 695 __fop_rename_args *argp; 696 u_int8_t *bp; 697 int ret; 698 699 if ((ret = __os_malloc(env, 700 sizeof(__fop_rename_args) + sizeof(DB_TXN), &argp)) != 0) 701 return (ret); 702 bp = recbuf; 703 argp->txnp = (DB_TXN *)&argp[1]; 704 memset(argp->txnp, 0, sizeof(DB_TXN)); 705 706 LOGCOPY_32(env, &argp->type, bp); 707 bp += sizeof(argp->type); 708 709 LOGCOPY_32(env, &argp->txnp->txnid, bp); 710 bp += sizeof(argp->txnp->txnid); 711 712 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 713 bp += sizeof(DB_LSN); 714 715 memset(&argp->oldname, 0, sizeof(argp->oldname)); 716 LOGCOPY_32(env,&argp->oldname.size, bp); 717 bp += sizeof(u_int32_t); 718 argp->oldname.data = bp; 719 bp += argp->oldname.size; 720 721 memset(&argp->newname, 0, sizeof(argp->newname)); 722 LOGCOPY_32(env,&argp->newname.size, bp); 723 bp += sizeof(u_int32_t); 724 argp->newname.data = bp; 725 bp += argp->newname.size; 726 727 memset(&argp->fileid, 0, sizeof(argp->fileid)); 728 LOGCOPY_32(env,&argp->fileid.size, bp); 729 bp += sizeof(u_int32_t); 730 argp->fileid.data = bp; 731 bp += argp->fileid.size; 732 733 LOGCOPY_32(env, &argp->appname, bp); 734 bp += sizeof(argp->appname); 735 736 *argpp = argp; 737 return (ret); 738} 739 740/* 741 * PUBLIC: int __fop_rename_log __P((ENV *, DB_TXN *, DB_LSN *, 742 * PUBLIC: u_int32_t, const DBT *, const DBT *, const DBT *, u_int32_t)); 743 */ 744/* 745 * PUBLIC: int __fop_rename_noundo_log __P((ENV *, DB_TXN *, 746 * PUBLIC: DB_LSN *, u_int32_t, const DBT *, const DBT *, const DBT *, 747 * PUBLIC: u_int32_t)); 748 */ 749/* 750 * PUBLIC: int __fop_rename_int_log __P((ENV *, DB_TXN *, DB_LSN *, 751 * PUBLIC: u_int32_t, const DBT *, const DBT *, const DBT *, u_int32_t, 752 * PUBLIC: u_int32_t)); 753 */ 754int 755__fop_rename_log(env, txnp, ret_lsnp, flags, 756 oldname, newname, fileid, appname) 757 ENV *env; 758 DB_TXN *txnp; 759 DB_LSN *ret_lsnp; 760 u_int32_t flags; 761 const DBT *oldname; 762 const DBT *newname; 763 const DBT *fileid; 764 u_int32_t appname; 765 766{ 767 return (__fop_rename_int_log(env, txnp, ret_lsnp, flags, 768 oldname, newname, fileid, appname, DB___fop_rename)); 769} 770int 771__fop_rename_noundo_log(env, txnp, ret_lsnp, flags, 772 oldname, newname, fileid, appname) 773 ENV *env; 774 DB_TXN *txnp; 775 DB_LSN *ret_lsnp; 776 u_int32_t flags; 777 const DBT *oldname; 778 const DBT *newname; 779 const DBT *fileid; 780 u_int32_t appname; 781 782{ 783 return (__fop_rename_int_log(env, txnp, ret_lsnp, flags, 784 oldname, newname, fileid, appname, DB___fop_rename_noundo)); 785} 786int 787__fop_rename_int_log(env, txnp, ret_lsnp, flags, 788 oldname, newname, fileid, appname, type) 789 ENV *env; 790 DB_TXN *txnp; 791 DB_LSN *ret_lsnp; 792 u_int32_t flags; 793 const DBT *oldname; 794 const DBT *newname; 795 const DBT *fileid; 796 u_int32_t appname; 797 u_int32_t type; 798{ 799 DBT logrec; 800 DB_LSN *lsnp, null_lsn, *rlsnp; 801 DB_TXNLOGREC *lr; 802 u_int32_t zero, rectype, txn_num; 803 u_int npad; 804 u_int8_t *bp; 805 int is_durable, ret; 806 807 COMPQUIET(lr, NULL); 808 809 rlsnp = ret_lsnp; 810 rectype = type; 811 npad = 0; 812 ret = 0; 813 814 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 815 if (txnp == NULL) 816 return (0); 817 if (txnp == NULL) 818 return (0); 819 is_durable = 0; 820 } else 821 is_durable = 1; 822 823 if (txnp == NULL) { 824 txn_num = 0; 825 lsnp = &null_lsn; 826 null_lsn.file = null_lsn.offset = 0; 827 } else { 828 if (TAILQ_FIRST(&txnp->kids) != NULL && 829 (ret = __txn_activekids(env, rectype, txnp)) != 0) 830 return (ret); 831 /* 832 * We need to assign begin_lsn while holding region mutex. 833 * That assignment is done inside the DbEnv->log_put call, 834 * so pass in the appropriate memory location to be filled 835 * in by the log_put code. 836 */ 837 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 838 txn_num = txnp->txnid; 839 } 840 841 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 842 + sizeof(u_int32_t) + (oldname == NULL ? 0 : oldname->size) 843 + sizeof(u_int32_t) + (newname == NULL ? 0 : newname->size) 844 + sizeof(u_int32_t) + (fileid == NULL ? 0 : fileid->size) 845 + sizeof(u_int32_t); 846 if (CRYPTO_ON(env)) { 847 npad = env->crypto_handle->adj_size(logrec.size); 848 logrec.size += npad; 849 } 850 851 if (is_durable || txnp == NULL) { 852 if ((ret = 853 __os_malloc(env, logrec.size, &logrec.data)) != 0) 854 return (ret); 855 } else { 856 if ((ret = __os_malloc(env, 857 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 858 return (ret); 859#ifdef DIAGNOSTIC 860 if ((ret = 861 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 862 __os_free(env, lr); 863 return (ret); 864 } 865#else 866 logrec.data = lr->data; 867#endif 868 } 869 if (npad > 0) 870 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 871 872 bp = logrec.data; 873 874 LOGCOPY_32(env, bp, &rectype); 875 bp += sizeof(rectype); 876 877 LOGCOPY_32(env, bp, &txn_num); 878 bp += sizeof(txn_num); 879 880 LOGCOPY_FROMLSN(env, bp, lsnp); 881 bp += sizeof(DB_LSN); 882 883 if (oldname == NULL) { 884 zero = 0; 885 LOGCOPY_32(env, bp, &zero); 886 bp += sizeof(u_int32_t); 887 } else { 888 LOGCOPY_32(env, bp, &oldname->size); 889 bp += sizeof(oldname->size); 890 memcpy(bp, oldname->data, oldname->size); 891 bp += oldname->size; 892 } 893 894 if (newname == NULL) { 895 zero = 0; 896 LOGCOPY_32(env, bp, &zero); 897 bp += sizeof(u_int32_t); 898 } else { 899 LOGCOPY_32(env, bp, &newname->size); 900 bp += sizeof(newname->size); 901 memcpy(bp, newname->data, newname->size); 902 bp += newname->size; 903 } 904 905 if (fileid == NULL) { 906 zero = 0; 907 LOGCOPY_32(env, bp, &zero); 908 bp += sizeof(u_int32_t); 909 } else { 910 LOGCOPY_32(env, bp, &fileid->size); 911 bp += sizeof(fileid->size); 912 memcpy(bp, fileid->data, fileid->size); 913 bp += fileid->size; 914 } 915 916 LOGCOPY_32(env, bp, &appname); 917 bp += sizeof(appname); 918 919 DB_ASSERT(env, 920 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 921 922 if (is_durable || txnp == NULL) { 923 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 924 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 925 *lsnp = *rlsnp; 926 if (rlsnp != ret_lsnp) 927 *ret_lsnp = *rlsnp; 928 } 929 } else { 930 ret = 0; 931#ifdef DIAGNOSTIC 932 /* 933 * Set the debug bit if we are going to log non-durable 934 * transactions so they will be ignored by recovery. 935 */ 936 memcpy(lr->data, logrec.data, logrec.size); 937 rectype |= DB_debug_FLAG; 938 LOGCOPY_32(env, logrec.data, &rectype); 939 940 if (!IS_REP_CLIENT(env)) 941 ret = __log_put(env, 942 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 943#endif 944 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 945 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 946 LSN_NOT_LOGGED(*ret_lsnp); 947 } 948 949#ifdef LOG_DIAGNOSTIC 950 if (ret != 0) 951 (void)__fop_rename_print(env, 952 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 953#endif 954 955#ifdef DIAGNOSTIC 956 __os_free(env, logrec.data); 957#else 958 if (is_durable || txnp == NULL) 959 __os_free(env, logrec.data); 960#endif 961 return (ret); 962} 963 964/* 965 * PUBLIC: int __fop_file_remove_read __P((ENV *, void *, 966 * PUBLIC: __fop_file_remove_args **)); 967 */ 968int 969__fop_file_remove_read(env, recbuf, argpp) 970 ENV *env; 971 void *recbuf; 972 __fop_file_remove_args **argpp; 973{ 974 __fop_file_remove_args *argp; 975 u_int8_t *bp; 976 int ret; 977 978 if ((ret = __os_malloc(env, 979 sizeof(__fop_file_remove_args) + sizeof(DB_TXN), &argp)) != 0) 980 return (ret); 981 bp = recbuf; 982 argp->txnp = (DB_TXN *)&argp[1]; 983 memset(argp->txnp, 0, sizeof(DB_TXN)); 984 985 LOGCOPY_32(env, &argp->type, bp); 986 bp += sizeof(argp->type); 987 988 LOGCOPY_32(env, &argp->txnp->txnid, bp); 989 bp += sizeof(argp->txnp->txnid); 990 991 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 992 bp += sizeof(DB_LSN); 993 994 memset(&argp->real_fid, 0, sizeof(argp->real_fid)); 995 LOGCOPY_32(env,&argp->real_fid.size, bp); 996 bp += sizeof(u_int32_t); 997 argp->real_fid.data = bp; 998 bp += argp->real_fid.size; 999 1000 memset(&argp->tmp_fid, 0, sizeof(argp->tmp_fid)); 1001 LOGCOPY_32(env,&argp->tmp_fid.size, bp); 1002 bp += sizeof(u_int32_t); 1003 argp->tmp_fid.data = bp; 1004 bp += argp->tmp_fid.size; 1005 1006 memset(&argp->name, 0, sizeof(argp->name)); 1007 LOGCOPY_32(env,&argp->name.size, bp); 1008 bp += sizeof(u_int32_t); 1009 argp->name.data = bp; 1010 bp += argp->name.size; 1011 1012 LOGCOPY_32(env, &argp->appname, bp); 1013 bp += sizeof(argp->appname); 1014 1015 LOGCOPY_32(env, &argp->child, bp); 1016 bp += sizeof(argp->child); 1017 1018 *argpp = argp; 1019 return (ret); 1020} 1021 1022/* 1023 * PUBLIC: int __fop_file_remove_log __P((ENV *, DB_TXN *, DB_LSN *, 1024 * PUBLIC: u_int32_t, const DBT *, const DBT *, const DBT *, u_int32_t, 1025 * PUBLIC: u_int32_t)); 1026 */ 1027int 1028__fop_file_remove_log(env, txnp, ret_lsnp, flags, 1029 real_fid, tmp_fid, name, appname, child) 1030 ENV *env; 1031 DB_TXN *txnp; 1032 DB_LSN *ret_lsnp; 1033 u_int32_t flags; 1034 const DBT *real_fid; 1035 const DBT *tmp_fid; 1036 const DBT *name; 1037 u_int32_t appname; 1038 u_int32_t child; 1039{ 1040 DBT logrec; 1041 DB_LSN *lsnp, null_lsn, *rlsnp; 1042 DB_TXNLOGREC *lr; 1043 u_int32_t zero, rectype, txn_num; 1044 u_int npad; 1045 u_int8_t *bp; 1046 int is_durable, ret; 1047 1048 COMPQUIET(lr, NULL); 1049 1050 rlsnp = ret_lsnp; 1051 rectype = DB___fop_file_remove; 1052 npad = 0; 1053 ret = 0; 1054 1055 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 1056 if (txnp == NULL) 1057 return (0); 1058 if (txnp == NULL) 1059 return (0); 1060 is_durable = 0; 1061 } else 1062 is_durable = 1; 1063 1064 if (txnp == NULL) { 1065 txn_num = 0; 1066 lsnp = &null_lsn; 1067 null_lsn.file = null_lsn.offset = 0; 1068 } else { 1069 if (TAILQ_FIRST(&txnp->kids) != NULL && 1070 (ret = __txn_activekids(env, rectype, txnp)) != 0) 1071 return (ret); 1072 /* 1073 * We need to assign begin_lsn while holding region mutex. 1074 * That assignment is done inside the DbEnv->log_put call, 1075 * so pass in the appropriate memory location to be filled 1076 * in by the log_put code. 1077 */ 1078 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 1079 txn_num = txnp->txnid; 1080 } 1081 1082 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 1083 + sizeof(u_int32_t) + (real_fid == NULL ? 0 : real_fid->size) 1084 + sizeof(u_int32_t) + (tmp_fid == NULL ? 0 : tmp_fid->size) 1085 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 1086 + sizeof(u_int32_t) 1087 + sizeof(u_int32_t); 1088 if (CRYPTO_ON(env)) { 1089 npad = env->crypto_handle->adj_size(logrec.size); 1090 logrec.size += npad; 1091 } 1092 1093 if (is_durable || txnp == NULL) { 1094 if ((ret = 1095 __os_malloc(env, logrec.size, &logrec.data)) != 0) 1096 return (ret); 1097 } else { 1098 if ((ret = __os_malloc(env, 1099 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 1100 return (ret); 1101#ifdef DIAGNOSTIC 1102 if ((ret = 1103 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 1104 __os_free(env, lr); 1105 return (ret); 1106 } 1107#else 1108 logrec.data = lr->data; 1109#endif 1110 } 1111 if (npad > 0) 1112 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 1113 1114 bp = logrec.data; 1115 1116 LOGCOPY_32(env, bp, &rectype); 1117 bp += sizeof(rectype); 1118 1119 LOGCOPY_32(env, bp, &txn_num); 1120 bp += sizeof(txn_num); 1121 1122 LOGCOPY_FROMLSN(env, bp, lsnp); 1123 bp += sizeof(DB_LSN); 1124 1125 if (real_fid == NULL) { 1126 zero = 0; 1127 LOGCOPY_32(env, bp, &zero); 1128 bp += sizeof(u_int32_t); 1129 } else { 1130 LOGCOPY_32(env, bp, &real_fid->size); 1131 bp += sizeof(real_fid->size); 1132 memcpy(bp, real_fid->data, real_fid->size); 1133 bp += real_fid->size; 1134 } 1135 1136 if (tmp_fid == NULL) { 1137 zero = 0; 1138 LOGCOPY_32(env, bp, &zero); 1139 bp += sizeof(u_int32_t); 1140 } else { 1141 LOGCOPY_32(env, bp, &tmp_fid->size); 1142 bp += sizeof(tmp_fid->size); 1143 memcpy(bp, tmp_fid->data, tmp_fid->size); 1144 bp += tmp_fid->size; 1145 } 1146 1147 if (name == NULL) { 1148 zero = 0; 1149 LOGCOPY_32(env, bp, &zero); 1150 bp += sizeof(u_int32_t); 1151 } else { 1152 LOGCOPY_32(env, bp, &name->size); 1153 bp += sizeof(name->size); 1154 memcpy(bp, name->data, name->size); 1155 bp += name->size; 1156 } 1157 1158 LOGCOPY_32(env, bp, &appname); 1159 bp += sizeof(appname); 1160 1161 LOGCOPY_32(env, bp, &child); 1162 bp += sizeof(child); 1163 1164 DB_ASSERT(env, 1165 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 1166 1167 if (is_durable || txnp == NULL) { 1168 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 1169 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 1170 *lsnp = *rlsnp; 1171 if (rlsnp != ret_lsnp) 1172 *ret_lsnp = *rlsnp; 1173 } 1174 } else { 1175 ret = 0; 1176#ifdef DIAGNOSTIC 1177 /* 1178 * Set the debug bit if we are going to log non-durable 1179 * transactions so they will be ignored by recovery. 1180 */ 1181 memcpy(lr->data, logrec.data, logrec.size); 1182 rectype |= DB_debug_FLAG; 1183 LOGCOPY_32(env, logrec.data, &rectype); 1184 1185 if (!IS_REP_CLIENT(env)) 1186 ret = __log_put(env, 1187 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 1188#endif 1189 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 1190 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 1191 LSN_NOT_LOGGED(*ret_lsnp); 1192 } 1193 1194#ifdef LOG_DIAGNOSTIC 1195 if (ret != 0) 1196 (void)__fop_file_remove_print(env, 1197 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 1198#endif 1199 1200#ifdef DIAGNOSTIC 1201 __os_free(env, logrec.data); 1202#else 1203 if (is_durable || txnp == NULL) 1204 __os_free(env, logrec.data); 1205#endif 1206 return (ret); 1207} 1208 1209/* 1210 * PUBLIC: int __fop_init_recover __P((ENV *, DB_DISTAB *)); 1211 */ 1212int 1213__fop_init_recover(env, dtabp) 1214 ENV *env; 1215 DB_DISTAB *dtabp; 1216{ 1217 int ret; 1218 1219 if ((ret = __db_add_recovery_int(env, dtabp, 1220 __fop_create_recover, DB___fop_create)) != 0) 1221 return (ret); 1222 if ((ret = __db_add_recovery_int(env, dtabp, 1223 __fop_remove_recover, DB___fop_remove)) != 0) 1224 return (ret); 1225 if ((ret = __db_add_recovery_int(env, dtabp, 1226 __fop_write_recover, DB___fop_write)) != 0) 1227 return (ret); 1228 if ((ret = __db_add_recovery_int(env, dtabp, 1229 __fop_rename_recover, DB___fop_rename)) != 0) 1230 return (ret); 1231 if ((ret = __db_add_recovery_int(env, dtabp, 1232 __fop_rename_noundo_recover, DB___fop_rename_noundo)) != 0) 1233 return (ret); 1234 if ((ret = __db_add_recovery_int(env, dtabp, 1235 __fop_file_remove_recover, DB___fop_file_remove)) != 0) 1236 return (ret); 1237 return (0); 1238} 1239