1999-02-06 00:23:03 +08:00
|
|
|
/* porter.c - port functions of the bdb2 backend */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-04-01 17:58:36 +08:00
|
|
|
#include <ac/errno.h>
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-bdb2.h"
|
|
|
|
|
|
|
|
#define PORTER_OBJ "bdb2_backend"
|
|
|
|
|
|
|
|
|
1999-02-22 19:22:44 +08:00
|
|
|
int
|
1999-03-05 18:25:55 +08:00
|
|
|
bdb2i_enter_backend_rw( DB_LOCK *lock, int writer )
|
1999-02-06 00:23:03 +08:00
|
|
|
{
|
|
|
|
u_int32_t locker;
|
|
|
|
db_lockmode_t lock_type;
|
|
|
|
DBT lock_dbt;
|
1999-02-12 22:36:16 +08:00
|
|
|
int ret = 0;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
1999-03-05 18:25:55 +08:00
|
|
|
if ( ( ret = lock_id( bdb2i_dbEnv.lk_info, &locker )) != 0 ) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"bdb2i_enter_backend(): unable to get locker id -- %s\n",
|
|
|
|
strerror( ret ), 0, 0 );
|
|
|
|
return( ret );
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
lock_type = writer ? DB_LOCK_WRITE : DB_LOCK_READ;
|
|
|
|
lock_dbt.data = PORTER_OBJ;
|
|
|
|
lock_dbt.size = strlen( PORTER_OBJ );
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-03-05 18:25:55 +08:00
|
|
|
switch ( ( ret = lock_get( bdb2i_dbEnv.lk_info, locker, 0,
|
|
|
|
&lock_dbt, lock_type, lock ))) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case 0:
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb2i_enter_backend() -- %s lock granted\n",
|
1999-02-06 00:23:03 +08:00
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-06 00:23:03 +08:00
|
|
|
"bdb2i_enter_backend() -- %s lock NOT granted\n",
|
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-06 00:23:03 +08:00
|
|
|
"bdb2i_enter_backend() -- %s lock returned DEADLOCK\n",
|
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-04-08 12:17:32 +08:00
|
|
|
default:
|
|
|
|
ret = errno;
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-06 00:23:03 +08:00
|
|
|
"bdb2i_enter_backend() -- %s lock returned ERROR: %s\n",
|
1999-04-08 12:17:32 +08:00
|
|
|
writer ? "write" : "read", strerror( ret ), 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
/* if we are a writer and we have the backend lock,
|
|
|
|
start transaction control */
|
|
|
|
if ( writer && ( ret == 0 )) {
|
|
|
|
|
1999-03-05 18:25:55 +08:00
|
|
|
ret = bdb2i_start_transction( bdb2i_dbEnv.tx_info );
|
1999-03-01 19:30:18 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-02-06 00:23:03 +08:00
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
1999-03-05 18:25:55 +08:00
|
|
|
bdb2i_leave_backend_rw( DB_LOCK lock, int writer )
|
1999-02-06 00:23:03 +08:00
|
|
|
{
|
1999-03-01 19:30:18 +08:00
|
|
|
/* since one or more error can occure,
|
|
|
|
we must have several return codes that are or'ed at the end */
|
|
|
|
int ret_transaction = 0;
|
|
|
|
int ret_lock = 0;
|
|
|
|
|
|
|
|
/* if we are a writer, finish the transaction */
|
|
|
|
if ( writer ) {
|
|
|
|
|
|
|
|
ret_transaction = bdb2i_finish_transaction();
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check whether checkpointing is needed */
|
1999-03-05 18:25:55 +08:00
|
|
|
ret_transaction |= bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 0 );
|
1999-03-01 19:30:18 +08:00
|
|
|
|
|
|
|
/* now release the lock */
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
1999-03-05 18:25:55 +08:00
|
|
|
switch( ( ret_lock = lock_put( bdb2i_dbEnv.lk_info, lock ))) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case 0:
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
1999-02-22 19:22:44 +08:00
|
|
|
"bdb2i_leave_backend() -- %s lock released\n",
|
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case DB_LOCK_NOTHELD:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-22 19:22:44 +08:00
|
|
|
"bdb2i_leave_backend() -- %s lock NOT held\n",
|
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-22 19:22:44 +08:00
|
|
|
"bdb2i_leave_backend() -- %s lock returned DEADLOCK\n",
|
|
|
|
writer ? "write" : "read", 0, 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
default:
|
1999-04-08 12:17:32 +08:00
|
|
|
ret_lock = errno;
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-22 19:22:44 +08:00
|
|
|
"bdb2i_leave_backend() -- %s lock returned ERROR: %s\n",
|
1999-04-08 12:17:32 +08:00
|
|
|
writer ? "write" : "read", strerror( ret_lock ), 0 );
|
1999-02-12 22:36:16 +08:00
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
}
|
|
|
|
break;
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
return( ret_transaction | ret_lock );
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|