Commit 5f99f7c9 authored by Howard Chu's avatar Howard Chu
Browse files

More migration of syncrepl from frontend to syncprov overlay

define OPERATION_BUFFER_SIZE for dummy Operations
parent a2400fc0
......@@ -630,7 +630,7 @@ bdb_back_initialize(
bi->bi_op_unbind = 0;
#if 0
#if 0 /* DELETE ME */
bi->bi_op_abandon = bdb_abandon;
bi->bi_op_cancel = bdb_cancel;
#endif
......
......@@ -373,8 +373,8 @@ monitor_filter2ndn( struct berval *base, int scope, struct berval *filter,
struct berval *ndn )
{
Connection conn = { 0 };
Operation op = { 0 };
Opheader ohdr = { 0 };
char opbuf[OPERATION_BUFFER_SIZE];
Operation *op;
SlapReply rs = { 0 };
slap_callback cb = { NULL, monitor_filter2ndn_cb, NULL, NULL };
AttributeName anlist[ 2 ];
......@@ -386,52 +386,53 @@ monitor_filter2ndn( struct berval *base, int scope, struct berval *filter,
return -1;
}
connection_fake_init( &conn, &op, &ohdr, &conn );
op = (Operation *)opbuf;
connection_fake_init( &conn, op, &conn );
op.o_tag = LDAP_REQ_SEARCH;
op->o_tag = LDAP_REQ_SEARCH;
/* use global malloc for now */
op.o_tmpmemctx = NULL;
op.o_tmpmfuncs = &ch_mfuncs;
op->o_tmpmemctx = NULL;
op->o_tmpmfuncs = &ch_mfuncs;
op.o_bd = be_monitor;
op->o_bd = be_monitor;
if ( base == NULL || BER_BVISNULL( base ) ) {
ber_dupbv_x( &op.o_req_dn, &op.o_bd->be_suffix[ 0 ],
op.o_tmpmemctx );
ber_dupbv_x( &op.o_req_ndn, &op.o_bd->be_nsuffix[ 0 ],
op.o_tmpmemctx );
ber_dupbv_x( &op->o_req_dn, &op->o_bd->be_suffix[ 0 ],
op->o_tmpmemctx );
ber_dupbv_x( &op->o_req_ndn, &op->o_bd->be_nsuffix[ 0 ],
op->o_tmpmemctx );
} else {
if ( dnPrettyNormal( NULL, base, &op.o_req_dn, &op.o_req_ndn,
op.o_tmpmemctx ) ) {
if ( dnPrettyNormal( NULL, base, &op->o_req_dn, &op->o_req_ndn,
op->o_tmpmemctx ) ) {
/* error */
}
}
op.o_callback = &cb;
op->o_callback = &cb;
cb.sc_private = (void *)ndn;
op.ors_scope = scope;
ber_dupbv_x( &op.ors_filterstr, filter, op.o_tmpmemctx );
op.ors_filter = str2filter_x( &op, filter->bv_val );
op.ors_attrs = anlist;
op->ors_scope = scope;
ber_dupbv_x( &op->ors_filterstr, filter, op->o_tmpmemctx );
op->ors_filter = str2filter_x( op, filter->bv_val );
op->ors_attrs = anlist;
BER_BVSTR( &anlist[ 0 ].an_name, LDAP_NO_ATTRS );
BER_BVZERO( &anlist[ 1 ].an_name );
op.ors_attrsonly = 0;
op.ors_tlimit = SLAP_NO_LIMIT;
op.ors_slimit = 1;
op.ors_limit = NULL;
op.ors_deref = LDAP_DEREF_NEVER;
op->ors_attrsonly = 0;
op->ors_tlimit = SLAP_NO_LIMIT;
op->ors_slimit = 1;
op->ors_limit = NULL;
op->ors_deref = LDAP_DEREF_NEVER;
op.o_nocaching = 1;
op.o_managedsait = 1;
op->o_nocaching = 1;
op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
rc = op.o_bd->be_search( &op, &rs );
rc = op->o_bd->be_search( op, &rs );
filter_free_x( &op, op.ors_filter );
op.o_tmpfree( op.ors_filterstr.bv_val, op.o_tmpmemctx );
op.o_tmpfree( op.o_req_dn.bv_val, op.o_tmpmemctx );
op.o_tmpfree( op.o_req_ndn.bv_val, op.o_tmpmemctx );
filter_free_x( op, op->ors_filter );
op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
if ( rc != 0 ) {
return rc;
......
......@@ -289,6 +289,7 @@ glue_back_search ( Operation *op, SlapReply *rs )
case LDAP_SCOPE_SUBORDINATE: /* FIXME */
#endif
#if 0 /* DELETE ME - verify ITS first */
if ( op->o_sync_mode & SLAP_SYNC_REFRESH ) {
if (op->o_bd && op->o_bd->be_search) {
rs->sr_err = op->o_bd->be_search( op, rs );
......@@ -298,6 +299,7 @@ glue_back_search ( Operation *op, SlapReply *rs )
}
return rs->sr_err;
}
#endif
op->o_callback = &cb;
rs->sr_err = gs.err = LDAP_UNWILLING_TO_PERFORM;
......
......@@ -1068,21 +1068,21 @@ operations_error:
ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null );
#if 0 /* DELETE ME */
if ( op->o_cancel != SLAP_CANCEL_ACK &&
( op->o_sync_mode & SLAP_SYNC_PERSIST ) )
{
slap_sl_mem_detach( ctx, memctx );
#if 0
} else if ( op->o_sync_slog_size != -1 ) {
slap_sl_mem_detach( ctx, memctx );
LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
LDAP_STAILQ_NEXT(op, o_next) = NULL;
conn->c_n_ops_executing--;
conn->c_n_ops_completed++;
#endif
} else {
} else
#endif
{
LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
LDAP_STAILQ_NEXT(op, o_next) = NULL;
slap_op_free( op );
......@@ -1695,7 +1695,6 @@ void
connection_fake_init(
Connection *conn,
Operation *op,
Opheader *ohdr,
void *ctx )
{
conn->c_connid = -1;
......@@ -1706,7 +1705,9 @@ connection_fake_init(
conn->c_peer_domain = slap_empty_bv;
conn->c_peer_name = slap_empty_bv;
op->o_hdr = ohdr;
memset(op, 0, OPERATION_BUFFER_SIZE);
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
/* set memory context */
op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx);
op->o_tmpmfuncs = &slap_sl_mfuncs;
......
......@@ -41,7 +41,6 @@ static SLAP_CTRL_PARSE_FN parseSearchOptions;
#ifdef LDAP_CONTROL_SUBENTRIES
static SLAP_CTRL_PARSE_FN parseSubentries;
#endif
static SLAP_CTRL_PARSE_FN parseLDAPsync;
#undef sc_mask /* avoid conflict with Irix 6.5 <sys/signal.h> */
......@@ -139,10 +138,6 @@ static struct slap_control control_defs[] = {
(int)offsetof(struct slap_control_ids, sc_noOp),
SLAP_CTRL_HIDE|SLAP_CTRL_ACCESS, NULL,
parseNoOp, LDAP_SLIST_ENTRY_INITIALIZER(next) },
{ LDAP_CONTROL_SYNC,
(int)offsetof(struct slap_control_ids, sc_LDAPsync),
SLAP_CTRL_HIDE|SLAP_CTRL_SEARCH, NULL,
parseLDAPsync, LDAP_SLIST_ENTRY_INITIALIZER(next) },
#ifdef LDAP_CONTROL_MODIFY_INCREMENT
{ LDAP_CONTROL_MODIFY_INCREMENT,
(int)offsetof(struct slap_control_ids, sc_modifyIncrement),
......@@ -800,10 +795,12 @@ static int parsePagedResults (
return LDAP_PROTOCOL_ERROR;
}
#if 0 /* DELETE ME */
if ( op->o_sync != SLAP_CONTROL_NONE ) {
rs->sr_text = "paged results control specified with sync control";
return LDAP_PROTOCOL_ERROR;
}
#endif
if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
rs->sr_text = "paged results control value is empty (or absent)";
......@@ -1286,105 +1283,3 @@ static int parseSearchOptions (
}
#endif
static int parseLDAPsync (
Operation *op,
SlapReply *rs,
LDAPControl *ctrl )
{
ber_tag_t tag;
BerElement *ber;
ber_int_t mode;
ber_len_t len;
struct slap_session_entry *se;
struct berval cookie = BER_BVNULL;
syncrepl_state *sr;
int rhint = 0;
if ( op->o_sync != SLAP_CONTROL_NONE ) {
rs->sr_text = "Sync control specified multiple times";
return LDAP_PROTOCOL_ERROR;
}
if ( op->o_pagedresults != SLAP_CONTROL_NONE ) {
rs->sr_text = "Sync control specified with pagedResults control";
return LDAP_PROTOCOL_ERROR;
}
if ( ctrl->ldctl_value.bv_len == 0 ) {
rs->sr_text = "Sync control value is empty (or absent)";
return LDAP_PROTOCOL_ERROR;
}
/* Parse the control value
* syncRequestValue ::= SEQUENCE {
* mode ENUMERATED {
* -- 0 unused
* refreshOnly (1),
* -- 2 reserved
* refreshAndPersist (3)
* },
* cookie syncCookie OPTIONAL
* }
*/
ber = ber_init( &ctrl->ldctl_value );
if( ber == NULL ) {
rs->sr_text = "internal error";
return LDAP_OTHER;
}
if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
rs->sr_text = "Sync control : mode decoding error";
return LDAP_PROTOCOL_ERROR;
}
switch( mode ) {
case LDAP_SYNC_REFRESH_ONLY:
mode = SLAP_SYNC_REFRESH;
break;
case LDAP_SYNC_REFRESH_AND_PERSIST:
mode = SLAP_SYNC_REFRESH_AND_PERSIST;
break;
default:
rs->sr_text = "Sync control : unknown update mode";
return LDAP_PROTOCOL_ERROR;
}
tag = ber_peek_tag( ber, &len );
if ( tag == LDAP_TAG_SYNC_COOKIE ) {
if (( ber_scanf( ber, /*{*/ "o", &cookie )) == LBER_ERROR ) {
rs->sr_text = "Sync control : cookie decoding error";
return LDAP_PROTOCOL_ERROR;
}
}
if ( tag == LDAP_TAG_RELOAD_HINT ) {
if (( ber_scanf( ber, /*{*/ "b", &rhint )) == LBER_ERROR ) {
rs->sr_text = "Sync control : rhint decoding error";
return LDAP_PROTOCOL_ERROR;
}
}
if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
rs->sr_text = "Sync control : decoding error";
return LDAP_PROTOCOL_ERROR;
}
sr = op->o_tmpcalloc( 1, sizeof(struct syncrepl_state), op->o_tmpmemctx );
sr->sr_rhint = rhint;
if (!BER_BVISNULL(&cookie)) {
ber_bvarray_add( &sr->sr_state.octet_str, &cookie );
slap_parse_sync_cookie( &sr->sr_state );
}
op->o_controls[slap_cids.sc_LDAPsync] = sr;
(void) ber_free( ber, 1 );
op->o_sync = ctrl->ldctl_iscritical
? SLAP_CONTROL_CRITICAL
: SLAP_CONTROL_NONCRITICAL;
op->o_sync_mode |= mode; /* o_sync_mode shares o_sync */
return LDAP_SUCCESS;
}
......@@ -34,236 +34,6 @@ struct slap_sync_cookie_s slap_sync_cookie =
LDAP_STAILQ_HEAD_INITIALIZER( slap_sync_cookie );
#endif
int
slap_build_sync_state_ctrl(
Operation *op,
SlapReply *rs,
Entry *e,
int entry_sync_state,
LDAPControl **ctrls,
int num_ctrls,
int send_cookie,
struct berval *cookie)
{
Attribute* a;
int ret;
int res;
const char *text = NULL;
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
struct berval entryuuid_bv = BER_BVNULL;
ber_init2( ber, 0, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
ctrls[num_ctrls] = slap_sl_malloc ( sizeof ( LDAPControl ), op->o_tmpmemctx );
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
AttributeDescription *desc = a->a_desc;
if ( desc == slap_schema.si_ad_entryUUID ) {
entryuuid_bv = a->a_nvals[0];
break;
}
}
if ( send_cookie && cookie ) {
ber_printf( ber, "{eOON}",
entry_sync_state, &entryuuid_bv, cookie );
} else {
ber_printf( ber, "{eON}",
entry_sync_state, &entryuuid_bv );
}
ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_STATE;
ctrls[num_ctrls]->ldctl_iscritical = (op->o_sync == SLAP_CONTROL_CRITICAL);
ret = ber_flatten2( ber, &ctrls[num_ctrls]->ldctl_value, 1 );
ber_free_buf( ber );
if ( ret < 0 ) {
Debug( LDAP_DEBUG_TRACE,
"slap_build_sync_ctrl: ber_flatten2 failed\n",
0, 0, 0 );
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
return ret;
}
return LDAP_SUCCESS;
}
int
slap_build_sync_done_ctrl(
Operation *op,
SlapReply *rs,
LDAPControl **ctrls,
int num_ctrls,
int send_cookie,
struct berval *cookie,
int refreshDeletes )
{
int ret;
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
ber_init2( ber, NULL, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
ctrls[num_ctrls] = ch_malloc ( sizeof ( LDAPControl ) );
ber_printf( ber, "{" );
if ( send_cookie && cookie ) {
ber_printf( ber, "O", cookie );
}
if ( refreshDeletes == LDAP_SYNC_REFRESH_DELETES ) {
ber_printf( ber, "b", refreshDeletes );
}
ber_printf( ber, "N}" );
ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_DONE;
ctrls[num_ctrls]->ldctl_iscritical = (op->o_sync == SLAP_CONTROL_CRITICAL);
ret = ber_flatten2( ber, &ctrls[num_ctrls]->ldctl_value, 1 );
ber_free_buf( ber );
if ( ret < 0 ) {
Debug( LDAP_DEBUG_TRACE,
"slap_build_sync_done_ctrl: ber_flatten2 failed\n",
0, 0, 0 );
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
return ret;
}
return LDAP_SUCCESS;
}
int
slap_build_sync_state_ctrl_from_slog(
Operation *op,
SlapReply *rs,
struct slog_entry *slog_e,
int entry_sync_state,
LDAPControl **ctrls,
int num_ctrls,
int send_cookie,
struct berval *cookie)
{
Attribute* a;
int ret;
int res;
const char *text = NULL;
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
struct berval entryuuid_bv = BER_BVNULL;
ber_init2( ber, NULL, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
ctrls[num_ctrls] = ch_malloc ( sizeof ( LDAPControl ) );
entryuuid_bv = slog_e->sl_uuid;
if ( send_cookie && cookie ) {
ber_printf( ber, "{eOON}",
entry_sync_state, &entryuuid_bv, cookie );
} else {
ber_printf( ber, "{eON}",
entry_sync_state, &entryuuid_bv );
}
ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_STATE;
ctrls[num_ctrls]->ldctl_iscritical = (op->o_sync == SLAP_CONTROL_CRITICAL);
ret = ber_flatten2( ber, &ctrls[num_ctrls]->ldctl_value, 1 );
ber_free_buf( ber );
if ( ret < 0 ) {
Debug( LDAP_DEBUG_TRACE,
"slap_build_sync_ctrl: ber_flatten2 failed\n",
0, 0, 0 );
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
return ret;
}
return LDAP_SUCCESS;
}
int
slap_send_syncinfo(
Operation *op,
SlapReply *rs,
int type,
struct berval *cookie,
int refreshDone,
BerVarray syncUUIDs,
int refreshDeletes )
{
BerElementBuffer berbuf;
BerElement *ber = (BerElement *)&berbuf;
struct berval rspdata;
int ret;
ber_init2( ber, NULL, LBER_USE_DER );
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
if ( type ) {
switch ( type ) {
case LDAP_TAG_SYNC_NEW_COOKIE:
ber_printf( ber, "tO", type, cookie );
break;
case LDAP_TAG_SYNC_REFRESH_DELETE:
case LDAP_TAG_SYNC_REFRESH_PRESENT:
ber_printf( ber, "t{", type );
if ( cookie ) {
ber_printf( ber, "O", cookie );
}
if ( refreshDone == 0 ) {
ber_printf( ber, "b", refreshDone );
}
ber_printf( ber, "N}" );
break;
case LDAP_TAG_SYNC_ID_SET:
ber_printf( ber, "t{", type );
if ( cookie ) {
ber_printf( ber, "O", cookie );
}
if ( refreshDeletes == 1 ) {
ber_printf( ber, "b", refreshDeletes );
}
ber_printf( ber, "[W]", syncUUIDs );
ber_printf( ber, "N}" );
break;
default:
Debug( LDAP_DEBUG_TRACE,
"slap_send_syncinfo: invalid syncinfo type (%d)\n",
type, 0, 0 );
return LDAP_OTHER;
}
}
ret = ber_flatten2( ber, &rspdata, 0 );
if ( ret < 0 ) {
Debug( LDAP_DEBUG_TRACE,
"slap_send_syncinfo: ber_flatten2 failed\n",
0, 0, 0 );
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
return ret;
}
rs->sr_rspdata = &rspdata;
send_ldap_intermediate( op, rs );
rs->sr_rspdata = NULL;
ber_free_buf( ber );
return LDAP_SUCCESS;
}
void
slap_compose_sync_cookie(
Operation *op,
......
......@@ -108,7 +108,7 @@ slap_op_free( Operation *op )
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
#if 0
#if 0 /* DELETE ME */
slap_sync_cookie_free( &op->o_sync_state, 0 );
if ( op->o_sync_csn.bv_val != NULL ) {
ch_free( op->o_sync_csn.bv_val );
......@@ -155,7 +155,7 @@ slap_op_alloc(
op->o_opid = id;
op->o_res_ber = NULL;
#if 0
#if 0 /* DELETE ME */
op->o_sync_state.sid = -1;
op->o_sync_slog_size = -1;
op->o_sync_state.rid = -1;
......
......@@ -1410,20 +1410,21 @@ consistency_check(
slap_overinst *on = rtask->arg;
cache_manager *cm = on->on_bi.bi_private;
query_manager *qm = cm->qm;
Operation op = {0};
Opheader ohdr = {0};
Connection conn = {0};
char opbuf[OPERATION_BUFFER_SIZE];
Operation *op;
SlapReply rs = {REP_RESULT};
CachedQuery* query, *query_prev;
int i, return_val, pause = 1;
QueryTemplate* templ;
connection_fake_init( &conn, &op, &ohdr, ctx );
op = (Operation *)opbuf;
connection_fake_init( &conn, op, ctx );
op.o_bd = &cm->db;
op.o_dn = cm->db.be_rootdn;
op.o_ndn = cm->db.be_rootndn;
op->o_bd = &cm->db;
op->o_dn = cm->db.be_rootdn;
op->o_ndn = cm->db.be_rootndn;
cm->cc_arg = arg;
......@@ -1431,9 +1432,9 @@ consistency_check(
templ = qm->templates + i;
query = templ->query_last;
if ( query ) pause = 0;
op.o_time = slap_get_time();
op->o_time = slap_get_time();
ldap_pvt_thread_mutex_lock(&cm->remove_mutex);
while (query && (query->expiry_time < op.o_time)) {
while (query && (query->expiry_time < op->o_time)) {
ldap_pvt_thread_mutex_lock(&qm->lru_mutex);
remove_query(qm, query);
ldap_pvt_thread_mutex_unlock(&qm->lru_mutex);
......@@ -1446,7 +1447,7 @@ consistency_check(
Debug( LDAP_DEBUG_ANY, "Unlock CR index = %d\n",
i, 0, 0 );
ldap_pvt_thread_rdwr_wunlock(&templ->t_rwlock);
return_val = remove_query_data(&op, &rs, &query->q_uuid);
return_val = remove_query_data(op, &rs, &query->q_uuid);
Debug( LDAP_DEBUG_ANY, "STALE QUERY REMOVED, SIZE=%d\n",
return_val, 0, 0 );
ldap_pvt_thread_mutex_lock(&cm->cache_mutex);
......
......@@ -53,6 +53,21 @@ typedef struct syncops {