1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2000,2008 Oracle.  All rights reserved.
5 *
6 * $Id: db_server_int.h,v 12.13 2008/01/08 20:58:17 bostic Exp $
7 */
8
9#ifndef _DB_SERVER_INT_H_
10#define	_DB_SERVER_INT_H_
11
12#if defined(__cplusplus)
13extern "C" {
14#endif
15
16#define	DB_SERVER_TIMEOUT	300	/* 5 minutes */
17#define	DB_SERVER_MAXTIMEOUT	1200	/* 20 minutes */
18#define	DB_SERVER_IDLETIMEOUT	86400	/* 1 day */
19
20/*
21 * Ignore/mask off the following env->open flags:
22 * Most are illegal for a client to specify as they would control
23 * server resource usage.  We will just ignore them.
24 *	DB_LOCKDOWN
25 *	DB_PRIVATE
26 *	DB_RECOVER
27 *	DB_RECOVER_FATAL
28 *	DB_SYSTEM_MEM
29 *	DB_USE_ENVIRON, DB_USE_ENVIRON_ROOT	- handled on client
30 */
31#define	DB_SERVER_FLAGMASK	(					\
32DB_LOCKDOWN | DB_PRIVATE | DB_RECOVER | DB_RECOVER_FATAL |		\
33DB_SYSTEM_MEM | DB_USE_ENVIRON | DB_USE_ENVIRON_ROOT)
34
35#define	CT_CURSOR	0x001		/* Cursor */
36#define	CT_DB		0x002		/* Database */
37#define	CT_ENV		0x004		/* Env */
38#define	CT_TXN		0x008		/* Txn */
39
40#define	CT_JOIN		0x10000000	/* Join cursor component */
41#define	CT_JOINCUR	0x20000000	/* Join cursor */
42
43typedef struct home_entry home_entry;
44struct home_entry {
45	LIST_ENTRY(home_entry) entries;
46	char *home;
47	char *dir;
48	char *name;
49	char *passwd;
50};
51
52/*
53 * Data needed for sharing handles.
54 * To share an env handle, on the open call, they must have matching
55 * env flags, and matching set_flags.
56 *
57 * To share a db handle on the open call, the db, subdb and flags must
58 * all be the same.
59 */
60#define	DB_SERVER_ENVFLAGS	 (					\
61DB_INIT_CDB | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |		\
62DB_INIT_TXN | DB_JOINENV)
63
64#define	DB_SERVER_DBFLAGS	 (DB_NOMMAP | DB_RDONLY | DB_READ_UNCOMMITTED)
65#define	DB_SERVER_DBNOSHARE	 (DB_EXCL | DB_TRUNCATE)
66
67typedef struct ct_envdata ct_envdata;
68typedef struct ct_dbdata ct_dbdata;
69struct ct_envdata {
70	u_int32_t	envflags;
71	u_int32_t	onflags;
72	u_int32_t	offflags;
73	home_entry	*home;
74};
75
76struct ct_dbdata {
77	u_int32_t	dbflags;
78	u_int32_t	setflags;
79	char		*db;
80	char		*subdb;
81	DBTYPE		type;
82};
83
84/*
85 * We maintain an activity timestamp for each handle.  However, we
86 * set it to point, possibly to the ct_active field of its own handle
87 * or it may point to the ct_active field of a parent.  In the case
88 * of nested transactions and any cursors within transactions it must
89 * point to the ct_active field of the ultimate parent of the transaction
90 * no matter how deeply it is nested.
91 */
92typedef struct ct_entry ct_entry;
93struct ct_entry {
94	LIST_ENTRY(ct_entry) entries;		/* List of entries */
95	union {
96#ifdef __cplusplus
97		DbEnv *envp;			/* H_ENV */
98		DbTxn *txnp;			/* H_TXN */
99		Db *dbp;			/* H_DB */
100		Dbc *dbc;			/* H_CURSOR */
101#else
102		DB_ENV *envp;			/* H_ENV */
103		DB_TXN *txnp;			/* H_TXN */
104		DB *dbp;			/* H_DB */
105		DBC *dbc;			/* H_CURSOR */
106#endif
107		void *anyp;
108	} handle_u;
109	union {					/* Private data per type */
110		ct_envdata	envdp;		/* Env info */
111		ct_dbdata	dbdp;		/* Db info */
112	} private_u;
113	long ct_id;				/* Client ID */
114	long *ct_activep;			/* Activity timestamp pointer*/
115	long *ct_origp;				/* Original timestamp pointer*/
116	long ct_active;				/* Activity timestamp */
117	long ct_timeout;			/* Resource timeout */
118	long ct_idle;				/* Idle timeout */
119	u_int32_t ct_refcount;			/* Ref count for sharing */
120	u_int32_t ct_type;			/* This entry's type */
121	struct ct_entry *ct_parent;		/* Its parent */
122	struct ct_entry *ct_envparent;		/* Its environment */
123};
124
125#define	ct_envp handle_u.envp
126#define	ct_txnp handle_u.txnp
127#define	ct_dbp handle_u.dbp
128#define	ct_dbc handle_u.dbc
129#define	ct_anyp handle_u.anyp
130
131#define	ct_envdp private_u.envdp
132#define	ct_dbdp private_u.dbdp
133
134extern int __dbsrv_verbose;
135
136/*
137 * Get ctp and activate it.
138 * Assumes local variable 'replyp'.
139 * NOTE: May 'return' from macro.
140 */
141#define	ACTIVATE_CTP(ctp, id, type) {					\
142	(ctp) = get_tableent(id);					\
143	if ((ctp) == NULL) {						\
144		replyp->status = DB_NOSERVER_ID;			\
145		return;							\
146	}								\
147	/* We don't have a dbenv handle at this point. */		\
148	DB_ASSERT(NULL, (ctp)->ct_type & (type));			\
149	__dbsrv_active(ctp);						\
150}
151
152#define	FREE_IF_CHANGED(env, p, orig) do {				\
153	if ((p) != NULL && (p) != (orig))				\
154		__os_ufree((env), (p));				\
155} while (0)
156
157#if defined(__cplusplus)
158}
159#endif
160#endif	/* !_DB_SERVER_INT_H_ */
161