Commit 886c1ff9 authored by Juan Gomez's avatar Juan Gomez
Browse files

Added MDBM support.

parent 3ade81d8
......@@ -2,6 +2,7 @@ OpenLDAP Change Log
Changes included in OpenLDAP 1.2 Release Engineering
CVS Tag: OPENLDAP_REL_ENG_1_2
Added the mdbm to the ldbm backends (memory mapped dbm).
Updated README to require BerkeleyDB 2.7.5
Added #define _SGI_MP_SOURCE to enable per-thread errno in
IRIX
......
......@@ -230,6 +230,52 @@ AC_DEFUN([OL_GDBM],
AC_DEFINE(HAVE_GDBM,1)
fi
])dnl
dnl
dnl ====================================================================
dnl Check if MDBM library exists
dnl Check for mdbm_open in standard libraries or -lmdbm
dnl
dnl defines ol_cv_lib_mdbm to 'yes' or '-lmdbm' or 'no'
dnl 'yes' implies mdbm_open is in $LIBS
dnl
dnl uses:
dnl AC_CHECK_FUNC(mdbm_set_chain)
dnl AC_CHECK_LIB(mdbm,mdbm_set_chain)
dnl
AC_DEFUN([OL_LIB_MDBM],
[AC_CACHE_CHECK(for MDBM library, [ol_cv_lib_mdbm],
[ ol_LIBS="$LIBS"
AC_CHECK_FUNC(mdbm_set_chain,[ol_cv_lib_mdbm=yes], [
AC_CHECK_LIB(mdbm,mdbm_set_chain,[ol_cv_lib_mdbm=-lmdbm],[ol_cv_lib_mdbm=no])
])
LIBS="$ol_LIBS"
])
])dnl
dnl
dnl --------------------------------------------------------------------
dnl Check if MDBM exists
dnl
dnl defines ol_cv_mdbm to 'yes' or 'no'
dnl
dnl uses:
dnl OL_LIB_MDBM
dnl AC_CHECK_HEADERS(mdbm.h)
dnl
AC_DEFUN([OL_MDBM],
[AC_REQUIRE([OL_LIB_MDBM])
AC_CHECK_HEADERS(mdbm.h)
AC_CACHE_CHECK(for db, [ol_cv_mdbm], [
if test $ol_cv_lib_mdbm = no -o $ac_cv_header_mdbm_h = no ; then
ol_cv_mdbm=no
else
ol_cv_mdbm=yes
fi
])
if test $ol_cv_mdbm = yes ; then
AC_DEFINE(HAVE_MDBM,1, [define if MDBM is available])
fi
])dnl
dnl
dnl ====================================================================
dnl Check if NDBM library exists
......
This diff is collapsed.
......@@ -77,7 +77,7 @@ OL_ARG_ENABLE(rlookups,[ --enable-rlookups enable reverse lookups], auto)dnl
dnl SLAPD Backend options
OL_ARG_ENABLE(ldbm,[ --enable-ldbm enable ldbm backend], yes)dnl
OL_ARG_WITH(ldbm_api,[ --with-ldbm-api use LDBM API], auto,
[auto db2 db gdbm ndbm manual])
[auto db2 db mdbm gdbm ndbm manual])
OL_ARG_WITH(ldbm_type,[ --with-ldbm-type use LDBM type], auto,
[auto btree hash])
......@@ -175,6 +175,10 @@ else
$ol_with_ldbm_type = btree ; then
AC_MSG_ERROR([GDBM only supports LDBM type hash])
fi
if test $ol_with_ldbm_api = mdbm -a \
$ol_with_ldbm_type = btree ; then
AC_MSG_ERROR([MDBM only supports LDBM type hash])
fi
if test $ol_with_ldbm_api = ndbm -a \
$ol_with_ldbm_type = btree ; then
AC_MSG_ERROR([NDBM only supports LDBM type hash])
......@@ -1140,6 +1144,18 @@ if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = gdbm ; then
fi
fi
if test $ol_with_ldbm_api = auto -o $ol_with_ldbm_api = mdbm ; then
OL_MDBM
if test $ol_cv_mdbm = yes ; then
ol_link_ldbm=mdbm
ol_with_ldbm_api=mdbm
if test $ol_cv_lib_mdbm != yes ; then
LDBM_LIBS="$LDBM_LIBS $ol_cv_lib_mdbm"
fi
fi
fi
if test $ol_with_ldbm_api = auto ; then
AC_MSG_WARN([skipping automatic checking for NDBM, must be manually enabled.])
elif test $ol_with_ldbm_api = ndbm ; then
......
......@@ -161,6 +161,41 @@ LDAP_END_DECL
#define LDBM_REPLACE GDBM_REPLACE
#define LDBM_SYNC 0x80000000
#elif defined( HAVE_MDBM )
/*****************************************************************
* *
* use mdbm if possible *
* *
*****************************************************************/
#include <mdbm.h>
LDAP_BEGIN_DECL
typedef datum Datum;
typedef MDBM *LDBM;
LDAP_END_DECL
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/* for ldbm_open */
#define LDBM_READER O_RDONLY
#define LDBM_WRITER O_RDWR
#define LDBM_WRCREAT (O_RDWR|O_CREAT)
#define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT)
#define LDBM_FAST 0
#define LDBM_SUFFIX ".mdbm"
/* for ldbm_insert */
#define LDBM_INSERT MDBM_INSERT
#define LDBM_REPLACE MDBM_REPLACE
#define LDBM_SYNC 0x80000000
#elif defined( HAVE_NDBM )
......
......@@ -127,6 +127,9 @@
/* define if you have crypt */
#undef HAVE_CRYPT
/* define if MDBM is available */
#undef HAVE_MDBM
/* define if you have GDBM */
#undef HAVE_GDBM
......@@ -391,6 +394,9 @@
/* Define if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
/* Define if you have the <mdbm.h> header file. */
#undef HAVE_MDBM_H
/* Define if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
......
......@@ -509,6 +509,363 @@ ldbm_errno( LDBM ldbm )
return( err );
}
#elif defined( HAVE_MDBM )
/* MMAPED DBM HASHING DATABASE */
#include <ac/string.h>
/* #define MDBM_DEBUG */
#ifdef MDBM_DEBUG
#include <stdio.h>
#endif
#define NO_NULL_KEY
/* #define MDBM_CHAIN */
#ifdef MDBM_CHAIN
/* Use chaining */
#define mdbm_store mdbm_chain_store
#define mdbm_fetch mdbm_chain_fetch
#define mdbm_delete mdbm_chain_delete
#define mdbm_first mdbm_chain_first
#define mdbm_next mdbm_chain_next
#endif
#define MDBM_PG_SZ (4*1024)
/*****************************************************************
* *
* use mdbm *
* *
*****************************************************************/
LDBM
ldbm_open( char *name, int rw, int mode, int dbcachesize )
{
LDBM db;
#ifdef MDBM_DEBUG
fprintf( stdout,
"==>(mdbm)ldbm_open(name=%s,rw=%x,mode=%x,cachesize=%d)\n",
name ? name : "NULL", rw, mode, dbcachesize );
fflush( stdout );
#endif
LDBM_LOCK; /* We need locking here, this is the only non-thread
* safe function we have.
*/
if ( (db = mdbm_open( name, rw, mode, MDBM_PG_SZ )) == NULL ) {
LDBM_UNLOCK;
#ifdef MDBM_DEBUG
fprintf( stdout, "<==(mdbm)ldbm_open(db=NULL)\n" );
fflush( stdout );
#endif
return( NULL );
}
#ifdef MDBM_CHAIN
(void)mdbm_set_chain(db);
#endif
LDBM_UNLOCK;
#ifdef MDBM_DEBUG
fprintf( stdout, "<==(mdbm)ldbm_open(db=%p)\n", db );
fflush( stdout );
#endif
return( db );
}/* LDBM ldbm_open() */
void
ldbm_close( LDBM ldbm )
{
/* Open and close are not reentrant so we need to use locks here */
#ifdef MDBM_DEBUG
fprintf( stdout,
"==>(mdbm)ldbm_close(db=%p)\n", ldbm );
fflush( stdout );
#endif
LDBM_LOCK;
mdbm_close( ldbm );
LDBM_UNLOCK;
#ifdef MDBM_DEBUG
fprintf( stdout, "<==(mdbm)ldbm_close()\n" );
fflush( stdout );
#endif
}/* void ldbm_close() */
void
ldbm_sync( LDBM ldbm )
{
/* XXX: Not sure if this is re-entrant need to check code, if so
* you can leave LOCKS out.
*/
LDBM_LOCK;
mdbm_sync( ldbm );
LDBM_UNLOCK;
}/* void ldbm_sync() */
#define MAX_MDBM_RETRY 5
Datum
ldbm_fetch( LDBM ldbm, Datum key )
{
Datum d;
kvpair k;
int retry = 0;
/* This hack is needed because MDBM does not take keys
* which begin with NULL when working in the chaining
* mode.
*/
/* LDBM_LOCK; */
#ifdef NO_NULL_KEY
k.key.dsize = key.dsize + 1;
k.key.dptr = malloc(k.key.dsize);
*(k.key.dptr) = 'l';
memcpy( (void *)(k.key.dptr + 1), key.dptr, key.dsize );
#else
k.key = key;
#endif
k.val.dptr = NULL;
k.val.dsize = 0;
do {
d = mdbm_fetch( ldbm, k );
if ( d.dsize > 0 ) {
if ( k.val.dptr != NULL ) {
free( k.val.dptr );
}
if ( (k.val.dptr = malloc( d.dsize )) != NULL ) {
k.val.dsize = d.dsize;
d = mdbm_fetch( ldbm, k );
} else {
d.dsize = 0;
break;
}
}/* if ( d.dsize > 0 ) */
} while ((d.dsize > k.val.dsize) && (++retry < MAX_MDBM_RETRY));
/* LDBM_UNLOCK; */
#ifdef NO_NULL_KEY
free(k.key.dptr);
#endif
return d;
}/* Datum ldbm_fetch() */
int
ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
{
int rc;
Datum int_key; /* Internal key */
#ifdef MDBM_DEBUG
fprintf( stdout,
"==>(mdbm)ldbm_store(db=%p, key(dptr=%p,sz=%d), data(dptr=%p,sz=%d), flags=%x)\n",
ldbm, key.dptr, key.dsize, data.dptr, data.dsize, flags );
fflush( stdout );
#endif
/* LDBM_LOCK; */
#ifdef NO_NULL_KEY
int_key.dsize = key.dsize + 1;
int_key.dptr = malloc( int_key.dsize );
*(int_key.dptr) = 'l'; /* Must not be NULL !*/
memcpy( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
#else
int_key = key;
#endif
rc = mdbm_store( ldbm, int_key, data, flags );
if ( flags & LDBM_SYNC ) {
mdbm_sync( ldbm );
}
/* LDBM_UNLOCK; */
#ifdef MDBM_DEBUG
fprintf( stdout, "<==(mdbm)ldbm_store(rc=%d)\n", rc );
fflush( stdout );
#endif
#ifdef NO_NULL_KEY
free(int_key.dptr);
#endif
return( rc );
}/* int ldbm_store() */
int
ldbm_delete( LDBM ldbm, Datum key )
{
int rc;
Datum int_key;
/* LDBM_LOCK; */
#ifdef NO_NULL_KEY
int_key.dsize = key.dsize + 1;
int_key.dptr = malloc(int_key.dsize);
*(int_key.dptr) = 'l';
memcpy( (void *)(int_key.dptr + 1), key.dptr, key.dsize );
#else
int_key = key;
#endif
rc = mdbm_delete( ldbm, int_key );
/* LDBM_UNLOCK; */
#ifdef NO_NULL_KEY
free(int_key.dptr);
#endif
return( rc );
}/* int ldbm_delete() */
static Datum
ldbm_get_next( LDBM ldbm, kvpair (*fptr)(MDBM *, kvpair) )
{
kvpair out;
kvpair in;
Datum ret;
size_t sz = MDBM_PAGE_SIZE(ldbm);
#ifdef NO_NULL_KEY
int delta = 1;
#else
int delta = 0;
#endif
/* LDBM_LOCK; */
in.key.dsize = sz; /* Assume first key in one pg */
in.key.dptr = malloc(sz);
in.val.dptr = NULL; /* Don't need data just key */
in.val.dsize = 0;
ret.dptr = NULL;
ret.dsize = NULL;
out = fptr( ldbm, in );
if (out.key.dsize > 0) {
ret.dsize = out.key.dsize - delta;
if ((ret.dptr = (char *)malloc(ret.dsize)) == NULL) {
ret.dsize = 0;
ret.dptr = NULL;
} else {
memcpy(ret.dptr, (void *)(out.key.dptr + delta),
ret.dsize );
}
}
/* LDBM_UNLOCK; */
free(in.key.dptr);
return ret;
}/* static Datum ldbm_get_next() */
Datum
ldbm_firstkey( LDBM ldbm )
{
return ldbm_get_next( ldbm, mdbm_first );
}/* Datum ldbm_firstkey() */
Datum
ldbm_nextkey( LDBM ldbm, Datum key )
{
/* XXX:
* don't know if this will affect the LDAP server opertaion
* but mdbm cannot take and input key.
*/
return ldbm_get_next( ldbm, mdbm_next );
}/* Datum ldbm_nextkey() */
int
ldbm_errno( LDBM ldbm )
{
/* XXX: best we can do with current mdbm interface */
return( errno );
}/* int ldbm_errno() */
#elif defined( HAVE_NDBM )
/*****************************************************************
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment