1999-02-06 00:23:03 +08:00
|
|
|
/* ldbmcache.c - maintain a cache of open bdb2 files */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/errno.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-bdb2.h"
|
|
|
|
|
|
|
|
struct dbcache *
|
|
|
|
bdb2i_cache_open(
|
1999-02-08 19:42:14 +08:00
|
|
|
BackendDB *be,
|
1999-02-06 00:23:03 +08:00
|
|
|
char *name,
|
|
|
|
char *suffix,
|
|
|
|
int flags
|
|
|
|
)
|
|
|
|
{
|
1999-02-10 21:19:11 +08:00
|
|
|
/* all files are open, so return handle from file cache */
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-08 19:42:14 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
char buf[MAXPATHLEN];
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
/* use short name */
|
|
|
|
sprintf( buf, "%s%s", name, suffix );
|
|
|
|
return( bdb2i_get_db_file_cache( li, buf ));
|
1999-02-08 19:42:14 +08:00
|
|
|
|
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:
|
|
|
|
/* if not SERVER or TOOL, who else would ask?
|
|
|
|
NO ONE, so return error */
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n",
|
|
|
|
slapMode, name, suffix );
|
|
|
|
return( NULL );
|
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-08 19:42:14 +08:00
|
|
|
bdb2i_cache_close( BackendDB *be, struct dbcache *db )
|
1999-02-06 00:23:03 +08:00
|
|
|
{
|
1999-02-10 21:19:11 +08:00
|
|
|
/* all files stay open until SERVER or TOOL shut down */
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
|
|
|
return;
|
1999-02-10 21:19:11 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
default:
|
|
|
|
/* if unknown user, complain */
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"bdb2i_cache_close: database user (%d) unknown -- ignored.\n",
|
|
|
|
slapMode, 0, 0 );
|
|
|
|
return;
|
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-08 19:42:14 +08:00
|
|
|
bdb2i_cache_really_close( BackendDB *be, struct dbcache *db )
|
1999-02-06 00:23:03 +08:00
|
|
|
{
|
1999-02-10 21:19:11 +08:00
|
|
|
/* all files stay open until SERVER or TOOL shut down */
|
1999-08-18 03:00:59 +08:00
|
|
|
switch ( slapMode & SLAP_MODE ) {
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TOOL_MODE:
|
1999-02-08 19:42:14 +08:00
|
|
|
return;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
default:
|
|
|
|
/* if unknown user, complain */
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
1999-02-10 21:19:11 +08:00
|
|
|
"bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n",
|
1999-02-12 22:36:16 +08:00
|
|
|
slapMode, 0, 0 );
|
|
|
|
return;
|
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-08 19:42:14 +08:00
|
|
|
bdb2i_cache_flush_all( BackendDB *be )
|
1999-02-06 00:23:03 +08:00
|
|
|
{
|
1999-02-10 21:19:11 +08:00
|
|
|
/* if SERVER or TOOL, syncing is done by TP, or during shutdown */
|
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:
|
|
|
|
return;
|
1999-02-10 21:19:11 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
default:
|
|
|
|
/* if unknown user, complain */
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"bdb2i_cache_flush_all: database user (%d) unknown -- ignored.\n",
|
|
|
|
slapMode, 0, 0 );
|
|
|
|
return;
|
|
|
|
}
|
1999-02-06 00:23:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Datum
|
|
|
|
bdb2i_cache_fetch(
|
|
|
|
struct dbcache *db,
|
|
|
|
Datum key
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Datum data;
|
|
|
|
|
|
|
|
ldbm_datum_init( data );
|
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
data = bdb2i_db_fetch( db->dbc_db, key );
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
return( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bdb2i_cache_store(
|
|
|
|
struct dbcache *db,
|
|
|
|
Datum key,
|
|
|
|
Datum data,
|
|
|
|
int flags
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
1999-02-22 19:22:44 +08:00
|
|
|
struct timeval time1;
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
#ifdef LDBM_DEBUG
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
|
|
|
"=> bdb2i_cache_store(): key.dptr=%s, key.dsize=%d\n",
|
|
|
|
key.dptr, key.dsize, 0, 0, 0 );
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
|
|
|
"=> bdb2i_cache_store(): key.dptr=0x%08x, data.dptr=0x%0 8x\n",
|
|
|
|
key.dptr, data.dptr, 0, 0, 0 );
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
|
|
|
"=> bdb2i_cache_store(): data.dptr=%s, data.dsize=%d\n",
|
|
|
|
data.dptr, data.dsize, 0, 0, 0 );
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS,
|
|
|
|
"=> bdb2i_cache_store(): flags=0x%08x\n",
|
|
|
|
flags, 0, 0, 0, 0 );
|
|
|
|
#endif /* LDBM_DEBUG */
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
if ( slapMode & SLAP_TIMED_MODE )
|
1999-02-22 19:22:44 +08:00
|
|
|
bdb2i_uncond_start_timing( &time1 );
|
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
rc = bdb2i_db_store( db->dbc_db, key, data, flags );
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
if ( slapMode & SLAP_TIMED_MODE ) {
|
1999-02-22 19:22:44 +08:00
|
|
|
char buf[BUFSIZ];
|
|
|
|
char buf2[BUFSIZ];
|
|
|
|
|
|
|
|
*buf2 = '\0';
|
|
|
|
if ( !( strcasecmp( db->dbc_name, "dn.bdb2" )))
|
|
|
|
sprintf( buf2, " [%s]", key.dptr );
|
|
|
|
sprintf( buf, "ADD-BDB2( %s%s )", db->dbc_name, buf2 );
|
|
|
|
bdb2i_uncond_stop_timing( time1, buf,
|
|
|
|
NULL, NULL, LDAP_DEBUG_TRACE );
|
|
|
|
}
|
|
|
|
|
1999-02-06 00:23:03 +08:00
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bdb2i_cache_delete(
|
|
|
|
struct dbcache *db,
|
|
|
|
Datum key
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
1999-03-01 19:30:18 +08:00
|
|
|
rc = bdb2i_db_delete( db->dbc_db, key );
|
1999-02-06 00:23:03 +08:00
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|