1*7c478bd9Sstevel@tonic-gate /*- 2*7c478bd9Sstevel@tonic-gate * See the file LICENSE for redistribution information. 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996, 1997, 1998 5*7c478bd9Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 6*7c478bd9Sstevel@tonic-gate * 7*7c478bd9Sstevel@tonic-gate * @(#)db_int.h 10.77 (Sleepycat) 1/3/99 8*7c478bd9Sstevel@tonic-gate */ 9*7c478bd9Sstevel@tonic-gate 10*7c478bd9Sstevel@tonic-gate #ifndef _DB_INTERNAL_H_ 11*7c478bd9Sstevel@tonic-gate #define _DB_INTERNAL_H_ 12*7c478bd9Sstevel@tonic-gate 13*7c478bd9Sstevel@tonic-gate #include "db.h" /* Standard DB include file. */ 14*7c478bd9Sstevel@tonic-gate #include "queue.h" 15*7c478bd9Sstevel@tonic-gate #include "shqueue.h" 16*7c478bd9Sstevel@tonic-gate 17*7c478bd9Sstevel@tonic-gate /******************************************************* 18*7c478bd9Sstevel@tonic-gate * General purpose constants and macros. 19*7c478bd9Sstevel@tonic-gate *******************************************************/ 20*7c478bd9Sstevel@tonic-gate #define UINT16_T_MAX 0xffff /* Maximum 16 bit unsigned. */ 21*7c478bd9Sstevel@tonic-gate #define UINT32_T_MAX 0xffffffff /* Maximum 32 bit unsigned. */ 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate #define DB_MIN_PGSIZE 0x000200 /* Minimum page size. */ 24*7c478bd9Sstevel@tonic-gate #define DB_MAX_PGSIZE 0x010000 /* Maximum page size. */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #define DB_MINCACHE 10 /* Minimum cached pages */ 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #define MEGABYTE 1048576 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * If we are unable to determine the underlying filesystem block size, use 32*7c478bd9Sstevel@tonic-gate * 8K on the grounds that most OS's use less than 8K as their VM page size. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate #define DB_DEF_IOSIZE (8 * 1024) 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * Aligning items to particular sizes or in pages or memory. ALIGNP is a 38*7c478bd9Sstevel@tonic-gate * separate macro, as we've had to cast the pointer to different integral 39*7c478bd9Sstevel@tonic-gate * types on different architectures. 40*7c478bd9Sstevel@tonic-gate * 41*7c478bd9Sstevel@tonic-gate * We cast pointers into unsigned longs when manipulating them because C89 42*7c478bd9Sstevel@tonic-gate * guarantees that u_long is the largest available integral type and further, 43*7c478bd9Sstevel@tonic-gate * to never generate overflows. However, neither C89 or C9X requires that 44*7c478bd9Sstevel@tonic-gate * any integer type be large enough to hold a pointer, although C9X created 45*7c478bd9Sstevel@tonic-gate * the intptr_t type, which is guaranteed to hold a pointer but may or may 46*7c478bd9Sstevel@tonic-gate * not exist. At some point in the future, we should test for intptr_t and 47*7c478bd9Sstevel@tonic-gate * use it where available. 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate #undef ALIGNTYPE 50*7c478bd9Sstevel@tonic-gate #define ALIGNTYPE u_long 51*7c478bd9Sstevel@tonic-gate #undef ALIGNP 52*7c478bd9Sstevel@tonic-gate #define ALIGNP(value, bound) ALIGN((ALIGNTYPE)value, bound) 53*7c478bd9Sstevel@tonic-gate #undef ALIGN 54*7c478bd9Sstevel@tonic-gate #define ALIGN(value, bound) (((value) + (bound) - 1) & ~((bound) - 1)) 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* 57*7c478bd9Sstevel@tonic-gate * There are several on-page structures that are declared to have a number of 58*7c478bd9Sstevel@tonic-gate * fields followed by a variable length array of items. The structure size 59*7c478bd9Sstevel@tonic-gate * without including the variable length array or the address of the first of 60*7c478bd9Sstevel@tonic-gate * those elements can be found using SSZ. 61*7c478bd9Sstevel@tonic-gate * 62*7c478bd9Sstevel@tonic-gate * This macro can also be used to find the offset of a structure element in a 63*7c478bd9Sstevel@tonic-gate * structure. This is used in various places to copy structure elements from 64*7c478bd9Sstevel@tonic-gate * unaligned memory references, e.g., pointers into a packed page. 65*7c478bd9Sstevel@tonic-gate * 66*7c478bd9Sstevel@tonic-gate * There are two versions because compilers object if you take the address of 67*7c478bd9Sstevel@tonic-gate * an array. 68*7c478bd9Sstevel@tonic-gate */ 69*7c478bd9Sstevel@tonic-gate #undef SSZ 70*7c478bd9Sstevel@tonic-gate #define SSZ(name, field) ((int)&(((name *)0)->field)) 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate #undef SSZA 73*7c478bd9Sstevel@tonic-gate #define SSZA(name, field) ((int)&(((name *)0)->field[0])) 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate /* Macros to return per-process address, offsets based on shared regions. */ 76*7c478bd9Sstevel@tonic-gate #define R_ADDR(base, offset) ((void *)((u_int8_t *)((base)->addr) + offset)) 77*7c478bd9Sstevel@tonic-gate #define R_OFFSET(base, p) ((u_int8_t *)(p) - (u_int8_t *)(base)->addr) 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate #define DB_DEFAULT 0x000000 /* No flag was specified. */ 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* Structure used to print flag values. */ 82*7c478bd9Sstevel@tonic-gate typedef struct __fn { 83*7c478bd9Sstevel@tonic-gate u_int32_t mask; /* Flag value. */ 84*7c478bd9Sstevel@tonic-gate const char *name; /* Flag name. */ 85*7c478bd9Sstevel@tonic-gate } FN; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* Set, clear and test flags. */ 88*7c478bd9Sstevel@tonic-gate #define F_SET(p, f) (p)->flags |= (f) 89*7c478bd9Sstevel@tonic-gate #define F_CLR(p, f) (p)->flags &= ~(f) 90*7c478bd9Sstevel@tonic-gate #define F_ISSET(p, f) ((p)->flags & (f)) 91*7c478bd9Sstevel@tonic-gate #define LF_SET(f) (flags |= (f)) 92*7c478bd9Sstevel@tonic-gate #define LF_CLR(f) (flags &= ~(f)) 93*7c478bd9Sstevel@tonic-gate #define LF_ISSET(f) (flags & (f)) 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate /* 96*7c478bd9Sstevel@tonic-gate * Panic check: 97*7c478bd9Sstevel@tonic-gate * All interfaces check the panic flag, if it's set, the tree is dead. 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate #define DB_PANIC_CHECK(dbp) { \ 100*7c478bd9Sstevel@tonic-gate if ((dbp)->dbenv != NULL && (dbp)->dbenv->db_panic != 0) \ 101*7c478bd9Sstevel@tonic-gate return (DB_RUNRECOVERY); \ 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* Display separator string. */ 105*7c478bd9Sstevel@tonic-gate #undef DB_LINE 106*7c478bd9Sstevel@tonic-gate #define DB_LINE "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* Unused, or not-used-yet variable. "Shut that bloody compiler up!" */ 109*7c478bd9Sstevel@tonic-gate #define COMPQUIET(n, v) (n) = (v) 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate /* 112*7c478bd9Sstevel@tonic-gate * Purify and similar run-time tools complain about unitialized reads/writes 113*7c478bd9Sstevel@tonic-gate * for structure fields whose only purpose is padding. 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate #define UMRW(v) (v) = 0 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate /* 118*7c478bd9Sstevel@tonic-gate * Win16 needs specific syntax on callback functions. Nobody else cares. 119*7c478bd9Sstevel@tonic-gate */ 120*7c478bd9Sstevel@tonic-gate #ifndef DB_CALLBACK 121*7c478bd9Sstevel@tonic-gate #define DB_CALLBACK /* Nothing. */ 122*7c478bd9Sstevel@tonic-gate #endif 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /******************************************************* 125*7c478bd9Sstevel@tonic-gate * Files. 126*7c478bd9Sstevel@tonic-gate *******************************************************/ 127*7c478bd9Sstevel@tonic-gate /* 128*7c478bd9Sstevel@tonic-gate * We use 1024 as the maximum path length. It's too hard to figure out what 129*7c478bd9Sstevel@tonic-gate * the real path length is, as it was traditionally stored in <sys/param.h>, 130*7c478bd9Sstevel@tonic-gate * and that file isn't always available. 131*7c478bd9Sstevel@tonic-gate */ 132*7c478bd9Sstevel@tonic-gate #undef MAXPATHLEN 133*7c478bd9Sstevel@tonic-gate #define MAXPATHLEN 1024 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate #define PATH_DOT "." /* Current working directory. */ 136*7c478bd9Sstevel@tonic-gate #define PATH_SEPARATOR "/" /* Path separator character. */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate /******************************************************* 139*7c478bd9Sstevel@tonic-gate * Mutex support. 140*7c478bd9Sstevel@tonic-gate *******************************************************/ 141*7c478bd9Sstevel@tonic-gate #include <sys/machlock.h> 142*7c478bd9Sstevel@tonic-gate typedef lock_t tsl_t; 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * !!! 147*7c478bd9Sstevel@tonic-gate * Various systems require different alignments for mutexes (the worst we've 148*7c478bd9Sstevel@tonic-gate * seen so far is 16-bytes on some HP architectures). The mutex (tsl_t) must 149*7c478bd9Sstevel@tonic-gate * be first in the db_mutex_t structure, which must itself be first in the 150*7c478bd9Sstevel@tonic-gate * region. This ensures the alignment is as returned by mmap(2), which should 151*7c478bd9Sstevel@tonic-gate * be sufficient. All other mutex users must ensure proper alignment locally. 152*7c478bd9Sstevel@tonic-gate */ 153*7c478bd9Sstevel@tonic-gate #define MUTEX_ALIGNMENT sizeof(int) 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate /* 156*7c478bd9Sstevel@tonic-gate * The offset of a mutex in memory. 157*7c478bd9Sstevel@tonic-gate * 158*7c478bd9Sstevel@tonic-gate * !!! 159*7c478bd9Sstevel@tonic-gate * Not an off_t, so backing file offsets MUST be less than 4Gb. See the 160*7c478bd9Sstevel@tonic-gate * off field of the db_mutex_t as well. 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate #define MUTEX_LOCK_OFFSET(a, b) ((u_int32_t)((u_int8_t *)b - (u_int8_t *)a)) 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate typedef struct _db_mutex_t { 165*7c478bd9Sstevel@tonic-gate #ifdef HAVE_SPINLOCKS 166*7c478bd9Sstevel@tonic-gate tsl_t tsl_resource; /* Resource test and set. */ 167*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC 168*7c478bd9Sstevel@tonic-gate u_int32_t pid; /* Lock holder: 0 or process pid. */ 169*7c478bd9Sstevel@tonic-gate #endif 170*7c478bd9Sstevel@tonic-gate #else 171*7c478bd9Sstevel@tonic-gate u_int32_t off; /* Backing file offset. */ 172*7c478bd9Sstevel@tonic-gate u_int32_t pid; /* Lock holder: 0 or process pid. */ 173*7c478bd9Sstevel@tonic-gate #endif 174*7c478bd9Sstevel@tonic-gate u_int32_t spins; /* Spins before block. */ 175*7c478bd9Sstevel@tonic-gate u_int32_t mutex_set_wait; /* Granted after wait. */ 176*7c478bd9Sstevel@tonic-gate u_int32_t mutex_set_nowait; /* Granted without waiting. */ 177*7c478bd9Sstevel@tonic-gate } db_mutex_t; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate #include "mutex_ext.h" 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate /******************************************************* 182*7c478bd9Sstevel@tonic-gate * Access methods. 183*7c478bd9Sstevel@tonic-gate *******************************************************/ 184*7c478bd9Sstevel@tonic-gate /* Lock/unlock a DB thread. */ 185*7c478bd9Sstevel@tonic-gate #define DB_THREAD_LOCK(dbp) \ 186*7c478bd9Sstevel@tonic-gate if (F_ISSET(dbp, DB_AM_THREAD)) \ 187*7c478bd9Sstevel@tonic-gate (void)__db_mutex_lock((db_mutex_t *)(dbp)->mutexp, -1); 188*7c478bd9Sstevel@tonic-gate #define DB_THREAD_UNLOCK(dbp) \ 189*7c478bd9Sstevel@tonic-gate if (F_ISSET(dbp, DB_AM_THREAD)) \ 190*7c478bd9Sstevel@tonic-gate (void)__db_mutex_unlock((db_mutex_t *)(dbp)->mutexp, -1); 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate /******************************************************* 193*7c478bd9Sstevel@tonic-gate * Environment. 194*7c478bd9Sstevel@tonic-gate *******************************************************/ 195*7c478bd9Sstevel@tonic-gate /* Type passed to __db_appname(). */ 196*7c478bd9Sstevel@tonic-gate typedef enum { 197*7c478bd9Sstevel@tonic-gate DB_APP_NONE=0, /* No type (region). */ 198*7c478bd9Sstevel@tonic-gate DB_APP_DATA, /* Data file. */ 199*7c478bd9Sstevel@tonic-gate DB_APP_LOG, /* Log file. */ 200*7c478bd9Sstevel@tonic-gate DB_APP_TMP /* Temporary file. */ 201*7c478bd9Sstevel@tonic-gate } APPNAME; 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /******************************************************* 204*7c478bd9Sstevel@tonic-gate * Shared memory regions. 205*7c478bd9Sstevel@tonic-gate *******************************************************/ 206*7c478bd9Sstevel@tonic-gate /* 207*7c478bd9Sstevel@tonic-gate * The shared memory regions share an initial structure so that the general 208*7c478bd9Sstevel@tonic-gate * region code can handle races between the region being deleted and other 209*7c478bd9Sstevel@tonic-gate * processes waiting on the region mutex. 210*7c478bd9Sstevel@tonic-gate * 211*7c478bd9Sstevel@tonic-gate * !!! 212*7c478bd9Sstevel@tonic-gate * Note, the mutex must be the first entry in the region; see comment above. 213*7c478bd9Sstevel@tonic-gate */ 214*7c478bd9Sstevel@tonic-gate typedef struct _rlayout { 215*7c478bd9Sstevel@tonic-gate db_mutex_t lock; /* Region mutex. */ 216*7c478bd9Sstevel@tonic-gate #define DB_REGIONMAGIC 0x120897 217*7c478bd9Sstevel@tonic-gate u_int32_t valid; /* Valid magic number. */ 218*7c478bd9Sstevel@tonic-gate u_int32_t refcnt; /* Region reference count. */ 219*7c478bd9Sstevel@tonic-gate size_t size; /* Region length. */ 220*7c478bd9Sstevel@tonic-gate int majver; /* Major version number. */ 221*7c478bd9Sstevel@tonic-gate int minver; /* Minor version number. */ 222*7c478bd9Sstevel@tonic-gate int patch; /* Patch version number. */ 223*7c478bd9Sstevel@tonic-gate int panic; /* Region is dead. */ 224*7c478bd9Sstevel@tonic-gate #define INVALID_SEGID -1 225*7c478bd9Sstevel@tonic-gate int segid; /* shmget(2) ID, or Win16 segment ID. */ 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate #define REGION_ANONYMOUS 0x01 /* Region is/should be in anon mem. */ 228*7c478bd9Sstevel@tonic-gate u_int32_t flags; 229*7c478bd9Sstevel@tonic-gate } RLAYOUT; 230*7c478bd9Sstevel@tonic-gate 231*7c478bd9Sstevel@tonic-gate /* 232*7c478bd9Sstevel@tonic-gate * DB creates all regions on 4K boundaries out of sheer paranoia, so that 233*7c478bd9Sstevel@tonic-gate * we don't make the underlying VM unhappy. 234*7c478bd9Sstevel@tonic-gate */ 235*7c478bd9Sstevel@tonic-gate #define DB_VMPAGESIZE (4 * 1024) 236*7c478bd9Sstevel@tonic-gate #define DB_ROUNDOFF(n, round) { \ 237*7c478bd9Sstevel@tonic-gate (n) += (round) - 1; \ 238*7c478bd9Sstevel@tonic-gate (n) -= (n) % (round); \ 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate 241*7c478bd9Sstevel@tonic-gate /* 242*7c478bd9Sstevel@tonic-gate * The interface to region attach is nasty, there is a lot of complex stuff 243*7c478bd9Sstevel@tonic-gate * going on, which has to be retained between create/attach and detach. The 244*7c478bd9Sstevel@tonic-gate * REGINFO structure keeps track of it. 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate struct __db_reginfo; typedef struct __db_reginfo REGINFO; 247*7c478bd9Sstevel@tonic-gate struct __db_reginfo { 248*7c478bd9Sstevel@tonic-gate /* Arguments. */ 249*7c478bd9Sstevel@tonic-gate DB_ENV *dbenv; /* Region naming info. */ 250*7c478bd9Sstevel@tonic-gate APPNAME appname; /* Region naming info. */ 251*7c478bd9Sstevel@tonic-gate char *path; /* Region naming info. */ 252*7c478bd9Sstevel@tonic-gate const char *file; /* Region naming info. */ 253*7c478bd9Sstevel@tonic-gate int mode; /* Region mode, if a file. */ 254*7c478bd9Sstevel@tonic-gate size_t size; /* Region size. */ 255*7c478bd9Sstevel@tonic-gate u_int32_t dbflags; /* Region file open flags, if a file. */ 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate /* Results. */ 258*7c478bd9Sstevel@tonic-gate char *name; /* Region name. */ 259*7c478bd9Sstevel@tonic-gate void *addr; /* Region address. */ 260*7c478bd9Sstevel@tonic-gate int fd; /* Fcntl(2) locking file descriptor. 261*7c478bd9Sstevel@tonic-gate NB: this is only valid if a regular 262*7c478bd9Sstevel@tonic-gate file is backing the shared region, 263*7c478bd9Sstevel@tonic-gate and mmap(2) is being used to map it 264*7c478bd9Sstevel@tonic-gate into our address space. */ 265*7c478bd9Sstevel@tonic-gate int segid; /* shmget(2) ID, or Win16 segment ID. */ 266*7c478bd9Sstevel@tonic-gate void *wnt_handle; /* Win/NT HANDLE. */ 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate /* Shared flags. */ 269*7c478bd9Sstevel@tonic-gate /* 0x0001 COMMON MASK with RLAYOUT structure. */ 270*7c478bd9Sstevel@tonic-gate #define REGION_CANGROW 0x0002 /* Can grow. */ 271*7c478bd9Sstevel@tonic-gate #define REGION_CREATED 0x0004 /* Created. */ 272*7c478bd9Sstevel@tonic-gate #define REGION_HOLDINGSYS 0x0008 /* Holding system resources. */ 273*7c478bd9Sstevel@tonic-gate #define REGION_LASTDETACH 0x0010 /* Delete on last detach. */ 274*7c478bd9Sstevel@tonic-gate #define REGION_MALLOC 0x0020 /* Created in malloc'd memory. */ 275*7c478bd9Sstevel@tonic-gate #define REGION_PRIVATE 0x0040 /* Private to thread/process. */ 276*7c478bd9Sstevel@tonic-gate #define REGION_REMOVED 0x0080 /* Already deleted. */ 277*7c478bd9Sstevel@tonic-gate #define REGION_SIZEDEF 0x0100 /* Use default region size if exists. */ 278*7c478bd9Sstevel@tonic-gate u_int32_t flags; 279*7c478bd9Sstevel@tonic-gate }; 280*7c478bd9Sstevel@tonic-gate 281*7c478bd9Sstevel@tonic-gate /******************************************************* 282*7c478bd9Sstevel@tonic-gate * Mpool. 283*7c478bd9Sstevel@tonic-gate *******************************************************/ 284*7c478bd9Sstevel@tonic-gate /* 285*7c478bd9Sstevel@tonic-gate * File types for DB access methods. Negative numbers are reserved to DB. 286*7c478bd9Sstevel@tonic-gate */ 287*7c478bd9Sstevel@tonic-gate #define DB_FTYPE_BTREE -1 /* Btree. */ 288*7c478bd9Sstevel@tonic-gate #define DB_FTYPE_HASH -2 /* Hash. */ 289*7c478bd9Sstevel@tonic-gate 290*7c478bd9Sstevel@tonic-gate /* Structure used as the DB pgin/pgout pgcookie. */ 291*7c478bd9Sstevel@tonic-gate typedef struct __dbpginfo { 292*7c478bd9Sstevel@tonic-gate size_t db_pagesize; /* Underlying page size. */ 293*7c478bd9Sstevel@tonic-gate int needswap; /* If swapping required. */ 294*7c478bd9Sstevel@tonic-gate } DB_PGINFO; 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate /******************************************************* 297*7c478bd9Sstevel@tonic-gate * Log. 298*7c478bd9Sstevel@tonic-gate *******************************************************/ 299*7c478bd9Sstevel@tonic-gate /* Initialize an LSN to 'zero'. */ 300*7c478bd9Sstevel@tonic-gate #define ZERO_LSN(LSN) { \ 301*7c478bd9Sstevel@tonic-gate (LSN).file = 0; \ 302*7c478bd9Sstevel@tonic-gate (LSN).offset = 0; \ 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate /* Return 1 if LSN is a 'zero' lsn, otherwise return 0. */ 306*7c478bd9Sstevel@tonic-gate #define IS_ZERO_LSN(LSN) ((LSN).file == 0) 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate /* Test if we need to log a change. */ 309*7c478bd9Sstevel@tonic-gate #define DB_LOGGING(dbc) \ 310*7c478bd9Sstevel@tonic-gate (F_ISSET((dbc)->dbp, DB_AM_LOGGING) && !F_ISSET(dbc, DBC_RECOVER)) 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC 313*7c478bd9Sstevel@tonic-gate /* 314*7c478bd9Sstevel@tonic-gate * Debugging macro to log operations. 315*7c478bd9Sstevel@tonic-gate * If DEBUG_WOP is defined, log operations that modify the database. 316*7c478bd9Sstevel@tonic-gate * If DEBUG_ROP is defined, log operations that read the database. 317*7c478bd9Sstevel@tonic-gate * 318*7c478bd9Sstevel@tonic-gate * D dbp 319*7c478bd9Sstevel@tonic-gate * T txn 320*7c478bd9Sstevel@tonic-gate * O operation (string) 321*7c478bd9Sstevel@tonic-gate * K key 322*7c478bd9Sstevel@tonic-gate * A data 323*7c478bd9Sstevel@tonic-gate * F flags 324*7c478bd9Sstevel@tonic-gate */ 325*7c478bd9Sstevel@tonic-gate #define LOG_OP(C, T, O, K, A, F) { \ 326*7c478bd9Sstevel@tonic-gate DB_LSN _lsn; \ 327*7c478bd9Sstevel@tonic-gate DBT _op; \ 328*7c478bd9Sstevel@tonic-gate if (DB_LOGGING((C))) { \ 329*7c478bd9Sstevel@tonic-gate memset(&_op, 0, sizeof(_op)); \ 330*7c478bd9Sstevel@tonic-gate _op.data = O; \ 331*7c478bd9Sstevel@tonic-gate _op.size = strlen(O) + 1; \ 332*7c478bd9Sstevel@tonic-gate (void)__db_debug_log((C)->dbp->dbenv->lg_info, \ 333*7c478bd9Sstevel@tonic-gate T, &_lsn, 0, &_op, (C)->dbp->log_fileid, K, A, F); \ 334*7c478bd9Sstevel@tonic-gate } \ 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate #ifdef DEBUG_ROP 337*7c478bd9Sstevel@tonic-gate #define DEBUG_LREAD(C, T, O, K, A, F) LOG_OP(C, T, O, K, A, F) 338*7c478bd9Sstevel@tonic-gate #else 339*7c478bd9Sstevel@tonic-gate #define DEBUG_LREAD(C, T, O, K, A, F) 340*7c478bd9Sstevel@tonic-gate #endif 341*7c478bd9Sstevel@tonic-gate #ifdef DEBUG_WOP 342*7c478bd9Sstevel@tonic-gate #define DEBUG_LWRITE(C, T, O, K, A, F) LOG_OP(C, T, O, K, A, F) 343*7c478bd9Sstevel@tonic-gate #else 344*7c478bd9Sstevel@tonic-gate #define DEBUG_LWRITE(C, T, O, K, A, F) 345*7c478bd9Sstevel@tonic-gate #endif 346*7c478bd9Sstevel@tonic-gate #else 347*7c478bd9Sstevel@tonic-gate #define DEBUG_LREAD(C, T, O, K, A, F) 348*7c478bd9Sstevel@tonic-gate #define DEBUG_LWRITE(C, T, O, K, A, F) 349*7c478bd9Sstevel@tonic-gate #endif /* DIAGNOSTIC */ 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate /******************************************************* 352*7c478bd9Sstevel@tonic-gate * Transactions and recovery. 353*7c478bd9Sstevel@tonic-gate *******************************************************/ 354*7c478bd9Sstevel@tonic-gate /* 355*7c478bd9Sstevel@tonic-gate * Out of band value for a lock. The locks are returned to callers as offsets 356*7c478bd9Sstevel@tonic-gate * into the lock regions. Since the RLAYOUT structure begins all regions, an 357*7c478bd9Sstevel@tonic-gate * offset of 0 is guaranteed not to be a valid lock. 358*7c478bd9Sstevel@tonic-gate */ 359*7c478bd9Sstevel@tonic-gate #define LOCK_INVALID 0 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate /* The structure allocated for every transaction. */ 362*7c478bd9Sstevel@tonic-gate struct __db_txn { 363*7c478bd9Sstevel@tonic-gate DB_TXNMGR *mgrp; /* Pointer to transaction manager. */ 364*7c478bd9Sstevel@tonic-gate DB_TXN *parent; /* Pointer to transaction's parent. */ 365*7c478bd9Sstevel@tonic-gate DB_LSN last_lsn; /* Lsn of last log write. */ 366*7c478bd9Sstevel@tonic-gate u_int32_t txnid; /* Unique transaction id. */ 367*7c478bd9Sstevel@tonic-gate size_t off; /* Detail structure within region. */ 368*7c478bd9Sstevel@tonic-gate TAILQ_ENTRY(__db_txn) links; /* Links transactions off manager. */ 369*7c478bd9Sstevel@tonic-gate TAILQ_HEAD(__kids, __db_txn) kids; /* Child transactions. */ 370*7c478bd9Sstevel@tonic-gate TAILQ_ENTRY(__db_txn) klinks; /* Links child transactions. */ 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate #define TXN_MALLOC 0x01 /* Structure allocated by TXN system. */ 373*7c478bd9Sstevel@tonic-gate u_int32_t flags; 374*7c478bd9Sstevel@tonic-gate }; 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate /******************************************************* 377*7c478bd9Sstevel@tonic-gate * Global variables. 378*7c478bd9Sstevel@tonic-gate *******************************************************/ 379*7c478bd9Sstevel@tonic-gate /* 380*7c478bd9Sstevel@tonic-gate * !!! 381*7c478bd9Sstevel@tonic-gate * Initialized in os/os_config.c, don't change this unless you change it 382*7c478bd9Sstevel@tonic-gate * as well. 383*7c478bd9Sstevel@tonic-gate */ 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate struct __rmname { 386*7c478bd9Sstevel@tonic-gate char *dbhome; 387*7c478bd9Sstevel@tonic-gate int rmid; 388*7c478bd9Sstevel@tonic-gate TAILQ_ENTRY(__rmname) links; 389*7c478bd9Sstevel@tonic-gate }; 390*7c478bd9Sstevel@tonic-gate 391*7c478bd9Sstevel@tonic-gate typedef struct __db_globals { 392*7c478bd9Sstevel@tonic-gate int db_mutexlocks; /* DB_MUTEXLOCKS */ 393*7c478bd9Sstevel@tonic-gate int db_pageyield; /* DB_PAGEYIELD */ 394*7c478bd9Sstevel@tonic-gate int db_region_anon; /* DB_REGION_ANON, DB_REGION_NAME */ 395*7c478bd9Sstevel@tonic-gate int db_region_init; /* DB_REGION_INIT */ 396*7c478bd9Sstevel@tonic-gate int db_tsl_spins; /* DB_TSL_SPINS */ 397*7c478bd9Sstevel@tonic-gate /* XA: list of opened environments. */ 398*7c478bd9Sstevel@tonic-gate TAILQ_HEAD(__db_envq, __db_env) db_envq; 399*7c478bd9Sstevel@tonic-gate /* XA: list of id to dbhome mappings. */ 400*7c478bd9Sstevel@tonic-gate TAILQ_HEAD(__db_nameq, __rmname) db_nameq; 401*7c478bd9Sstevel@tonic-gate } DB_GLOBALS; 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate extern DB_GLOBALS __db_global_values; 404*7c478bd9Sstevel@tonic-gate #define DB_GLOBAL(v) __db_global_values.v 405*7c478bd9Sstevel@tonic-gate 406*7c478bd9Sstevel@tonic-gate #include "os.h" 407*7c478bd9Sstevel@tonic-gate #include "os_ext.h" 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate #endif /* !_DB_INTERNAL_H_ */ 410