From 543396c804d1b6e56c7f406705919a5297c4549e Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 4 Apr 2006 17:41:50 +0000 Subject: [PATCH] make sure only on bind at a time occurs; release resources only when appropriate --- servers/slapd/back-meta/back-meta.h | 6 ------ servers/slapd/back-meta/bind.c | 18 +++++++++++++++++- servers/slapd/back-meta/conn.c | 12 +++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index 43d5fa3da5..9d6eba8ab8 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -167,12 +167,6 @@ typedef struct metasingleconn_t { /* NOTE: lc_lcflags is redefined to msc_mscflags to reuse the macros * defined for back-ldap */ #define lc_lcflags msc_mscflags -#if 0 - int msc_bound; -#define META_UNBOUND 0 -#define META_BOUND 1 -#define META_ANONYMOUS 2 -#endif struct metainfo_t *msc_info; } metasingleconn_t; diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 1ca6a0a9e5..82ece95fa0 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -679,10 +679,23 @@ meta_back_dobind( /* * If the target is already bound it is skipped */ + +retry_binding:; + ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); if ( LDAP_BACK_CONN_ISBOUND( msc ) || LDAP_BACK_CONN_ISANON( msc ) ) { + ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); ++bound; continue; - } + + } else if ( LDAP_BACK_CONN_BINDING( msc ) ) { + ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); + ldap_pvt_thread_yield(); + goto retry_binding; + + } else { + LDAP_BACK_CONN_BINDING_SET( msc ); + ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); + } retry:; rc = meta_back_single_dobind( op, rs, &mc, i, @@ -739,11 +752,14 @@ retry:; op->o_log_prefix, i, rootdn ? rootdn : "anonymous" ); + ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); + LDAP_BACK_CONN_BINDING_CLEAR( msc ); if ( rootdn ) { LDAP_BACK_CONN_ISBOUND_SET( msc ); } else { LDAP_BACK_CONN_ISANON_SET( msc ); } + ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); ++bound; } diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 5b516c6d2b..9faa12d7ac 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -213,7 +213,7 @@ metaconn_alloc( mc->mc_conns[ i ].msc_ld = NULL; BER_BVZERO( &mc->mc_conns[ i ].msc_bound_ndn ); BER_BVZERO( &mc->mc_conns[ i ].msc_cred ); - LDAP_BACK_CONN_ISBOUND_CLEAR( &mc->mc_conns[ i ] ); + mc->mc_conns[ i ].msc_mscflags = 0; mc->mc_conns[ i ].msc_info = mi; } @@ -270,6 +270,8 @@ meta_back_init_one_conn( if ( msc->msc_ld != NULL ) { return rs->sr_err = LDAP_SUCCESS; } + + msc->msc_mscflags = 0; /* * Attempts to initialize the connection to the target ds @@ -453,8 +455,6 @@ retry:; assert( !BER_BVISNULL( &msc->msc_bound_ndn ) ); - LDAP_BACK_CONN_ISBOUND_CLEAR( msc ); - error_return:; if ( rs->sr_err == LDAP_SUCCESS ) { /* @@ -523,8 +523,10 @@ meta_back_retry( } if ( rc != LDAP_SUCCESS ) { - meta_back_release_conn_lock( op, mc, 1, 0 ); - *mcp = NULL; + if ( *mcp != NULL ) { + meta_back_release_conn_lock( op, mc, 1, 0 ); + *mcp = NULL; + } if ( sendok ) { rs->sr_err = LDAP_UNAVAILABLE; -- 2.39.5