1999-02-06 00:23:03 +08:00
|
|
|
/* ldbmcache.c - maintain a cache of open bdb2 files */
|
|
|
|
|
|
|
|
#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 "ldapconfig.h"
|
|
|
|
#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-02-12 22:36:16 +08:00
|
|
|
switch ( slapMode ) {
|
1999-02-08 19:42:14 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TIMEDSERVER_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-02-12 22:36:16 +08:00
|
|
|
switch ( slapMode ) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TIMEDSERVER_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-02-12 22:36:16 +08:00
|
|
|
switch ( slapMode ) {
|
|
|
|
|
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TIMEDSERVER_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-02-12 22:36:16 +08:00
|
|
|
switch ( slapMode ) {
|
1999-02-06 00:23:03 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
case SLAP_SERVER_MODE:
|
|
|
|
case SLAP_TIMEDSERVER_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 );
|
|
|
|
|
|
|
|
data = ldbm_fetch( db->dbc_db, key );
|
|
|
|
|
|
|
|
return( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bdb2i_cache_store(
|
|
|
|
struct dbcache *db,
|
|
|
|
Datum key,
|
|
|
|
Datum data,
|
|
|
|
int flags
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
rc = ldbm_store( db->dbc_db, key, data, flags );
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bdb2i_cache_delete(
|
|
|
|
struct dbcache *db,
|
|
|
|
Datum key
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ldbm_delete( db->dbc_db, key );
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|