2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
34 #include "../back-ldap/back-ldap.h"
35 #include "back-meta.h"
38 * Set PRINT_CONNTREE larger than 0 to dump the connection tree (debug only)
40 #define PRINT_CONNTREE 0
45 * compares two struct metaconn based on the value of the conn pointer;
53 metaconn_t *mc1 = ( metaconn_t * )c1;
54 metaconn_t *mc2 = ( metaconn_t * )c2;
56 return SLAP_PTRCMP( mc1->mc_conn, mc2->mc_conn );
62 * returns -1 in case a duplicate struct metaconn has been inserted;
70 metaconn_t *mc1 = ( metaconn_t * )c1;
71 metaconn_t *mc2 = ( metaconn_t * )c2;
73 return( ( mc1->mc_conn == mc2->mc_conn ) ? -1 : 0 );
77 * Debug stuff (got it from libavl)
79 #if PRINT_CONNTREE > 0
81 ravl_print( Avlnode *root, int depth )
89 ravl_print( root->avl_right, depth + 1 );
91 for ( i = 0; i < depth; i++ ) {
95 printf( "c(%d) %d\n", ( ( metaconn_t * )root->avl_data )->mc_conn->c_connid, root->avl_bf );
97 ravl_print( root->avl_left, depth + 1 );
101 myprint( Avlnode *root )
103 printf( "********\n" );
106 printf( "\tNULL\n" );
108 ravl_print( root, 0 );
111 printf( "********\n" );
113 #endif /* PRINT_CONNTREE */
121 * Allocates a connection structure, making room for all the referenced targets
127 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
129 int i, ntargets = mi->mi_ntargets;
131 assert( ntargets > 0 );
133 /* malloc all in one */
134 mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t )
135 + sizeof( metasingleconn_t ) * ntargets );
140 for ( i = 0; i < ntargets; i++ ) {
141 mc->mc_conns[ i ].msc_ld = NULL;
142 BER_BVZERO( &mc->mc_conns[ i ].msc_bound_ndn );
143 BER_BVZERO( &mc->mc_conns[ i ].msc_cred );
144 mc->mc_conns[ i ].msc_bound = META_UNBOUND;
145 mc->mc_conns[ i ].msc_info = mi;
148 mc->mc_auth_target = META_BOUND_NONE;
149 ldap_pvt_thread_mutex_init( &mc->mc_mutex );
156 * meta_back_conn_free
165 assert( mc != NULL );
166 assert( mc->mc_refcnt == 0 );
168 ldap_pvt_thread_mutex_destroy( &mc->mc_mutex );
177 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
179 assert( mc != NULL );
182 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
183 case LDAP_PVT_THREAD_EBUSY:
185 ldap_pvt_thread_yield();
192 if ( --mc->mc_refcnt == 0 ) {
193 meta_back_conn_free( mc );
196 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
200 * meta_back_init_one_conn
202 * Initializes one connection
205 meta_back_init_one_conn(
209 metasingleconn_t *msc,
210 ldap_back_send_t sendok )
212 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
219 if ( msc->msc_ld != NULL ) {
220 rs->sr_err = LDAP_SUCCESS;
225 * Attempts to initialize the connection to the target ds
227 rs->sr_err = ldap_initialize( &msc->msc_ld, mt->mt_uri );
228 if ( rs->sr_err != LDAP_SUCCESS ) {
233 * Set LDAP version. This will always succeed: If the client
234 * bound with a particular version, then so can we.
236 vers = op->o_conn->c_protocol;
237 ldap_set_option( msc->msc_ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
239 /* automatically chase referrals ("chase-referrals"/"dont-chase-referrals" statement) */
240 if ( LDAP_BACK_CHASE_REFERRALS( mi ) ) {
241 ldap_set_option( msc->msc_ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
245 /* start TLS ("start-tls"/"try-start-tls" statements) */
246 if ( ( LDAP_BACK_USE_TLS( mi ) || ( op->o_conn->c_is_tls && LDAP_BACK_PROPAGATE_TLS( mi ) ) )
247 && !ldap_is_ldaps_url( mt->mt_uri ) )
249 #ifdef SLAP_STARTTLS_ASYNCHRONOUS
251 * use asynchronous StartTLS
252 * in case, chase referral (not implemented yet)
256 rs->sr_err = ldap_start_tls( msc->msc_ld, NULL, NULL, &msgid );
257 if ( rs->sr_err == LDAP_SUCCESS ) {
258 LDAPMessage *res = NULL;
259 int rc, nretries = mt->mt_nretries;
260 struct timeval tv = { 0, 0 };
263 rc = ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res );
265 rs->sr_err = LDAP_OTHER;
267 } else if ( rc == 0 ) {
268 if ( nretries != 0 ) {
269 if ( nretries > 0 ) {
276 rs->sr_err = LDAP_OTHER;
278 } else if ( rc == LDAP_RES_EXTENDED ) {
279 struct berval *data = NULL;
281 rs->sr_err = ldap_parse_extended_result( msc->msc_ld, res,
283 if ( rs->sr_err == LDAP_SUCCESS ) {
284 rs->sr_err = ldap_result2error( msc->msc_ld, res, 1 );
287 /* FIXME: in case a referral
288 * is returned, should we try
289 * using it instead of the
291 if ( rs->sr_err == LDAP_SUCCESS ) {
292 ldap_install_tls( msc->msc_ld );
294 } else if ( rs->sr_err == LDAP_REFERRAL ) {
295 rs->sr_err = LDAP_OTHER;
296 rs->sr_text = "unwilling to chase referral returned by Start TLS exop";
300 if ( data->bv_val ) {
301 ber_memfree( data->bv_val );
308 rs->sr_err = LDAP_OTHER;
315 #else /* ! SLAP_STARTTLS_ASYNCHRONOUS */
317 * use synchronous StartTLS
319 rs->sr_err = ldap_start_tls_s( msc->msc_ld, NULL, NULL );
320 #endif /* ! SLAP_STARTTLS_ASYNCHRONOUS */
322 /* if StartTLS is requested, only attempt it if the URL
323 * is not "ldaps://"; this may occur not only in case
324 * of misconfiguration, but also when used in the chain
325 * overlay, where the "uri" can be parsed out of a referral */
326 if ( rs->sr_err == LDAP_SERVER_DOWN
327 || ( rs->sr_err != LDAP_SUCCESS && LDAP_BACK_TLS_CRITICAL( mi ) ) )
329 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
333 #endif /* HAVE_TLS */
336 * Set the network timeout if set
338 if ( mi->mi_network_timeout != 0 ) {
339 struct timeval network_timeout;
341 network_timeout.tv_usec = 0;
342 network_timeout.tv_sec = mi->mi_network_timeout;
344 ldap_set_option( msc->msc_ld, LDAP_OPT_NETWORK_TIMEOUT,
345 (void *)&network_timeout );
349 * Sets a cookie for the rewrite session
351 ( void )rewrite_session_init( mt->mt_rwmap.rwm_rw, op->o_conn );
354 * If the connection DN is not null, an attempt to rewrite it is made
356 if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
358 dc.conn = op->o_conn;
363 * Rewrite the bind dn if needed
365 if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
366 &msc->msc_bound_ndn ) )
371 /* copy the DN idf needed */
372 if ( msc->msc_bound_ndn.bv_val == op->o_conn->c_dn.bv_val ) {
373 ber_dupbv( &msc->msc_bound_ndn, &op->o_conn->c_dn );
376 assert( !BER_BVISNULL( &msc->msc_bound_ndn ) );
379 ber_str2bv( "", 0, 1, &msc->msc_bound_ndn );
382 msc->msc_bound = META_UNBOUND;
385 if ( rs->sr_err != LDAP_SUCCESS ) {
386 rs->sr_err = slap_map_api2result( rs );
387 if ( sendok & LDAP_BACK_SENDERR ) {
388 send_ldap_result( op, rs );
399 * Retries one connection
407 ldap_back_send_t sendok )
409 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
410 metatarget_t *mt = &mi->mi_targets[ candidate ];
411 int rc = LDAP_UNAVAILABLE;
412 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
415 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
416 case LDAP_PVT_THREAD_EBUSY:
418 ldap_pvt_thread_yield();
425 assert( mc->mc_refcnt > 0 );
427 if ( mc->mc_refcnt == 1 ) {
428 ldap_pvt_thread_mutex_lock( &mc->mc_mutex );
430 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
434 /* mc here must be the regular mc, reset and ready for init */
435 rc = meta_back_init_one_conn( op, rs, mt, msc, sendok );
437 if ( rc == LDAP_SUCCESS ) {
438 rc = meta_back_single_dobind( op, rs, mc, candidate,
439 sendok, mt->mt_nretries, 0 );
442 ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
445 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
447 return rc == LDAP_SUCCESS ? 1 : 0;
451 * callback for unique candidate selection
454 meta_back_conn_cb( Operation *op, SlapReply *rs )
456 assert( op->o_tag == LDAP_REQ_SEARCH );
458 switch ( rs->sr_type ) {
460 ((int *)op->o_callback->sc_private)[0] = (int)op->o_private;
476 meta_back_get_candidate(
481 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
485 * tries to get a unique candidate
486 * (takes care of default target)
488 candidate = meta_back_select_unique_candidate( mi, ndn );
491 * if any is found, inits the connection
493 if ( candidate == META_TARGET_NONE ) {
494 rs->sr_err = LDAP_NO_SUCH_OBJECT;
495 rs->sr_text = "no suitable candidate target found";
497 } else if ( candidate == META_TARGET_MULTIPLE ) {
500 SlapReply rs2 = { 0 };
501 slap_callback cb2 = { 0 };
504 /* try to get a unique match for the request ndn
505 * among the multiple candidates available */
506 op2.o_tag = LDAP_REQ_SEARCH;
508 op2.o_req_ndn = *ndn;
509 op2.ors_scope = LDAP_SCOPE_BASE;
510 op2.ors_deref = LDAP_DEREF_NEVER;
511 op2.ors_attrs = slap_anlist_no_attrs;
512 op2.ors_attrsonly = 0;
513 op2.ors_limit = NULL;
515 op2.ors_tlimit = SLAP_NO_LIMIT;
517 f.f_choice = LDAP_FILTER_PRESENT;
518 f.f_desc = slap_schema.si_ad_objectClass;
520 BER_BVSTR( &op2.ors_filterstr, "(objectClass=*)" );
522 op2.o_callback = &cb2;
523 cb2.sc_response = meta_back_conn_cb;
524 cb2.sc_private = (void *)&candidate;
526 rc = op->o_bd->be_search( &op2, &rs2 );
528 switch ( rs2.sr_err ) {
531 rs->sr_err = rs2.sr_err;
534 case LDAP_SIZELIMIT_EXCEEDED:
535 /* if multiple candidates can serve the operation,
536 * and a default target is defined, and it is
537 * a candidate, try using it (FIXME: YMMV) */
538 if ( mi->mi_defaulttarget != META_DEFAULT_TARGET_NONE
539 && meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ].mt_nsuffix,
540 ndn, op->o_tag == LDAP_REQ_SEARCH ? op->ors_scope : LDAP_SCOPE_BASE ) )
542 candidate = mi->mi_defaulttarget;
543 rs->sr_err = LDAP_SUCCESS;
547 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
548 rs->sr_text = "cannot select unique candidate target";
558 meta_back_candidates_keyfree(
562 metacandidates_t *mc = (metacandidates_t *)data;
564 ber_memfree_x( mc->mc_candidates, NULL );
565 ber_memfree_x( data, NULL );
569 meta_back_candidates_get( Operation *op )
571 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
572 metacandidates_t *mc;
574 if ( op->o_threadctx ) {
577 ldap_pvt_thread_pool_getkey( op->o_threadctx,
578 meta_back_candidates_keyfree, &data, NULL );
579 mc = (metacandidates_t *)data;
582 mc = mi->mi_candidates;
586 mc = ch_calloc( sizeof( metacandidates_t ), 1 );
587 mc->mc_ntargets = mi->mi_ntargets;
588 mc->mc_candidates = ch_calloc( sizeof( SlapReply ), mc->mc_ntargets );
589 if ( op->o_threadctx ) {
593 ldap_pvt_thread_pool_setkey( op->o_threadctx,
594 meta_back_candidates_keyfree, data,
595 meta_back_candidates_keyfree );
598 mi->mi_candidates = mc;
601 } else if ( mc->mc_ntargets < mi->mi_ntargets ) {
602 /* NOTE: in the future, may want to allow back-config
603 * to add/remove targets from back-meta... */
604 mc->mc_ntargets = mi->mi_ntargets;
605 mc->mc_candidates = ch_realloc( mc->mc_candidates,
606 sizeof( SlapReply ) * mc->mc_ntargets );
609 return mc->mc_candidates;
615 * Prepares the connection structure
619 * - determine what DN is being requested:
621 * op requires candidate checks
623 * add unique parent of o_req_ndn
624 * bind unique^*[/all] o_req_ndn [no check]
625 * compare unique^+ o_req_ndn
626 * delete unique o_req_ndn
627 * modify unique o_req_ndn
628 * search any o_req_ndn
629 * modrdn unique[, unique] o_req_ndn[, orr_nnewSup]
631 * - for ops that require the candidate to be unique, in case of multiple
632 * occurrences an internal search with sizeLimit=1 is performed
633 * if a unique candidate can actually be determined. If none is found,
634 * the operation aborts; if multiple are found, the default target
635 * is used if defined and candidate; otherwise the operation aborts.
637 * *^note: actually, the bind operation is handled much like a search;
638 * i.e. the bind is broadcast to all candidate targets.
640 * +^note: actually, the compare operation is handled much like a search;
641 * i.e. the compare is broadcast to all candidate targets, while checking
642 * that exactly none (noSuchObject) or one (TRUE/FALSE/UNDEFINED) is
650 ldap_back_send_t sendok )
652 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
653 metaconn_t *mc = NULL,
655 int cached = META_TARGET_NONE,
656 i = META_TARGET_NONE,
662 meta_op_type op_type = META_OP_REQUIRE_SINGLE;
665 struct berval ndn = op->o_req_ndn,
668 SlapReply *candidates = meta_back_candidates_get( op );
670 /* Searches for a metaconn in the avl tree */
671 mc_curr.mc_conn = op->o_conn;
673 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
674 case LDAP_PVT_THREAD_EBUSY:
676 ldap_pvt_thread_yield();
682 mc = (metaconn_t *)avl_find( mi->mi_conntree,
683 (caddr_t)&mc_curr, meta_back_conn_cmp );
687 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
689 switch ( op->o_tag ) {
691 /* if we go to selection, the entry must not exist,
692 * and we must be able to resolve the parent */
694 dnParent( &ndn, &pndn );
697 case LDAP_REQ_MODRDN:
698 /* if nnewSuperior is not NULL, it must resolve
699 * to the same candidate as the req_ndn */
700 if ( op->orr_nnewSup ) {
706 /* if bound as rootdn, the backend must bind to all targets
707 * with the administrative identity */
708 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
709 op_type = META_OP_REQUIRE_ALL;
713 case LDAP_REQ_DELETE:
714 case LDAP_REQ_MODIFY:
715 /* just a unique candidate */
718 case LDAP_REQ_COMPARE:
719 case LDAP_REQ_SEARCH:
720 /* allow multiple candidates for the searchBase */
721 op_type = META_OP_ALLOW_MULTIPLE;
725 /* right now, just break (exop?) */
730 * require all connections ...
732 if ( op_type == META_OP_REQUIRE_ALL ) {
734 /* Looks like we didn't get a bind. Open a new session... */
736 mc = metaconn_alloc( op );
737 mc->mc_conn = op->o_conn;
741 for ( i = 0; i < mi->mi_ntargets; i++ ) {
744 * The target is activated; if needed, it is
747 int lerr = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
748 &mc->mc_conns[ i ], sendok );
749 if ( lerr == LDAP_SUCCESS ) {
750 candidates[ i ].sr_tag = META_CANDIDATE;
756 * FIXME: in case one target cannot
757 * be init'd, should the other ones
760 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
766 if ( ncandidates == 0 ) {
768 meta_back_freeconn( op, mc );
771 meta_back_release_conn( op, mc );
774 rs->sr_err = LDAP_NO_SUCH_OBJECT;
775 rs->sr_text = "Unable to select valid candidates";
777 if ( sendok & LDAP_BACK_SENDERR ) {
778 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
779 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
781 send_ldap_result( op, rs );
783 rs->sr_matched = NULL;
793 * looks in cache, if any
795 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
796 cached = i = meta_dncache_get_target( &mi->mi_cache, &op->o_req_ndn );
799 if ( op_type == META_OP_REQUIRE_SINGLE ) {
802 for ( j = 0; j < mi->mi_ntargets; j++ ) {
803 candidates[ j ].sr_tag = META_NOT_CANDIDATE;
807 * tries to get a unique candidate
808 * (takes care of default target)
810 if ( i == META_TARGET_NONE ) {
811 i = meta_back_get_candidate( op, rs, &ndn );
813 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT && parent ) {
814 i = meta_back_get_candidate( op, rs, &pndn );
817 if ( rs->sr_err != LDAP_SUCCESS ) {
818 if ( sendok & LDAP_BACK_SENDERR ) {
819 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
820 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
822 send_ldap_result( op, rs );
824 rs->sr_matched = NULL;
830 if ( newparent && meta_back_get_candidate( op, rs, op->orr_nnewSup ) != i )
832 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
833 rs->sr_text = "cross-target rename not supported";
834 if ( sendok & LDAP_BACK_SENDERR ) {
835 send_ldap_result( op, rs );
841 Debug( LDAP_DEBUG_TRACE,
842 "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n",
843 i, op->o_req_ndn.bv_val, 0 );
846 /* Retries searching for a metaconn in the avl tree
847 * the reason is that the connection might have been
848 * created by meta_back_get_candidate() */
849 mc_curr.mc_conn = op->o_conn;
851 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
852 case LDAP_PVT_THREAD_EBUSY:
854 ldap_pvt_thread_yield();
860 mc = (metaconn_t *)avl_find( mi->mi_conntree,
861 (caddr_t)&mc_curr, meta_back_conn_cmp );
865 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
867 /* Looks like we didn't get a bind. Open a new session... */
869 mc = metaconn_alloc( op );
870 mc->mc_conn = op->o_conn;
876 * Clear all other candidates
878 ( void )meta_clear_unused_candidates( op, i );
881 * The target is activated; if needed, it is
882 * also init'd. In case of error, meta_back_init_one_conn
883 * sends the appropriate result.
885 err = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
886 &mc->mc_conns[ i ], sendok );
887 if ( err != LDAP_SUCCESS ) {
889 * FIXME: in case one target cannot
890 * be init'd, should the other ones
893 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
895 (void)meta_clear_one_candidate( &mc->mc_conns[ i ] );
896 meta_back_freeconn( op, mc );
899 meta_back_release_conn( op, mc );
904 candidates[ i ].sr_tag = META_CANDIDATE;
912 * if no unique candidate ...
916 /* Looks like we didn't get a bind. Open a new session... */
918 mc = metaconn_alloc( op );
919 mc->mc_conn = op->o_conn;
923 for ( i = 0; i < mi->mi_ntargets; i++ ) {
925 || meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix,
926 &op->o_req_ndn, LDAP_SCOPE_SUBTREE ) )
930 * The target is activated; if needed, it is
933 int lerr = meta_back_init_one_conn( op, rs,
934 &mi->mi_targets[ i ],
935 &mc->mc_conns[ i ], sendok );
936 if ( lerr == LDAP_SUCCESS ) {
937 candidates[ i ].sr_tag = META_CANDIDATE;
940 Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n",
941 op->o_log_prefix, i, 0 );
946 * FIXME: in case one target cannot
947 * be init'd, should the other ones
951 ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] );
953 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
956 Debug( LDAP_DEBUG_ANY, "%s: meta_back_init_one_conn(%d) failed: %d\n",
957 op->o_log_prefix, i, lerr );
964 ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] );
966 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
970 if ( ncandidates == 0 ) {
972 meta_back_freeconn( op, mc );
975 meta_back_release_conn( op, mc );
978 rs->sr_err = LDAP_NO_SUCH_OBJECT;
979 rs->sr_text = "Unable to select valid candidates";
981 if ( sendok & LDAP_BACK_SENDERR ) {
982 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
983 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
985 send_ldap_result( op, rs );
987 rs->sr_matched = NULL;
995 /* clear out meta_back_init_one_conn non-fatal errors */
996 rs->sr_err = LDAP_SUCCESS;
1002 * Inserts the newly created metaconn in the avl tree
1005 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
1006 case LDAP_PVT_THREAD_EBUSY:
1008 ldap_pvt_thread_yield();
1014 err = avl_insert( &mi->mi_conntree, ( caddr_t )mc,
1015 meta_back_conn_cmp, meta_back_conn_dup );
1017 #if PRINT_CONNTREE > 0
1018 myprint( mi->mi_conntree );
1019 #endif /* PRINT_CONNTREE */
1021 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
1024 * Err could be -1 in case a duplicate metaconn is inserted
1026 * FIXME: what if the same client issues more than one
1027 * asynchronous operations?
1030 Debug( LDAP_DEBUG_ANY,
1031 "%s meta_back_getconn: candidates=%d conn=%ld insert failed\n",
1032 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1034 rs->sr_err = LDAP_OTHER;
1035 rs->sr_text = "Internal server error";
1036 meta_back_freeconn( op, mc );
1037 if ( sendok & LDAP_BACK_SENDERR ) {
1038 send_ldap_result( op, rs );
1044 Debug( LDAP_DEBUG_TRACE,
1045 "%s meta_back_getconn: candidates=%d conn=%ld inserted\n",
1046 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1049 Debug( LDAP_DEBUG_TRACE,
1050 "%s meta_back_getconn: candidates=%d conn=%ld fetched\n",
1051 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1058 meta_back_release_conn(
1062 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
1064 assert( mc != NULL );
1067 switch ( ldap_pvt_thread_mutex_trylock( &mi->mi_conn_mutex ) ) {
1068 case LDAP_PVT_THREAD_EBUSY:
1070 ldap_pvt_thread_yield();
1077 assert( mc->mc_refcnt > 0 );
1079 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );