1 /* dn2id.c - routines to deal with the dn2id index */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
25 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
26 DB *db = bdb->bi_dn2id->bdi_db;
30 struct berval ptr, pdn;
33 LDAP_LOG ( INDEX, ARGS, "bdb_dn2id_add( \"%s\", 0x%08lx )\n",
34 e->e_ndn, (long) e->e_id, 0 );
36 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
37 e->e_ndn, (long) e->e_id, 0 );
39 assert( e->e_id != NOID );
42 key.size = e->e_nname.bv_len + 2;
44 key.flags = DB_DBT_USERMEM;
45 buf = ch_malloc( key.size );
47 buf[0] = DN_BASE_PREFIX;
49 ptr.bv_len = e->e_nname.bv_len;
50 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
51 ptr.bv_val[ptr.bv_len] = '\0';
54 data.data = (char *) &e->e_id;
55 data.size = sizeof( e->e_id );
57 /* store it -- don't override */
58 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
61 LDAP_LOG ( INDEX, ERR, "bdb_dn2id_add: put failed: %s %d\n",
62 db_strerror(rc), rc, 0 );
64 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
65 db_strerror(rc), rc, 0 );
70 #ifndef BDB_MULTIPLE_SUFFIXES
71 if( !be_issuffix( be, &ptr )) {
73 buf[0] = DN_SUBTREE_PREFIX;
74 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
77 LDAP_LOG ( INDEX, ERR,
78 "=> bdb_dn2id_add: subtree (%s) put failed: %d\n",
81 Debug( LDAP_DEBUG_ANY,
82 "=> bdb_dn2id_add: subtree (%s) put failed: %d\n",
88 #ifdef BDB_MULTIPLE_SUFFIXES
89 if( !be_issuffix( be, &ptr )) {
91 dnParent( &ptr, &pdn );
93 key.size = pdn.bv_len + 2;
95 pdn.bv_val[-1] = DN_ONE_PREFIX;
96 key.data = pdn.bv_val-1;
99 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
103 LDAP_LOG ( INDEX, ERR,
104 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
107 Debug( LDAP_DEBUG_ANY,
108 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
113 #ifndef BDB_MULTIPLE_SUFFIXES
116 while( !be_issuffix( be, &ptr )) {
120 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
122 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
126 LDAP_LOG ( INDEX, ERR,
127 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
130 Debug( LDAP_DEBUG_ANY,
131 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
136 #ifdef BDB_MULTIPLE_SUFFIXES
137 if( be_issuffix( be, &ptr )) break;
139 dnParent( &ptr, &pdn );
141 key.size = pdn.bv_len + 2;
143 key.data = pdn.bv_val - 1;
146 #ifdef BDB_MULTIPLE_SUFFIXES
153 LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
155 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
167 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
168 DB *db = bdb->bi_dn2id->bdi_db;
172 struct berval pdn, ptr;
175 LDAP_LOG ( INDEX, ARGS,
176 "=> bdb_dn2id_delete ( \"%s\", 0x%08lx )\n", e->e_ndn, e->e_id, 0);
178 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
179 e->e_ndn, e->e_id, 0 );
183 key.size = e->e_nname.bv_len + 2;
184 buf = ch_malloc( key.size );
186 key.flags = DB_DBT_USERMEM;
187 buf[0] = DN_BASE_PREFIX;
189 ptr.bv_len = e->e_nname.bv_len;
190 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
191 ptr.bv_val[ptr.bv_len] = '\0';
194 rc = db->del( db, txn, &key, 0 );
197 LDAP_LOG ( INDEX, ERR,
198 "=> bdb_dn2id_delete: delete failed: %s %d\n",
199 db_strerror(rc), rc, 0 );
201 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
202 db_strerror(rc), rc, 0 );
207 #ifndef BDB_MULTIPLE_SUFFIXES
208 if( !be_issuffix( be, &ptr )) {
210 buf[0] = DN_SUBTREE_PREFIX;
211 rc = db->del( db, txn, &key, 0 );
214 LDAP_LOG ( INDEX, ERR,
215 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
218 Debug( LDAP_DEBUG_ANY,
219 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
225 #ifdef BDB_MULTIPLE_SUFFIXES
226 if( !be_issuffix( be, &ptr )) {
228 dnParent( &ptr, &pdn );
230 key.size = pdn.bv_len + 2;
232 pdn.bv_val[-1] = DN_ONE_PREFIX;
233 key.data = pdn.bv_val - 1;
236 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
240 LDAP_LOG ( INDEX, ERR,
241 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
244 Debug( LDAP_DEBUG_ANY,
245 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
250 #ifndef BDB_MULTIPLE_SUFFIXES
253 while( !be_issuffix( be, &ptr )) {
257 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
259 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
262 LDAP_LOG ( INDEX, ERR,
263 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
266 Debug( LDAP_DEBUG_ANY,
267 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
272 #ifdef BDB_MULTIPLE_SUFFIXES
273 if( be_issuffix( be, &ptr )) break;
275 dnParent( &ptr, &pdn );
277 key.size = pdn.bv_len + 2;
279 key.data = pdn.bv_val - 1;
282 #ifdef BDB_MULTIPLE_SUFFIXES
289 LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
291 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
306 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
307 DB *db = bdb->bi_dn2id->bdi_db;
310 LDAP_LOG ( INDEX, ARGS, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
312 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
317 *id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, dn);
323 key.size = dn->bv_len + 2;
324 key.data = ch_malloc( key.size );
325 ((char *)key.data)[0] = DN_BASE_PREFIX;
326 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
331 data.ulen = sizeof(ID);
332 data.flags = DB_DBT_USERMEM;
335 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags);
339 LDAP_LOG ( INDEX, ERR, "<= bdb_dn2id: get failed %s (%d)\n",
340 db_strerror(rc), rc, 0 );
342 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
343 db_strerror( rc ), rc, 0 );
347 LDAP_LOG ( INDEX, RESULTS,
348 "<= bdb_dn2id: got id=0x%08lx\n", *id, 0, 0 );
350 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n",
370 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
371 DB *db = bdb->bi_dn2id->bdi_db;
377 LDAP_LOG ( INDEX, ARGS,
378 "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 );
380 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 );
384 key.size = in->bv_len + 2;
385 buf = ch_malloc( key.size );
388 dn.bv_len = key.size - 2;
389 AC_MEMCPY( dn.bv_val, in->bv_val, key.size - 1 );
394 data.ulen = sizeof(ID);
395 data.flags = DB_DBT_USERMEM;
398 dn.bv_val[-1] = DN_BASE_PREFIX;
403 cached_id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, &dn);
405 if (cached_id != NOID) {
408 if ( dn.bv_val != buf+1 ) {
414 rc = db->get(db, txn, &key, &data, bdb->bi_db_opflags | flags );
417 if( rc == DB_NOTFOUND ) {
420 if ( ! be_issuffix( be, &dn ) ) {
421 dnParent( &dn, &pdn );
424 LDAP_LOG ( INDEX, DETAIL1,
425 "<= bdb_dn2id_matched: no match\n", 0, 0, 0 );
427 Debug( LDAP_DEBUG_TRACE,
428 "<= bdb_dn2id_matched: no match\n",
434 key.size = pdn.bv_len + 2;
436 key.data = pdn.bv_val - 1;
438 } else if ( rc == 0 ) {
439 if( data.size != sizeof( ID ) ) {
441 LDAP_LOG ( INDEX, DETAIL1,
442 "<= bdb_dn2id_matched: get size mismatch:"
443 "expected %ld, got %ld\n",
444 (long) sizeof(ID), (long) data.size, 0 );
446 Debug( LDAP_DEBUG_ANY,
447 "<= bdb_dn2id_matched: get size mismatch: "
448 "expected %ld, got %ld\n",
449 (long) sizeof(ID), (long) data.size, 0 );
453 if( dn.bv_val != buf+1 ) {
458 LDAP_LOG ( INDEX, DETAIL1,
459 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
460 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val );
462 Debug( LDAP_DEBUG_TRACE,
463 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
464 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val );
470 LDAP_LOG ( INDEX, ERR,
471 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
472 db_strerror(rc), rc, 0 );
474 Debug( LDAP_DEBUG_ANY,
475 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
476 db_strerror(rc), rc, 0 );
495 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
496 DB *db = bdb->bi_dn2id->bdi_db;
500 LDAP_LOG ( INDEX, ARGS,
501 "=> bdb_dn2id_children( %s )\n", dn->bv_val, 0, 0 );
503 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
508 key.size = dn->bv_len + 2;
509 key.data = ch_malloc( key.size );
510 ((char *)key.data)[0] = DN_ONE_PREFIX;
511 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
513 /* we actually could do a empty get... */
516 data.ulen = sizeof(id);
517 data.flags = DB_DBT_USERMEM;
519 data.dlen = sizeof(id);
521 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags );
525 LDAP_LOG ( INDEX, DETAIL1,
526 "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
527 dn->bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
528 db_strerror(rc)), rc );
530 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
532 rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
533 db_strerror(rc) ), rc );
548 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
549 DB *db = bdb->bi_dn2id->bdi_db;
552 LDAP_LOG ( INDEX, ARGS,
553 "=> bdb_dn2ididl( \"%s\" )\n", dn->bv_val, 0, 0 );
555 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
558 #ifndef BDB_MULTIPLE_SUFFIXES
559 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
561 BDB_IDL_ALL(bdb, ids);
567 key.size = dn->bv_len + 2;
569 key.flags = DB_DBT_USERMEM;
570 key.data = ch_malloc( key.size );
571 ((char *)key.data)[0] = prefix;
572 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
574 rc = bdb_idl_fetch_key( be, db, NULL, &key, ids );
578 LDAP_LOG ( INDEX, ERR,
579 "<= bdb_dn2ididl: get failed: %s (%d)\n", db_strerror(rc), rc, 0 );
581 Debug( LDAP_DEBUG_TRACE,
582 "<= bdb_dn2idl: get failed: %s (%d)\n",
583 db_strerror( rc ), rc, 0 );
588 LDAP_LOG ( INDEX, RESULTS,
589 "<= bdb_dn2ididl: id=%ld first=%ld last=%ld\n",
590 (long) ids[0], (long) BDB_IDL_FIRST( ids ),
591 (long) BDB_IDL_LAST( ids ) );
593 Debug( LDAP_DEBUG_TRACE,
594 "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
596 (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
605 /* Experimental management routines for a hierarchically structured backend.
607 * Unsupported! Use at your own risk!
609 * Instead of a dn2id database, we use an id2parent database. Each entry in
610 * this database is a struct diskNode, containing the ID of the node's parent
611 * and the RDN of the node.
613 typedef struct diskNode {
619 /* In bdb_db_open() we call bdb_build_tree() which reads the entire id2parent
620 * database into memory (into an AVL tree). Next we iterate through each node
621 * of this tree, connecting each child to its parent. The nodes in this AVL
622 * tree are a struct idNode. The immediate (Onelevel) children of a node are
623 * referenced in the i_kids AVL tree. With this arrangement, there is no need
624 * to maintain the DN_ONE_PREFIX or DN_SUBTREE_PREFIX database keys. Note that
625 * the DN of an entry is constructed by walking up the list of i_parent
626 * pointers, so no full DN is stored on disk anywhere. This makes modrdn
627 * extremely efficient, even when operating on a populated subtree.
629 * The idNode tree is searched directly from the root when performing id to
630 * entry lookups. The tree is traversed using the i_kids subtrees when
631 * performing dn to id lookups.
633 typedef struct idNode {
635 struct idNode *i_parent;
638 ldap_pvt_thread_rdwr_t i_kids_rdwr;
642 /* The main AVL tree is sorted in ID order. The i_kids AVL trees are
643 * sorted in lexical order. These are the various helper routines used
644 * for the searches and sorts.
652 return *(const ID *)id - ((const idNode *)node)->i_id;
661 const struct berval *nrdn = v_nrdn;
662 const idNode *n = v_n;
663 return ber_bvcmp(nrdn, &n->i_rdn->nrdn);
672 const idNode *a = v_a, *b = v_b;
673 return a->i_id - b->i_id;
682 const idNode *a = v_a, *b = v_b;
683 /* should be slightly better without ordering drawbacks */
684 return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn);
687 idNode * bdb_find_id_node(
692 return avl_find(tree, &id, node_find_cmp);
695 idNode * bdb_find_rdn_node(
700 return avl_find(tree, nrdn, node_frdn_cmp);
703 /* This function links a node into its parent's i_kids tree. */
704 static int bdb_insert_kid(
710 Avlnode *tree = v_tree;
713 if (a->i_rdn->parent == 0)
715 a->i_parent = bdb_find_id_node(a->i_rdn->parent, tree);
718 ldap_pvt_thread_rdwr_wlock(&a->i_parent->i_kids_rdwr);
719 rc = avl_insert( &a->i_parent->i_kids, (caddr_t) a,
720 node_rdn_cmp, avl_dup_error );
721 ldap_pvt_thread_rdwr_wunlock(&a->i_parent->i_kids_rdwr);
725 /* This function adds a node into the main AVL tree */
726 idNode *bdb_add_node(
734 node = (idNode *)ch_malloc(sizeof(idNode));
736 node->i_parent = NULL;
738 node->i_rdn = (diskNode *)d;
739 node->i_rdn->rdn.bv_val += (long)d;
740 node->i_rdn->nrdn.bv_val += (long)d;
741 ldap_pvt_thread_rdwr_init(&node->i_kids_rdwr);
742 avl_insert( &bdb->bi_tree, (caddr_t) node, node_add_cmp, avl_dup_error );
744 bdb->bi_troot = node;
748 /* This function initializes the trees at startup time. */
753 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
762 rc = bdb->bi_id2parent->bdi_db->cursor(
763 bdb->bi_id2parent->bdi_db, NULL, &cursor,
764 bdb->bi_db_opflags );
771 key.data = (char *)&id;
772 key.ulen = sizeof( id );
773 key.flags = DB_DBT_USERMEM;
774 data.flags = DB_DBT_MALLOC;
776 while (cursor->c_get( cursor, &key, &data, DB_NEXT ) == 0) {
777 bdb_add_node( id, data.data, bdb );
779 cursor->c_close( cursor );
781 rc = avl_apply(bdb->bi_tree, bdb_insert_kid, bdb->bi_tree,
787 /* This function constructs a full DN for a given id. We really should
788 * be passing idNodes directly, to save some effort...
796 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
801 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
802 o = bdb_find_id_node(id, bdb->bi_tree);
803 rlen = be->be_suffix[0].bv_len + 1;
804 nrlen = be->be_nsuffix[0].bv_len + 1;
805 for (n = o; n && n->i_parent; n=n->i_parent) {
806 rlen += n->i_rdn->rdn.bv_len + 1;
807 nrlen += n->i_rdn->nrdn.bv_len + 1;
809 e->e_name.bv_len = rlen - 1;
810 e->e_nname.bv_len = nrlen - 1;
811 e->e_name.bv_val = ch_malloc(rlen + nrlen);
812 e->e_nname.bv_val = e->e_name.bv_val + rlen;
813 ptr = e->e_name.bv_val;
814 nptr = e->e_nname.bv_val;
815 for (n = o; n && n->i_parent; n=n->i_parent) {
816 ptr = lutil_strcopy(ptr, n->i_rdn->rdn.bv_val);
818 nptr = lutil_strcopy(nptr, n->i_rdn->nrdn.bv_val);
821 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
823 strcpy(ptr, be->be_suffix[0].bv_val);
824 strcpy(nptr, be->be_nsuffix[0].bv_val);
836 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
839 DB *db = bdb->bi_id2parent->bdi_db;
843 nrlen = dn_rdnlen( be, &e->e_nname );
845 rlen = dn_rdnlen( be, &e->e_name );
850 d = ch_malloc(sizeof(diskNode) + rlen + nrlen + 2);
851 d->rdn.bv_len = rlen;
852 d->nrdn.bv_len = nrlen;
853 d->rdn.bv_val = (char *)(d+1);
854 d->nrdn.bv_val = d->rdn.bv_val + rlen + 1;
855 strncpy(d->rdn.bv_val, e->e_dn, rlen);
856 d->rdn.bv_val[rlen] = '\0';
857 strncpy(d->nrdn.bv_val, e->e_ndn, nrlen);
858 d->nrdn.bv_val[nrlen] = '\0';
859 d->rdn.bv_val -= (long)d;
860 d->nrdn.bv_val -= (long)d;
863 bdb_dn2id(be, txn, pdn, &d->parent, 0);
871 key.size = sizeof(ID);
872 key.flags = DB_DBT_USERMEM;
875 data.size = sizeof(diskNode) + rlen + nrlen + 2;
876 data.flags = DB_DBT_USERMEM;
878 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
881 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
882 n = bdb_add_node( e->e_id, data.data, bdb);
883 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
886 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
887 bdb_insert_kid(n, bdb->bi_tree);
888 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
903 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
906 DB *db = bdb->bi_id2parent->bdi_db;
910 key.size = sizeof(e->e_id);
913 rc = db->del( db, txn, &key, 0);
915 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
916 n = avl_delete(&bdb->bi_tree, &e->e_id, node_find_cmp);
919 ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr);
920 avl_delete(&n->i_parent->i_kids, &n->i_rdn->nrdn, node_frdn_cmp);
921 ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr);
924 ldap_pvt_thread_rdwr_destroy(&n->i_kids_rdwr);
928 bdb->bi_troot = NULL;
929 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
943 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
953 if (be_issuffix(be, in)) {
958 p1 = in->bv_val + in->bv_len - be->be_nsuffix[0].bv_len - 1;
961 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
963 for (p2 = p1-1; (p2 >= in->bv_val) && !DN_SEPARATOR(*p2); p2--);
965 rdn.bv_len = p1-rdn.bv_val;
968 ldap_pvt_thread_rdwr_rlock(&p->i_kids_rdwr);
969 n = bdb_find_rdn_node(&rdn, p->i_kids);
970 ldap_pvt_thread_rdwr_runlock(&p->i_kids_rdwr);
971 if (!n || p2 < in->bv_val) break;
974 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
995 return bdb_dn2id_matched(be, txn, dn, id, NULL, flags);
1006 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
1010 rc = bdb_dn2id(be, txn, dn, &id, flags);
1014 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
1015 n = bdb_find_id_node(id, bdb->bi_tree);
1016 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
1024 /* Since we don't store IDLs for onelevel or subtree, we have to construct
1025 * them on the fly... Perhaps the i_kids tree ought to just be an IDL?
1035 return bdb_idl_insert(ids, n->i_id);
1048 rc = bdb_idl_insert(ids, n->i_id);
1050 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1051 rc = avl_apply(n->i_kids, insert_sub, ids, -1, AVL_INORDER);
1052 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1064 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
1069 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) {
1070 BDB_IDL_ALL(bdb, ids);
1074 rc = bdb_dn2id(be, NULL, dn, &id, 0);
1077 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
1078 n = bdb_find_id_node(id, bdb->bi_tree);
1079 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
1082 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1083 if (prefix == DN_ONE_PREFIX) {
1084 rc = avl_apply(n->i_kids, insert_one, ids, -1, AVL_INORDER);
1086 rc = bdb_idl_insert(ids, id);
1088 rc = avl_apply(n->i_kids, insert_sub, ids, -1, AVL_INORDER);
1090 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1093 #endif /* BDB_HIER */