Update.
[glibc.git] / db2 / txn / txn_auto.c
blobf03a52991f32c48ff8d3801e1001879f8adcd475
1 /* Do not edit: automatically built by dist/db_gen.sh. */
2 #include "config.h"
4 #ifndef NO_SYSTEM_INCLUDES
5 #include <ctype.h>
6 #include <errno.h>
7 #include <stddef.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #endif
12 #include "db_int.h"
13 #include "shqueue.h"
14 #include "db_page.h"
15 #include "db_dispatch.h"
16 #include "txn.h"
17 #include "db_am.h"
19 * PUBLIC: int __txn_regop_log
20 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
21 * PUBLIC: u_int32_t));
23 int __txn_regop_log(logp, txnid, ret_lsnp, flags,
24 opcode)
25 DB_LOG *logp;
26 DB_TXN *txnid;
27 DB_LSN *ret_lsnp;
28 u_int32_t flags;
29 u_int32_t opcode;
31 DBT logrec;
32 DB_LSN *lsnp, null_lsn;
33 u_int32_t rectype, txn_num;
34 int ret;
35 u_int8_t *bp;
37 rectype = DB_txn_regop;
38 txn_num = txnid == NULL ? 0 : txnid->txnid;
39 if (txnid == NULL) {
40 null_lsn.file = 0;
41 null_lsn.offset = 0;
42 lsnp = &null_lsn;
43 } else
44 lsnp = &txnid->last_lsn;
45 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
46 + sizeof(opcode);
47 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
48 return (ENOMEM);
50 bp = logrec.data;
51 memcpy(bp, &rectype, sizeof(rectype));
52 bp += sizeof(rectype);
53 memcpy(bp, &txn_num, sizeof(txn_num));
54 bp += sizeof(txn_num);
55 memcpy(bp, lsnp, sizeof(DB_LSN));
56 bp += sizeof(DB_LSN);
57 memcpy(bp, &opcode, sizeof(opcode));
58 bp += sizeof(opcode);
59 #ifdef DIAGNOSTIC
60 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
61 fprintf(stderr, "Error in log record length");
62 #endif
63 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
64 if (txnid != NULL)
65 txnid->last_lsn = *ret_lsnp;
66 __db_free(logrec.data);
67 return (ret);
71 * PUBLIC: int __txn_regop_print
72 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
74 int
75 __txn_regop_print(notused1, dbtp, lsnp, notused2, notused3)
76 DB_LOG *notused1;
77 DBT *dbtp;
78 DB_LSN *lsnp;
79 int notused2;
80 void *notused3;
82 __txn_regop_args *argp;
83 u_int32_t i;
84 u_int ch;
85 int ret;
87 i = 0;
88 ch = 0;
89 notused1 = NULL;
90 notused2 = 0;
91 notused3 = NULL;
93 if ((ret = __txn_regop_read(dbtp->data, &argp)) != 0)
94 return (ret);
95 printf("[%lu][%lu]txn_regop: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
96 (u_long)lsnp->file,
97 (u_long)lsnp->offset,
98 (u_long)argp->type,
99 (u_long)argp->txnid->txnid,
100 (u_long)argp->prev_lsn.file,
101 (u_long)argp->prev_lsn.offset);
102 printf("\topcode: %lu\n", (u_long)argp->opcode);
103 printf("\n");
104 __db_free(argp);
105 return (0);
109 * PUBLIC: int __txn_regop_read __P((void *, __txn_regop_args **));
112 __txn_regop_read(recbuf, argpp)
113 void *recbuf;
114 __txn_regop_args **argpp;
116 __txn_regop_args *argp;
117 u_int8_t *bp;
119 argp = (__txn_regop_args *)__db_malloc(sizeof(__txn_regop_args) +
120 sizeof(DB_TXN));
121 if (argp == NULL)
122 return (ENOMEM);
123 argp->txnid = (DB_TXN *)&argp[1];
124 bp = recbuf;
125 memcpy(&argp->type, bp, sizeof(argp->type));
126 bp += sizeof(argp->type);
127 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
128 bp += sizeof(argp->txnid->txnid);
129 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
130 bp += sizeof(DB_LSN);
131 memcpy(&argp->opcode, bp, sizeof(argp->opcode));
132 bp += sizeof(argp->opcode);
133 *argpp = argp;
134 return (0);
138 * PUBLIC: int __txn_ckp_log
139 * PUBLIC: __P((DB_LOG *, DB_TXN *, DB_LSN *, u_int32_t,
140 * PUBLIC: DB_LSN *, DB_LSN *));
142 int __txn_ckp_log(logp, txnid, ret_lsnp, flags,
143 ckp_lsn, last_ckp)
144 DB_LOG *logp;
145 DB_TXN *txnid;
146 DB_LSN *ret_lsnp;
147 u_int32_t flags;
148 DB_LSN * ckp_lsn;
149 DB_LSN * last_ckp;
151 DBT logrec;
152 DB_LSN *lsnp, null_lsn;
153 u_int32_t rectype, txn_num;
154 int ret;
155 u_int8_t *bp;
157 rectype = DB_txn_ckp;
158 txn_num = txnid == NULL ? 0 : txnid->txnid;
159 if (txnid == NULL) {
160 null_lsn.file = 0;
161 null_lsn.offset = 0;
162 lsnp = &null_lsn;
163 } else
164 lsnp = &txnid->last_lsn;
165 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
166 + sizeof(*ckp_lsn)
167 + sizeof(*last_ckp);
168 if ((logrec.data = (void *)__db_malloc(logrec.size)) == NULL)
169 return (ENOMEM);
171 bp = logrec.data;
172 memcpy(bp, &rectype, sizeof(rectype));
173 bp += sizeof(rectype);
174 memcpy(bp, &txn_num, sizeof(txn_num));
175 bp += sizeof(txn_num);
176 memcpy(bp, lsnp, sizeof(DB_LSN));
177 bp += sizeof(DB_LSN);
178 if (ckp_lsn != NULL)
179 memcpy(bp, ckp_lsn, sizeof(*ckp_lsn));
180 else
181 memset(bp, 0, sizeof(*ckp_lsn));
182 bp += sizeof(*ckp_lsn);
183 if (last_ckp != NULL)
184 memcpy(bp, last_ckp, sizeof(*last_ckp));
185 else
186 memset(bp, 0, sizeof(*last_ckp));
187 bp += sizeof(*last_ckp);
188 #ifdef DIAGNOSTIC
189 if ((u_int32_t)(bp - (u_int8_t *)logrec.data) != logrec.size)
190 fprintf(stderr, "Error in log record length");
191 #endif
192 ret = log_put(logp, ret_lsnp, (DBT *)&logrec, flags);
193 if (txnid != NULL)
194 txnid->last_lsn = *ret_lsnp;
195 __db_free(logrec.data);
196 return (ret);
200 * PUBLIC: int __txn_ckp_print
201 * PUBLIC: __P((DB_LOG *, DBT *, DB_LSN *, int, void *));
204 __txn_ckp_print(notused1, dbtp, lsnp, notused2, notused3)
205 DB_LOG *notused1;
206 DBT *dbtp;
207 DB_LSN *lsnp;
208 int notused2;
209 void *notused3;
211 __txn_ckp_args *argp;
212 u_int32_t i;
213 u_int ch;
214 int ret;
216 i = 0;
217 ch = 0;
218 notused1 = NULL;
219 notused2 = 0;
220 notused3 = NULL;
222 if ((ret = __txn_ckp_read(dbtp->data, &argp)) != 0)
223 return (ret);
224 printf("[%lu][%lu]txn_ckp: rec: %lu txnid %lx prevlsn [%lu][%lu]\n",
225 (u_long)lsnp->file,
226 (u_long)lsnp->offset,
227 (u_long)argp->type,
228 (u_long)argp->txnid->txnid,
229 (u_long)argp->prev_lsn.file,
230 (u_long)argp->prev_lsn.offset);
231 printf("\tckp_lsn: [%lu][%lu]\n",
232 (u_long)argp->ckp_lsn.file, (u_long)argp->ckp_lsn.offset);
233 printf("\tlast_ckp: [%lu][%lu]\n",
234 (u_long)argp->last_ckp.file, (u_long)argp->last_ckp.offset);
235 printf("\n");
236 __db_free(argp);
237 return (0);
241 * PUBLIC: int __txn_ckp_read __P((void *, __txn_ckp_args **));
244 __txn_ckp_read(recbuf, argpp)
245 void *recbuf;
246 __txn_ckp_args **argpp;
248 __txn_ckp_args *argp;
249 u_int8_t *bp;
251 argp = (__txn_ckp_args *)__db_malloc(sizeof(__txn_ckp_args) +
252 sizeof(DB_TXN));
253 if (argp == NULL)
254 return (ENOMEM);
255 argp->txnid = (DB_TXN *)&argp[1];
256 bp = recbuf;
257 memcpy(&argp->type, bp, sizeof(argp->type));
258 bp += sizeof(argp->type);
259 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
260 bp += sizeof(argp->txnid->txnid);
261 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
262 bp += sizeof(DB_LSN);
263 memcpy(&argp->ckp_lsn, bp, sizeof(argp->ckp_lsn));
264 bp += sizeof(argp->ckp_lsn);
265 memcpy(&argp->last_ckp, bp, sizeof(argp->last_ckp));
266 bp += sizeof(argp->last_ckp);
267 *argpp = argp;
268 return (0);
272 * PUBLIC: int __txn_init_print __P((DB_ENV *));
275 __txn_init_print(dbenv)
276 DB_ENV *dbenv;
278 int ret;
280 if ((ret = __db_add_recovery(dbenv,
281 __txn_regop_print, DB_txn_regop)) != 0)
282 return (ret);
283 if ((ret = __db_add_recovery(dbenv,
284 __txn_ckp_print, DB_txn_ckp)) != 0)
285 return (ret);
286 return (0);
290 * PUBLIC: int __txn_init_recover __P((DB_ENV *));
293 __txn_init_recover(dbenv)
294 DB_ENV *dbenv;
296 int ret;
298 if ((ret = __db_add_recovery(dbenv,
299 __txn_regop_recover, DB_txn_regop)) != 0)
300 return (ret);
301 if ((ret = __db_add_recovery(dbenv,
302 __txn_ckp_recover, DB_txn_ckp)) != 0)
303 return (ret);
304 return (0);