1 /* ctxcsn.c -- Context CSN Management Routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003 The OpenLDAP Foundation.
6 * Portions Copyright 2003 IBM Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
28 #include "lutil_ldap.h"
30 const struct berval slap_ldapsync_bv = BER_BVC("ldapsync");
31 const struct berval slap_ldapsync_cn_bv = BER_BVC("cn=ldapsync");
34 slap_get_commit_csn( Operation *op, struct berval *csn )
36 struct slap_csn_entry *csne = NULL, *committed_csne = NULL;
42 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
44 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
45 if ( csne->opid == op->o_opid && csne->connid == op->o_connid ) break;
49 csne->state = SLAP_CSN_COMMIT;
52 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
53 if ( csne->state == SLAP_CSN_COMMIT ) committed_csne = csne;
54 if ( csne->state == SLAP_CSN_PENDING ) break;
57 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
59 if ( committed_csne ) {
60 ber_dupbv( csn, committed_csne->csn );
65 slap_rewind_commit_csn( Operation *op )
67 struct slap_csn_entry *csne = NULL;
69 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
71 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
72 if ( csne->opid == op->o_opid && csne->connid == op->o_connid ) break;
76 csne->state = SLAP_CSN_PENDING;
79 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
83 slap_graduate_commit_csn( Operation *op )
85 struct slap_csn_entry *csne = NULL;
90 if ( op->o_bd == NULL )
93 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
95 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
96 if ( csne->opid == op->o_opid && csne->connid == op->o_connid ) break;
100 LDAP_TAILQ_REMOVE( &op->o_bd->be_pending_csn_list, csne, csn_link );
101 ch_free( csne->csn->bv_val );
102 ch_free( csne->csn );
106 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
111 static struct berval ocbva[] = {
114 BER_BVC("syncProviderSubentry"),
119 slap_create_context_csn_entry(
121 struct berval *context_csn
129 e = (Entry *) ch_calloc( 1, sizeof( Entry ));
131 attr_merge( e, slap_schema.si_ad_objectClass,
133 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
135 attr_merge_one( e, slap_schema.si_ad_cn,
136 (struct berval *)&slap_ldapsync_bv, NULL );
139 attr_merge_one( e, slap_schema.si_ad_contextCSN,
144 bv.bv_len = sizeof("{}")-1;
145 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
147 build_new_dn( &e->e_name, &be->be_nsuffix[0],
148 (struct berval *)&slap_ldapsync_cn_bv, NULL );
149 ber_dupbv( &e->e_nname, &e->e_name );
155 slap_contextcsn_callback(
160 if ( rs->sr_type != REP_SEARCH ) {
161 *((int*)op->o_callback->sc_private) = 0;
163 *((int*)op->o_callback->sc_private) = 1;
177 struct slap_csn_entry *pending;
179 if ( csn == NULL ) return LDAP_OTHER;
181 csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
182 csn->bv_val = csnbuf;
184 if ( manage_ctxcsn ) {
185 pending = (struct slap_csn_entry *) ch_calloc( 1,
186 sizeof( struct slap_csn_entry ));
187 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
188 ber_dupbv( &op->o_sync_csn, csn );
189 pending->csn = ber_dupbv( NULL, csn );
190 pending->connid = op->o_connid;
191 pending->opid = op->o_opid;
192 pending->state = SLAP_CSN_PENDING;
193 LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list,
195 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );