From: Pierangelo Masarati Date: Fri, 2 Jun 2006 17:30:15 +0000 (+0000) Subject: refine (and fix) back-meta handling of search initialization (ITS#4519) X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~183 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=63d5a939b3f30b1e0d2a3f2def7c076f7ebbaf32;p=openldap refine (and fix) back-meta handling of search initialization (ITS#4519) --- diff --git a/servers/slapd/back-meta/back-meta.h b/servers/slapd/back-meta/back-meta.h index 0a33025a44..8d327adf2f 100644 --- a/servers/slapd/back-meta/back-meta.h +++ b/servers/slapd/back-meta/back-meta.h @@ -157,8 +157,21 @@ struct metainfo_t; typedef struct metasingleconn_t { int msc_candidate; -#define META_NOT_CANDIDATE ((ber_tag_t)0) -#define META_CANDIDATE ((ber_tag_t)1) +#define META_NOT_CANDIDATE ((ber_tag_t)0x0) +#define META_CANDIDATE ((ber_tag_t)0x1) +#define META_BINDING ((ber_tag_t)0x2) + +#define META_CND_ISSET(rs,f) ( ( (rs)->sr_tag & (f) ) == (f) ) +#define META_CND_SET(rs,f) ( (rs)->sr_tag |= (f) ) +#define META_CND_CLEAR(rs,f) ( (rs)->sr_tag &= ~(f) ) + +#define META_CANDIDATE_RESET(rs) ( (rs)->sr_tag = 0 ) +#define META_IS_CANDIDATE(rs) META_CND_ISSET( (rs), META_CANDIDATE ) +#define META_CANDIDATE_SET(rs) META_CND_SET( (rs), META_CANDIDATE ) +#define META_CANDIDATE_CLEAR(rs) META_CND_CLEAR( (rs), META_CANDIDATE ) +#define META_IS_BINDING(rs) META_CND_ISSET( (rs), META_BINDING ) +#define META_BINDING_SET(rs) META_CND_SET( (rs), META_BINDING ) +#define META_BINDING_CLEAR(rs) META_CND_CLEAR( (rs), META_BINDING ) LDAP *msc_ld; struct berval msc_bound_ndn; diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index ca504df6b3..eb06923e9d 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -116,7 +116,7 @@ meta_back_bind( Operation *op, SlapReply *rs ) /* * Skip non-candidates */ - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { + if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) { continue; } @@ -177,7 +177,7 @@ meta_back_bind( Operation *op, SlapReply *rs ) * do not assume it's not candidate; rather * mark this as an error to be eventually * reported to client */ - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_CLEAR( &candidates[ i ] ); break; } } @@ -710,7 +710,7 @@ meta_back_dobind( /* * Not a candidate */ - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { + if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) { continue; } diff --git a/servers/slapd/back-meta/candidates.c b/servers/slapd/back-meta/candidates.c index f16a9d0eda..a3c3732c92 100644 --- a/servers/slapd/back-meta/candidates.c +++ b/servers/slapd/back-meta/candidates.c @@ -168,7 +168,7 @@ meta_clear_unused_candidates( if ( i == candidate ) { continue; } - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_RESET( &candidates[ i ] ); } return 0; diff --git a/servers/slapd/back-meta/compare.c b/servers/slapd/back-meta/compare.c index cd6815bee7..75272d6744 100644 --- a/servers/slapd/back-meta/compare.c +++ b/servers/slapd/back-meta/compare.c @@ -75,7 +75,7 @@ meta_back_compare( Operation *op, SlapReply *rs ) struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname; struct berval mapped_value = op->orc_ava->aa_value; - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { + if ( ! META_IS_CANDIDATE( &candidates[ i ] ) ) { msgid[ i ] = -1; continue; } diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 01d8fad382..d7421ac3a8 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -976,7 +976,7 @@ retry_lock: rs, mc, i, LDAP_BACK_CONN_ISPRIV( &mc_curr ), sendok ); if ( candidates[ i ].sr_err == LDAP_SUCCESS ) { - candidates[ i ].sr_tag = META_CANDIDATE; + META_CANDIDATE_SET( &candidates[ i ] ); ncandidates++; } else { @@ -986,7 +986,7 @@ retry_lock: * be init'd, should the other ones * be tried? */ - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_RESET( &candidates[ i ] ); err = candidates[ i ].sr_err; continue; } @@ -1032,7 +1032,7 @@ retry_lock: int j; for ( j = 0; j < mi->mi_ntargets; j++ ) { - candidates[ j ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_RESET( &candidates[ j ] ); } /* @@ -1139,7 +1139,7 @@ retry_lock2:; * be init'd, should the other ones * be tried? */ - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_RESET( &candidates[ i ] ); if ( new_conn ) { (void)meta_clear_one_candidate( msc ); meta_back_freeconn( op, mc ); @@ -1151,7 +1151,7 @@ retry_lock2:; } candidates[ i ].sr_err = LDAP_SUCCESS; - candidates[ i ].sr_tag = META_CANDIDATE; + META_CANDIDATE_SET( &candidates[ i ] ); ncandidates++; if ( candidate ) { @@ -1190,7 +1190,7 @@ retry_lock2:; int lerr = meta_back_init_one_conn( op, rs, mc, i, LDAP_BACK_CONN_ISPRIV( &mc_curr ), LDAP_BACK_DONTSEND ); if ( lerr == LDAP_SUCCESS ) { - candidates[ i ].sr_tag = META_CANDIDATE; + META_CANDIDATE_SET( &candidates[ i ] ); candidates[ i ].sr_err = LDAP_SUCCESS; ncandidates++; @@ -1237,7 +1237,7 @@ retry_lock2:; if ( new_conn ) { ( void )meta_clear_one_candidate( msc ); } - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + META_CANDIDATE_RESET( &candidates[ i ] ); } } diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index b026770328..d600446783 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -137,6 +137,7 @@ retry:; NULL, NULL, &candidates[ candidate ].sr_msgid ); switch ( rc ) { case LDAP_SUCCESS: + META_BINDING_SET( &candidates[ candidate ] ); return META_SEARCH_BINDING; case LDAP_SERVER_DOWN: @@ -221,6 +222,8 @@ meta_search_dobind_result( } ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); + META_BINDING_CLEAR( &candidates[ candidate ] ); + return retcode; } @@ -483,7 +486,7 @@ meta_back_search( Operation *op, SlapReply *rs ) for ( i = 0; i < mi->mi_ntargets; i++ ) { candidates[ i ].sr_msgid = META_MSGID_IGNORE; - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { + if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) { continue; } @@ -494,7 +497,7 @@ meta_back_search( Operation *op, SlapReply *rs ) } for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag != META_CANDIDATE + if ( !META_IS_CANDIDATE( &candidates[ i ] ) || candidates[ i ].sr_err != LDAP_SUCCESS ) { continue; @@ -530,7 +533,7 @@ meta_back_search( Operation *op, SlapReply *rs ) int i; for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag == META_CANDIDATE ) { + if ( META_IS_CANDIDATE( &candidates[ i ] ) ) { cnd[ i ] = '*'; } else { cnd[ i ] = ' '; @@ -561,7 +564,7 @@ meta_back_search( Operation *op, SlapReply *rs ) * maybe we should pick the worst... */ rc = LDAP_NO_SUCH_OBJECT; for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag == META_CANDIDATE + if ( META_IS_CANDIDATE( &candidates[ i ] ) && candidates[ i ].sr_err != LDAP_SUCCESS ) { rc = candidates[ i ].sr_err; @@ -1129,7 +1132,7 @@ really_bad:; /* we use the first one */ for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag == META_CANDIDATE + if ( META_IS_CANDIDATE( &candidates[ i ] ) && candidates[ i ].sr_matched != NULL ) { struct berval bv, pbv; @@ -1190,7 +1193,7 @@ really_bad:; int i; for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag == META_CANDIDATE ) { + if ( META_IS_CANDIDATE( &candidates[ i ] ) ) { cnd[ i ] = '*'; } else { cnd[ i ] = ' '; @@ -1234,16 +1237,17 @@ finish:; } for ( i = 0; i < mi->mi_ntargets; i++ ) { - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { + if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) { continue; } - if ( mc && candidates[ i ].sr_msgid >= 0 ) { + if ( mc && META_IS_BINDING( &candidates[ i ] ) ) { ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); if ( LDAP_BACK_CONN_BINDING( &mc->mc_conns[ i ] ) ) { LDAP_BACK_CONN_BINDING_CLEAR( &mc->mc_conns[ i ] ); } ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); + META_BINDING_CLEAR( &candidates[ i ] ); } if ( candidates[ i ].sr_matched ) {