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 __crdel_metasub_read __P((ENV *, DB **, void *,
14 * PUBLIC:     void *, __crdel_metasub_args **));
15 */
16int
17__crdel_metasub_read(env, dbpp, td, recbuf, argpp)
18	ENV *env;
19	DB **dbpp;
20	void *td;
21	void *recbuf;
22	__crdel_metasub_args **argpp;
23{
24	__crdel_metasub_args *argp;
25	u_int32_t uinttmp;
26	u_int8_t *bp;
27	int ret;
28
29	if ((ret = __os_malloc(env,
30	    sizeof(__crdel_metasub_args) + sizeof(DB_TXN), &argp)) != 0)
31		return (ret);
32	bp = recbuf;
33	argp->txnp = (DB_TXN *)&argp[1];
34	memset(argp->txnp, 0, sizeof(DB_TXN));
35
36	argp->txnp->td = td;
37	LOGCOPY_32(env, &argp->type, bp);
38	bp += sizeof(argp->type);
39
40	LOGCOPY_32(env, &argp->txnp->txnid, bp);
41	bp += sizeof(argp->txnp->txnid);
42
43	LOGCOPY_TOLSN(env, &argp->prev_lsn, bp);
44	bp += sizeof(DB_LSN);
45
46	LOGCOPY_32(env, &uinttmp, bp);
47	argp->fileid = (int32_t)uinttmp;
48	bp += sizeof(uinttmp);
49	if (dbpp != NULL) {
50		*dbpp = NULL;
51		ret = __dbreg_id_to_db(
52		    env, argp->txnp, dbpp, argp->fileid, 1);
53	}
54
55	LOGCOPY_32(env, &uinttmp, bp);
56	argp->pgno = (db_pgno_t)uinttmp;
57	bp += sizeof(uinttmp);
58
59	memset(&argp->page, 0, sizeof(argp->page));
60	LOGCOPY_32(env,&argp->page.size, bp);
61	bp += sizeof(u_int32_t);
62	argp->page.data = bp;
63	bp += argp->page.size;
64	if (LOG_SWAPPED(env) && dbpp != NULL && *dbpp != NULL) {
65		int t_ret;
66		if ((t_ret = __db_pageswap(*dbpp, (PAGE *)argp->page.data,
67		    (size_t)argp->page.size, NULL, 1)) != 0)
68			return (t_ret);
69	}
70
71	LOGCOPY_TOLSN(env, &argp->lsn, bp);
72	bp += sizeof(DB_LSN);
73
74	*argpp = argp;
75	return (ret);
76}
77
78/*
79 * PUBLIC: int __crdel_metasub_log __P((DB *, DB_TXN *, DB_LSN *,
80 * PUBLIC:     u_int32_t, db_pgno_t, const DBT *, DB_LSN *));
81 */
82int
83__crdel_metasub_log(dbp, txnp, ret_lsnp, flags, pgno, page, lsn)
84	DB *dbp;
85	DB_TXN *txnp;
86	DB_LSN *ret_lsnp;
87	u_int32_t flags;
88	db_pgno_t pgno;
89	const DBT *page;
90	DB_LSN * lsn;
91{
92	DBT logrec;
93	DB_LSN *lsnp, null_lsn, *rlsnp;
94	DB_TXNLOGREC *lr;
95	ENV *env;
96	u_int32_t zero, uinttmp, rectype, txn_num;
97	u_int npad;
98	u_int8_t *bp;
99	int is_durable, ret;
100
101	COMPQUIET(lr, NULL);
102
103	env = dbp->env;
104	rlsnp = ret_lsnp;
105	rectype = DB___crdel_metasub;
106	npad = 0;
107	ret = 0;
108
109	if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
110	    F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
111		if (txnp == NULL)
112			return (0);
113		is_durable = 0;
114	} else
115		is_durable = 1;
116
117	if (txnp == NULL) {
118		txn_num = 0;
119		lsnp = &null_lsn;
120		null_lsn.file = null_lsn.offset = 0;
121	} else {
122		if (TAILQ_FIRST(&txnp->kids) != NULL &&
123		    (ret = __txn_activekids(env, rectype, txnp)) != 0)
124			return (ret);
125		/*
126		 * We need to assign begin_lsn while holding region mutex.
127		 * That assignment is done inside the DbEnv->log_put call,
128		 * so pass in the appropriate memory location to be filled
129		 * in by the log_put code.
130		 */
131		DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp);
132		txn_num = txnp->txnid;
133	}
134
135	DB_ASSERT(env, dbp->log_filename != NULL);
136	if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
137	    (ret = __dbreg_lazy_id(dbp)) != 0)
138		return (ret);
139
140	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
141	    + sizeof(u_int32_t)
142	    + sizeof(u_int32_t)
143	    + sizeof(u_int32_t) + (page == NULL ? 0 : page->size)
144	    + sizeof(*lsn);
145	if (CRYPTO_ON(env)) {
146		npad = env->crypto_handle->adj_size(logrec.size);
147		logrec.size += npad;
148	}
149
150	if (is_durable || txnp == NULL) {
151		if ((ret =
152		    __os_malloc(env, logrec.size, &logrec.data)) != 0)
153			return (ret);
154	} else {
155		if ((ret = __os_malloc(env,
156		    logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
157			return (ret);
158#ifdef DIAGNOSTIC
159		if ((ret =
160		    __os_malloc(env, logrec.size, &logrec.data)) != 0) {
161			__os_free(env, lr);
162			return (ret);
163		}
164#else
165		logrec.data = lr->data;
166#endif
167	}
168	if (npad > 0)
169		memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
170
171	bp = logrec.data;
172
173	LOGCOPY_32(env, bp, &rectype);
174	bp += sizeof(rectype);
175
176	LOGCOPY_32(env, bp, &txn_num);
177	bp += sizeof(txn_num);
178
179	LOGCOPY_FROMLSN(env, bp, lsnp);
180	bp += sizeof(DB_LSN);
181
182	uinttmp = (u_int32_t)dbp->log_filename->id;
183	LOGCOPY_32(env, bp, &uinttmp);
184	bp += sizeof(uinttmp);
185
186	uinttmp = (u_int32_t)pgno;
187	LOGCOPY_32(env,bp, &uinttmp);
188	bp += sizeof(uinttmp);
189
190	if (page == NULL) {
191		zero = 0;
192		LOGCOPY_32(env, bp, &zero);
193		bp += sizeof(u_int32_t);
194	} else {
195		LOGCOPY_32(env, bp, &page->size);
196		bp += sizeof(page->size);
197		memcpy(bp, page->data, page->size);
198		if (LOG_SWAPPED(env))
199			if ((ret = __db_pageswap(dbp,
200			    (PAGE *)bp, (size_t)page->size, (DBT *)NULL, 0)) != 0)
201				return (ret);
202		bp += page->size;
203	}
204
205	if (lsn != NULL) {
206		if (txnp != NULL) {
207			LOG *lp = env->lg_handle->reginfo.primary;
208			if (LOG_COMPARE(lsn, &lp->lsn) >= 0 && (ret =
209			    __log_check_page_lsn(env, dbp, lsn) != 0))
210				return (ret);
211		}
212		LOGCOPY_FROMLSN(env, bp, lsn);
213	} else
214		memset(bp, 0, sizeof(*lsn));
215	bp += sizeof(*lsn);
216
217	DB_ASSERT(env,
218	    (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
219
220	if (is_durable || txnp == NULL) {
221		if ((ret = __log_put(env, rlsnp,(DBT *)&logrec,
222		    flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) {
223			*lsnp = *rlsnp;
224			if (rlsnp != ret_lsnp)
225				 *ret_lsnp = *rlsnp;
226		}
227	} else {
228		ret = 0;
229#ifdef DIAGNOSTIC
230		/*
231		 * Set the debug bit if we are going to log non-durable
232		 * transactions so they will be ignored by recovery.
233		 */
234		memcpy(lr->data, logrec.data, logrec.size);
235		rectype |= DB_debug_FLAG;
236		LOGCOPY_32(env, logrec.data, &rectype);
237
238		if (!IS_REP_CLIENT(env))
239			ret = __log_put(env,
240			    rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
241#endif
242		STAILQ_INSERT_HEAD(&txnp->logs, lr, links);
243		F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY);
244		LSN_NOT_LOGGED(*ret_lsnp);
245	}
246
247#ifdef LOG_DIAGNOSTIC
248	if (ret != 0)
249		(void)__crdel_metasub_print(env,
250		    (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
251#endif
252
253#ifdef DIAGNOSTIC
254	__os_free(env, logrec.data);
255#else
256	if (is_durable || txnp == NULL)
257		__os_free(env, logrec.data);
258#endif
259	return (ret);
260}
261
262/*
263 * PUBLIC: int __crdel_inmem_create_read __P((ENV *, void *,
264 * PUBLIC:     __crdel_inmem_create_args **));
265 */
266int
267__crdel_inmem_create_read(env, recbuf, argpp)
268	ENV *env;
269	void *recbuf;
270	__crdel_inmem_create_args **argpp;
271{
272	__crdel_inmem_create_args *argp;
273	u_int32_t uinttmp;
274	u_int8_t *bp;
275	int ret;
276
277	if ((ret = __os_malloc(env,
278	    sizeof(__crdel_inmem_create_args) + sizeof(DB_TXN), &argp)) != 0)
279		return (ret);
280	bp = recbuf;
281	argp->txnp = (DB_TXN *)&argp[1];
282	memset(argp->txnp, 0, sizeof(DB_TXN));
283
284	LOGCOPY_32(env, &argp->type, bp);
285	bp += sizeof(argp->type);
286
287	LOGCOPY_32(env, &argp->txnp->txnid, bp);
288	bp += sizeof(argp->txnp->txnid);
289
290	LOGCOPY_TOLSN(env, &argp->prev_lsn, bp);
291	bp += sizeof(DB_LSN);
292
293	LOGCOPY_32(env, &uinttmp, bp);
294	argp->fileid = (int32_t)uinttmp;
295	bp += sizeof(uinttmp);
296
297	memset(&argp->name, 0, sizeof(argp->name));
298	LOGCOPY_32(env,&argp->name.size, bp);
299	bp += sizeof(u_int32_t);
300	argp->name.data = bp;
301	bp += argp->name.size;
302
303	memset(&argp->fid, 0, sizeof(argp->fid));
304	LOGCOPY_32(env,&argp->fid.size, bp);
305	bp += sizeof(u_int32_t);
306	argp->fid.data = bp;
307	bp += argp->fid.size;
308
309	LOGCOPY_32(env, &argp->pgsize, bp);
310	bp += sizeof(argp->pgsize);
311
312	*argpp = argp;
313	return (ret);
314}
315
316/*
317 * PUBLIC: int __crdel_inmem_create_log __P((ENV *, DB_TXN *,
318 * PUBLIC:     DB_LSN *, u_int32_t, int32_t, const DBT *, const DBT *,
319 * PUBLIC:     u_int32_t));
320 */
321int
322__crdel_inmem_create_log(env, txnp, ret_lsnp, flags,
323    fileid, name, fid, pgsize)
324	ENV *env;
325	DB_TXN *txnp;
326	DB_LSN *ret_lsnp;
327	u_int32_t flags;
328	int32_t fileid;
329	const DBT *name;
330	const DBT *fid;
331	u_int32_t pgsize;
332{
333	DBT logrec;
334	DB_LSN *lsnp, null_lsn, *rlsnp;
335	DB_TXNLOGREC *lr;
336	u_int32_t zero, uinttmp, rectype, txn_num;
337	u_int npad;
338	u_int8_t *bp;
339	int is_durable, ret;
340
341	COMPQUIET(lr, NULL);
342
343	rlsnp = ret_lsnp;
344	rectype = DB___crdel_inmem_create;
345	npad = 0;
346	ret = 0;
347
348	if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
349		if (txnp == NULL)
350			return (0);
351		if (txnp == NULL)
352			return (0);
353		is_durable = 0;
354	} else
355		is_durable = 1;
356
357	if (txnp == NULL) {
358		txn_num = 0;
359		lsnp = &null_lsn;
360		null_lsn.file = null_lsn.offset = 0;
361	} else {
362		if (TAILQ_FIRST(&txnp->kids) != NULL &&
363		    (ret = __txn_activekids(env, rectype, txnp)) != 0)
364			return (ret);
365		/*
366		 * We need to assign begin_lsn while holding region mutex.
367		 * That assignment is done inside the DbEnv->log_put call,
368		 * so pass in the appropriate memory location to be filled
369		 * in by the log_put code.
370		 */
371		DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp);
372		txn_num = txnp->txnid;
373	}
374
375	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
376	    + sizeof(u_int32_t)
377	    + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
378	    + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size)
379	    + sizeof(u_int32_t);
380	if (CRYPTO_ON(env)) {
381		npad = env->crypto_handle->adj_size(logrec.size);
382		logrec.size += npad;
383	}
384
385	if (is_durable || txnp == NULL) {
386		if ((ret =
387		    __os_malloc(env, logrec.size, &logrec.data)) != 0)
388			return (ret);
389	} else {
390		if ((ret = __os_malloc(env,
391		    logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
392			return (ret);
393#ifdef DIAGNOSTIC
394		if ((ret =
395		    __os_malloc(env, logrec.size, &logrec.data)) != 0) {
396			__os_free(env, lr);
397			return (ret);
398		}
399#else
400		logrec.data = lr->data;
401#endif
402	}
403	if (npad > 0)
404		memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
405
406	bp = logrec.data;
407
408	LOGCOPY_32(env, bp, &rectype);
409	bp += sizeof(rectype);
410
411	LOGCOPY_32(env, bp, &txn_num);
412	bp += sizeof(txn_num);
413
414	LOGCOPY_FROMLSN(env, bp, lsnp);
415	bp += sizeof(DB_LSN);
416
417	uinttmp = (u_int32_t)fileid;
418	LOGCOPY_32(env,bp, &uinttmp);
419	bp += sizeof(uinttmp);
420
421	if (name == NULL) {
422		zero = 0;
423		LOGCOPY_32(env, bp, &zero);
424		bp += sizeof(u_int32_t);
425	} else {
426		LOGCOPY_32(env, bp, &name->size);
427		bp += sizeof(name->size);
428		memcpy(bp, name->data, name->size);
429		bp += name->size;
430	}
431
432	if (fid == NULL) {
433		zero = 0;
434		LOGCOPY_32(env, bp, &zero);
435		bp += sizeof(u_int32_t);
436	} else {
437		LOGCOPY_32(env, bp, &fid->size);
438		bp += sizeof(fid->size);
439		memcpy(bp, fid->data, fid->size);
440		bp += fid->size;
441	}
442
443	LOGCOPY_32(env, bp, &pgsize);
444	bp += sizeof(pgsize);
445
446	DB_ASSERT(env,
447	    (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
448
449	if (is_durable || txnp == NULL) {
450		if ((ret = __log_put(env, rlsnp,(DBT *)&logrec,
451		    flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) {
452			*lsnp = *rlsnp;
453			if (rlsnp != ret_lsnp)
454				 *ret_lsnp = *rlsnp;
455		}
456	} else {
457		ret = 0;
458#ifdef DIAGNOSTIC
459		/*
460		 * Set the debug bit if we are going to log non-durable
461		 * transactions so they will be ignored by recovery.
462		 */
463		memcpy(lr->data, logrec.data, logrec.size);
464		rectype |= DB_debug_FLAG;
465		LOGCOPY_32(env, logrec.data, &rectype);
466
467		if (!IS_REP_CLIENT(env))
468			ret = __log_put(env,
469			    rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
470#endif
471		STAILQ_INSERT_HEAD(&txnp->logs, lr, links);
472		F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY);
473		LSN_NOT_LOGGED(*ret_lsnp);
474	}
475
476#ifdef LOG_DIAGNOSTIC
477	if (ret != 0)
478		(void)__crdel_inmem_create_print(env,
479		    (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
480#endif
481
482#ifdef DIAGNOSTIC
483	__os_free(env, logrec.data);
484#else
485	if (is_durable || txnp == NULL)
486		__os_free(env, logrec.data);
487#endif
488	return (ret);
489}
490
491/*
492 * PUBLIC: int __crdel_inmem_rename_read __P((ENV *, void *,
493 * PUBLIC:     __crdel_inmem_rename_args **));
494 */
495int
496__crdel_inmem_rename_read(env, recbuf, argpp)
497	ENV *env;
498	void *recbuf;
499	__crdel_inmem_rename_args **argpp;
500{
501	__crdel_inmem_rename_args *argp;
502	u_int8_t *bp;
503	int ret;
504
505	if ((ret = __os_malloc(env,
506	    sizeof(__crdel_inmem_rename_args) + sizeof(DB_TXN), &argp)) != 0)
507		return (ret);
508	bp = recbuf;
509	argp->txnp = (DB_TXN *)&argp[1];
510	memset(argp->txnp, 0, sizeof(DB_TXN));
511
512	LOGCOPY_32(env, &argp->type, bp);
513	bp += sizeof(argp->type);
514
515	LOGCOPY_32(env, &argp->txnp->txnid, bp);
516	bp += sizeof(argp->txnp->txnid);
517
518	LOGCOPY_TOLSN(env, &argp->prev_lsn, bp);
519	bp += sizeof(DB_LSN);
520
521	memset(&argp->oldname, 0, sizeof(argp->oldname));
522	LOGCOPY_32(env,&argp->oldname.size, bp);
523	bp += sizeof(u_int32_t);
524	argp->oldname.data = bp;
525	bp += argp->oldname.size;
526
527	memset(&argp->newname, 0, sizeof(argp->newname));
528	LOGCOPY_32(env,&argp->newname.size, bp);
529	bp += sizeof(u_int32_t);
530	argp->newname.data = bp;
531	bp += argp->newname.size;
532
533	memset(&argp->fid, 0, sizeof(argp->fid));
534	LOGCOPY_32(env,&argp->fid.size, bp);
535	bp += sizeof(u_int32_t);
536	argp->fid.data = bp;
537	bp += argp->fid.size;
538
539	*argpp = argp;
540	return (ret);
541}
542
543/*
544 * PUBLIC: int __crdel_inmem_rename_log __P((ENV *, DB_TXN *,
545 * PUBLIC:     DB_LSN *, u_int32_t, const DBT *, const DBT *, const DBT *));
546 */
547int
548__crdel_inmem_rename_log(env, txnp, ret_lsnp, flags,
549    oldname, newname, fid)
550	ENV *env;
551	DB_TXN *txnp;
552	DB_LSN *ret_lsnp;
553	u_int32_t flags;
554	const DBT *oldname;
555	const DBT *newname;
556	const DBT *fid;
557{
558	DBT logrec;
559	DB_LSN *lsnp, null_lsn, *rlsnp;
560	DB_TXNLOGREC *lr;
561	u_int32_t zero, rectype, txn_num;
562	u_int npad;
563	u_int8_t *bp;
564	int is_durable, ret;
565
566	COMPQUIET(lr, NULL);
567
568	rlsnp = ret_lsnp;
569	rectype = DB___crdel_inmem_rename;
570	npad = 0;
571	ret = 0;
572
573	if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
574		if (txnp == NULL)
575			return (0);
576		if (txnp == NULL)
577			return (0);
578		is_durable = 0;
579	} else
580		is_durable = 1;
581
582	if (txnp == NULL) {
583		txn_num = 0;
584		lsnp = &null_lsn;
585		null_lsn.file = null_lsn.offset = 0;
586	} else {
587		if (TAILQ_FIRST(&txnp->kids) != NULL &&
588		    (ret = __txn_activekids(env, rectype, txnp)) != 0)
589			return (ret);
590		/*
591		 * We need to assign begin_lsn while holding region mutex.
592		 * That assignment is done inside the DbEnv->log_put call,
593		 * so pass in the appropriate memory location to be filled
594		 * in by the log_put code.
595		 */
596		DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp);
597		txn_num = txnp->txnid;
598	}
599
600	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
601	    + sizeof(u_int32_t) + (oldname == NULL ? 0 : oldname->size)
602	    + sizeof(u_int32_t) + (newname == NULL ? 0 : newname->size)
603	    + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size);
604	if (CRYPTO_ON(env)) {
605		npad = env->crypto_handle->adj_size(logrec.size);
606		logrec.size += npad;
607	}
608
609	if (is_durable || txnp == NULL) {
610		if ((ret =
611		    __os_malloc(env, logrec.size, &logrec.data)) != 0)
612			return (ret);
613	} else {
614		if ((ret = __os_malloc(env,
615		    logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
616			return (ret);
617#ifdef DIAGNOSTIC
618		if ((ret =
619		    __os_malloc(env, logrec.size, &logrec.data)) != 0) {
620			__os_free(env, lr);
621			return (ret);
622		}
623#else
624		logrec.data = lr->data;
625#endif
626	}
627	if (npad > 0)
628		memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
629
630	bp = logrec.data;
631
632	LOGCOPY_32(env, bp, &rectype);
633	bp += sizeof(rectype);
634
635	LOGCOPY_32(env, bp, &txn_num);
636	bp += sizeof(txn_num);
637
638	LOGCOPY_FROMLSN(env, bp, lsnp);
639	bp += sizeof(DB_LSN);
640
641	if (oldname == NULL) {
642		zero = 0;
643		LOGCOPY_32(env, bp, &zero);
644		bp += sizeof(u_int32_t);
645	} else {
646		LOGCOPY_32(env, bp, &oldname->size);
647		bp += sizeof(oldname->size);
648		memcpy(bp, oldname->data, oldname->size);
649		bp += oldname->size;
650	}
651
652	if (newname == NULL) {
653		zero = 0;
654		LOGCOPY_32(env, bp, &zero);
655		bp += sizeof(u_int32_t);
656	} else {
657		LOGCOPY_32(env, bp, &newname->size);
658		bp += sizeof(newname->size);
659		memcpy(bp, newname->data, newname->size);
660		bp += newname->size;
661	}
662
663	if (fid == NULL) {
664		zero = 0;
665		LOGCOPY_32(env, bp, &zero);
666		bp += sizeof(u_int32_t);
667	} else {
668		LOGCOPY_32(env, bp, &fid->size);
669		bp += sizeof(fid->size);
670		memcpy(bp, fid->data, fid->size);
671		bp += fid->size;
672	}
673
674	DB_ASSERT(env,
675	    (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
676
677	if (is_durable || txnp == NULL) {
678		if ((ret = __log_put(env, rlsnp,(DBT *)&logrec,
679		    flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) {
680			*lsnp = *rlsnp;
681			if (rlsnp != ret_lsnp)
682				 *ret_lsnp = *rlsnp;
683		}
684	} else {
685		ret = 0;
686#ifdef DIAGNOSTIC
687		/*
688		 * Set the debug bit if we are going to log non-durable
689		 * transactions so they will be ignored by recovery.
690		 */
691		memcpy(lr->data, logrec.data, logrec.size);
692		rectype |= DB_debug_FLAG;
693		LOGCOPY_32(env, logrec.data, &rectype);
694
695		if (!IS_REP_CLIENT(env))
696			ret = __log_put(env,
697			    rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
698#endif
699		STAILQ_INSERT_HEAD(&txnp->logs, lr, links);
700		F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY);
701		LSN_NOT_LOGGED(*ret_lsnp);
702	}
703
704#ifdef LOG_DIAGNOSTIC
705	if (ret != 0)
706		(void)__crdel_inmem_rename_print(env,
707		    (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
708#endif
709
710#ifdef DIAGNOSTIC
711	__os_free(env, logrec.data);
712#else
713	if (is_durable || txnp == NULL)
714		__os_free(env, logrec.data);
715#endif
716	return (ret);
717}
718
719/*
720 * PUBLIC: int __crdel_inmem_remove_read __P((ENV *, void *,
721 * PUBLIC:     __crdel_inmem_remove_args **));
722 */
723int
724__crdel_inmem_remove_read(env, recbuf, argpp)
725	ENV *env;
726	void *recbuf;
727	__crdel_inmem_remove_args **argpp;
728{
729	__crdel_inmem_remove_args *argp;
730	u_int8_t *bp;
731	int ret;
732
733	if ((ret = __os_malloc(env,
734	    sizeof(__crdel_inmem_remove_args) + sizeof(DB_TXN), &argp)) != 0)
735		return (ret);
736	bp = recbuf;
737	argp->txnp = (DB_TXN *)&argp[1];
738	memset(argp->txnp, 0, sizeof(DB_TXN));
739
740	LOGCOPY_32(env, &argp->type, bp);
741	bp += sizeof(argp->type);
742
743	LOGCOPY_32(env, &argp->txnp->txnid, bp);
744	bp += sizeof(argp->txnp->txnid);
745
746	LOGCOPY_TOLSN(env, &argp->prev_lsn, bp);
747	bp += sizeof(DB_LSN);
748
749	memset(&argp->name, 0, sizeof(argp->name));
750	LOGCOPY_32(env,&argp->name.size, bp);
751	bp += sizeof(u_int32_t);
752	argp->name.data = bp;
753	bp += argp->name.size;
754
755	memset(&argp->fid, 0, sizeof(argp->fid));
756	LOGCOPY_32(env,&argp->fid.size, bp);
757	bp += sizeof(u_int32_t);
758	argp->fid.data = bp;
759	bp += argp->fid.size;
760
761	*argpp = argp;
762	return (ret);
763}
764
765/*
766 * PUBLIC: int __crdel_inmem_remove_log __P((ENV *, DB_TXN *,
767 * PUBLIC:     DB_LSN *, u_int32_t, const DBT *, const DBT *));
768 */
769int
770__crdel_inmem_remove_log(env, txnp, ret_lsnp, flags,
771    name, fid)
772	ENV *env;
773	DB_TXN *txnp;
774	DB_LSN *ret_lsnp;
775	u_int32_t flags;
776	const DBT *name;
777	const DBT *fid;
778{
779	DBT logrec;
780	DB_LSN *lsnp, null_lsn, *rlsnp;
781	DB_TXNLOGREC *lr;
782	u_int32_t zero, rectype, txn_num;
783	u_int npad;
784	u_int8_t *bp;
785	int is_durable, ret;
786
787	COMPQUIET(lr, NULL);
788
789	rlsnp = ret_lsnp;
790	rectype = DB___crdel_inmem_remove;
791	npad = 0;
792	ret = 0;
793
794	if (LF_ISSET(DB_LOG_NOT_DURABLE)) {
795		if (txnp == NULL)
796			return (0);
797		if (txnp == NULL)
798			return (0);
799		is_durable = 0;
800	} else
801		is_durable = 1;
802
803	if (txnp == NULL) {
804		txn_num = 0;
805		lsnp = &null_lsn;
806		null_lsn.file = null_lsn.offset = 0;
807	} else {
808		if (TAILQ_FIRST(&txnp->kids) != NULL &&
809		    (ret = __txn_activekids(env, rectype, txnp)) != 0)
810			return (ret);
811		/*
812		 * We need to assign begin_lsn while holding region mutex.
813		 * That assignment is done inside the DbEnv->log_put call,
814		 * so pass in the appropriate memory location to be filled
815		 * in by the log_put code.
816		 */
817		DB_SET_TXN_LSNP(txnp, &rlsnp, &lsnp);
818		txn_num = txnp->txnid;
819	}
820
821	logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
822	    + sizeof(u_int32_t) + (name == NULL ? 0 : name->size)
823	    + sizeof(u_int32_t) + (fid == NULL ? 0 : fid->size);
824	if (CRYPTO_ON(env)) {
825		npad = env->crypto_handle->adj_size(logrec.size);
826		logrec.size += npad;
827	}
828
829	if (is_durable || txnp == NULL) {
830		if ((ret =
831		    __os_malloc(env, logrec.size, &logrec.data)) != 0)
832			return (ret);
833	} else {
834		if ((ret = __os_malloc(env,
835		    logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
836			return (ret);
837#ifdef DIAGNOSTIC
838		if ((ret =
839		    __os_malloc(env, logrec.size, &logrec.data)) != 0) {
840			__os_free(env, lr);
841			return (ret);
842		}
843#else
844		logrec.data = lr->data;
845#endif
846	}
847	if (npad > 0)
848		memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
849
850	bp = logrec.data;
851
852	LOGCOPY_32(env, bp, &rectype);
853	bp += sizeof(rectype);
854
855	LOGCOPY_32(env, bp, &txn_num);
856	bp += sizeof(txn_num);
857
858	LOGCOPY_FROMLSN(env, bp, lsnp);
859	bp += sizeof(DB_LSN);
860
861	if (name == NULL) {
862		zero = 0;
863		LOGCOPY_32(env, bp, &zero);
864		bp += sizeof(u_int32_t);
865	} else {
866		LOGCOPY_32(env, bp, &name->size);
867		bp += sizeof(name->size);
868		memcpy(bp, name->data, name->size);
869		bp += name->size;
870	}
871
872	if (fid == NULL) {
873		zero = 0;
874		LOGCOPY_32(env, bp, &zero);
875		bp += sizeof(u_int32_t);
876	} else {
877		LOGCOPY_32(env, bp, &fid->size);
878		bp += sizeof(fid->size);
879		memcpy(bp, fid->data, fid->size);
880		bp += fid->size;
881	}
882
883	DB_ASSERT(env,
884	    (u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
885
886	if (is_durable || txnp == NULL) {
887		if ((ret = __log_put(env, rlsnp,(DBT *)&logrec,
888		    flags | DB_LOG_NOCOPY)) == 0 && txnp != NULL) {
889			*lsnp = *rlsnp;
890			if (rlsnp != ret_lsnp)
891				 *ret_lsnp = *rlsnp;
892		}
893	} else {
894		ret = 0;
895#ifdef DIAGNOSTIC
896		/*
897		 * Set the debug bit if we are going to log non-durable
898		 * transactions so they will be ignored by recovery.
899		 */
900		memcpy(lr->data, logrec.data, logrec.size);
901		rectype |= DB_debug_FLAG;
902		LOGCOPY_32(env, logrec.data, &rectype);
903
904		if (!IS_REP_CLIENT(env))
905			ret = __log_put(env,
906			    rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
907#endif
908		STAILQ_INSERT_HEAD(&txnp->logs, lr, links);
909		F_SET((TXN_DETAIL *)txnp->td, TXN_DTL_INMEMORY);
910		LSN_NOT_LOGGED(*ret_lsnp);
911	}
912
913#ifdef LOG_DIAGNOSTIC
914	if (ret != 0)
915		(void)__crdel_inmem_remove_print(env,
916		    (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
917#endif
918
919#ifdef DIAGNOSTIC
920	__os_free(env, logrec.data);
921#else
922	if (is_durable || txnp == NULL)
923		__os_free(env, logrec.data);
924#endif
925	return (ret);
926}
927
928/*
929 * PUBLIC: int __crdel_init_recover __P((ENV *, DB_DISTAB *));
930 */
931int
932__crdel_init_recover(env, dtabp)
933	ENV *env;
934	DB_DISTAB *dtabp;
935{
936	int ret;
937
938	if ((ret = __db_add_recovery_int(env, dtabp,
939	    __crdel_metasub_recover, DB___crdel_metasub)) != 0)
940		return (ret);
941	if ((ret = __db_add_recovery_int(env, dtabp,
942	    __crdel_inmem_create_recover, DB___crdel_inmem_create)) != 0)
943		return (ret);
944	if ((ret = __db_add_recovery_int(env, dtabp,
945	    __crdel_inmem_rename_recover, DB___crdel_inmem_rename)) != 0)
946		return (ret);
947	if ((ret = __db_add_recovery_int(env, dtabp,
948	    __crdel_inmem_remove_recover, DB___crdel_inmem_remove)) != 0)
949		return (ret);
950	return (0);
951}
952