00001
00002
00003 #include "db_config.h"
00004
00005 #ifndef NO_SYSTEM_INCLUDES
00006 #include <sys/types.h>
00007
00008 #include <ctype.h>
00009 #include <string.h>
00010 #endif
00011
00012 #include "db_int.h"
00013 #include "dbinc/crypto.h"
00014 #include "dbinc/db_page.h"
00015 #include "dbinc/db_am.h"
00016 #include "dbinc/log.h"
00017 #include "dbinc/txn.h"
00018 #include "dbinc/fop.h"
00019
00020
00021
00022
00023
00024 int
00025 __fop_create_log(dbenv, txnid, ret_lsnp, flags,
00026 name, appname, mode)
00027 DB_ENV *dbenv;
00028 DB_TXN *txnid;
00029 DB_LSN *ret_lsnp;
00030 u_int32_t flags;
00031 const DBT *name;
00032 u_int32_t appname;
00033 u_int32_t mode;
00034 {
00035 DBT logrec;
00036 DB_TXNLOGREC *lr;
00037 DB_LSN *lsnp, null_lsn, *rlsnp;
00038 u_int32_t zero, uinttmp, rectype, txn_num;
00039 u_int npad;
00040 u_int8_t *bp;
00041 int is_durable, ret;
00042
00043 COMPQUIET(lr, NULL);
00044
00045 rectype = DB___fop_create;
00046 npad = 0;
00047 rlsnp = ret_lsnp;
00048
00049 ret = 0;
00050
00051 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00052 if (txnid == NULL)
00053 return (0);
00054 is_durable = 0;
00055 } else
00056 is_durable = 1;
00057
00058 if (txnid == NULL) {
00059 txn_num = 0;
00060 lsnp = &null_lsn;
00061 null_lsn.file = null_lsn.offset = 0;
00062 } else {
00063 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00064 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00065 return (ret);
00066
00067
00068
00069
00070
00071
00072 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00073 txn_num = txnid->txnid;
00074 }
00075
00076 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00077 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00078 + sizeof(u_int32_t)
00079 + sizeof(u_int32_t);
00080 if (CRYPTO_ON(dbenv)) {
00081 npad =
00082 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00083 logrec.size += npad;
00084 }
00085
00086 if (is_durable || txnid == NULL) {
00087 if ((ret =
00088 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00089 return (ret);
00090 } else {
00091 if ((ret = __os_malloc(dbenv,
00092 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00093 return (ret);
00094 #ifdef DIAGNOSTIC
00095 if ((ret =
00096 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00097 __os_free(dbenv, lr);
00098 return (ret);
00099 }
00100 #else
00101 logrec.data = lr->data;
00102 #endif
00103 }
00104 if (npad > 0)
00105 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00106
00107 bp = logrec.data;
00108
00109 memcpy(bp, &rectype, sizeof(rectype));
00110 bp += sizeof(rectype);
00111
00112 memcpy(bp, &txn_num, sizeof(txn_num));
00113 bp += sizeof(txn_num);
00114
00115 memcpy(bp, lsnp, sizeof(DB_LSN));
00116 bp += sizeof(DB_LSN);
00117
00118 if (name == NULL) {
00119 zero = 0;
00120 memcpy(bp, &zero, sizeof(u_int32_t));
00121 bp += sizeof(u_int32_t);
00122 } else {
00123 memcpy(bp, &name->size, sizeof(name->size));
00124 bp += sizeof(name->size);
00125 memcpy(bp, name->data, name->size);
00126 bp += name->size;
00127 }
00128
00129 uinttmp = (u_int32_t)appname;
00130 memcpy(bp, &uinttmp, sizeof(uinttmp));
00131 bp += sizeof(uinttmp);
00132
00133 uinttmp = (u_int32_t)mode;
00134 memcpy(bp, &uinttmp, sizeof(uinttmp));
00135 bp += sizeof(uinttmp);
00136
00137 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00138
00139 if (is_durable || txnid == NULL) {
00140 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00141 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00142 *lsnp = *rlsnp;
00143 if (rlsnp != ret_lsnp)
00144 *ret_lsnp = *rlsnp;
00145 }
00146 } else {
00147 #ifdef DIAGNOSTIC
00148
00149
00150
00151
00152 memcpy(lr->data, logrec.data, logrec.size);
00153 rectype |= DB_debug_FLAG;
00154 memcpy(logrec.data, &rectype, sizeof(rectype));
00155
00156 ret = __log_put(dbenv,
00157 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00158 #else
00159 ret = 0;
00160 #endif
00161 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00162 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00163 LSN_NOT_LOGGED(*ret_lsnp);
00164 }
00165
00166 #ifdef LOG_DIAGNOSTIC
00167 if (ret != 0)
00168 (void)__fop_create_print(dbenv,
00169 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00170 #endif
00171
00172 #ifdef DIAGNOSTIC
00173 __os_free(dbenv, logrec.data);
00174 #else
00175 if (is_durable || txnid == NULL)
00176 __os_free(dbenv, logrec.data);
00177 #endif
00178 return (ret);
00179 }
00180
00181
00182
00183
00184 int
00185 __fop_create_read(dbenv, recbuf, argpp)
00186 DB_ENV *dbenv;
00187 void *recbuf;
00188 __fop_create_args **argpp;
00189 {
00190 __fop_create_args *argp;
00191 u_int32_t uinttmp;
00192 u_int8_t *bp;
00193 int ret;
00194
00195 if ((ret = __os_malloc(dbenv,
00196 sizeof(__fop_create_args) + sizeof(DB_TXN), &argp)) != 0)
00197 return (ret);
00198 bp = recbuf;
00199 argp->txnid = (DB_TXN *)&argp[1];
00200
00201 memcpy(&argp->type, bp, sizeof(argp->type));
00202 bp += sizeof(argp->type);
00203
00204 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00205 bp += sizeof(argp->txnid->txnid);
00206
00207 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00208 bp += sizeof(DB_LSN);
00209
00210 memset(&argp->name, 0, sizeof(argp->name));
00211 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00212 bp += sizeof(u_int32_t);
00213 argp->name.data = bp;
00214 bp += argp->name.size;
00215
00216 memcpy(&uinttmp, bp, sizeof(uinttmp));
00217 argp->appname = (u_int32_t)uinttmp;
00218 bp += sizeof(uinttmp);
00219
00220 memcpy(&uinttmp, bp, sizeof(uinttmp));
00221 argp->mode = (u_int32_t)uinttmp;
00222 bp += sizeof(uinttmp);
00223
00224 *argpp = argp;
00225 return (0);
00226 }
00227
00228
00229
00230
00231
00232 int
00233 __fop_remove_log(dbenv, txnid, ret_lsnp, flags,
00234 name, fid, appname)
00235 DB_ENV *dbenv;
00236 DB_TXN *txnid;
00237 DB_LSN *ret_lsnp;
00238 u_int32_t flags;
00239 const DBT *name;
00240 const DBT *fid;
00241 u_int32_t appname;
00242 {
00243 DBT logrec;
00244 DB_TXNLOGREC *lr;
00245 DB_LSN *lsnp, null_lsn, *rlsnp;
00246 u_int32_t zero, uinttmp, rectype, txn_num;
00247 u_int npad;
00248 u_int8_t *bp;
00249 int is_durable, ret;
00250
00251 COMPQUIET(lr, NULL);
00252
00253 rectype = DB___fop_remove;
00254 npad = 0;
00255 rlsnp = ret_lsnp;
00256
00257 ret = 0;
00258
00259 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00260 if (txnid == NULL)
00261 return (0);
00262 is_durable = 0;
00263 } else
00264 is_durable = 1;
00265
00266 if (txnid == NULL) {
00267 txn_num = 0;
00268 lsnp = &null_lsn;
00269 null_lsn.file = null_lsn.offset = 0;
00270 } else {
00271 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00272 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00273 return (ret);
00274
00275
00276
00277
00278
00279
00280 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00281 txn_num = txnid->txnid;
00282 }
00283
00284 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00285 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00286 + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size)
00287 + sizeof(u_int32_t);
00288 if (CRYPTO_ON(dbenv)) {
00289 npad =
00290 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00291 logrec.size += npad;
00292 }
00293
00294 if (is_durable || txnid == NULL) {
00295 if ((ret =
00296 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00297 return (ret);
00298 } else {
00299 if ((ret = __os_malloc(dbenv,
00300 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00301 return (ret);
00302 #ifdef DIAGNOSTIC
00303 if ((ret =
00304 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00305 __os_free(dbenv, lr);
00306 return (ret);
00307 }
00308 #else
00309 logrec.data = lr->data;
00310 #endif
00311 }
00312 if (npad > 0)
00313 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00314
00315 bp = logrec.data;
00316
00317 memcpy(bp, &rectype, sizeof(rectype));
00318 bp += sizeof(rectype);
00319
00320 memcpy(bp, &txn_num, sizeof(txn_num));
00321 bp += sizeof(txn_num);
00322
00323 memcpy(bp, lsnp, sizeof(DB_LSN));
00324 bp += sizeof(DB_LSN);
00325
00326 if (name == NULL) {
00327 zero = 0;
00328 memcpy(bp, &zero, sizeof(u_int32_t));
00329 bp += sizeof(u_int32_t);
00330 } else {
00331 memcpy(bp, &name->size, sizeof(name->size));
00332 bp += sizeof(name->size);
00333 memcpy(bp, name->data, name->size);
00334 bp += name->size;
00335 }
00336
00337 if (fid == NULL) {
00338 zero = 0;
00339 memcpy(bp, &zero, sizeof(u_int32_t));
00340 bp += sizeof(u_int32_t);
00341 } else {
00342 memcpy(bp, &fid->size, sizeof(fid->size));
00343 bp += sizeof(fid->size);
00344 memcpy(bp, fid->data, fid->size);
00345 bp += fid->size;
00346 }
00347
00348 uinttmp = (u_int32_t)appname;
00349 memcpy(bp, &uinttmp, sizeof(uinttmp));
00350 bp += sizeof(uinttmp);
00351
00352 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00353
00354 if (is_durable || txnid == NULL) {
00355 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00356 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00357 *lsnp = *rlsnp;
00358 if (rlsnp != ret_lsnp)
00359 *ret_lsnp = *rlsnp;
00360 }
00361 } else {
00362 #ifdef DIAGNOSTIC
00363
00364
00365
00366
00367 memcpy(lr->data, logrec.data, logrec.size);
00368 rectype |= DB_debug_FLAG;
00369 memcpy(logrec.data, &rectype, sizeof(rectype));
00370
00371 ret = __log_put(dbenv,
00372 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00373 #else
00374 ret = 0;
00375 #endif
00376 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00377 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00378 LSN_NOT_LOGGED(*ret_lsnp);
00379 }
00380
00381 #ifdef LOG_DIAGNOSTIC
00382 if (ret != 0)
00383 (void)__fop_remove_print(dbenv,
00384 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00385 #endif
00386
00387 #ifdef DIAGNOSTIC
00388 __os_free(dbenv, logrec.data);
00389 #else
00390 if (is_durable || txnid == NULL)
00391 __os_free(dbenv, logrec.data);
00392 #endif
00393 return (ret);
00394 }
00395
00396
00397
00398
00399 int
00400 __fop_remove_read(dbenv, recbuf, argpp)
00401 DB_ENV *dbenv;
00402 void *recbuf;
00403 __fop_remove_args **argpp;
00404 {
00405 __fop_remove_args *argp;
00406 u_int32_t uinttmp;
00407 u_int8_t *bp;
00408 int ret;
00409
00410 if ((ret = __os_malloc(dbenv,
00411 sizeof(__fop_remove_args) + sizeof(DB_TXN), &argp)) != 0)
00412 return (ret);
00413 bp = recbuf;
00414 argp->txnid = (DB_TXN *)&argp[1];
00415
00416 memcpy(&argp->type, bp, sizeof(argp->type));
00417 bp += sizeof(argp->type);
00418
00419 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00420 bp += sizeof(argp->txnid->txnid);
00421
00422 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00423 bp += sizeof(DB_LSN);
00424
00425 memset(&argp->name, 0, sizeof(argp->name));
00426 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00427 bp += sizeof(u_int32_t);
00428 argp->name.data = bp;
00429 bp += argp->name.size;
00430
00431 memset(&argp->fid, 0, sizeof(argp->fid));
00432 memcpy(&argp->fid.size, bp, sizeof(u_int32_t));
00433 bp += sizeof(u_int32_t);
00434 argp->fid.data = bp;
00435 bp += argp->fid.size;
00436
00437 memcpy(&uinttmp, bp, sizeof(uinttmp));
00438 argp->appname = (u_int32_t)uinttmp;
00439 bp += sizeof(uinttmp);
00440
00441 *argpp = argp;
00442 return (0);
00443 }
00444
00445
00446
00447
00448
00449
00450 int
00451 __fop_write_log(dbenv, txnid, ret_lsnp, flags,
00452 name, appname, pgsize, pageno, offset, page,
00453 flag)
00454 DB_ENV *dbenv;
00455 DB_TXN *txnid;
00456 DB_LSN *ret_lsnp;
00457 u_int32_t flags;
00458 const DBT *name;
00459 u_int32_t appname;
00460 u_int32_t pgsize;
00461 db_pgno_t pageno;
00462 u_int32_t offset;
00463 const DBT *page;
00464 u_int32_t flag;
00465 {
00466 DBT logrec;
00467 DB_TXNLOGREC *lr;
00468 DB_LSN *lsnp, null_lsn, *rlsnp;
00469 u_int32_t zero, uinttmp, rectype, txn_num;
00470 u_int npad;
00471 u_int8_t *bp;
00472 int is_durable, ret;
00473
00474 COMPQUIET(lr, NULL);
00475
00476 rectype = DB___fop_write;
00477 npad = 0;
00478 rlsnp = ret_lsnp;
00479
00480 ret = 0;
00481
00482 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00483 if (txnid == NULL)
00484 return (0);
00485 is_durable = 0;
00486 } else
00487 is_durable = 1;
00488
00489 if (txnid == NULL) {
00490 txn_num = 0;
00491 lsnp = &null_lsn;
00492 null_lsn.file = null_lsn.offset = 0;
00493 } else {
00494 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00495 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00496 return (ret);
00497
00498
00499
00500
00501
00502
00503 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00504 txn_num = txnid->txnid;
00505 }
00506
00507 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00508 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00509 + sizeof(u_int32_t)
00510 + sizeof(u_int32_t)
00511 + sizeof(u_int32_t)
00512 + sizeof(u_int32_t)
00513 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size)
00514 + sizeof(u_int32_t);
00515 if (CRYPTO_ON(dbenv)) {
00516 npad =
00517 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00518 logrec.size += npad;
00519 }
00520
00521 if (is_durable || txnid == NULL) {
00522 if ((ret =
00523 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00524 return (ret);
00525 } else {
00526 if ((ret = __os_malloc(dbenv,
00527 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00528 return (ret);
00529 #ifdef DIAGNOSTIC
00530 if ((ret =
00531 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00532 __os_free(dbenv, lr);
00533 return (ret);
00534 }
00535 #else
00536 logrec.data = lr->data;
00537 #endif
00538 }
00539 if (npad > 0)
00540 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00541
00542 bp = logrec.data;
00543
00544 memcpy(bp, &rectype, sizeof(rectype));
00545 bp += sizeof(rectype);
00546
00547 memcpy(bp, &txn_num, sizeof(txn_num));
00548 bp += sizeof(txn_num);
00549
00550 memcpy(bp, lsnp, sizeof(DB_LSN));
00551 bp += sizeof(DB_LSN);
00552
00553 if (name == NULL) {
00554 zero = 0;
00555 memcpy(bp, &zero, sizeof(u_int32_t));
00556 bp += sizeof(u_int32_t);
00557 } else {
00558 memcpy(bp, &name->size, sizeof(name->size));
00559 bp += sizeof(name->size);
00560 memcpy(bp, name->data, name->size);
00561 bp += name->size;
00562 }
00563
00564 uinttmp = (u_int32_t)appname;
00565 memcpy(bp, &uinttmp, sizeof(uinttmp));
00566 bp += sizeof(uinttmp);
00567
00568 uinttmp = (u_int32_t)pgsize;
00569 memcpy(bp, &uinttmp, sizeof(uinttmp));
00570 bp += sizeof(uinttmp);
00571
00572 uinttmp = (u_int32_t)pageno;
00573 memcpy(bp, &uinttmp, sizeof(uinttmp));
00574 bp += sizeof(uinttmp);
00575
00576 uinttmp = (u_int32_t)offset;
00577 memcpy(bp, &uinttmp, sizeof(uinttmp));
00578 bp += sizeof(uinttmp);
00579
00580 if (page == NULL) {
00581 zero = 0;
00582 memcpy(bp, &zero, sizeof(u_int32_t));
00583 bp += sizeof(u_int32_t);
00584 } else {
00585 memcpy(bp, &page->size, sizeof(page->size));
00586 bp += sizeof(page->size);
00587 memcpy(bp, page->data, page->size);
00588 bp += page->size;
00589 }
00590
00591 uinttmp = (u_int32_t)flag;
00592 memcpy(bp, &uinttmp, sizeof(uinttmp));
00593 bp += sizeof(uinttmp);
00594
00595 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00596
00597 if (is_durable || txnid == NULL) {
00598 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00599 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00600 *lsnp = *rlsnp;
00601 if (rlsnp != ret_lsnp)
00602 *ret_lsnp = *rlsnp;
00603 }
00604 } else {
00605 #ifdef DIAGNOSTIC
00606
00607
00608
00609
00610 memcpy(lr->data, logrec.data, logrec.size);
00611 rectype |= DB_debug_FLAG;
00612 memcpy(logrec.data, &rectype, sizeof(rectype));
00613
00614 ret = __log_put(dbenv,
00615 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00616 #else
00617 ret = 0;
00618 #endif
00619 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00620 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00621 LSN_NOT_LOGGED(*ret_lsnp);
00622 }
00623
00624 #ifdef LOG_DIAGNOSTIC
00625 if (ret != 0)
00626 (void)__fop_write_print(dbenv,
00627 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00628 #endif
00629
00630 #ifdef DIAGNOSTIC
00631 __os_free(dbenv, logrec.data);
00632 #else
00633 if (is_durable || txnid == NULL)
00634 __os_free(dbenv, logrec.data);
00635 #endif
00636 return (ret);
00637 }
00638
00639
00640
00641
00642 int
00643 __fop_write_read(dbenv, recbuf, argpp)
00644 DB_ENV *dbenv;
00645 void *recbuf;
00646 __fop_write_args **argpp;
00647 {
00648 __fop_write_args *argp;
00649 u_int32_t uinttmp;
00650 u_int8_t *bp;
00651 int ret;
00652
00653 if ((ret = __os_malloc(dbenv,
00654 sizeof(__fop_write_args) + sizeof(DB_TXN), &argp)) != 0)
00655 return (ret);
00656 bp = recbuf;
00657 argp->txnid = (DB_TXN *)&argp[1];
00658
00659 memcpy(&argp->type, bp, sizeof(argp->type));
00660 bp += sizeof(argp->type);
00661
00662 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00663 bp += sizeof(argp->txnid->txnid);
00664
00665 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00666 bp += sizeof(DB_LSN);
00667
00668 memset(&argp->name, 0, sizeof(argp->name));
00669 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00670 bp += sizeof(u_int32_t);
00671 argp->name.data = bp;
00672 bp += argp->name.size;
00673
00674 memcpy(&uinttmp, bp, sizeof(uinttmp));
00675 argp->appname = (u_int32_t)uinttmp;
00676 bp += sizeof(uinttmp);
00677
00678 memcpy(&uinttmp, bp, sizeof(uinttmp));
00679 argp->pgsize = (u_int32_t)uinttmp;
00680 bp += sizeof(uinttmp);
00681
00682 memcpy(&uinttmp, bp, sizeof(uinttmp));
00683 argp->pageno = (db_pgno_t)uinttmp;
00684 bp += sizeof(uinttmp);
00685
00686 memcpy(&uinttmp, bp, sizeof(uinttmp));
00687 argp->offset = (u_int32_t)uinttmp;
00688 bp += sizeof(uinttmp);
00689
00690 memset(&argp->page, 0, sizeof(argp->page));
00691 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
00692 bp += sizeof(u_int32_t);
00693 argp->page.data = bp;
00694 bp += argp->page.size;
00695
00696 memcpy(&uinttmp, bp, sizeof(uinttmp));
00697 argp->flag = (u_int32_t)uinttmp;
00698 bp += sizeof(uinttmp);
00699
00700 *argpp = argp;
00701 return (0);
00702 }
00703
00704
00705
00706
00707
00708 int
00709 __fop_rename_log(dbenv, txnid, ret_lsnp, flags,
00710 oldname, newname, fileid, appname)
00711 DB_ENV *dbenv;
00712 DB_TXN *txnid;
00713 DB_LSN *ret_lsnp;
00714 u_int32_t flags;
00715 const DBT *oldname;
00716 const DBT *newname;
00717 const DBT *fileid;
00718 u_int32_t appname;
00719 {
00720 DBT logrec;
00721 DB_TXNLOGREC *lr;
00722 DB_LSN *lsnp, null_lsn, *rlsnp;
00723 u_int32_t zero, uinttmp, rectype, txn_num;
00724 u_int npad;
00725 u_int8_t *bp;
00726 int is_durable, ret;
00727
00728 COMPQUIET(lr, NULL);
00729
00730 rectype = DB___fop_rename;
00731 npad = 0;
00732 rlsnp = ret_lsnp;
00733
00734 ret = 0;
00735
00736 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00737 if (txnid == NULL)
00738 return (0);
00739 is_durable = 0;
00740 } else
00741 is_durable = 1;
00742
00743 if (txnid == NULL) {
00744 txn_num = 0;
00745 lsnp = &null_lsn;
00746 null_lsn.file = null_lsn.offset = 0;
00747 } else {
00748 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00749 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00750 return (ret);
00751
00752
00753
00754
00755
00756
00757 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00758 txn_num = txnid->txnid;
00759 }
00760
00761 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00762 + sizeof(u_int32_t) + (oldname == NULL ? 0 : oldname->size)
00763 + sizeof(u_int32_t) + (newname == NULL ? 0 : newname->size)
00764 + sizeof(u_int32_t) + (fileid == NULL ? 0 : fileid->size)
00765 + sizeof(u_int32_t);
00766 if (CRYPTO_ON(dbenv)) {
00767 npad =
00768 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00769 logrec.size += npad;
00770 }
00771
00772 if (is_durable || txnid == NULL) {
00773 if ((ret =
00774 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00775 return (ret);
00776 } else {
00777 if ((ret = __os_malloc(dbenv,
00778 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00779 return (ret);
00780 #ifdef DIAGNOSTIC
00781 if ((ret =
00782 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00783 __os_free(dbenv, lr);
00784 return (ret);
00785 }
00786 #else
00787 logrec.data = lr->data;
00788 #endif
00789 }
00790 if (npad > 0)
00791 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00792
00793 bp = logrec.data;
00794
00795 memcpy(bp, &rectype, sizeof(rectype));
00796 bp += sizeof(rectype);
00797
00798 memcpy(bp, &txn_num, sizeof(txn_num));
00799 bp += sizeof(txn_num);
00800
00801 memcpy(bp, lsnp, sizeof(DB_LSN));
00802 bp += sizeof(DB_LSN);
00803
00804 if (oldname == NULL) {
00805 zero = 0;
00806 memcpy(bp, &zero, sizeof(u_int32_t));
00807 bp += sizeof(u_int32_t);
00808 } else {
00809 memcpy(bp, &oldname->size, sizeof(oldname->size));
00810 bp += sizeof(oldname->size);
00811 memcpy(bp, oldname->data, oldname->size);
00812 bp += oldname->size;
00813 }
00814
00815 if (newname == NULL) {
00816 zero = 0;
00817 memcpy(bp, &zero, sizeof(u_int32_t));
00818 bp += sizeof(u_int32_t);
00819 } else {
00820 memcpy(bp, &newname->size, sizeof(newname->size));
00821 bp += sizeof(newname->size);
00822 memcpy(bp, newname->data, newname->size);
00823 bp += newname->size;
00824 }
00825
00826 if (fileid == NULL) {
00827 zero = 0;
00828 memcpy(bp, &zero, sizeof(u_int32_t));
00829 bp += sizeof(u_int32_t);
00830 } else {
00831 memcpy(bp, &fileid->size, sizeof(fileid->size));
00832 bp += sizeof(fileid->size);
00833 memcpy(bp, fileid->data, fileid->size);
00834 bp += fileid->size;
00835 }
00836
00837 uinttmp = (u_int32_t)appname;
00838 memcpy(bp, &uinttmp, sizeof(uinttmp));
00839 bp += sizeof(uinttmp);
00840
00841 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00842
00843 if (is_durable || txnid == NULL) {
00844 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00845 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00846 *lsnp = *rlsnp;
00847 if (rlsnp != ret_lsnp)
00848 *ret_lsnp = *rlsnp;
00849 }
00850 } else {
00851 #ifdef DIAGNOSTIC
00852
00853
00854
00855
00856 memcpy(lr->data, logrec.data, logrec.size);
00857 rectype |= DB_debug_FLAG;
00858 memcpy(logrec.data, &rectype, sizeof(rectype));
00859
00860 ret = __log_put(dbenv,
00861 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00862 #else
00863 ret = 0;
00864 #endif
00865 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00866 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00867 LSN_NOT_LOGGED(*ret_lsnp);
00868 }
00869
00870 #ifdef LOG_DIAGNOSTIC
00871 if (ret != 0)
00872 (void)__fop_rename_print(dbenv,
00873 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00874 #endif
00875
00876 #ifdef DIAGNOSTIC
00877 __os_free(dbenv, logrec.data);
00878 #else
00879 if (is_durable || txnid == NULL)
00880 __os_free(dbenv, logrec.data);
00881 #endif
00882 return (ret);
00883 }
00884
00885
00886
00887
00888 int
00889 __fop_rename_read(dbenv, recbuf, argpp)
00890 DB_ENV *dbenv;
00891 void *recbuf;
00892 __fop_rename_args **argpp;
00893 {
00894 __fop_rename_args *argp;
00895 u_int32_t uinttmp;
00896 u_int8_t *bp;
00897 int ret;
00898
00899 if ((ret = __os_malloc(dbenv,
00900 sizeof(__fop_rename_args) + sizeof(DB_TXN), &argp)) != 0)
00901 return (ret);
00902 bp = recbuf;
00903 argp->txnid = (DB_TXN *)&argp[1];
00904
00905 memcpy(&argp->type, bp, sizeof(argp->type));
00906 bp += sizeof(argp->type);
00907
00908 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00909 bp += sizeof(argp->txnid->txnid);
00910
00911 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00912 bp += sizeof(DB_LSN);
00913
00914 memset(&argp->oldname, 0, sizeof(argp->oldname));
00915 memcpy(&argp->oldname.size, bp, sizeof(u_int32_t));
00916 bp += sizeof(u_int32_t);
00917 argp->oldname.data = bp;
00918 bp += argp->oldname.size;
00919
00920 memset(&argp->newname, 0, sizeof(argp->newname));
00921 memcpy(&argp->newname.size, bp, sizeof(u_int32_t));
00922 bp += sizeof(u_int32_t);
00923 argp->newname.data = bp;
00924 bp += argp->newname.size;
00925
00926 memset(&argp->fileid, 0, sizeof(argp->fileid));
00927 memcpy(&argp->fileid.size, bp, sizeof(u_int32_t));
00928 bp += sizeof(u_int32_t);
00929 argp->fileid.data = bp;
00930 bp += argp->fileid.size;
00931
00932 memcpy(&uinttmp, bp, sizeof(uinttmp));
00933 argp->appname = (u_int32_t)uinttmp;
00934 bp += sizeof(uinttmp);
00935
00936 *argpp = argp;
00937 return (0);
00938 }
00939
00940
00941
00942
00943
00944
00945 int
00946 __fop_file_remove_log(dbenv, txnid, ret_lsnp, flags,
00947 real_fid, tmp_fid, name, appname, child)
00948 DB_ENV *dbenv;
00949 DB_TXN *txnid;
00950 DB_LSN *ret_lsnp;
00951 u_int32_t flags;
00952 const DBT *real_fid;
00953 const DBT *tmp_fid;
00954 const DBT *name;
00955 u_int32_t appname;
00956 u_int32_t child;
00957 {
00958 DBT logrec;
00959 DB_TXNLOGREC *lr;
00960 DB_LSN *lsnp, null_lsn, *rlsnp;
00961 u_int32_t zero, uinttmp, rectype, txn_num;
00962 u_int npad;
00963 u_int8_t *bp;
00964 int is_durable, ret;
00965
00966 COMPQUIET(lr, NULL);
00967
00968 rectype = DB___fop_file_remove;
00969 npad = 0;
00970 rlsnp = ret_lsnp;
00971
00972 ret = 0;
00973
00974 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00975 if (txnid == NULL)
00976 return (0);
00977 is_durable = 0;
00978 } else
00979 is_durable = 1;
00980
00981 if (txnid == NULL) {
00982 txn_num = 0;
00983 lsnp = &null_lsn;
00984 null_lsn.file = null_lsn.offset = 0;
00985 } else {
00986 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00987 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00988 return (ret);
00989
00990
00991
00992
00993
00994
00995 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00996 txn_num = txnid->txnid;
00997 }
00998
00999 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01000 + sizeof(u_int32_t) + (real_fid == NULL ? 0 : real_fid->size)
01001 + sizeof(u_int32_t) + (tmp_fid == NULL ? 0 : tmp_fid->size)
01002 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
01003 + sizeof(u_int32_t)
01004 + sizeof(u_int32_t);
01005 if (CRYPTO_ON(dbenv)) {
01006 npad =
01007 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01008 logrec.size += npad;
01009 }
01010
01011 if (is_durable || txnid == NULL) {
01012 if ((ret =
01013 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01014 return (ret);
01015 } else {
01016 if ((ret = __os_malloc(dbenv,
01017 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01018 return (ret);
01019 #ifdef DIAGNOSTIC
01020 if ((ret =
01021 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01022 __os_free(dbenv, lr);
01023 return (ret);
01024 }
01025 #else
01026 logrec.data = lr->data;
01027 #endif
01028 }
01029 if (npad > 0)
01030 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01031
01032 bp = logrec.data;
01033
01034 memcpy(bp, &rectype, sizeof(rectype));
01035 bp += sizeof(rectype);
01036
01037 memcpy(bp, &txn_num, sizeof(txn_num));
01038 bp += sizeof(txn_num);
01039
01040 memcpy(bp, lsnp, sizeof(DB_LSN));
01041 bp += sizeof(DB_LSN);
01042
01043 if (real_fid == NULL) {
01044 zero = 0;
01045 memcpy(bp, &zero, sizeof(u_int32_t));
01046 bp += sizeof(u_int32_t);
01047 } else {
01048 memcpy(bp, &real_fid->size, sizeof(real_fid->size));
01049 bp += sizeof(real_fid->size);
01050 memcpy(bp, real_fid->data, real_fid->size);
01051 bp += real_fid->size;
01052 }
01053
01054 if (tmp_fid == NULL) {
01055 zero = 0;
01056 memcpy(bp, &zero, sizeof(u_int32_t));
01057 bp += sizeof(u_int32_t);
01058 } else {
01059 memcpy(bp, &tmp_fid->size, sizeof(tmp_fid->size));
01060 bp += sizeof(tmp_fid->size);
01061 memcpy(bp, tmp_fid->data, tmp_fid->size);
01062 bp += tmp_fid->size;
01063 }
01064
01065 if (name == NULL) {
01066 zero = 0;
01067 memcpy(bp, &zero, sizeof(u_int32_t));
01068 bp += sizeof(u_int32_t);
01069 } else {
01070 memcpy(bp, &name->size, sizeof(name->size));
01071 bp += sizeof(name->size);
01072 memcpy(bp, name->data, name->size);
01073 bp += name->size;
01074 }
01075
01076 uinttmp = (u_int32_t)appname;
01077 memcpy(bp, &uinttmp, sizeof(uinttmp));
01078 bp += sizeof(uinttmp);
01079
01080 uinttmp = (u_int32_t)child;
01081 memcpy(bp, &uinttmp, sizeof(uinttmp));
01082 bp += sizeof(uinttmp);
01083
01084 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01085
01086 if (is_durable || txnid == NULL) {
01087 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01088 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01089 *lsnp = *rlsnp;
01090 if (rlsnp != ret_lsnp)
01091 *ret_lsnp = *rlsnp;
01092 }
01093 } else {
01094 #ifdef DIAGNOSTIC
01095
01096
01097
01098
01099 memcpy(lr->data, logrec.data, logrec.size);
01100 rectype |= DB_debug_FLAG;
01101 memcpy(logrec.data, &rectype, sizeof(rectype));
01102
01103 ret = __log_put(dbenv,
01104 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01105 #else
01106 ret = 0;
01107 #endif
01108 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01109 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01110 LSN_NOT_LOGGED(*ret_lsnp);
01111 }
01112
01113 #ifdef LOG_DIAGNOSTIC
01114 if (ret != 0)
01115 (void)__fop_file_remove_print(dbenv,
01116 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01117 #endif
01118
01119 #ifdef DIAGNOSTIC
01120 __os_free(dbenv, logrec.data);
01121 #else
01122 if (is_durable || txnid == NULL)
01123 __os_free(dbenv, logrec.data);
01124 #endif
01125 return (ret);
01126 }
01127
01128
01129
01130
01131
01132 int
01133 __fop_file_remove_read(dbenv, recbuf, argpp)
01134 DB_ENV *dbenv;
01135 void *recbuf;
01136 __fop_file_remove_args **argpp;
01137 {
01138 __fop_file_remove_args *argp;
01139 u_int32_t uinttmp;
01140 u_int8_t *bp;
01141 int ret;
01142
01143 if ((ret = __os_malloc(dbenv,
01144 sizeof(__fop_file_remove_args) + sizeof(DB_TXN), &argp)) != 0)
01145 return (ret);
01146 bp = recbuf;
01147 argp->txnid = (DB_TXN *)&argp[1];
01148
01149 memcpy(&argp->type, bp, sizeof(argp->type));
01150 bp += sizeof(argp->type);
01151
01152 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
01153 bp += sizeof(argp->txnid->txnid);
01154
01155 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01156 bp += sizeof(DB_LSN);
01157
01158 memset(&argp->real_fid, 0, sizeof(argp->real_fid));
01159 memcpy(&argp->real_fid.size, bp, sizeof(u_int32_t));
01160 bp += sizeof(u_int32_t);
01161 argp->real_fid.data = bp;
01162 bp += argp->real_fid.size;
01163
01164 memset(&argp->tmp_fid, 0, sizeof(argp->tmp_fid));
01165 memcpy(&argp->tmp_fid.size, bp, sizeof(u_int32_t));
01166 bp += sizeof(u_int32_t);
01167 argp->tmp_fid.data = bp;
01168 bp += argp->tmp_fid.size;
01169
01170 memset(&argp->name, 0, sizeof(argp->name));
01171 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
01172 bp += sizeof(u_int32_t);
01173 argp->name.data = bp;
01174 bp += argp->name.size;
01175
01176 memcpy(&uinttmp, bp, sizeof(uinttmp));
01177 argp->appname = (u_int32_t)uinttmp;
01178 bp += sizeof(uinttmp);
01179
01180 memcpy(&uinttmp, bp, sizeof(uinttmp));
01181 argp->child = (u_int32_t)uinttmp;
01182 bp += sizeof(uinttmp);
01183
01184 *argpp = argp;
01185 return (0);
01186 }
01187
01188
01189
01190
01191
01192 int
01193 __fop_init_recover(dbenv, dtabp, dtabsizep)
01194 DB_ENV *dbenv;
01195 int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
01196 size_t *dtabsizep;
01197 {
01198 int ret;
01199
01200 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
01201 __fop_create_recover, DB___fop_create)) != 0)
01202 return (ret);
01203 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
01204 __fop_remove_recover, DB___fop_remove)) != 0)
01205 return (ret);
01206 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
01207 __fop_write_recover, DB___fop_write)) != 0)
01208 return (ret);
01209 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
01210 __fop_rename_recover, DB___fop_rename)) != 0)
01211 return (ret);
01212 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
01213 __fop_file_remove_recover, DB___fop_file_remove)) != 0)
01214 return (ret);
01215 return (0);
01216 }