2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * db_headers.h
2N/A *
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _DB_HEADERS_H
2N/A#define _DB_HEADERS_H
2N/A
2N/A#include <rpc/rpc.h>
2N/A#include <syslog.h>
2N/A#include <stdlib.h>
2N/A#include <setjmp.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/Aextern int verbose;
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/Aextern jmp_buf dbenv;
2N/A
2N/A#define FATAL(msg, fcode) \
2N/A { \
2N/A syslog(LOG_ERR, "ERROR: %s", (msg)); \
2N/A __nisdb_get_tsd()->fatalcode = (int)(fcode); \
2N/A __nisdb_get_tsd()->fatalmsg = msg; \
2N/A return; \
2N/A }
2N/A#define FATAL3(msg, fcode, retval) \
2N/A { \
2N/A syslog(LOG_ERR, "ERROR: %s", (msg)); \
2N/A __nisdb_get_tsd()->fatalcode = (int)(fcode); \
2N/A __nisdb_get_tsd()->fatalmsg = msg; \
2N/A return (retval); \
2N/A }
2N/A
2N/A#ifdef NISDB_MT_DEBUG
2N/A#define LOCKVAL(lockcall, msg, lockcode) \
2N/A { \
2N/A lockcode = lockcall(); \
2N/A if (lockcode != 0) { \
2N/A __nisdb_get_tsd()->fatalcode = lockcode; \
2N/A __nisdb_get_tsd()->fatalmsg = msg; \
2N/A abort(); \
2N/A } \
2N/A }
2N/A#else
2N/A#define LOCKVAL(lockcall, msg, lockcode) \
2N/A { \
2N/A lockcode = lockcall(); \
2N/A if (lockcode != 0) { \
2N/A __nisdb_get_tsd()->fatalcode = lockcode; \
2N/A __nisdb_get_tsd()->fatalmsg = msg; \
2N/A } \
2N/A }
2N/A#endif /* NISDB_MT_DEBUG */
2N/A
2N/A#define LOCKV(lockcall, msg) \
2N/A { \
2N/A int lockcode; \
2N/A LOCKVAL(lockcall, msg, lockcode); \
2N/A if (lockcode != 0) \
2N/A return; \
2N/A }
2N/A#define LOCK(lockcall, retval, msg) \
2N/A { \
2N/A int lockcode; \
2N/A LOCKVAL(lockcall, msg, lockcode); \
2N/A if (lockcode != 0) \
2N/A return (retval); \
2N/A }
2N/A
2N/A/* Read lock/unlock 'this', return 'retval' is unsuccessful, and save 'msg' */
2N/A#define READLOCK(this, retval, msg) \
2N/A LOCK(this->acqnonexcl, retval, msg)
2N/A#define READUNLOCK(this, retval, msg) \
2N/A LOCK(this->relnonexcl, retval, msg)
2N/A
2N/A/* Ditto, but return without a value (i.e., a "void" function */
2N/A#define READLOCKV(this, msg) \
2N/A LOCKV(this->acqnonexcl, msg)
2N/A#define READUNLOCKV(this, msg) \
2N/A LOCKV(this->relnonexcl, msg)
2N/A
2N/A/* As READLOCK/READUNLOCK, but set rescode instead of returning on failure */
2N/A#define READLOCKNR(this, rescode, msg) \
2N/A LOCKVAL(this->acqnonexcl, msg, rescode)
2N/A#define READUNLOCKNR(this, rescode, msg) \
2N/A LOCKVAL(this->relnonexcl, msg, rescode)
2N/A
2N/A/* As READLOCK/READUNLOCK, but use a write lock */
2N/A#define WRITELOCK(this, retval, msg) \
2N/A LOCK(this->acqexcl, retval, msg)
2N/A#define WRITEUNLOCK(this, retval, msg) \
2N/A LOCK(this->relexcl, retval, msg)
2N/A
2N/A/* Non-blocking write lock */
2N/A#define TRYWRITELOCK(this, rescode, msg) \
2N/A LOCKVAL(this->tryacqexcl, msg, rescode)
2N/A
2N/A/* Ditto, but return without a value */
2N/A#define WRITELOCKV(this, msg) \
2N/A LOCKV(this->acqexcl, msg)
2N/A#define WRITEUNLOCKV(this, msg) \
2N/A LOCKV(this->relexcl, msg)
2N/A
2N/A/* As WRITELOCK/WRITEUNLOCK, but set rescode instead of returning on failure */
2N/A#define WRITELOCKNR(this, rescode, msg) \
2N/A LOCKVAL(this->acqexcl, msg, rescode)
2N/A#define WRITEUNLOCKNR(this, rescode, msg) \
2N/A LOCKVAL(this->relexcl, msg, rescode)
2N/A
2N/A/* Apply a second write lock when already holding another write lock */
2N/A#define WRITELOCK2(this, retval, msg, that) \
2N/A if (this != 0) { \
2N/A int lockcode1, lockcode2; \
2N/A WRITELOCKNR(this, lockcode2, msg); \
2N/A if (lockcode2 != 0) { \
2N/A if (that != 0) { \
2N/A WRITEUNLOCKNR(that, lockcode1, msg); \
2N/A } \
2N/A return (retval); \
2N/A } \
2N/A }
2N/A/* Release two write locks */
2N/A#define WRITEUNLOCK2(this, that, retval1, retval2, msg1, msg2) \
2N/A { \
2N/A int lockcode1 = 0, lockcode2 = 0; \
2N/A if (this != 0) { \
2N/A WRITEUNLOCKNR(this, lockcode1, msg1); \
2N/A } \
2N/A if (that != 0) { \
2N/A WRITEUNLOCKNR(that, lockcode2, msg2); \
2N/A } \
2N/A if (lockcode2 != 0) { \
2N/A return (retval2); \
2N/A } else if (lockcode1 != 0) { \
2N/A return (retval1); \
2N/A } \
2N/A }
2N/A
2N/A/* Apply a second read lock when already holding another read lock */
2N/A#define READLOCK2(this, retval, msg, that) \
2N/A if (this != 0) { \
2N/A int lockcode1, lockcode2; \
2N/A READLOCKNR(this, lockcode2, msg); \
2N/A if (lockcode2 != 0) { \
2N/A if (that != 0) { \
2N/A READUNLOCKNR(that, lockcode1, msg); \
2N/A } \
2N/A return (retval); \
2N/A } \
2N/A }
2N/A/* Release two read locks */
2N/A#define READUNLOCK2(this, that, retval1, retval2, msg1, msg2) \
2N/A { \
2N/A int lockcode1 = 0, lockcode2 = 0; \
2N/A if (this != 0) { \
2N/A READUNLOCKNR(this, lockcode1, msg1); \
2N/A } \
2N/A if (that != 0) { \
2N/A READUNLOCKNR(that, lockcode2, msg2); \
2N/A } \
2N/A if (lockcode2 != 0) { \
2N/A return (retval2); \
2N/A } else if (lockcode1 != 0) { \
2N/A return (retval1); \
2N/A } \
2N/A }
2N/A
2N/A#define ASSERTWRITELOCKHELD(lvar, retval, msg) \
2N/A { \
2N/A int lc; \
2N/A if ((lc = __nisdb_assert_wheld(&lvar ## _rwlock)) != 0) { \
2N/A __nisdb_get_tsd()->fatalcode = lc; \
2N/A __nisdb_get_tsd()->fatalmsg = msg; \
2N/A return (retval); \
2N/A } \
2N/A }
2N/A
2N/A#define WARNING(x) { syslog(LOG_ERR, "WARNING: %s", (x)); }
2N/A
2N/A#define WARNING_M(x) { syslog(LOG_ERR, "WARNING: %s: %m", (x)); }
2N/A
2N/A
2N/Aenum db_status {DB_SUCCESS, DB_NOTFOUND, DB_NOTUNIQUE,
2N/A DB_BADTABLE, DB_BADQUERY, DB_BADOBJECT,
2N/A DB_MEMORY_LIMIT, DB_STORAGE_LIMIT, DB_INTERNAL_ERROR,
2N/A DB_BADDICTIONARY, DB_SYNC_FAILED, DB_LOCK_ERROR};
2N/Atypedef enum db_status db_status;
2N/A
2N/Aenum db_action {DB_LOOKUP, DB_REMOVE, DB_ADD, DB_FIRST, DB_NEXT, DB_ALL,
2N/A DB_RESET_NEXT, DB_ADD_NOLOG,
2N/A DB_ADD_NOSYNC, DB_REMOVE_NOSYNC };
2N/Atypedef enum db_action db_action;
2N/A
2N/A#endif /* _DB_HEADERS_H */