/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#endif
{
buf[0] = DN_SUBTREE_PREFIX;
- rc = db->del( db, txn, &key, 0 );
+ rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
int
bdb_dn2idl(
Operation *op,
- Entry *e,
+ u_int32_t locker,
+ struct berval *ndn,
+ EntryInfo *ei,
ID *ids,
ID *stack )
{
? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl(\"%s\")\n",
- e->e_nname.bv_val, 0, 0 );
+ ndn->bv_val, 0, 0 );
#ifndef BDB_MULTIPLE_SUFFIXES
- if ( prefix == DN_SUBTREE_PREFIX && BEI(e)->bei_parent->bei_id == 0 ) {
+ if ( prefix == DN_SUBTREE_PREFIX
+ && ( ei->bei_id == 0 || ei->bei_parent->bei_id == 0 )) {
BDB_IDL_ALL(bdb, ids);
return 0;
}
#endif
DBTzero( &key );
- key.size = e->e_nname.bv_len + 2;
+ key.size = ndn->bv_len + 2;
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
((char *)key.data)[0] = prefix;
- AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
+ AC_MEMCPY( &((char *)key.data)[1], ndn->bv_val, key.size - 1 );
BDB_IDL_ZERO( ids );
- rc = bdb_idl_fetch_key( op->o_bd, db, NULL, &key, ids, NULL, 0 );
+ rc = bdb_idl_fetch_key( op->o_bd, db, locker, &key, ids, NULL, 0 );
if( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE,
struct dn2id_cookie {
struct bdb_info *bdb;
Operation *op;
+ u_int32_t locker;
EntryInfo *ei;
ID *ids;
ID *tmp;
cx->data.ulen = BDB_IDL_UM_SIZE * sizeof(ID);
cx->data.flags = DB_DBT_USERMEM;
- /* Fetch the rest of the IDs in a loop... */
- while ( (cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data,
- DB_MULTIPLE | DB_NEXT_DUP )) == 0 ) {
- u_int8_t *j;
- size_t len;
- void *ptr;
- DB_MULTIPLE_INIT( ptr, &cx->data );
- while (ptr) {
- DB_MULTIPLE_NEXT( ptr, &cx->data, j, len );
- if (j) {
- EntryInfo *ei2;
- diskNode *d = (diskNode *)j;
- short nrlen;
-
- BDB_DISK2ID( j + len - sizeof(ID), &ei.bei_id );
- nrlen = ((d->nrdnlen[0] ^ 0x80) << 8) | d->nrdnlen[1];
- ei.bei_nrdn.bv_len = nrlen;
- /* nrdn/rdn are set in-place.
- * hdb_cache_load will copy them as needed
- */
- ei.bei_nrdn.bv_val = d->nrdn;
- ei.bei_rdn.bv_len = len - sizeof(diskNode)
- - ei.bei_nrdn.bv_len;
- ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1;
- bdb_idl_append_one( cx->tmp, ei.bei_id );
- hdb_cache_load( cx->bdb, &ei, &ei2 );
+ if ( dkids > 1 ) {
+ /* Fetch the rest of the IDs in a loop... */
+ while ( (cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data,
+ DB_MULTIPLE | DB_NEXT_DUP )) == 0 ) {
+ u_int8_t *j;
+ size_t len;
+ void *ptr;
+ DB_MULTIPLE_INIT( ptr, &cx->data );
+ while (ptr) {
+ DB_MULTIPLE_NEXT( ptr, &cx->data, j, len );
+ if (j) {
+ EntryInfo *ei2;
+ diskNode *d = (diskNode *)j;
+ short nrlen;
+
+ BDB_DISK2ID( j + len - sizeof(ID), &ei.bei_id );
+ nrlen = ((d->nrdnlen[0] ^ 0x80) << 8) | d->nrdnlen[1];
+ ei.bei_nrdn.bv_len = nrlen;
+ /* nrdn/rdn are set in-place.
+ * hdb_cache_load will copy them as needed
+ */
+ ei.bei_nrdn.bv_val = d->nrdn;
+ ei.bei_rdn.bv_len = len - sizeof(diskNode)
+ - ei.bei_nrdn.bv_len;
+ ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1;
+ bdb_idl_append_one( cx->tmp, ei.bei_id );
+ hdb_cache_load( cx->bdb, &ei, &ei2 );
+ }
}
}
}
+
cx->rc = cx->dbc->c_close( cx->dbc );
done_one:
bdb_cache_entryinfo_lock( cx->ei );
if ( !BDB_IDL_IS_RANGE( cx->tmp ) && cx->tmp[0] > 3 )
bdb_idl_sort( cx->tmp, cx->buf );
- if ( cx->bdb->bi_idl_cache_max_size ) {
+ if ( cx->bdb->bi_idl_cache_max_size && !BDB_IDL_IS_ZERO( cx->tmp )) {
char *ptr = ((char *)&cx->id)-1;
cx->key.data = ptr;
cx->key.size = sizeof(ID)+1;
int
hdb_dn2idl(
Operation *op,
- Entry *e,
+ u_int32_t locker,
+ struct berval *ndn,
+ EntryInfo *ei,
ID *ids,
ID *stack )
{
struct dn2id_cookie cx;
Debug( LDAP_DEBUG_TRACE, "=> hdb_dn2idl(\"%s\")\n",
- e->e_nname.bv_val, 0, 0 );
+ ndn->bv_val, 0, 0 );
#ifndef BDB_MULTIPLE_SUFFIXES
if ( op->ors_scope != LDAP_SCOPE_ONELEVEL &&
- BEI(e)->bei_parent->bei_id == 0 )
+ ( ei->bei_id == 0 ||
+ ei->bei_parent->bei_id == 0 ))
{
BDB_IDL_ALL( bdb, ids );
return 0;
}
#endif
- cx.id = e->e_id;
+ cx.id = ei->bei_id;
BDB_ID2DISK( cx.id, &cx.nid );
- cx.ei = e->e_id ? BEI(e) : &bdb->bi_cache.c_dntree;
+ cx.ei = ei;
cx.bdb = bdb;
cx.db = cx.bdb->bi_dn2id->bdi_db;
cx.prefix = (op->ors_scope == LDAP_SCOPE_ONELEVEL) ?
cx.tmp = stack;
cx.buf = stack + BDB_IDL_UM_SIZE;
cx.op = op;
+ cx.locker = locker;
cx.need_sort = 0;
cx.depth = 0;
cx.key.data = ptr;
cx.key.size = sizeof(ID)+1;
*ptr = cx.prefix;
- cx.id = e->e_id;
- bdb_idl_cache_put( cx.bdb, cx.db, &cx.key, cx.ids, cx.rc );
+ cx.id = ei->bei_id;
+ if ( cx.bdb->bi_idl_cache_max_size )
+ bdb_idl_cache_put( cx.bdb, cx.db, &cx.key, cx.ids, cx.rc );
}
if ( cx.rc == DB_NOTFOUND )