From b836fc3ea2f9c690a8b3e458ae455e1781ec22f7 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 19 Jun 2005 22:41:12 +0000 Subject: [PATCH] first round of provisions for back-config --- servers/slapd/back-meta/back-meta.h | 7 ++++- servers/slapd/back-meta/conn.c | 44 +++++++++++++++++++++-------- servers/slapd/back-meta/init.c | 3 +- servers/slapd/back-meta/search.c | 1 + servers/slapd/back-meta/unbind.c | 11 ++++---- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index 620bb93e14..882a38d747 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -222,6 +222,11 @@ typedef struct metadncache_t { long int ttl; /* seconds; 0: no cache, -1: no expiry */ } metadncache_t; +typedef struct metacandidates_t { + int mc_ntargets; + SlapReply *mc_candidates; +} metacandidates_t; + typedef struct metainfo_t { int mi_ntargets; int mi_defaulttarget; @@ -230,7 +235,7 @@ typedef struct metainfo_t { int mi_nretries; metatarget_t *mi_targets; - SlapReply *mi_candidates; + metacandidates_t *mi_candidates; metadncache_t mi_cache; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 7a325905fb..8935ff13a8 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -129,7 +129,7 @@ metaconn_alloc( assert( ntargets > 0 ); - /* malloc once only; leave an extra one for one-past-end */ + /* malloc all in one */ mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t ) + sizeof( metasingleconn_t ) * ntargets ); if ( mc == NULL ) { @@ -512,39 +512,59 @@ meta_back_get_candidate( } static void -meta_back_candidate_keyfree( +meta_back_candidates_keyfree( void *key, void *data ) { + metacandidates_t *mc = (metacandidates_t *)data; + + ber_memfree_x( mc->mc_candidates, NULL ); ber_memfree_x( data, NULL ); } SlapReply * meta_back_candidates_get( Operation *op ) { - metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; - void *data = NULL; + metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; + metacandidates_t *mc; + SlapReply *rs; if ( op->o_threadctx ) { + void *data = NULL; + ldap_pvt_thread_pool_getkey( op->o_threadctx, - meta_back_candidate_keyfree, &data, NULL ); + meta_back_candidates_keyfree, &data, NULL ); + mc = (metacandidates_t *)data; + } else { - data = (void *)mi->mi_candidates; + mc = mi->mi_candidates; } - if ( data == NULL ) { - data = ch_calloc( sizeof( SlapReply ), mi->mi_ntargets ); + if ( mc == NULL ) { + mc = ch_calloc( sizeof( metacandidates_t ), 1 ); + mc->mc_ntargets = mi->mi_ntargets; + mc->mc_candidates = ch_calloc( sizeof( SlapReply ), mc->mc_ntargets ); if ( op->o_threadctx ) { + void *data = NULL; + + data = (void *)mc; ldap_pvt_thread_pool_setkey( op->o_threadctx, - meta_back_candidate_keyfree, data, - meta_back_candidate_keyfree ); + meta_back_candidates_keyfree, data, + meta_back_candidates_keyfree ); } else { - mi->mi_candidates = (SlapReply *)data; + mi->mi_candidates = mc; } + + } else if ( mc->mc_ntargets < mi->mi_ntargets ) { + /* NOTE: in the future, may want to allow back-config + * to add/remove targets from back-meta... */ + mc->mc_ntargets = mi->mi_ntargets; + mc->mc_candidates = ch_realloc( mc->mc_candidates, + sizeof( SlapReply ) * mc->mc_ntargets ); } - return (SlapReply *)data; + return mc->mc_candidates; } /* diff --git a/servers/slapd/back-meta/init.c b/servers/slapd/back-meta/init.c index 336f001713..3b50226603 100644 --- a/servers/slapd/back-meta/init.c +++ b/servers/slapd/back-meta/init.c @@ -108,7 +108,8 @@ meta_back_db_open( int i, rc; for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) { + if ( mi->mi_targets[ i ].mt_flags & LDAP_BACK_F_SUPPORT_T_F_DISCOVER ) + { mi->mi_targets[ i ].mt_flags &= ~LDAP_BACK_F_SUPPORT_T_F_DISCOVER; rc = slap_discover_feature( mi->mi_targets[ i ].mt_uri, mi->mi_targets[ i ].mt_version, diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index fe1e403a21..039e085bdb 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -267,6 +267,7 @@ meta_back_search( Operation *op, SlapReply *rs ) if ( candidates[ i ].sr_tag != META_CANDIDATE ) { continue; } + candidates[ i ].sr_err = LDAP_SUCCESS; candidates[ i ].sr_matched = NULL; candidates[ i ].sr_text = NULL; diff --git a/servers/slapd/back-meta/unbind.c b/servers/slapd/back-meta/unbind.c index 97f26bc7db..f6d62ced67 100644 --- a/servers/slapd/back-meta/unbind.c +++ b/servers/slapd/back-meta/unbind.c @@ -38,7 +38,7 @@ meta_back_conn_destroy( Connection *conn ) { metainfo_t *mi = ( metainfo_t * )be->be_private; - metaconn_t *mc, + metaconn_t *mc, mc_curr = { 0 }; Debug( LDAP_DEBUG_TRACE, @@ -63,12 +63,11 @@ meta_back_conn_destroy( * Cleanup rewrite session */ for ( i = 0; i < mi->mi_ntargets; ++i ) { - if ( mc->mc_conns[ i ].msc_ld == NULL ) { - continue; - } - rewrite_session_delete( mi->mi_targets[ i ].mt_rwmap.rwm_rw, conn ); - meta_clear_one_candidate( &mc->mc_conns[ i ] ); + + if ( mc->mc_conns[ i ].msc_ld != NULL ) { + meta_clear_one_candidate( &mc->mc_conns[ i ] ); + } } meta_back_conn_free( mc ); } -- 2.39.5