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 )
50 csne->state = SLAP_CSN_COMMIT;
53 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
54 if ( csne->state == SLAP_CSN_COMMIT )
55 committed_csne = csne;
56 if ( csne->state == SLAP_CSN_PENDING )
60 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
62 if ( committed_csne ) {
63 ber_dupbv( csn, committed_csne->csn );
68 slap_rewind_commit_csn( Operation *op )
70 struct slap_csn_entry *csne = NULL;
72 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
74 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
75 if ( csne->opid == op->o_opid && csne->connid == op->o_connid )
80 csne->state = SLAP_CSN_PENDING;
83 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
87 slap_graduate_commit_csn( Operation *op )
89 struct slap_csn_entry *csne = NULL;
94 if ( op->o_bd == NULL )
97 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
99 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
100 if ( csne->opid == op->o_opid && csne->connid == op->o_connid )
105 LDAP_TAILQ_REMOVE( &op->o_bd->be_pending_csn_list, csne, csn_link );
106 ch_free( csne->csn->bv_val );
107 ch_free( csne->csn );
111 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
116 static struct berval ocbva[] = {
119 BER_BVC("syncProviderSubentry"),
124 slap_create_context_csn_entry(
126 struct berval *context_csn
134 e = ( Entry * ) ch_calloc( 1, sizeof( Entry ));
136 attr_merge( e, slap_schema.si_ad_objectClass, ocbva, NULL );
138 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass, &ocbva[1], NULL );
140 attr_merge_one( e, slap_schema.si_ad_cn, (struct berval *)&slap_ldapsync_bv, NULL );
143 attr_merge_one( e, slap_schema.si_ad_contextCSN,
148 bv.bv_len = sizeof("{}")-1;
149 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
151 build_new_dn( &e->e_name, &be->be_nsuffix[0], (struct berval *)&slap_ldapsync_cn_bv, NULL );
152 ber_dupbv( &e->e_nname, &e->e_name );
158 slap_contextcsn_callback(
163 if ( rs->sr_type != REP_SEARCH ) {
164 *((int*)op->o_callback->sc_private) = 0;
166 *((int*)op->o_callback->sc_private) = 1;
180 struct slap_csn_entry *pending;
185 csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
186 csn->bv_val = csnbuf;
188 if ( manage_ctxcsn ) {
189 pending = (struct slap_csn_entry *) ch_calloc( 1, sizeof( struct slap_csn_entry ));
190 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
191 ber_dupbv( &op->o_sync_csn, csn );
192 pending->csn = ber_dupbv( NULL, csn );
193 pending->connid = op->o_connid;
194 pending->opid = op->o_opid;
195 pending->state = SLAP_CSN_PENDING;
196 LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list, pending, csn_link );
197 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );