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_dispatch.h"
00016 #include "dbinc/db_am.h"
00017 #include "dbinc/log.h"
00018 #include "dbinc/txn.h"
00019
00020
00021
00022
00023
00024 int
00025 __crdel_metasub_log(dbp, txnid, ret_lsnp, flags, pgno, page, lsn)
00026 DB *dbp;
00027 DB_TXN *txnid;
00028 DB_LSN *ret_lsnp;
00029 u_int32_t flags;
00030 db_pgno_t pgno;
00031 const DBT *page;
00032 DB_LSN * lsn;
00033 {
00034 DBT logrec;
00035 DB_ENV *dbenv;
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 dbenv = dbp->dbenv;
00044 COMPQUIET(lr, NULL);
00045
00046 rectype = DB___crdel_metasub;
00047 npad = 0;
00048 rlsnp = ret_lsnp;
00049
00050 ret = 0;
00051
00052 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00053 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
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 DB_ASSERT(dbp->log_filename != NULL);
00077 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00078 (ret = __dbreg_lazy_id(dbp)) != 0)
00079 return (ret);
00080
00081 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00082 + sizeof(u_int32_t)
00083 + sizeof(u_int32_t)
00084 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size)
00085 + sizeof(*lsn);
00086 if (CRYPTO_ON(dbenv)) {
00087 npad =
00088 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00089 logrec.size += npad;
00090 }
00091
00092 if (is_durable || txnid == NULL) {
00093 if ((ret =
00094 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00095 return (ret);
00096 } else {
00097 if ((ret = __os_malloc(dbenv,
00098 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00099 return (ret);
00100 #ifdef DIAGNOSTIC
00101 if ((ret =
00102 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00103 __os_free(dbenv, lr);
00104 return (ret);
00105 }
00106 #else
00107 logrec.data = lr->data;
00108 #endif
00109 }
00110 if (npad > 0)
00111 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00112
00113 bp = logrec.data;
00114
00115 memcpy(bp, &rectype, sizeof(rectype));
00116 bp += sizeof(rectype);
00117
00118 memcpy(bp, &txn_num, sizeof(txn_num));
00119 bp += sizeof(txn_num);
00120
00121 memcpy(bp, lsnp, sizeof(DB_LSN));
00122 bp += sizeof(DB_LSN);
00123
00124 uinttmp = (u_int32_t)dbp->log_filename->id;
00125 memcpy(bp, &uinttmp, sizeof(uinttmp));
00126 bp += sizeof(uinttmp);
00127
00128 uinttmp = (u_int32_t)pgno;
00129 memcpy(bp, &uinttmp, sizeof(uinttmp));
00130 bp += sizeof(uinttmp);
00131
00132 if (page == NULL) {
00133 zero = 0;
00134 memcpy(bp, &zero, sizeof(u_int32_t));
00135 bp += sizeof(u_int32_t);
00136 } else {
00137 memcpy(bp, &page->size, sizeof(page->size));
00138 bp += sizeof(page->size);
00139 memcpy(bp, page->data, page->size);
00140 bp += page->size;
00141 }
00142
00143 if (lsn != NULL)
00144 memcpy(bp, lsn, sizeof(*lsn));
00145 else
00146 memset(bp, 0, sizeof(*lsn));
00147 bp += sizeof(*lsn);
00148
00149 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00150
00151 if (is_durable || txnid == NULL) {
00152 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00153 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00154 *lsnp = *rlsnp;
00155 if (rlsnp != ret_lsnp)
00156 *ret_lsnp = *rlsnp;
00157 }
00158 } else {
00159 #ifdef DIAGNOSTIC
00160
00161
00162
00163
00164 memcpy(lr->data, logrec.data, logrec.size);
00165 rectype |= DB_debug_FLAG;
00166 memcpy(logrec.data, &rectype, sizeof(rectype));
00167
00168 ret = __log_put(dbenv,
00169 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00170 #else
00171 ret = 0;
00172 #endif
00173 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00174 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00175 LSN_NOT_LOGGED(*ret_lsnp);
00176 }
00177
00178 #ifdef LOG_DIAGNOSTIC
00179 if (ret != 0)
00180 (void)__crdel_metasub_print(dbenv,
00181 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00182 #endif
00183
00184 #ifdef DIAGNOSTIC
00185 __os_free(dbenv, logrec.data);
00186 #else
00187 if (is_durable || txnid == NULL)
00188 __os_free(dbenv, logrec.data);
00189 #endif
00190 return (ret);
00191 }
00192
00193
00194
00195
00196
00197 int
00198 __crdel_metasub_read(dbenv, recbuf, argpp)
00199 DB_ENV *dbenv;
00200 void *recbuf;
00201 __crdel_metasub_args **argpp;
00202 {
00203 __crdel_metasub_args *argp;
00204 u_int32_t uinttmp;
00205 u_int8_t *bp;
00206 int ret;
00207
00208 if ((ret = __os_malloc(dbenv,
00209 sizeof(__crdel_metasub_args) + sizeof(DB_TXN), &argp)) != 0)
00210 return (ret);
00211 bp = recbuf;
00212 argp->txnid = (DB_TXN *)&argp[1];
00213
00214 memcpy(&argp->type, bp, sizeof(argp->type));
00215 bp += sizeof(argp->type);
00216
00217 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00218 bp += sizeof(argp->txnid->txnid);
00219
00220 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00221 bp += sizeof(DB_LSN);
00222
00223 memcpy(&uinttmp, bp, sizeof(uinttmp));
00224 argp->fileid = (int32_t)uinttmp;
00225 bp += sizeof(uinttmp);
00226
00227 memcpy(&uinttmp, bp, sizeof(uinttmp));
00228 argp->pgno = (db_pgno_t)uinttmp;
00229 bp += sizeof(uinttmp);
00230
00231 memset(&argp->page, 0, sizeof(argp->page));
00232 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
00233 bp += sizeof(u_int32_t);
00234 argp->page.data = bp;
00235 bp += argp->page.size;
00236
00237 memcpy(&argp->lsn, bp, sizeof(argp->lsn));
00238 bp += sizeof(argp->lsn);
00239
00240 *argpp = argp;
00241 return (0);
00242 }
00243
00244
00245
00246
00247
00248
00249 int
00250 __crdel_inmem_create_log(dbenv, txnid, ret_lsnp, flags,
00251 fileid, name, fid, pgsize)
00252 DB_ENV *dbenv;
00253 DB_TXN *txnid;
00254 DB_LSN *ret_lsnp;
00255 u_int32_t flags;
00256 int32_t fileid;
00257 const DBT *name;
00258 const DBT *fid;
00259 u_int32_t pgsize;
00260 {
00261 DBT logrec;
00262 DB_TXNLOGREC *lr;
00263 DB_LSN *lsnp, null_lsn, *rlsnp;
00264 u_int32_t zero, uinttmp, rectype, txn_num;
00265 u_int npad;
00266 u_int8_t *bp;
00267 int is_durable, ret;
00268
00269 COMPQUIET(lr, NULL);
00270
00271 rectype = DB___crdel_inmem_create;
00272 npad = 0;
00273 rlsnp = ret_lsnp;
00274
00275 ret = 0;
00276
00277 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00278 if (txnid == NULL)
00279 return (0);
00280 is_durable = 0;
00281 } else
00282 is_durable = 1;
00283
00284 if (txnid == NULL) {
00285 txn_num = 0;
00286 lsnp = &null_lsn;
00287 null_lsn.file = null_lsn.offset = 0;
00288 } else {
00289 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00290 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00291 return (ret);
00292
00293
00294
00295
00296
00297
00298 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00299 txn_num = txnid->txnid;
00300 }
00301
00302 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00303 + sizeof(u_int32_t)
00304 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00305 + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size)
00306 + sizeof(u_int32_t);
00307 if (CRYPTO_ON(dbenv)) {
00308 npad =
00309 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00310 logrec.size += npad;
00311 }
00312
00313 if (is_durable || txnid == NULL) {
00314 if ((ret =
00315 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00316 return (ret);
00317 } else {
00318 if ((ret = __os_malloc(dbenv,
00319 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00320 return (ret);
00321 #ifdef DIAGNOSTIC
00322 if ((ret =
00323 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00324 __os_free(dbenv, lr);
00325 return (ret);
00326 }
00327 #else
00328 logrec.data = lr->data;
00329 #endif
00330 }
00331 if (npad > 0)
00332 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00333
00334 bp = logrec.data;
00335
00336 memcpy(bp, &rectype, sizeof(rectype));
00337 bp += sizeof(rectype);
00338
00339 memcpy(bp, &txn_num, sizeof(txn_num));
00340 bp += sizeof(txn_num);
00341
00342 memcpy(bp, lsnp, sizeof(DB_LSN));
00343 bp += sizeof(DB_LSN);
00344
00345 uinttmp = (u_int32_t)fileid;
00346 memcpy(bp, &uinttmp, sizeof(uinttmp));
00347 bp += sizeof(uinttmp);
00348
00349 if (name == NULL) {
00350 zero = 0;
00351 memcpy(bp, &zero, sizeof(u_int32_t));
00352 bp += sizeof(u_int32_t);
00353 } else {
00354 memcpy(bp, &name->size, sizeof(name->size));
00355 bp += sizeof(name->size);
00356 memcpy(bp, name->data, name->size);
00357 bp += name->size;
00358 }
00359
00360 if (fid == NULL) {
00361 zero = 0;
00362 memcpy(bp, &zero, sizeof(u_int32_t));
00363 bp += sizeof(u_int32_t);
00364 } else {
00365 memcpy(bp, &fid->size, sizeof(fid->size));
00366 bp += sizeof(fid->size);
00367 memcpy(bp, fid->data, fid->size);
00368 bp += fid->size;
00369 }
00370
00371 uinttmp = (u_int32_t)pgsize;
00372 memcpy(bp, &uinttmp, sizeof(uinttmp));
00373 bp += sizeof(uinttmp);
00374
00375 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00376
00377 if (is_durable || txnid == NULL) {
00378 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00379 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00380 *lsnp = *rlsnp;
00381 if (rlsnp != ret_lsnp)
00382 *ret_lsnp = *rlsnp;
00383 }
00384 } else {
00385 #ifdef DIAGNOSTIC
00386
00387
00388
00389
00390 memcpy(lr->data, logrec.data, logrec.size);
00391 rectype |= DB_debug_FLAG;
00392 memcpy(logrec.data, &rectype, sizeof(rectype));
00393
00394 ret = __log_put(dbenv,
00395 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00396 #else
00397 ret = 0;
00398 #endif
00399 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00400 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00401 LSN_NOT_LOGGED(*ret_lsnp);
00402 }
00403
00404 #ifdef LOG_DIAGNOSTIC
00405 if (ret != 0)
00406 (void)__crdel_inmem_create_print(dbenv,
00407 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00408 #endif
00409
00410 #ifdef DIAGNOSTIC
00411 __os_free(dbenv, logrec.data);
00412 #else
00413 if (is_durable || txnid == NULL)
00414 __os_free(dbenv, logrec.data);
00415 #endif
00416 return (ret);
00417 }
00418
00419
00420
00421
00422
00423 int
00424 __crdel_inmem_create_read(dbenv, recbuf, argpp)
00425 DB_ENV *dbenv;
00426 void *recbuf;
00427 __crdel_inmem_create_args **argpp;
00428 {
00429 __crdel_inmem_create_args *argp;
00430 u_int32_t uinttmp;
00431 u_int8_t *bp;
00432 int ret;
00433
00434 if ((ret = __os_malloc(dbenv,
00435 sizeof(__crdel_inmem_create_args) + sizeof(DB_TXN), &argp)) != 0)
00436 return (ret);
00437 bp = recbuf;
00438 argp->txnid = (DB_TXN *)&argp[1];
00439
00440 memcpy(&argp->type, bp, sizeof(argp->type));
00441 bp += sizeof(argp->type);
00442
00443 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00444 bp += sizeof(argp->txnid->txnid);
00445
00446 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00447 bp += sizeof(DB_LSN);
00448
00449 memcpy(&uinttmp, bp, sizeof(uinttmp));
00450 argp->fileid = (int32_t)uinttmp;
00451 bp += sizeof(uinttmp);
00452
00453 memset(&argp->name, 0, sizeof(argp->name));
00454 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00455 bp += sizeof(u_int32_t);
00456 argp->name.data = bp;
00457 bp += argp->name.size;
00458
00459 memset(&argp->fid, 0, sizeof(argp->fid));
00460 memcpy(&argp->fid.size, bp, sizeof(u_int32_t));
00461 bp += sizeof(u_int32_t);
00462 argp->fid.data = bp;
00463 bp += argp->fid.size;
00464
00465 memcpy(&uinttmp, bp, sizeof(uinttmp));
00466 argp->pgsize = (u_int32_t)uinttmp;
00467 bp += sizeof(uinttmp);
00468
00469 *argpp = argp;
00470 return (0);
00471 }
00472
00473
00474
00475
00476
00477 int
00478 __crdel_inmem_rename_log(dbenv, txnid, ret_lsnp, flags,
00479 oldname, newname, fid)
00480 DB_ENV *dbenv;
00481 DB_TXN *txnid;
00482 DB_LSN *ret_lsnp;
00483 u_int32_t flags;
00484 const DBT *oldname;
00485 const DBT *newname;
00486 const DBT *fid;
00487 {
00488 DBT logrec;
00489 DB_TXNLOGREC *lr;
00490 DB_LSN *lsnp, null_lsn, *rlsnp;
00491 u_int32_t zero, rectype, txn_num;
00492 u_int npad;
00493 u_int8_t *bp;
00494 int is_durable, ret;
00495
00496 COMPQUIET(lr, NULL);
00497
00498 rectype = DB___crdel_inmem_rename;
00499 npad = 0;
00500 rlsnp = ret_lsnp;
00501
00502 ret = 0;
00503
00504 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00505 if (txnid == NULL)
00506 return (0);
00507 is_durable = 0;
00508 } else
00509 is_durable = 1;
00510
00511 if (txnid == NULL) {
00512 txn_num = 0;
00513 lsnp = &null_lsn;
00514 null_lsn.file = null_lsn.offset = 0;
00515 } else {
00516 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00517 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00518 return (ret);
00519
00520
00521
00522
00523
00524
00525 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00526 txn_num = txnid->txnid;
00527 }
00528
00529 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00530 + sizeof(u_int32_t) + (oldname == NULL ? 0 : oldname->size)
00531 + sizeof(u_int32_t) + (newname == NULL ? 0 : newname->size)
00532 + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size);
00533 if (CRYPTO_ON(dbenv)) {
00534 npad =
00535 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00536 logrec.size += npad;
00537 }
00538
00539 if (is_durable || txnid == NULL) {
00540 if ((ret =
00541 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00542 return (ret);
00543 } else {
00544 if ((ret = __os_malloc(dbenv,
00545 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00546 return (ret);
00547 #ifdef DIAGNOSTIC
00548 if ((ret =
00549 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00550 __os_free(dbenv, lr);
00551 return (ret);
00552 }
00553 #else
00554 logrec.data = lr->data;
00555 #endif
00556 }
00557 if (npad > 0)
00558 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00559
00560 bp = logrec.data;
00561
00562 memcpy(bp, &rectype, sizeof(rectype));
00563 bp += sizeof(rectype);
00564
00565 memcpy(bp, &txn_num, sizeof(txn_num));
00566 bp += sizeof(txn_num);
00567
00568 memcpy(bp, lsnp, sizeof(DB_LSN));
00569 bp += sizeof(DB_LSN);
00570
00571 if (oldname == NULL) {
00572 zero = 0;
00573 memcpy(bp, &zero, sizeof(u_int32_t));
00574 bp += sizeof(u_int32_t);
00575 } else {
00576 memcpy(bp, &oldname->size, sizeof(oldname->size));
00577 bp += sizeof(oldname->size);
00578 memcpy(bp, oldname->data, oldname->size);
00579 bp += oldname->size;
00580 }
00581
00582 if (newname == NULL) {
00583 zero = 0;
00584 memcpy(bp, &zero, sizeof(u_int32_t));
00585 bp += sizeof(u_int32_t);
00586 } else {
00587 memcpy(bp, &newname->size, sizeof(newname->size));
00588 bp += sizeof(newname->size);
00589 memcpy(bp, newname->data, newname->size);
00590 bp += newname->size;
00591 }
00592
00593 if (fid == NULL) {
00594 zero = 0;
00595 memcpy(bp, &zero, sizeof(u_int32_t));
00596 bp += sizeof(u_int32_t);
00597 } else {
00598 memcpy(bp, &fid->size, sizeof(fid->size));
00599 bp += sizeof(fid->size);
00600 memcpy(bp, fid->data, fid->size);
00601 bp += fid->size;
00602 }
00603
00604 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00605
00606 if (is_durable || txnid == NULL) {
00607 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00608 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00609 *lsnp = *rlsnp;
00610 if (rlsnp != ret_lsnp)
00611 *ret_lsnp = *rlsnp;
00612 }
00613 } else {
00614 #ifdef DIAGNOSTIC
00615
00616
00617
00618
00619 memcpy(lr->data, logrec.data, logrec.size);
00620 rectype |= DB_debug_FLAG;
00621 memcpy(logrec.data, &rectype, sizeof(rectype));
00622
00623 ret = __log_put(dbenv,
00624 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00625 #else
00626 ret = 0;
00627 #endif
00628 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00629 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00630 LSN_NOT_LOGGED(*ret_lsnp);
00631 }
00632
00633 #ifdef LOG_DIAGNOSTIC
00634 if (ret != 0)
00635 (void)__crdel_inmem_rename_print(dbenv,
00636 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00637 #endif
00638
00639 #ifdef DIAGNOSTIC
00640 __os_free(dbenv, logrec.data);
00641 #else
00642 if (is_durable || txnid == NULL)
00643 __os_free(dbenv, logrec.data);
00644 #endif
00645 return (ret);
00646 }
00647
00648
00649
00650
00651
00652 int
00653 __crdel_inmem_rename_read(dbenv, recbuf, argpp)
00654 DB_ENV *dbenv;
00655 void *recbuf;
00656 __crdel_inmem_rename_args **argpp;
00657 {
00658 __crdel_inmem_rename_args *argp;
00659 u_int8_t *bp;
00660 int ret;
00661
00662 if ((ret = __os_malloc(dbenv,
00663 sizeof(__crdel_inmem_rename_args) + sizeof(DB_TXN), &argp)) != 0)
00664 return (ret);
00665 bp = recbuf;
00666 argp->txnid = (DB_TXN *)&argp[1];
00667
00668 memcpy(&argp->type, bp, sizeof(argp->type));
00669 bp += sizeof(argp->type);
00670
00671 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00672 bp += sizeof(argp->txnid->txnid);
00673
00674 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00675 bp += sizeof(DB_LSN);
00676
00677 memset(&argp->oldname, 0, sizeof(argp->oldname));
00678 memcpy(&argp->oldname.size, bp, sizeof(u_int32_t));
00679 bp += sizeof(u_int32_t);
00680 argp->oldname.data = bp;
00681 bp += argp->oldname.size;
00682
00683 memset(&argp->newname, 0, sizeof(argp->newname));
00684 memcpy(&argp->newname.size, bp, sizeof(u_int32_t));
00685 bp += sizeof(u_int32_t);
00686 argp->newname.data = bp;
00687 bp += argp->newname.size;
00688
00689 memset(&argp->fid, 0, sizeof(argp->fid));
00690 memcpy(&argp->fid.size, bp, sizeof(u_int32_t));
00691 bp += sizeof(u_int32_t);
00692 argp->fid.data = bp;
00693 bp += argp->fid.size;
00694
00695 *argpp = argp;
00696 return (0);
00697 }
00698
00699
00700
00701
00702
00703 int
00704 __crdel_inmem_remove_log(dbenv, txnid, ret_lsnp, flags,
00705 name, fid)
00706 DB_ENV *dbenv;
00707 DB_TXN *txnid;
00708 DB_LSN *ret_lsnp;
00709 u_int32_t flags;
00710 const DBT *name;
00711 const DBT *fid;
00712 {
00713 DBT logrec;
00714 DB_TXNLOGREC *lr;
00715 DB_LSN *lsnp, null_lsn, *rlsnp;
00716 u_int32_t zero, rectype, txn_num;
00717 u_int npad;
00718 u_int8_t *bp;
00719 int is_durable, ret;
00720
00721 COMPQUIET(lr, NULL);
00722
00723 rectype = DB___crdel_inmem_remove;
00724 npad = 0;
00725 rlsnp = ret_lsnp;
00726
00727 ret = 0;
00728
00729 if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
00730 if (txnid == NULL)
00731 return (0);
00732 is_durable = 0;
00733 } else
00734 is_durable = 1;
00735
00736 if (txnid == NULL) {
00737 txn_num = 0;
00738 lsnp = &null_lsn;
00739 null_lsn.file = null_lsn.offset = 0;
00740 } else {
00741 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00742 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00743 return (ret);
00744
00745
00746
00747
00748
00749
00750 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00751 txn_num = txnid->txnid;
00752 }
00753
00754 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00755 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
00756 + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size);
00757 if (CRYPTO_ON(dbenv)) {
00758 npad =
00759 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00760 logrec.size += npad;
00761 }
00762
00763 if (is_durable || txnid == NULL) {
00764 if ((ret =
00765 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00766 return (ret);
00767 } else {
00768 if ((ret = __os_malloc(dbenv,
00769 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00770 return (ret);
00771 #ifdef DIAGNOSTIC
00772 if ((ret =
00773 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00774 __os_free(dbenv, lr);
00775 return (ret);
00776 }
00777 #else
00778 logrec.data = lr->data;
00779 #endif
00780 }
00781 if (npad > 0)
00782 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00783
00784 bp = logrec.data;
00785
00786 memcpy(bp, &rectype, sizeof(rectype));
00787 bp += sizeof(rectype);
00788
00789 memcpy(bp, &txn_num, sizeof(txn_num));
00790 bp += sizeof(txn_num);
00791
00792 memcpy(bp, lsnp, sizeof(DB_LSN));
00793 bp += sizeof(DB_LSN);
00794
00795 if (name == NULL) {
00796 zero = 0;
00797 memcpy(bp, &zero, sizeof(u_int32_t));
00798 bp += sizeof(u_int32_t);
00799 } else {
00800 memcpy(bp, &name->size, sizeof(name->size));
00801 bp += sizeof(name->size);
00802 memcpy(bp, name->data, name->size);
00803 bp += name->size;
00804 }
00805
00806 if (fid == NULL) {
00807 zero = 0;
00808 memcpy(bp, &zero, sizeof(u_int32_t));
00809 bp += sizeof(u_int32_t);
00810 } else {
00811 memcpy(bp, &fid->size, sizeof(fid->size));
00812 bp += sizeof(fid->size);
00813 memcpy(bp, fid->data, fid->size);
00814 bp += fid->size;
00815 }
00816
00817 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00818
00819 if (is_durable || txnid == NULL) {
00820 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00821 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00822 *lsnp = *rlsnp;
00823 if (rlsnp != ret_lsnp)
00824 *ret_lsnp = *rlsnp;
00825 }
00826 } else {
00827 #ifdef DIAGNOSTIC
00828
00829
00830
00831
00832 memcpy(lr->data, logrec.data, logrec.size);
00833 rectype |= DB_debug_FLAG;
00834 memcpy(logrec.data, &rectype, sizeof(rectype));
00835
00836 ret = __log_put(dbenv,
00837 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00838 #else
00839 ret = 0;
00840 #endif
00841 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00842 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00843 LSN_NOT_LOGGED(*ret_lsnp);
00844 }
00845
00846 #ifdef LOG_DIAGNOSTIC
00847 if (ret != 0)
00848 (void)__crdel_inmem_remove_print(dbenv,
00849 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00850 #endif
00851
00852 #ifdef DIAGNOSTIC
00853 __os_free(dbenv, logrec.data);
00854 #else
00855 if (is_durable || txnid == NULL)
00856 __os_free(dbenv, logrec.data);
00857 #endif
00858 return (ret);
00859 }
00860
00861
00862
00863
00864
00865 int
00866 __crdel_inmem_remove_read(dbenv, recbuf, argpp)
00867 DB_ENV *dbenv;
00868 void *recbuf;
00869 __crdel_inmem_remove_args **argpp;
00870 {
00871 __crdel_inmem_remove_args *argp;
00872 u_int8_t *bp;
00873 int ret;
00874
00875 if ((ret = __os_malloc(dbenv,
00876 sizeof(__crdel_inmem_remove_args) + sizeof(DB_TXN), &argp)) != 0)
00877 return (ret);
00878 bp = recbuf;
00879 argp->txnid = (DB_TXN *)&argp[1];
00880
00881 memcpy(&argp->type, bp, sizeof(argp->type));
00882 bp += sizeof(argp->type);
00883
00884 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00885 bp += sizeof(argp->txnid->txnid);
00886
00887 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00888 bp += sizeof(DB_LSN);
00889
00890 memset(&argp->name, 0, sizeof(argp->name));
00891 memcpy(&argp->name.size, bp, sizeof(u_int32_t));
00892 bp += sizeof(u_int32_t);
00893 argp->name.data = bp;
00894 bp += argp->name.size;
00895
00896 memset(&argp->fid, 0, sizeof(argp->fid));
00897 memcpy(&argp->fid.size, bp, sizeof(u_int32_t));
00898 bp += sizeof(u_int32_t);
00899 argp->fid.data = bp;
00900 bp += argp->fid.size;
00901
00902 *argpp = argp;
00903 return (0);
00904 }
00905
00906
00907
00908
00909
00910 int
00911 __crdel_init_recover(dbenv, dtabp, dtabsizep)
00912 DB_ENV *dbenv;
00913 int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
00914 size_t *dtabsizep;
00915 {
00916 int ret;
00917
00918 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
00919 __crdel_metasub_recover, DB___crdel_metasub)) != 0)
00920 return (ret);
00921 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
00922 __crdel_inmem_create_recover, DB___crdel_inmem_create)) != 0)
00923 return (ret);
00924 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
00925 __crdel_inmem_rename_recover, DB___crdel_inmem_rename)) != 0)
00926 return (ret);
00927 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
00928 __crdel_inmem_remove_recover, DB___crdel_inmem_remove)) != 0)
00929 return (ret);
00930 return (0);
00931 }