X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Foverlays%2Fsyncprov.c;h=a284d2ae0a619d3df6801445ce98f03ec0ea928f;hb=c68bb6a0e1e760b2a03f9745a44fbadb98b22061;hp=3021369f08f6b744d6cf5f2bbf9c04c544a59b13;hpb=6f34a8be0e79bd395556ed691a1121609771c057;p=openldap diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 3021369f08..a284d2ae0a 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -2,7 +2,7 @@ /* syncprov.c - syncrepl provider */ /* This work is part of OpenLDAP Software . * - * Copyright 2004-2007 The OpenLDAP Foundation. + * Copyright 2004-2008 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -401,6 +401,7 @@ syncprov_findbase( Operation *op, fbase_cookie *fc ) slap_callback cb = {0}; Operation fop; SlapReply frs = { REP_RESULT }; + BackendInfo *bi; int rc; fc->fss->s_flags ^= PS_FIND_BASE; @@ -412,6 +413,7 @@ syncprov_findbase( Operation *op, fbase_cookie *fc ) fop.o_bd = op->o_bd; fop.o_time = op->o_time; fop.o_tincr = op->o_tincr; + bi = op->o_bd->bd_info; cb.sc_response = findbase_cb; cb.sc_private = fc; @@ -429,9 +431,8 @@ syncprov_findbase( Operation *op, fbase_cookie *fc ) fop.ors_filter = &generic_filter; fop.ors_filterstr = generic_filterstr; - fop.o_bd->bd_info = on->on_info->oi_orig; - rc = fop.o_bd->be_search( &fop, &frs ); - fop.o_bd->bd_info = (BackendInfo *)on; + rc = overlay_op_walk( &fop, &frs, op_search, on->on_info, on ); + op->o_bd->bd_info = bi; } else { ldap_pvt_thread_mutex_unlock( &fc->fss->s_mutex ); fc->fbase = 1; @@ -641,6 +642,7 @@ again: } else { cf.f_choice = LDAP_FILTER_LE; fop.ors_limit = &fc_limits; + memset( &fc_limits, 0, sizeof( fc_limits )); fc_limits.lms_s_unchecked = 1; fop.ors_filterstr.bv_len = sprintf( buf, "(entryCSN<=%s)", cf.f_av_value.bv_val ); @@ -818,7 +820,6 @@ syncprov_qplay( Operation *op, slap_overinst *on, syncops *so ) int rc = 0; opc.son = on; - op->o_bd->bd_info = (BackendInfo *)on->on_info; for (;;) { ldap_pvt_thread_mutex_lock( &so->s_mutex ); @@ -840,7 +841,7 @@ syncprov_qplay( Operation *op, slap_overinst *on, syncops *so ) e = NULL; if ( sr->s_mode != LDAP_SYNC_DELETE ) { - rc = be_entry_get_rw( op, &opc.sndn, NULL, NULL, 0, &e ); + rc = overlay_entry_get_ov( op, &opc.sndn, NULL, NULL, 0, &e, on ); if ( rc ) { Debug( LDAP_DEBUG_SYNC, "syncprov_qplay: failed to get %s, " "error (%d), ignoring...\n", opc.sndn.bv_val, rc, 0 ); @@ -852,7 +853,7 @@ syncprov_qplay( Operation *op, slap_overinst *on, syncops *so ) rc = syncprov_sendresp( op, &opc, so, &e, sr->s_mode ); if ( e ) { - be_entry_release_rw( op, e, 0 ); + overlay_entry_release_ov( op, e, 0, on ); } ch_free( sr ); @@ -860,7 +861,6 @@ syncprov_qplay( Operation *op, slap_overinst *on, syncops *so ) if ( rc ) break; } - op->o_bd->bd_info = (BackendInfo *)on; return rc; } @@ -1060,7 +1060,7 @@ syncprov_matchops( Operation *op, opcookie *opc, int saveit ) fbase_cookie fc; syncops *ss, *sprev, *snext; - Entry *e; + Entry *e = NULL; Attribute *a; int rc; struct berval newdn; @@ -1082,15 +1082,13 @@ syncprov_matchops( Operation *op, opcookie *opc, int saveit ) db = *op->o_bd; op->o_bd = &db; } - op->o_bd->bd_info = (BackendInfo *)on->on_info; - rc = be_entry_get_rw( op, fc.fdn, NULL, NULL, 0, &e ); + rc = overlay_entry_get_ov( op, fc.fdn, NULL, NULL, 0, &e, on ); /* If we're sending responses now, make a copy and unlock the DB */ if ( e && !saveit ) { Entry *e2 = entry_dup( e ); - be_entry_release_rw( op, e, 0 ); + overlay_entry_release_ov( op, e, 0, on ); e = e2; } - op->o_bd->bd_info = (BackendInfo *)on; if ( rc ) { op->o_bd = b0; return; @@ -1505,7 +1503,7 @@ syncprov_op_response( Operation *op, SlapReply *rs ) { struct berval maxcsn = BER_BVNULL; char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; - int do_check=0; + int do_check = 0, have_psearches; /* Update our context CSN */ cbuf[0] = '\0'; @@ -1550,7 +1548,10 @@ syncprov_op_response( Operation *op, SlapReply *rs ) opc->sctxcsn.bv_val = cbuf; /* Handle any persistent searches */ - if ( si->si_ops ) { + ldap_pvt_thread_mutex_lock( &si->si_ops_mutex ); + have_psearches = ( si->si_ops != NULL ); + ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex ); + if ( have_psearches ) { switch(op->o_tag) { case LDAP_REQ_ADD: case LDAP_REQ_MODIFY: @@ -1655,12 +1656,19 @@ syncprov_op_mod( Operation *op, SlapReply *rs ) { slap_overinst *on = (slap_overinst *)op->o_bd->bd_info; syncprov_info_t *si = on->on_bi.bi_private; + slap_callback *cb; + opcookie *opc; + int have_psearches, cbsize; + + ldap_pvt_thread_mutex_lock( &si->si_ops_mutex ); + have_psearches = ( si->si_ops != NULL ); + ldap_pvt_thread_mutex_unlock( &si->si_ops_mutex ); + + cbsize = sizeof(slap_callback) + sizeof(opcookie) + + (have_psearches ? sizeof(modinst) : 0 ); - slap_callback *cb = op->o_tmpcalloc(1, sizeof(slap_callback)+ - sizeof(opcookie) + - (si->si_ops ? sizeof(modinst) : 0 ), - op->o_tmpmemctx); - opcookie *opc = (opcookie *)(cb+1); + cb = op->o_tmpcalloc(1, cbsize, op->o_tmpmemctx); + opc = (opcookie *)(cb+1); opc->son = on; cb->sc_response = syncprov_op_response; cb->sc_cleanup = syncprov_op_cleanup; @@ -1671,7 +1679,7 @@ syncprov_op_mod( Operation *op, SlapReply *rs ) /* If there are active persistent searches, lock this operation. * See seqmod.c for the locking logic on its own. */ - if ( si->si_ops ) { + if ( have_psearches ) { modtarget *mt, mtdummy; modinst *mi; @@ -1718,7 +1726,7 @@ syncprov_op_mod( Operation *op, SlapReply *rs ) } } - if (( si->si_ops || si->si_logs ) && op->o_tag != LDAP_REQ_ADD ) + if (( have_psearches || si->si_logs ) && op->o_tag != LDAP_REQ_ADD ) syncprov_matchops( op, opc, 1 ); return SLAP_CB_CONTINUE; @@ -1832,12 +1840,10 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on ) op2->o_do_not_cache = 1; /* Add op2 to conn so abandon will find us */ - ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); op->o_conn->c_n_ops_executing++; op->o_conn->c_n_ops_completed--; LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op2, o_next ); so->s_flags |= PS_IS_DETACHED; - ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); /* Prevent anyone else from trying to send a result for this op */ op->o_abandon = 1; @@ -1848,6 +1854,7 @@ syncprov_search_response( Operation *op, SlapReply *rs ) { searchstate *ss = op->o_callback->sc_private; slap_overinst *on = ss->ss_on; + syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private; sync_control *srs = op->o_controls[slap_cids.sc_LDAPsync]; if ( rs->sr_type == REP_SEARCH || rs->sr_type == REP_SEARCHREF ) { @@ -1867,8 +1874,9 @@ syncprov_search_response( Operation *op, SlapReply *rs ) a = attr_find( rs->sr_operational_attrs, slap_schema.si_ad_entryCSN ); } if ( a ) { + /* If not a persistent search */ /* Make sure entry is less than the snapshot'd contextCSN */ - if ( ber_bvcmp( &a->a_nvals[0], &ss->ss_ctxcsn ) > 0 ) { + if ( !ss->ss_so && ber_bvcmp( &a->a_nvals[0], &ss->ss_ctxcsn ) > 0 ) { Debug( LDAP_DEBUG_SYNC, "Entry %s CSN %s greater than snapshot %s\n", rs->sr_entry->e_name.bv_val, a->a_nvals[0].bv_val, @@ -1889,8 +1897,16 @@ syncprov_search_response( Operation *op, SlapReply *rs ) rs->sr_ctrls = op->o_tmpalloc( sizeof(LDAPControl *)*2, op->o_tmpmemctx ); rs->sr_ctrls[1] = NULL; - rs->sr_err = syncprov_state_ctrl( op, rs, rs->sr_entry, - LDAP_SYNC_ADD, rs->sr_ctrls, 0, 0, NULL ); + /* If we're in delta-sync mode, always send a cookie */ + if ( si->si_nopres && si->si_usehint && a ) { + struct berval cookie; + slap_compose_sync_cookie( op, &cookie, a->a_nvals, srs->sr_state.rid ); + rs->sr_err = syncprov_state_ctrl( op, rs, rs->sr_entry, + LDAP_SYNC_ADD, rs->sr_ctrls, 0, 1, &cookie ); + } else { + rs->sr_err = syncprov_state_ctrl( op, rs, rs->sr_entry, + LDAP_SYNC_ADD, rs->sr_ctrls, 0, 0, NULL ); + } } else if ( rs->sr_type == REP_RESULT && rs->sr_err == LDAP_SUCCESS ) { struct berval cookie; @@ -1915,15 +1931,27 @@ syncprov_search_response( Operation *op, SlapReply *rs ) /* Detach this Op from frontend control */ ldap_pvt_thread_mutex_lock( &ss->ss_so->s_mutex ); + ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex ); - /* Turn off the refreshing flag */ - ss->ss_so->s_flags ^= PS_IS_REFRESHING; + /* But not if this connection was closed along the way */ + if ( op->o_abandon ) { + ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); + ldap_pvt_thread_mutex_unlock( &ss->ss_so->s_mutex ); + /* syncprov_ab_cleanup will free this syncop */ + return SLAPD_ABANDON; - syncprov_detach_op( op, ss->ss_so, on ); + } else { + /* Turn off the refreshing flag */ + ss->ss_so->s_flags ^= PS_IS_REFRESHING; - /* If there are queued responses, fire them off */ - if ( ss->ss_so->s_res ) - syncprov_qstart( ss->ss_so ); + syncprov_detach_op( op, ss->ss_so, on ); + + ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex ); + + /* If there are queued responses, fire them off */ + if ( ss->ss_so->s_res ) + syncprov_qstart( ss->ss_so ); + } ldap_pvt_thread_mutex_unlock( &ss->ss_so->s_mutex ); return LDAP_SUCCESS; @@ -2372,7 +2400,7 @@ syncprov_db_open( OperationBuffer opbuf = { 0 }; char ctxcsnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE]; Operation *op = (Operation *) &opbuf; - Entry *e; + Entry *e = NULL; Attribute *a; int rc; void *thrctx = NULL; @@ -2400,9 +2428,8 @@ syncprov_db_open( ctxcsnbuf[0] = '\0'; - op->o_bd->bd_info = on->on_info->oi_orig; - rc = be_entry_get_rw( op, be->be_nsuffix, NULL, - slap_schema.si_ad_contextCSN, 0, &e ); + rc = overlay_entry_get_ov( op, be->be_nsuffix, NULL, + slap_schema.si_ad_contextCSN, 0, &e, on ); if ( e ) { ldap_pvt_thread_t tid; @@ -2417,9 +2444,8 @@ syncprov_db_open( si->si_ctxcsnbuf[si->si_ctxcsn.bv_len] = '\0'; strcpy( ctxcsnbuf, si->si_ctxcsnbuf ); } - be_entry_release_rw( op, e, 0 ); + overlay_entry_release_ov( op, e, 0, on ); if ( !BER_BVISEMPTY( &si->si_ctxcsn ) ) { - op->o_bd->bd_info = (BackendInfo *)on; op->o_req_dn = be->be_suffix[0]; op->o_req_ndn = be->be_nsuffix[0]; op->ors_scope = LDAP_SCOPE_SUBTREE; @@ -2466,7 +2492,7 @@ syncprov_db_close( return 0; } if ( si->si_numops ) { - Connection conn; + Connection conn = {0}; OperationBuffer opbuf; Operation *op = (Operation *) &opbuf; SlapReply rs = {REP_RESULT};