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_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 ) {
46 csne->state = SLAP_CSN_COMMIT;
51 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
52 if ( csne->state == SLAP_CSN_COMMIT ) committed_csne = csne;
53 if ( csne->state == SLAP_CSN_PENDING ) break;
56 if ( committed_csne ) {
57 ber_dupbv( csn, committed_csne->csn );
60 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
65 slap_rewind_commit_csn( Operation *op )
67 struct slap_csn_entry *csne;
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 ) {
73 csne->state = SLAP_CSN_PENDING;
78 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
82 slap_graduate_commit_csn( Operation *op )
84 struct slap_csn_entry *csne;
89 if ( op->o_bd == NULL )
92 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
94 LDAP_TAILQ_FOREACH( csne, &op->o_bd->be_pending_csn_list, csn_link ) {
95 if ( csne->opid == op->o_opid && csne->connid == op->o_connid ) {
96 LDAP_TAILQ_REMOVE( &op->o_bd->be_pending_csn_list, csne, csn_link );
97 ch_free( csne->csn->bv_val );
104 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );
109 static struct berval ocbva[] = {
112 BER_BVC("syncProviderSubentry"),
117 slap_create_context_csn_entry(
119 struct berval *context_csn
127 e = (Entry *) ch_calloc( 1, sizeof( Entry ));
129 attr_merge( e, slap_schema.si_ad_objectClass,
131 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
133 attr_merge_one( e, slap_schema.si_ad_cn,
134 (struct berval *)&slap_ldapsync_bv, NULL );
137 attr_merge_one( e, slap_schema.si_ad_contextCSN,
142 bv.bv_len = sizeof("{}")-1;
143 attr_merge_one( e, slap_schema.si_ad_subtreeSpecification, &bv, NULL );
145 build_new_dn( &e->e_name, &be->be_nsuffix[0],
146 (struct berval *)&slap_ldapsync_cn_bv, NULL );
147 ber_dupbv( &e->e_nname, &e->e_name );
161 struct slap_csn_entry *pending;
163 if ( csn == NULL ) return LDAP_OTHER;
165 csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 );
166 csn->bv_val = csnbuf;
168 if ( manage_ctxcsn ) {
169 pending = (struct slap_csn_entry *) ch_calloc( 1,
170 sizeof( struct slap_csn_entry ));
171 ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex );
172 ber_dupbv( &op->o_sync_csn, csn );
173 pending->csn = ber_dupbv( NULL, csn );
174 pending->connid = op->o_connid;
175 pending->opid = op->o_opid;
176 pending->state = SLAP_CSN_PENDING;
177 LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list,
179 ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex );