00001 /* Do not edit: automatically built by gen_rec.awk. */ 00002 #include "config.h" 00003 00004 #ifndef NO_SYSTEM_INCLUDES 00005 #include <sys/types.h> 00006 00007 #include <ctype.h> 00008 #include <errno.h> 00009 #include <string.h> 00010 #endif 00011 00012 #include "db_int.h" 00013 #include "db_page.h" 00014 #include "db_dispatch.h" 00015 #include "db_am.h" 00016 #include "log.h" 00017 #include "txn.h" 00018 00019 int 00020 CDB___log_register1_print(dbenv, dbtp, lsnp, notused2, notused3) 00021 DB_ENV *dbenv; 00022 DBT *dbtp; 00023 DB_LSN *lsnp; 00024 db_recops notused2; 00025 void *notused3; 00026 { 00027 __log_register1_args *argp; 00028 u_int32_t i; 00029 u_int ch; 00030 int ret; 00031 00032 i = 0; 00033 ch = 0; 00034 notused2 = 0; 00035 notused3 = NULL; 00036 00037 if ((ret = CDB___log_register1_read(dbenv, dbtp->data, &argp)) != 0) 00038 return (ret); 00039 printf("[%lu][%lu]log_register1: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 00040 (u_long)lsnp->file, 00041 (u_long)lsnp->offset, 00042 (u_long)argp->type, 00043 (u_long)argp->txnid->txnid, 00044 (u_long)argp->prev_lsn.file, 00045 (u_long)argp->prev_lsn.offset); 00046 printf("\topcode: %lu\n", (u_long)argp->opcode); 00047 printf("\tname: "); 00048 for (i = 0; i < argp->name.size; i++) { 00049 ch = ((u_int8_t *)argp->name.data)[i]; 00050 if (isprint(ch) || ch == 0xa) 00051 putchar(ch); 00052 else 00053 printf("%#x ", ch); 00054 } 00055 printf("\n"); 00056 printf("\tuid: "); 00057 for (i = 0; i < argp->uid.size; i++) { 00058 ch = ((u_int8_t *)argp->uid.data)[i]; 00059 if (isprint(ch) || ch == 0xa) 00060 putchar(ch); 00061 else 00062 printf("%#x ", ch); 00063 } 00064 printf("\n"); 00065 printf("\tfileid: %ld\n", (long)argp->fileid); 00066 printf("\tftype: 0x%lx\n", (u_long)argp->ftype); 00067 printf("\n"); 00068 CDB___os_free(argp, 0); 00069 return (0); 00070 } 00071 00072 int 00073 CDB___log_register1_read(dbenv, recbuf, argpp) 00074 DB_ENV *dbenv; 00075 void *recbuf; 00076 __log_register1_args **argpp; 00077 { 00078 __log_register1_args *argp; 00079 u_int8_t *bp; 00080 int ret; 00081 00082 ret = CDB___os_malloc(dbenv, sizeof(__log_register1_args) + 00083 sizeof(DB_TXN), NULL, &argp); 00084 if (ret != 0) 00085 return (ret); 00086 argp->txnid = (DB_TXN *)&argp[1]; 00087 bp = recbuf; 00088 memcpy(&argp->type, bp, sizeof(argp->type)); 00089 bp += sizeof(argp->type); 00090 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 00091 bp += sizeof(argp->txnid->txnid); 00092 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 00093 bp += sizeof(DB_LSN); 00094 memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 00095 bp += sizeof(argp->opcode); 00096 memset(&argp->name, 0, sizeof(argp->name)); 00097 memcpy(&argp->name.size, bp, sizeof(u_int32_t)); 00098 bp += sizeof(u_int32_t); 00099 argp->name.data = bp; 00100 bp += argp->name.size; 00101 memset(&argp->uid, 0, sizeof(argp->uid)); 00102 memcpy(&argp->uid.size, bp, sizeof(u_int32_t)); 00103 bp += sizeof(u_int32_t); 00104 argp->uid.data = bp; 00105 bp += argp->uid.size; 00106 memcpy(&argp->fileid, bp, sizeof(argp->fileid)); 00107 bp += sizeof(argp->fileid); 00108 memcpy(&argp->ftype, bp, sizeof(argp->ftype)); 00109 bp += sizeof(argp->ftype); 00110 *argpp = argp; 00111 return (0); 00112 } 00113 00114 int CDB___log_register_log(dbenv, txnid, ret_lsnp, flags, 00115 opcode, name, uid, fileid, ftype, meta_pgno) 00116 DB_ENV *dbenv; 00117 DB_TXN *txnid; 00118 DB_LSN *ret_lsnp; 00119 u_int32_t flags; 00120 u_int32_t opcode; 00121 const DBT *name; 00122 const DBT *uid; 00123 int32_t fileid; 00124 DBTYPE ftype; 00125 db_pgno_t meta_pgno; 00126 { 00127 DBT logrec; 00128 DB_LSN *lsnp, null_lsn; 00129 u_int32_t zero; 00130 u_int32_t rectype, txn_num; 00131 int ret; 00132 u_int8_t *bp; 00133 00134 if (txnid != NULL && 00135 TAILQ_FIRST(&txnid->kids) != NULL && CDB___txn_activekids(txnid) != 0) 00136 return (CDB___db_child_active_err(dbenv)); 00137 rectype = DB_log_register; 00138 txn_num = txnid == NULL ? 0 : txnid->txnid; 00139 if (txnid == NULL) { 00140 ZERO_LSN(null_lsn); 00141 lsnp = &null_lsn; 00142 } else 00143 lsnp = &txnid->last_lsn; 00144 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN) 00145 + sizeof(opcode) 00146 + sizeof(u_int32_t) + (name == NULL ? 0 : name->size) 00147 + sizeof(u_int32_t) + (uid == NULL ? 0 : uid->size) 00148 + sizeof(fileid) 00149 + sizeof(ftype) 00150 + sizeof(meta_pgno); 00151 if ((ret = CDB___os_malloc(dbenv, logrec.size, NULL, &logrec.data)) != 0) 00152 return (ret); 00153 00154 bp = logrec.data; 00155 memcpy(bp, &rectype, sizeof(rectype)); 00156 bp += sizeof(rectype); 00157 memcpy(bp, &txn_num, sizeof(txn_num)); 00158 bp += sizeof(txn_num); 00159 memcpy(bp, lsnp, sizeof(DB_LSN)); 00160 bp += sizeof(DB_LSN); 00161 memcpy(bp, &opcode, sizeof(opcode)); 00162 bp += sizeof(opcode); 00163 if (name == NULL) { 00164 zero = 0; 00165 memcpy(bp, &zero, sizeof(u_int32_t)); 00166 bp += sizeof(u_int32_t); 00167 } else { 00168 memcpy(bp, &name->size, sizeof(name->size)); 00169 bp += sizeof(name->size); 00170 memcpy(bp, name->data, name->size); 00171 bp += name->size; 00172 } 00173 if (uid == NULL) { 00174 zero = 0; 00175 memcpy(bp, &zero, sizeof(u_int32_t)); 00176 bp += sizeof(u_int32_t); 00177 } else { 00178 memcpy(bp, &uid->size, sizeof(uid->size)); 00179 bp += sizeof(uid->size); 00180 memcpy(bp, uid->data, uid->size); 00181 bp += uid->size; 00182 } 00183 memcpy(bp, &fileid, sizeof(fileid)); 00184 bp += sizeof(fileid); 00185 memcpy(bp, &ftype, sizeof(ftype)); 00186 bp += sizeof(ftype); 00187 memcpy(bp, &meta_pgno, sizeof(meta_pgno)); 00188 bp += sizeof(meta_pgno); 00189 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) == logrec.size); 00190 ret = CDB___log_put(dbenv, ret_lsnp, (DBT *)&logrec, flags); 00191 if (txnid != NULL) 00192 txnid->last_lsn = *ret_lsnp; 00193 CDB___os_free(logrec.data, logrec.size); 00194 return (ret); 00195 } 00196 00197 int 00198 CDB___log_register_print(dbenv, dbtp, lsnp, notused2, notused3) 00199 DB_ENV *dbenv; 00200 DBT *dbtp; 00201 DB_LSN *lsnp; 00202 db_recops notused2; 00203 void *notused3; 00204 { 00205 __log_register_args *argp; 00206 u_int32_t i; 00207 u_int ch; 00208 int ret; 00209 00210 i = 0; 00211 ch = 0; 00212 notused2 = 0; 00213 notused3 = NULL; 00214 00215 if ((ret = CDB___log_register_read(dbenv, dbtp->data, &argp)) != 0) 00216 return (ret); 00217 printf("[%lu][%lu]CDB_log_register: rec: %lu txnid %lx prevlsn [%lu][%lu]\n", 00218 (u_long)lsnp->file, 00219 (u_long)lsnp->offset, 00220 (u_long)argp->type, 00221 (u_long)argp->txnid->txnid, 00222 (u_long)argp->prev_lsn.file, 00223 (u_long)argp->prev_lsn.offset); 00224 printf("\topcode: %lu\n", (u_long)argp->opcode); 00225 printf("\tname: "); 00226 for (i = 0; i < argp->name.size; i++) { 00227 ch = ((u_int8_t *)argp->name.data)[i]; 00228 if (isprint(ch) || ch == 0xa) 00229 putchar(ch); 00230 else 00231 printf("%#x ", ch); 00232 } 00233 printf("\n"); 00234 printf("\tuid: "); 00235 for (i = 0; i < argp->uid.size; i++) { 00236 ch = ((u_int8_t *)argp->uid.data)[i]; 00237 if (isprint(ch) || ch == 0xa) 00238 putchar(ch); 00239 else 00240 printf("%#x ", ch); 00241 } 00242 printf("\n"); 00243 printf("\tfileid: %ld\n", (long)argp->fileid); 00244 printf("\tftype: 0x%lx\n", (u_long)argp->ftype); 00245 printf("\tmeta_pgno: %lu\n", (u_long)argp->meta_pgno); 00246 printf("\n"); 00247 CDB___os_free(argp, 0); 00248 return (0); 00249 } 00250 00251 int 00252 CDB___log_register_read(dbenv, recbuf, argpp) 00253 DB_ENV *dbenv; 00254 void *recbuf; 00255 __log_register_args **argpp; 00256 { 00257 __log_register_args *argp; 00258 u_int8_t *bp; 00259 int ret; 00260 00261 ret = CDB___os_malloc(dbenv, sizeof(__log_register_args) + 00262 sizeof(DB_TXN), NULL, &argp); 00263 if (ret != 0) 00264 return (ret); 00265 argp->txnid = (DB_TXN *)&argp[1]; 00266 bp = recbuf; 00267 memcpy(&argp->type, bp, sizeof(argp->type)); 00268 bp += sizeof(argp->type); 00269 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid)); 00270 bp += sizeof(argp->txnid->txnid); 00271 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN)); 00272 bp += sizeof(DB_LSN); 00273 memcpy(&argp->opcode, bp, sizeof(argp->opcode)); 00274 bp += sizeof(argp->opcode); 00275 memset(&argp->name, 0, sizeof(argp->name)); 00276 memcpy(&argp->name.size, bp, sizeof(u_int32_t)); 00277 bp += sizeof(u_int32_t); 00278 argp->name.data = bp; 00279 bp += argp->name.size; 00280 memset(&argp->uid, 0, sizeof(argp->uid)); 00281 memcpy(&argp->uid.size, bp, sizeof(u_int32_t)); 00282 bp += sizeof(u_int32_t); 00283 argp->uid.data = bp; 00284 bp += argp->uid.size; 00285 memcpy(&argp->fileid, bp, sizeof(argp->fileid)); 00286 bp += sizeof(argp->fileid); 00287 memcpy(&argp->ftype, bp, sizeof(argp->ftype)); 00288 bp += sizeof(argp->ftype); 00289 memcpy(&argp->meta_pgno, bp, sizeof(argp->meta_pgno)); 00290 bp += sizeof(argp->meta_pgno); 00291 *argpp = argp; 00292 return (0); 00293 } 00294 00295 int 00296 CDB___log_init_print(dbenv) 00297 DB_ENV *dbenv; 00298 { 00299 int ret; 00300 00301 if ((ret = CDB___db_add_recovery(dbenv, 00302 CDB___log_register1_print, DB_log_register1)) != 0) 00303 return (ret); 00304 if ((ret = CDB___db_add_recovery(dbenv, 00305 CDB___log_register_print, DB_log_register)) != 0) 00306 return (ret); 00307 return (0); 00308 } 00309 00310 int 00311 CDB___log_init_recover(dbenv) 00312 DB_ENV *dbenv; 00313 { 00314 int ret; 00315 00316 if ((ret = CDB___db_add_recovery(dbenv, 00317 CDB___deprecated_recover, DB_log_register1)) != 0) 00318 return (ret); 00319 if ((ret = CDB___db_add_recovery(dbenv, 00320 CDB___log_register_recover, DB_log_register)) != 0) 00321 return (ret); 00322 return (0); 00323 } 00324