1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1999
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char sccsid[] = "@(#)env_method.c 11.5 (Sleepycat) 9/16/99";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#endif
#include "db_int.h"
#include "db_shash.h"
#include "db_page.h"
#include "db_am.h"
#include "lock.h"
#include "log.h"
#include "mp.h"
#include "txn.h"
DB_GLOBALS CDB___db_global_values = {
1, /* db_set_mutexlocks */
0, /* db_set_pageyield */
1, /* db_set_panic */
0, /* db_set_region_init */
0, /* db_set_tas_spins */
/* XA environment queue */
{NULL, &CDB___db_global_values.db_envq.tqh_first}
};
static void CDB___dbenv_err __P((const DB_ENV *, int, const char *, ...));
static void CDB___dbenv_errx __P((const DB_ENV *, const char *, ...));
static void CDB___dbenv_set_errcall __P((DB_ENV *, void (*)(const char *, char *)));
static void CDB___dbenv_set_errfile __P((DB_ENV *, FILE *));
static void CDB___dbenv_set_errpfx __P((DB_ENV *, const char *));
static void CDB___dbenv_set_feedback __P((DB_ENV *, void (*)(DB_ENV *, int, int)));
static int CDB___dbenv_set_mutexlocks __P((DB_ENV *, int));
static int CDB___dbenv_set_pageyield __P((DB_ENV *, int));
static int CDB___dbenv_set_panic __P((DB_ENV *, int));
static void CDB___dbenv_set_paniccall __P((DB_ENV *, void (*)(DB_ENV *, int)));
static int CDB___dbenv_set_recovery_init __P((DB_ENV *, int (*)(DB_ENV *)));
static int CDB___dbenv_set_region_init __P((DB_ENV *, int));
static int CDB___dbenv_set_tas_spins __P((DB_ENV *, u_int32_t));
static int CDB___dbenv_set_verbose __P((DB_ENV *, u_int32_t, int));
/*
* CDB_db_env_create --
* DB_ENV constructor.
*/
int
CDB_db_env_create(dbenvpp, flags)
DB_ENV **dbenvpp;
u_int32_t flags;
{
DB_ENV *dbenv;
int ret;
/*
* !!!
* We can't call the flags-checking routines, we don't have an
* environment yet.
*/
if (flags != 0)
return (EINVAL);
if ((ret = CDB___os_calloc(1, sizeof(*dbenv), &dbenv)) != 0)
return (ret);
if ((ret = CDB___dbenv_init(dbenv)) != 0) {
CDB___os_free(dbenv, sizeof(*dbenv));
return (ret);
}
*dbenvpp = dbenv;
return (0);
}
/*
* CDB___dbenv_init --
* Initialize a DB_ENV structure.
*
* PUBLIC: int CDB___dbenv_init __P((DB_ENV *));
*/
int
CDB___dbenv_init(dbenv)
DB_ENV *dbenv;
{
dbenv->close = CDB___dbenv_close;
dbenv->err = CDB___dbenv_err;
dbenv->errx = CDB___dbenv_errx;
dbenv->open = CDB___dbenv_open;
dbenv->remove = CDB___dbenv_remove;
dbenv->set_errcall = CDB___dbenv_set_errcall;
dbenv->set_errfile = CDB___dbenv_set_errfile;
dbenv->set_errpfx = CDB___dbenv_set_errpfx;
dbenv->set_feedback = CDB___dbenv_set_feedback;
dbenv->set_mutexlocks = CDB___dbenv_set_mutexlocks;
dbenv->set_pageyield = CDB___dbenv_set_pageyield;
dbenv->set_panic = CDB___dbenv_set_panic;
dbenv->set_paniccall = CDB___dbenv_set_paniccall;
dbenv->set_recovery_init = CDB___dbenv_set_recovery_init;
dbenv->set_region_init = CDB___dbenv_set_region_init;
dbenv->set_tas_spins = CDB___dbenv_set_tas_spins;
dbenv->set_verbose = CDB___dbenv_set_verbose;
CDB___log_dbenv_create(dbenv); /* Subsystem specific. */
CDB___lock_dbenv_create(dbenv);
CDB___memp_dbenv_create(dbenv);
CDB___txn_dbenv_create(dbenv);
CDB___os_dbenv_create(dbenv);
return (0);
}
/*
* CDB___dbenv_err --
* Error message, including the standard error string.
*/
static void
#if defined(__STDC__) || defined(_MSC_VER) /* WIN32 */
CDB___dbenv_err(const DB_ENV *dbenv, int error, const char *fmt, ...)
#else
CDB___dbenv_err(dbenv, error, fmt, va_alist)
const DB_ENV *dbenv;
int error;
const char *fmt;
va_dcl
#endif
{
va_list ap;
#if defined(__STDC__) || defined(_MSC_VER) /* WIN32 */
va_start(ap, fmt);
#else
va_start(ap);
#endif
CDB___db_real_err(dbenv, error, 1, 1, fmt, ap);
va_end(ap);
}
/*
* CDB___dbenv_errx --
* Error message.
*/
static void
#if defined(__STDC__) || defined(_MSC_VER) /* WIN32 */
CDB___dbenv_errx(const DB_ENV *dbenv, const char *fmt, ...)
#else
CDB___dbenv_errx(dbenv, fmt, va_alist)
const DB_ENV *dbenv;
const char *fmt;
va_dcl
#endif
{
va_list ap;
#if defined(__STDC__) || defined(_MSC_VER) /* WIN32 */
va_start(ap, fmt);
#else
va_start(ap);
#endif
CDB___db_real_err(dbenv, 0, 0, 1, fmt, ap);
va_end(ap);
}
static void
CDB___dbenv_set_errcall(dbenv, errcall)
DB_ENV *dbenv;
void (*errcall) __P((const char *, char *));
{
dbenv->db_errcall = errcall;
}
static void
CDB___dbenv_set_errfile(dbenv, errfile)
DB_ENV *dbenv;
FILE *errfile;
{
dbenv->db_errfile = errfile;
}
static void
CDB___dbenv_set_errpfx(dbenv, errpfx)
DB_ENV *dbenv;
const char *errpfx;
{
dbenv->db_errpfx = errpfx;
}
static void
CDB___dbenv_set_feedback(dbenv, feedback)
DB_ENV *dbenv;
void (*feedback) __P((DB_ENV *, int, int));
{
dbenv->db_feedback = feedback;
}
static int
CDB___dbenv_set_mutexlocks(dbenv, onoff)
DB_ENV *dbenv;
int onoff;
{
COMPQUIET(dbenv, NULL);
DB_GLOBAL(db_mutexlocks) = onoff;
return (0);
}
static int
CDB___dbenv_set_pageyield(dbenv, onoff)
DB_ENV *dbenv;
int onoff;
{
COMPQUIET(dbenv, NULL);
DB_GLOBAL(db_pageyield) = onoff;
return (0);
}
static int /* !!!: Undocumented. */
CDB___dbenv_set_panic(dbenv, onoff)
DB_ENV *dbenv;
int onoff;
{
COMPQUIET(dbenv, NULL);
DB_GLOBAL(db_panic) = onoff;
return (0);
}
static void
CDB___dbenv_set_paniccall(dbenv, paniccall)
DB_ENV *dbenv;
void (*paniccall) __P((DB_ENV *, int));
{
dbenv->db_paniccall = paniccall;
}
static int
CDB___dbenv_set_recovery_init(dbenv, recovery_init)
DB_ENV *dbenv;
int (*recovery_init) __P((DB_ENV *));
{
ENV_ILLEGAL_AFTER_OPEN(dbenv, "set_recovery_init");
dbenv->db_recovery_init = recovery_init;
return (0);
}
static int
CDB___dbenv_set_region_init(dbenv, onoff)
DB_ENV *dbenv;
int onoff;
{
COMPQUIET(dbenv, NULL);
DB_GLOBAL(db_region_init) = onoff;
return (0);
}
static int
CDB___dbenv_set_tas_spins(dbenv, tas_spins)
DB_ENV *dbenv;
u_int32_t tas_spins;
{
COMPQUIET(dbenv, NULL);
DB_GLOBAL(db_tas_spins) = tas_spins;
return (0);
}
static int
CDB___dbenv_set_verbose(dbenv, which, onoff)
DB_ENV *dbenv;
u_int32_t which;
int onoff;
{
switch (which) {
case DB_VERB_CHKPOINT:
case DB_VERB_DEADLOCK:
case DB_VERB_RECOVERY:
case DB_VERB_WAITSFOR:
if (onoff)
FLD_SET(dbenv->verbose, which);
else
FLD_CLR(dbenv->verbose, which);
break;
default:
return (EINVAL);
}
return (0);
}
/*
* CDB___db_mi_env --
* Method illegally called with public environment.
*
* PUBLIC: int CDB___db_mi_env __P((DB_ENV *, const char *));
*/
int
CDB___db_mi_env(dbenv, name)
DB_ENV *dbenv;
const char *name;
{
CDB___db_err(dbenv, "%s: method meaningless in shared environment", name);
return (EINVAL);
}
/*
* CDB___db_mi_open --
* Method illegally called after open.
*
* PUBLIC: int CDB___db_mi_open __P((DB_ENV *, const char *, int));
*/
int
CDB___db_mi_open(dbenv, name, after)
DB_ENV *dbenv;
const char *name;
int after;
{
CDB___db_err(dbenv,
"%s: method meaningless %s open", name, after ? "after" : "before");
return (EINVAL);
}
/*
* CDB___db_env_config --
* Method or function called without subsystem being configured.
*
* PUBLIC: int CDB___db_env_config __P((DB_ENV *, int));
*/
int
CDB___db_env_config(dbenv, subsystem)
DB_ENV *dbenv;
int subsystem;
{
const char *name;
switch (subsystem) {
case DB_INIT_LOCK:
name = "lock";
break;
case DB_INIT_LOG:
name = "log";
break;
case DB_INIT_MPOOL:
name = "mpool";
break;
case DB_INIT_TXN:
name = "txn";
break;
default:
name = "unknown";
break;
}
CDB___db_err(dbenv,
"%s interface called with environment not configured for that subsystem",
name);
return (EINVAL);
}
|