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_dispatch.h" 8#include "dbinc/db_am.h" 9#include "dbinc/log.h" 10#include "dbinc/txn.h" 11 12/* 13 * PUBLIC: int __dbreg_register_read __P((ENV *, void *, 14 * PUBLIC: __dbreg_register_args **)); 15 */ 16int 17__dbreg_register_read(env, recbuf, argpp) 18 ENV *env; 19 void *recbuf; 20 __dbreg_register_args **argpp; 21{ 22 __dbreg_register_args *argp; 23 u_int32_t uinttmp; 24 u_int8_t *bp; 25 int ret; 26 27 if ((ret = __os_malloc(env, 28 sizeof(__dbreg_register_args) + sizeof(DB_TXN), &argp)) != 0) 29 return (ret); 30 bp = recbuf; 31 argp->txnp = (DB_TXN *)&argp[1]; 32 memset(argp->txnp, 0, sizeof(DB_TXN)); 33 34 LOGCOPY_32(env, &argp->type, bp); 35 bp += sizeof(argp->type); 36 37 LOGCOPY_32(env, &argp->txnp->txnid, bp); 38 bp += sizeof(argp->txnp->txnid); 39 40 LOGCOPY_TOLSN(env, &argp->prev_lsn, bp); 41 bp += sizeof(DB_LSN); 42 43 LOGCOPY_32(env, &argp->opcode, bp); 44 bp += sizeof(argp->opcode); 45 46 memset(&argp->name, 0, sizeof(argp->name)); 47 LOGCOPY_32(env,&argp->name.size, bp); 48 bp += sizeof(u_int32_t); 49 argp->name.data = bp; 50 bp += argp->name.size; 51 52 memset(&argp->uid, 0, sizeof(argp->uid)); 53 LOGCOPY_32(env,&argp->uid.size, bp); 54 bp += sizeof(u_int32_t); 55 argp->uid.data = bp; 56 bp += argp->uid.size; 57 58 LOGCOPY_32(env, &uinttmp, bp); 59 argp->fileid = (int32_t)uinttmp; 60 bp += sizeof(uinttmp); 61 62 LOGCOPY_32(env, &uinttmp, bp); 63 argp->ftype = (DBTYPE)uinttmp; 64 bp += sizeof(uinttmp); 65 66 LOGCOPY_32(env, &uinttmp, bp); 67 argp->meta_pgno = (db_pgno_t)uinttmp; 68 bp += sizeof(uinttmp); 69 70 LOGCOPY_32(env, &argp->id, bp); 71 bp += sizeof(argp->id); 72 73 *argpp = argp; 74 return (ret); 75} 76 77/* 78 * PUBLIC: int __dbreg_register_log __P((ENV *, DB_TXN *, DB_LSN *, 79 * PUBLIC: u_int32_t, u_int32_t, const DBT *, const DBT *, int32_t, DBTYPE, 80 * PUBLIC: db_pgno_t, u_int32_t)); 81 */ 82int 83__dbreg_register_log(env, txnp, ret_lsnp, flags, 84 opcode, name, uid, fileid, ftype, meta_pgno, 85 id) 86 ENV *env; 87 DB_TXN *txnp; 88 DB_LSN *ret_lsnp; 89 u_int32_t flags; 90 u_int32_t opcode; 91 const DBT *name; 92 const DBT *uid; 93 int32_t fileid; 94 DBTYPE ftype; 95 db_pgno_t meta_pgno; 96 u_int32_t id; 97{ 98 DBT logrec; 99 DB_LSN *lsnp, null_lsn, *rlsnp; 100 DB_TXNLOGREC *lr; 101 u_int32_t zero, uinttmp, rectype, txn_num; 102 u_int npad; 103 u_int8_t *bp; 104 int is_durable, ret; 105 106 COMPQUIET(lr, NULL); 107 108 rlsnp = ret_lsnp; 109 rectype = DB___dbreg_register; 110 npad = 0; 111 ret = 0; 112 113 if (LF_ISSET(DB_LOG_NOT_DURABLE)) { 114 if (txnp == NULL) 115 return (0); 116 if (txnp == NULL) 117 return (0); 118 is_durable = 0; 119 } else 120 is_durable = 1; 121 122 if (txnp == NULL) { 123 txn_num = 0; 124 lsnp = &null_lsn; 125 null_lsn.file = null_lsn.offset = 0; 126 } else { 127 if (TAILQ_FIRST(&txnp->kids) != NULL && 128 (ret = __txn_activekids(env, rectype, txnp)) != 0) 129 return (ret); 130 /* 131 * We need to assign begin_lsn while holding region mutex. 132 * That assignment is done inside the DbEnv->log_put call, 133 * so pass in the appropriate memory location to be filled 134 * in by the log_put code. 135 */ 136 DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp); 137 txn_num = txnp->txnid; 138 } 139 140 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 141 + sizeof(u_int32_t) 142 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 143 + sizeof(u_int32_t) + (uid == NULL ? 0 : uid->size) 144 + sizeof(u_int32_t) 145 + sizeof(u_int32_t) 146 + sizeof(u_int32_t) 147 + sizeof(u_int32_t); 148 if (CRYPTO_ON(env)) { 149 npad = env->crypto_handle->adj_size(logrec.size); 150 logrec.size += npad; 151 } 152 153 if (is_durable || txnp == NULL) { 154 if ((ret = 155 __os_malloc(env, logrec.size, &logrec.data)) != 0) 156 return (ret); 157 } else { 158 if ((ret = __os_malloc(env, 159 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0) 160 return (ret); 161#ifdef DIAGNOSTIC 162 if ((ret = 163 __os_malloc(env, logrec.size, &logrec.data)) != 0) { 164 __os_free(env, lr); 165 return (ret); 166 } 167#else 168 logrec.data = lr->data; 169#endif 170 } 171 if (npad > 0) 172 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad); 173 174 bp = logrec.data; 175 176 LOGCOPY_32(env, bp, &rectype); 177 bp += sizeof(rectype); 178 179 LOGCOPY_32(env, bp, &txn_num); 180 bp += sizeof(txn_num); 181 182 LOGCOPY_FROMLSN(env, bp, lsnp); 183 bp += sizeof(DB_LSN); 184 185 LOGCOPY_32(env, bp, &opcode); 186 bp += sizeof(opcode); 187 188 if (name == NULL) { 189 zero = 0; 190 LOGCOPY_32(env, bp, &zero); 191 bp += sizeof(u_int32_t); 192 } else { 193 LOGCOPY_32(env, bp, &name->size); 194 bp += sizeof(name->size); 195 memcpy(bp, name->data, name->size); 196 bp += name->size; 197 } 198 199 if (uid == NULL) { 200 zero = 0; 201 LOGCOPY_32(env, bp, &zero); 202 bp += sizeof(u_int32_t); 203 } else { 204 LOGCOPY_32(env, bp, &uid->size); 205 bp += sizeof(uid->size); 206 memcpy(bp, uid->data, uid->size); 207 bp += uid->size; 208 } 209 210 uinttmp = (u_int32_t)fileid; 211 LOGCOPY_32(env,bp, &uinttmp); 212 bp += sizeof(uinttmp); 213 214 uinttmp = (u_int32_t)ftype; 215 LOGCOPY_32(env,bp, &uinttmp); 216 bp += sizeof(uinttmp); 217 218 uinttmp = (u_int32_t)meta_pgno; 219 LOGCOPY_32(env,bp, &uinttmp); 220 bp += sizeof(uinttmp); 221 222 LOGCOPY_32(env, bp, &id); 223 bp += sizeof(id); 224 225 DB_ASSERT(env, 226 (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size); 227 228 if (is_durable || txnp == NULL) { 229 if ((ret = __log_put(env, rlsnp,(DBT *)&logrec, 230 flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) { 231 *lsnp = *rlsnp; 232 if (rlsnp != ret_lsnp) 233 *ret_lsnp = *rlsnp; 234 } 235 } else { 236 ret = 0; 237#ifdef DIAGNOSTIC 238 /* 239 * Set the debug bit if we are going to log non-durable 240 * transactions so they will be ignored by recovery. 241 */ 242 memcpy(lr->data, logrec.data, logrec.size); 243 rectype |= DB_debug_FLAG; 244 LOGCOPY_32(env, logrec.data, &rectype); 245 246 if (!IS_REP_CLIENT(env)) 247 ret = __log_put(env, 248 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY); 249#endif 250 STAILQ_INSERT_HEAD(&txnp->logs, lr, links); 251 F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY); 252 LSN_NOT_LOGGED(*ret_lsnp); 253 } 254 255#ifdef LOG_DIAGNOSTIC 256 if (ret != 0) 257 (void)__dbreg_register_print(env, 258 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL); 259#endif 260 261#ifdef DIAGNOSTIC 262 __os_free(env, logrec.data); 263#else 264 if (is_durable || txnp == NULL) 265 __os_free(env, logrec.data); 266#endif 267 return (ret); 268} 269 270/* 271 * PUBLIC: int __dbreg_init_recover __P((ENV *, DB_DISTAB *)); 272 */ 273int 274__dbreg_init_recover(env, dtabp) 275 ENV *env; 276 DB_DISTAB *dtabp; 277{ 278 int ret; 279 280 if ((ret = __db_add_recovery_int(env, dtabp, 281 __dbreg_register_recover, DB___dbreg_register)) != 0) 282 return (ret); 283 return (0); 284} 285