1 /* ctxcsn.c -- Context CSN Management Routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2003-2004 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, *committed_csne = NULL;
42 ldap_pvt_thread_mutex_lock( op->o_bd->be_pcl_mutexp );
44 LDAP_TAILQ_FOREACH( csne, op->o_bd->be_pending_csn_list, ce_csn_link ) {
45 if ( csne->ce_opid == op->o_opid && csne->ce_connid == op->o_connid ) {
46 csne->ce_state = SLAP_CSN_COMMIT;
51 LDAP_TAILQ_FOREACH( csne, op->o_bd->be_pending_csn_list, ce_csn_link ) {
52 if ( csne->ce_state == SLAP_CSN_COMMIT ) committed_csne = csne;
53 if ( csne->ce_state == SLAP_CSN_PENDING ) break;
56 if ( committed_csne ) ber_dupbv_x( csn, committed_csne->ce_csn, op->o_tmpmemctx );
57 ldap_pvt_thread_mutex_unlock( op->o_bd->be_pcl_mutexp );
61 slap_rewind_commit_csn( Operation *op )
63 struct slap_csn_entry *csne;
65 ldap_pvt_thread_mutex_lock( op->o_bd->be_pcl_mutexp );
67 LDAP_TAILQ_FOREACH( csne, op->o_bd->be_pending_csn_list, ce_csn_link ) {
68 if ( csne->ce_opid == op->o_opid && csne->ce_connid == op->o_connid ) {
69 csne->ce_state = SLAP_CSN_PENDING;
74 ldap_pvt_thread_mutex_unlock( op->o_bd->be_pcl_mutexp );
78 slap_graduate_commit_csn( Operation *op )
80 struct slap_csn_entry *csne;
82 if ( op == NULL ) return;
83 if ( op->o_bd == NULL ) return;
85 ldap_pvt_thread_mutex_lock( op->o_bd->be_pcl_mutexp );
87 LDAP_TAILQ_FOREACH( csne, op->o_bd->be_pending_csn_list, ce_csn_link ) {
88 if ( csne->ce_opid == op->o_opid && csne->ce_connid == op->o_connid ) {
89 LDAP_TAILQ_REMOVE( op->o_bd->be_pending_csn_list,
91 ch_free( csne->ce_csn->bv_val );
92 ch_free( csne->ce_csn );
98 ldap_pvt_thread_mutex_unlock( op->o_bd->be_pcl_mutexp );
103 static struct berval ocbva[] = {
106 BER_BVC("syncProviderSubentry"),
111 slap_create_context_csn_entry(
113 struct berval *context_csn )
120 e = (Entry *) ch_calloc( 1, sizeof( Entry ));
122 attr_merge( e, slap_schema.si_ad_objectClass,
124 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
126 attr_merge_one( e, slap_schema.si_ad_cn,
127 (struct berval *)&slap_ldapsync_bv, NULL );
130 attr_merge_one( e, slap_schema.si_ad_contextCSN,
135 bv.bv_len = sizeof("{}")-1;
136 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
138 build_new_dn( &e->e_name, &be->be_nsuffix[0],
139 (struct berval *)&slap_ldapsync_cn_bv, NULL );
140 ber_dupbv( &e->e_nname, &e->e_name );
153 struct slap_csn_entry *pending;
155 if ( csn == NULL ) return LDAP_OTHER;
157 csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
158 csn->bv_val = csnbuf;
160 if ( manage_ctxcsn ) {
161 pending = (struct slap_csn_entry *) ch_calloc( 1,
162 sizeof( struct slap_csn_entry ));
163 ldap_pvt_thread_mutex_lock( op->o_bd->be_pcl_mutexp );
164 ber_dupbv( &op->o_sync_csn, csn );
165 pending->ce_csn = ber_dupbv( NULL, csn );
166 pending->ce_connid = op->o_connid;
167 pending->ce_opid = op->o_opid;
168 pending->ce_state = SLAP_CSN_PENDING;
169 LDAP_TAILQ_INSERT_TAIL( op->o_bd->be_pending_csn_list,
170 pending, ce_csn_link );
171 ldap_pvt_thread_mutex_unlock( op->o_bd->be_pcl_mutexp );