Commit 4c7d288e authored by Howard Chu's avatar Howard Chu
Browse files

More for BDB 4.6 compatibility

parent 8e66538d
......@@ -35,7 +35,7 @@ bdb_add(Operation *op, SlapReply *rs )
DB_TXN *ltid = NULL, *lt2;
struct bdb_op_info opinfo = {0};
int subentry;
u_int32_t locker = 0, rlocker = 0;
BDB_LOCKER locker = 0, rlocker = 0;
DB_LOCK lock;
int num_retries = 0;
......
......@@ -58,6 +58,28 @@ LDAP_BEGIN_DECL
#define BDB_PAGESIZE 4096 /* BDB's original default */
#endif
/* 4.6.18 redefines cursor->locker */
#if DB_VERSION_FULL >= 0x04060012
struct __db_locker {
u_int32_t id;
};
typedef struct __db_locker * BDB_LOCKER;
extern int __lock_getlocker(DB_LOCKTAB *lt, u_int32_t locker, int create, DB_LOCKER **ret);
#define CURSOR_SETLOCKER(cursor, id) cursor->locker = id
#define CURSOR_GETLOCKER(cursor) cursor->locker
#else
typedef u_int32_t BDB_LOCKER;
#define CURSOR_SETLOCKER(cursor, id) cursor->locker = id
#define CURSOR_GETLOCKER(cursor) cursor->locker
#endif
#define DEFAULT_CACHE_SIZE 1000
/* The default search IDL stack cache depth */
......@@ -135,7 +157,7 @@ typedef struct bdb_cache {
int c_eiused; /* EntryInfo's in use */
int c_leaves; /* EntryInfo leaf nodes */
int c_purging;
u_int32_t c_locker; /* used by lru cleaner */
BDB_LOCKER c_locker; /* used by lru cleaner */
ldap_pvt_thread_rdwr_t c_rwlock;
ldap_pvt_thread_mutex_t c_lru_mutex;
ldap_pvt_thread_mutex_t c_count_mutex;
......@@ -230,6 +252,7 @@ struct bdb_info {
#define bi_id2entry bi_databases[BDB_ID2ENTRY]
#define bi_dn2id bi_databases[BDB_DN2ID]
struct bdb_lock_info {
struct bdb_lock_info *bli_next;
ID bli_id;
......@@ -239,8 +262,8 @@ struct bdb_lock_info {
struct bdb_op_info {
BackendDB* boi_bdb;
DB_TXN* boi_txn;
BDB_LOCKER boi_locker;
u_int32_t boi_err;
u_int32_t boi_locker;
int boi_acl_cache;
struct bdb_lock_info *boi_locks; /* used when no txn */
};
......@@ -280,23 +303,12 @@ struct bdb_op_info {
((db)->open)(db, NULL, file, name, type, flags, mode)
#endif
#endif
/* 4.6.18 redefines cursor->locker */
/* BDB 4.6.18 makes locker a struct instead of an int */
#if DB_VERSION_FULL >= 0x04060012
#undef TXN_ID
#define TXN_ID(txn) (txn)->locker
#endif
struct __db_locker {
u_int32_t id;
};
extern int __lock_getlocker(DB_LOCKTAB *lt, u_int32_t locker, int create, DB_LOCKER **ret);
#define CURSOR_SETLOCKER(cursor, id) \
__lock_getlocker(cursor->dbp->dbenv->lk_handle, id, 0, &cursor->locker)
#define CURSOR_GETLOCKER(cursor) cursor->locker->id
#else
#define CURSOR_SETLOCKER(cursor, id) cursor->locker = id
#define CURSOR_GETLOCKER(cursor) cursor->locker
#endif
#ifndef DB_BUFFER_SMALL
......
......@@ -32,7 +32,7 @@ bdb_bind( Operation *op, SlapReply *rs )
AttributeDescription *password = slap_schema.si_ad_userPassword;
u_int32_t locker;
BDB_LOCKER locker;
DB_LOCK lock;
Debug( LDAP_DEBUG_ARGS,
......
......@@ -155,11 +155,17 @@ bdb_cache_lru_link( struct bdb_info *bdb, EntryInfo *ei )
* alternatives though.
*/
#if DB_VERSION_FULL >= 0x04060012
#define BDB_LOCKID(locker) locker->id
#else
#define BDB_LOCKID(locker) locker
#endif
/* Atomically release and reacquire a lock */
int
bdb_cache_entry_db_relock(
struct bdb_info *bdb,
u_int32_t locker,
BDB_LOCKER locker,
EntryInfo *ei,
int rw,
int tryOnly,
......@@ -183,7 +189,7 @@ bdb_cache_entry_db_relock(
list[1].lock = *lock;
list[1].mode = rw ? DB_LOCK_WRITE : DB_LOCK_READ;
list[1].obj = &lockobj;
rc = bdb->bi_dbenv->lock_vec(bdb->bi_dbenv, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
rc = bdb->bi_dbenv->lock_vec(bdb->bi_dbenv, BDB_LOCKID(locker), tryOnly ? DB_LOCK_NOWAIT : 0,
list, 2, NULL );
if (rc && !tryOnly) {
......@@ -198,7 +204,7 @@ bdb_cache_entry_db_relock(
}
static int
bdb_cache_entry_db_lock( struct bdb_info *bdb, u_int32_t locker, EntryInfo *ei,
bdb_cache_entry_db_lock( struct bdb_info *bdb, BDB_LOCKER locker, EntryInfo *ei,
int rw, int tryOnly, DB_LOCK *lock )
{
#ifdef NO_DB_LOCK
......@@ -218,7 +224,7 @@ bdb_cache_entry_db_lock( struct bdb_info *bdb, u_int32_t locker, EntryInfo *ei,
lockobj.data = &ei->bei_id;
lockobj.size = sizeof(ei->bei_id) + 1;
rc = LOCK_GET(bdb->bi_dbenv, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
rc = LOCK_GET(bdb->bi_dbenv, BDB_LOCKID(locker), tryOnly ? DB_LOCK_NOWAIT : 0,
&lockobj, db_rw, lock);
if (rc && !tryOnly) {
Debug( LDAP_DEBUG_TRACE,
......@@ -457,7 +463,7 @@ int
hdb_cache_find_parent(
Operation *op,
DB_TXN *txn,
u_int32_t locker,
BDB_LOCKER locker,
ID id,
EntryInfo **res )
{
......@@ -742,7 +748,7 @@ bdb_cache_find_id(
ID id,
EntryInfo **eip,
int islocked,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
......@@ -963,7 +969,7 @@ bdb_cache_add(
EntryInfo *eip,
Entry *e,
struct berval *nrdn,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
EntryInfo *new, ei;
......@@ -1038,7 +1044,7 @@ bdb_cache_modify(
struct bdb_info *bdb,
Entry *e,
Attribute *newAttrs,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
EntryInfo *ei = BEI(e);
......@@ -1068,7 +1074,7 @@ bdb_cache_modrdn(
struct berval *nrdn,
Entry *new,
EntryInfo *ein,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
EntryInfo *ei = BEI(e), *pei;
......@@ -1163,7 +1169,7 @@ int
bdb_cache_delete(
struct bdb_info *bdb,
Entry *e,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
EntryInfo *ei = BEI(e);
......@@ -1354,9 +1360,15 @@ static void
bdb_locker_id_free( void *key, void *data )
{
DB_ENV *env = key;
u_int32_t lockid = (long)data;
u_int32_t lockid;
int rc;
#if DB_VERSION_FULL >= 0x04060012
BDB_LOCKER lptr = data;
lockid = lptr->id;
#else
lockid = (long)data;
#endif
rc = XLOCK_ID_FREE( env, lockid );
if ( rc == EINVAL ) {
DB_LOCKREQ lr;
......@@ -1385,7 +1397,7 @@ bdb_locker_flush( DB_ENV *env )
}
int
bdb_locker_id( Operation *op, DB_ENV *env, u_int32_t *locker )
bdb_locker_id( Operation *op, DB_ENV *env, BDB_LOCKER *locker )
{
int i, rc;
u_int32_t lockid;
......@@ -1415,7 +1427,14 @@ bdb_locker_id( Operation *op, DB_ENV *env, u_int32_t *locker )
if ( rc != 0) {
return rc;
}
#if DB_VERSION_FULL >= 0x04060012
{ BDB_LOCKER lptr;
__lock_getlocker( env->lk_handle, lockid, 0, &lptr );
data = lptr;
}
#else
data = (void *)((long)lockid);
#endif
if ( ( rc = ldap_pvt_thread_pool_setkey( ctx, env,
data, bdb_locker_id_free ) ) ) {
XLOCK_ID_FREE( env, lockid );
......@@ -1427,7 +1446,11 @@ bdb_locker_id( Operation *op, DB_ENV *env, u_int32_t *locker )
} else {
lockid = (long)data;
}
#if DB_VERSION_FULL >= 0x04060012
*locker = data;
#else
*locker = lockid;
#endif
return 0;
}
#endif /* BDB_REUSE_LOCKERS */
......@@ -30,7 +30,7 @@ bdb_compare( Operation *op, SlapReply *rs )
Attribute *a;
int manageDSAit = get_manageDSAit( op );
u_int32_t locker;
BDB_LOCKER locker;
DB_LOCK lock;
rs->sr_err = LOCK_ID(bdb->bi_dbenv, &locker);
......
......@@ -190,7 +190,7 @@ bdb_online_index( void *ctx, void *arg )
DBT key, data;
DB_TXN *txn;
DB_LOCK lock;
u_int32_t locker;
BDB_LOCKER locker;
ID id, nid;
EntryInfo *ei;
int rc, getnext = 1;
......
......@@ -38,7 +38,7 @@ bdb_delete( Operation *op, SlapReply *rs )
struct bdb_op_info opinfo = {0};
ID eid;
u_int32_t locker = 0;
BDB_LOCKER locker = 0;
DB_LOCK lock, plock;
int num_retries = 0;
......
......@@ -34,7 +34,7 @@ bdb_dn2entry(
struct berval *dn,
EntryInfo **e,
int matched,
u_int32_t locker,
BDB_LOCKER locker,
DB_LOCK *lock )
{
EntryInfo *ei = NULL;
......
......@@ -332,7 +332,7 @@ bdb_dn2id_children(
int
bdb_dn2idl(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
struct berval *ndn,
EntryInfo *ei,
ID *ids,
......@@ -712,7 +712,7 @@ int
hdb_dn2id_parent(
Operation *op,
DB_TXN *txn,
u_int32_t locker,
BDB_LOCKER locker,
EntryInfo *ei,
ID *idp )
{
......@@ -833,7 +833,7 @@ hdb_dn2id_children(
struct dn2id_cookie {
struct bdb_info *bdb;
Operation *op;
u_int32_t locker;
BDB_LOCKER locker;
EntryInfo *ei;
ID *ids;
ID *tmp;
......@@ -1064,7 +1064,7 @@ gotit:
int
hdb_dn2idl(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
struct berval *ndn,
EntryInfo *ei,
ID *ids,
......
......@@ -27,39 +27,39 @@
static int presence_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeDescription *desc,
ID *ids );
static int equality_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp );
static int inequality_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp,
int gtorlt );
static int approx_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp );
static int substring_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
SubstringsAssertion *sub,
ID *ids,
ID *tmp );
static int list_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
Filter *flist,
int ftype,
ID *ids,
......@@ -69,7 +69,7 @@ static int list_candidates(
static int
ext_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion *mra,
ID *ids,
ID *tmp,
......@@ -79,7 +79,7 @@ ext_candidates(
static int
comp_candidates (
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion *mra,
ComponentFilter *f,
ID *ids,
......@@ -89,7 +89,7 @@ comp_candidates (
static int
ava_comp_candidates (
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
AttributeAliasing *aa,
ID *ids,
......@@ -100,7 +100,7 @@ ava_comp_candidates (
int
bdb_filter_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
Filter *f,
ID *ids,
ID *tmp,
......@@ -231,7 +231,7 @@ out:
static int
comp_list_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion* mra,
ComponentFilter *flist,
int ftype,
......@@ -296,7 +296,7 @@ comp_list_candidates(
static int
comp_equality_candidates (
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion *mra,
ComponentAssertion *ca,
ID *ids,
......@@ -407,7 +407,7 @@ comp_equality_candidates (
static int
ava_comp_candidates (
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
AttributeAliasing *aa,
ID *ids,
......@@ -431,7 +431,7 @@ ava_comp_candidates (
static int
comp_candidates (
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion *mra,
ComponentFilter *f,
ID *ids,
......@@ -480,7 +480,7 @@ comp_candidates (
static int
ext_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
MatchingRuleAssertion *mra,
ID *ids,
ID *tmp,
......@@ -559,7 +559,7 @@ ext_candidates(
static int
list_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
Filter *flist,
int ftype,
ID *ids,
......@@ -625,7 +625,7 @@ list_candidates(
static int
presence_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeDescription *desc,
ID *ids )
{
......@@ -696,7 +696,7 @@ done:
static int
equality_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp )
......@@ -813,7 +813,7 @@ equality_candidates(
static int
approx_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp )
......@@ -933,7 +933,7 @@ approx_candidates(
static int
substring_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
SubstringsAssertion *sub,
ID *ids,
ID *tmp )
......@@ -1049,7 +1049,7 @@ substring_candidates(
static int
inequality_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
AttributeAssertion *ava,
ID *ids,
ID *tmp,
......
......@@ -93,7 +93,7 @@ int bdb_id2entry_update(
int bdb_id2entry(
BackendDB *be,
DB_TXN *tid,
u_int32_t locker,
BDB_LOCKER locker,
ID id,
Entry **e )
{
......@@ -318,7 +318,7 @@ int bdb_entry_get(
int rc;
const char *at_name = at ? at->ad_cname.bv_val : "(null)";
u_int32_t locker = 0;
BDB_LOCKER locker = 0;
DB_LOCK lock;
int free_lock_id = 0;
......
......@@ -480,7 +480,7 @@ int
bdb_idl_fetch_key(
BackendDB *be,
DB *db,
u_int32_t locker,
BDB_LOCKER locker,
DBT *key,
ID *ids,
DBC **saved_cursor,
......
......@@ -451,7 +451,13 @@ shm_retry:
}
if ( !quick ) {
#if DB_VERSION_FULL >= 0x04060012
u_int32_t lid;
XLOCK_ID(bdb->bi_dbenv, &lid);
__lock_getlocker(bdb->bi_dbenv->lk_handle, lid, 0, &bdb->bi_cache.c_locker);
#else
XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
#endif
}
entry_prealloc( bdb->bi_cache.c_maxsize );
......@@ -543,7 +549,11 @@ bdb_db_close( BackendDB *be, ConfigReply *cr )
if( bdb->bi_dbenv ) {
/* Free cache locker if we enabled locking */
if ( !( slapMode & SLAP_TOOL_QUICK )) {
#if DB_VERSION_FULL >= 0x04060012
XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker->id);
#else
XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
#endif
bdb->bi_cache.c_locker = 0;
}
#ifdef BDB_REUSE_LOCKERS
......
......@@ -30,7 +30,7 @@ int
bdb_key_read(
Backend *be,
DB *db,
u_int32_t locker,
BDB_LOCKER locker,
struct berval *k,
ID *ids,
DBC **saved_cursor,
......
......@@ -281,7 +281,7 @@ bdb_modify( Operation *op, SlapReply *rs )
Entry dummy = {0};
int fakeroot = 0;
u_int32_t locker = 0;
BDB_LOCKER locker = 0;
DB_LOCK lock;
int num_retries = 0;
......
......@@ -46,7 +46,7 @@ bdb_modrdn( Operation *op, SlapReply *rs )
int manageDSAit = get_manageDSAit( op );
u_int32_t locker = 0;
BDB_LOCKER locker = 0;
DB_LOCK lock, plock, nplock;
int num_retries = 0;
......
......@@ -84,7 +84,7 @@ bdb_db_cache(
int bdb_dn2entry LDAP_P(( Operation *op, DB_TXN *tid,
struct berval *dn, EntryInfo **e, int matched,
u_int32_t locker, DB_LOCK *lock ));
BDB_LOCKER locker, DB_LOCK *lock ));
/*
* dn2id.c
......@@ -120,7 +120,7 @@ int bdb_dn2id_children(
int bdb_dn2idl(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
struct berval *ndn,
EntryInfo *ei,
ID *ids,
......@@ -133,7 +133,7 @@ int bdb_dn2idl(
int bdb_dn2id_parent(
Operation *op,
DB_TXN *txn,
u_int32_t locker,
BDB_LOCKER locker,
EntryInfo *ei,
ID *idp );
......@@ -168,7 +168,7 @@ char *ebcdic_dberror( int rc );
int bdb_filter_candidates(
Operation *op,
u_int32_t locker,
BDB_LOCKER locker,
Filter *f,
ID *ids,
ID *tmp,
......@@ -202,7 +202,7 @@ int bdb_id2entry_delete(
int bdb_id2entry(
BackendDB *be,
DB_TXN *tid,
u_int32_t locker,
BDB_LOCKER locker,
ID id,
Entry **e);
#endif
......@@ -285,7 +285,7 @@ unsigned bdb_idl_search( ID *ids, ID id );
int bdb_idl_fetch_key(
BackendDB *be,
DB *db,