]> git.sur5r.net Git - openldap/commitdiff
first round of provisions for back-config
authorPierangelo Masarati <ando@openldap.org>
Sun, 19 Jun 2005 22:41:12 +0000 (22:41 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 19 Jun 2005 22:41:12 +0000 (22:41 +0000)
servers/slapd/back-meta/back-meta.h
servers/slapd/back-meta/conn.c
servers/slapd/back-meta/init.c
servers/slapd/back-meta/search.c
servers/slapd/back-meta/unbind.c

index 620bb93e14c96ef7976c3e43c5cb6adff728166e..882a38d7479ccec7732be536ad4237fc7b03887c 100644 (file)
@@ -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;
        
index 7a325905fbe681c9e8fc0653526314f8477ab525..8935ff13a8d3f5fb6ded3ee92c3b0cd8c612a1b6 100644 (file)
@@ -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;
 }
 
 /*
index 336f00171303d65ea08997f9c0f99f638e1cb66b..3b50226603d2826e39df0dd19bd13fc7f8571ddf 100644 (file)
@@ -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,
index fe1e403a21cec4e0f88f6708afbc4f9926f567b8..039e085bdb9126cd60e94742e16a5f7391cfcdee 100644 (file)
@@ -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;
index 97f26bc7db9a7c030bb61e07bce609f26887568d..f6d62ced67583fb398196b135eeeed990a3e9c2e 100644 (file)
@@ -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 );
        }