Give OperationBuffer normal struct members instead of using

LBER_ALIGNED_BUFFER(OPERATION_BUFFER_SIZE), as discussed in ITS#4078.
Add a corresponding SyncOperationBuffer in overlays/syncprov.c.
This commit is contained in:
Hallvard Furuseth 2007-05-18 23:54:26 +00:00
parent a376bb455e
commit 93fbb87545
19 changed files with 98 additions and 78 deletions

View File

@ -179,7 +179,7 @@ bdb_online_index( void *ctx, void *arg )
Connection conn = {0};
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
Operation *op;
DBC *curs;
DBT key, data;
@ -191,7 +191,8 @@ bdb_online_index( void *ctx, void *arg )
int rc, getnext = 1;
int i;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
op->o_bd = be;

View File

@ -813,9 +813,9 @@ monitor_search2ndn(
return -1;
}
op = (Operation *) &opbuf;
thrctx = ldap_pvt_thread_pool_context();
connection_fake_init( &conn, op, thrctx );
connection_fake_init( &conn, &opbuf, thrctx );
op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;

View File

@ -223,8 +223,8 @@ backsql_db_open(
SQLHDBC dbh = SQL_NULL_HDBC;
struct berbuf bb = BB_NULL;
OperationBuffer opbuf;
Operation* op = (Operation *) &opbuf;
OperationBuffer opbuf;
Operation* op;
Debug( LDAP_DEBUG_TRACE, "==>backsql_db_open(): "
"testing RDBMS connection\n", 0, 0, 0 );
@ -470,7 +470,8 @@ backsql_db_open(
}
/* This should just be to force schema loading */
op->o_hdr = (Opheader *)&op[ 1 ];
op = &opbuf.ob_op;
op->o_hdr = &opbuf.ob_hdr;
op->o_connid = (unsigned long)(-1);
op->o_bd = bd;
if ( backsql_get_db_conn( op, &dbh ) != LDAP_SUCCESS ) {
@ -581,9 +582,9 @@ int
backsql_connection_destroy( Backend *bd, Connection *c )
{
OperationBuffer opbuf;
Operation* op = (Operation *) &opbuf;
Operation* op = &opbuf.ob_op;
op->o_hdr = (Opheader *)&op[ 1 ];
op->o_hdr = &opbuf.ob_hdr;
op->o_connid = c->c_connid;
op->o_bd = bd;

View File

@ -3128,8 +3128,8 @@ config_setup_ldif( BackendDB *be, const char *dir, int readit ) {
void *thrctx = ldap_pvt_thread_pool_context();
int prev_DN_strict;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, thrctx );
connection_fake_init( &conn, &opbuf, thrctx );
op = &opbuf.ob_op;
filter.f_desc = slap_schema.si_ad_objectClass;
@ -5420,8 +5420,8 @@ config_back_db_open( BackendDB *be )
}
thrctx = ldap_pvt_thread_pool_context();
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, thrctx );
connection_fake_init( &conn, &opbuf, thrctx );
op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_ADD;
op->o_callback = &cb;
@ -5802,9 +5802,9 @@ config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
ca.bi->bi_type);
ce = config_build_entry( NULL, NULL, cfb->cb_root, &ca, &rdn,
&CFOC_DATABASE, ca.be->be_cf_ocs );
op = (Operation *) &opbuf;
thrctx = ldap_pvt_thread_pool_context();
connection_fake_init2( &conn, op, thrctx,0 );
connection_fake_init2( &conn, &opbuf, thrctx,0 );
op = &opbuf.ob_op;
op->o_bd = &cfb->cb_db;
op->o_tag = LDAP_REQ_ADD;
op->ora_e = ce;
@ -5854,8 +5854,8 @@ config_tool_entry_put( BackendDB *be, Entry *e, struct berval *text )
ca.be->be_cf_ocs );
if ( ! op ) {
thrctx = ldap_pvt_thread_pool_context();
op = (Operation *) &opbuf;
connection_fake_init2( &conn, op, thrctx,0 );
connection_fake_init2( &conn, &opbuf, thrctx,0 );
op = &opbuf.ob_op;
op->o_bd = &cfb->cb_db;
op->o_tag = LDAP_REQ_ADD;
op->o_dn = be->be_rootdn;

View File

@ -1993,19 +1993,21 @@ connection_fake_destroy(
void
connection_fake_init(
Connection *conn,
Operation *op,
OperationBuffer *opbuf,
void *ctx )
{
connection_fake_init2( conn, op, ctx, 1 );
connection_fake_init2( conn, opbuf, ctx, 1 );
}
void
connection_fake_init2(
Connection *conn,
Operation *op,
OperationBuffer *opbuf,
void *ctx,
int newmem )
{
Operation *op = (Operation *) opbuf;
conn->c_connid = -1;
conn->c_send_ldap_result = slap_send_ldap_result;
conn->c_send_search_entry = slap_send_search_entry;
@ -2014,9 +2016,10 @@ connection_fake_init2(
conn->c_peer_domain = slap_empty_bv;
conn->c_peer_name = slap_empty_bv;
memset(op, 0, OPERATION_BUFFER_SIZE);
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
memset( opbuf, 0, sizeof( *opbuf ));
op->o_hdr = &opbuf->ob_hdr;
op->o_controls = opbuf->ob_controls;
/* set memory context */
op->o_tmpmemctx = slap_sl_mem_create(SLAP_SLAB_SIZE, SLAP_SLAB_STACK, ctx,
newmem );

View File

@ -74,6 +74,8 @@ slap_op_groups_free( Operation *op )
void
slap_op_free( Operation *op )
{
OperationBuffer *opbuf;
assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );
if ( op->o_ber != NULL ) {
@ -109,9 +111,10 @@ slap_op_free( Operation *op )
#endif /* defined( LDAP_SLAPI ) */
memset( op, 0, sizeof(Operation) + sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
opbuf = (OperationBuffer *) op;
memset( opbuf, 0, sizeof(*opbuf) );
op->o_hdr = &opbuf->ob_hdr;
op->o_controls = opbuf->ob_controls;
ldap_pvt_thread_mutex_lock( &slap_op_mutex );
LDAP_STAILQ_INSERT_HEAD( &slap_free_ops, op, o_next );
@ -149,10 +152,9 @@ slap_op_alloc(
ldap_pvt_thread_mutex_unlock( &slap_op_mutex );
if (!op) {
op = (Operation *) ch_calloc( 1, sizeof(Operation)
+ sizeof(Opheader) + SLAP_MAX_CIDS * sizeof(void *) );
op->o_hdr = (Opheader *)(op + 1);
op->o_controls = (void **)(op->o_hdr+1);
op = (Operation *) ch_calloc( 1, sizeof(OperationBuffer) );
op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
op->o_controls = ((OperationBuffer *) op)->ob_controls;
}
op->o_ber = ber;

View File

@ -561,7 +561,7 @@ accesslog_purge( void *ctx, void *arg )
Connection conn = {0};
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
Operation *op;
SlapReply rs = {REP_RESULT};
slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
Filter f;
@ -571,7 +571,8 @@ accesslog_purge( void *ctx, void *arg )
char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
time_t old = slap_get_time();
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
f.f_choice = LDAP_FILTER_LE;
f.f_ava = &ava;
@ -1522,12 +1523,13 @@ accesslog_db_root(
Connection conn = {0};
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
Operation *op;
Entry *e;
int rc;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
op->o_bd = li->li_db;
op->o_dn = li->li_db->be_rootdn;
op->o_ndn = li->li_db->be_rootndn;

View File

@ -134,8 +134,8 @@ dds_expire( void *ctx, dds_info_t *di )
int ndeletes, ntotdeletes;
op = (Operation *)&opbuf;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
memset( &op->oq_search, 0, sizeof( op->oq_search ) );
@ -1606,8 +1606,8 @@ dds_count( void *ctx, BackendDB *be )
slap_callback sc = { 0 };
SlapReply rs = { REP_RESULT };
op = (Operation *)&opbuf;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
memset( &op->oq_search, 0, sizeof( op->oq_search ) );

View File

@ -1641,8 +1641,8 @@ consistency_check(
int return_val, pause = 1;
QueryTemplate* templ;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
op->o_bd = &cm->db;
op->o_dn = cm->db.be_rootdn;

View File

@ -414,8 +414,8 @@ refint_qtask( void *ctx, void *arg )
refint_attrs *ra, *ip;
int rc;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
/*
** build a search filter for all configured attributes;

View File

@ -896,11 +896,11 @@ syncprov_qtask( void *ctx, void *arg )
BackendDB be;
int rc;
op = (Operation *) &opbuf;
op = &opbuf.ob_op;
*op = *so->s_op;
op->o_hdr = (Opheader *)(op+1);
op->o_controls = (void **)(op->o_hdr+1);
memset( op->o_controls, 0, SLAP_MAX_CIDS * sizeof(void *));
op->o_hdr = &opbuf.ob_hdr;
op->o_controls = opbuf.ob_controls;
memset( op->o_controls, 0, sizeof(opbuf.ob_controls) );
*op->o_hdr = *so->s_op->o_hdr;
@ -1811,9 +1811,17 @@ syncprov_search_cleanup( Operation *op, SlapReply *rs )
return 0;
}
typedef struct SyncOperationBuffer {
Operation sob_op;
Opheader sob_hdr;
AttributeName sob_extra; /* not always present */
/* Further data allocated here */
} SyncOperationBuffer;
static void
syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on )
{
SyncOperationBuffer *sopbuf2;
Operation *op2;
int i, alen = 0;
size_t size;
@ -1825,14 +1833,15 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on )
alen += op->ors_attrs[i].an_name.bv_len + 1;
}
/* Make a new copy of the operation */
size = sizeof(Operation) + sizeof(Opheader) +
size = offsetof( SyncOperationBuffer, sob_extra ) +
(i ? ( (i+1) * sizeof(AttributeName) + alen) : 0) +
op->o_req_dn.bv_len + 1 +
op->o_req_ndn.bv_len + 1 +
op->o_ndn.bv_len + 1 +
so->s_filterstr.bv_len + 1;
op2 = (Operation *)ch_calloc( 1, size );
op2->o_hdr = (Opheader *)(op2+1);
sopbuf2 = ch_calloc( 1, size );
op2 = &sopbuf2->sob_op;
op2->o_hdr = &sopbuf2->sob_hdr;
/* Copy the fields we care about explicitly, leave the rest alone */
*op2->o_hdr = *op->o_hdr;
@ -1842,18 +1851,18 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on )
op2->o_request = op->o_request;
op2->o_private = on;
ptr = (char *) sopbuf2 + offsetof( SyncOperationBuffer, sob_extra );
if ( i ) {
op2->ors_attrs = (AttributeName *)(op2->o_hdr + 1);
ptr = (char *)(op2->ors_attrs+i+1);
op2->ors_attrs = (AttributeName *) ptr;
ptr = (char *) &op2->ors_attrs[i+1];
for (i=0; !BER_BVISNULL( &op->ors_attrs[i].an_name ); i++) {
op2->ors_attrs[i] = op->ors_attrs[i];
op2->ors_attrs[i].an_name.bv_val = ptr;
ptr = lutil_strcopy( ptr, op->ors_attrs[i].an_name.bv_val ) + 1;
}
BER_BVZERO( &op2->ors_attrs[i].an_name );
} else {
ptr = (char *)(op2->o_hdr + 1);
}
op2->o_authz = op->o_authz;
op2->o_ndn.bv_val = ptr;
ptr = lutil_strcopy(ptr, op->o_ndn.bv_val) + 1;
@ -2508,8 +2517,8 @@ syncprov_db_open(
syncprov_info_t *si = (syncprov_info_t *)on->on_bi.bi_private;
Connection conn = { 0 };
OperationBuffer opbuf = { 0 };
Operation *op = (Operation *) &opbuf;
OperationBuffer opbuf;
Operation *op;
Entry *e = NULL;
Attribute *a;
int rc;
@ -2531,7 +2540,8 @@ syncprov_db_open(
}
thrctx = ldap_pvt_thread_pool_context();
connection_fake_init( &conn, op, thrctx );
connection_fake_init( &conn, &opbuf, thrctx );
op = &opbuf.ob_op;
op->o_bd = be;
op->o_dn = be->be_rootdn;
op->o_ndn = be->be_rootndn;
@ -2605,12 +2615,13 @@ syncprov_db_close(
if ( si->si_numops ) {
Connection conn;
OperationBuffer opbuf;
Operation *op = (Operation *) &opbuf;
Operation *op;
SlapReply rs = {REP_RESULT};
void *thrctx;
thrctx = ldap_pvt_thread_pool_context();
connection_fake_init( &conn, op, thrctx );
connection_fake_init( &conn, &opbuf, thrctx );
op = &opbuf.ob_op;
op->o_bd = be;
op->o_dn = be->be_rootdn;
op->o_ndn = be->be_rootndn;

View File

@ -724,11 +724,11 @@ LDAP_SLAPD_F (void) connection_done LDAP_P((Connection *));
LDAP_SLAPD_F (void) connection2anonymous LDAP_P((Connection *));
LDAP_SLAPD_F (void) connection_fake_init LDAP_P((
Connection *conn,
Operation *op,
OperationBuffer *opbuf,
void *threadctx ));
LDAP_SLAPD_F (void) connection_fake_init2 LDAP_P((
Connection *conn,
Operation *op,
OperationBuffer *opbuf,
void *threadctx,
int newmem ));
LDAP_SLAPD_F (void) connection_assign_nextid LDAP_P((Connection *));

View File

@ -1093,8 +1093,8 @@ slapd_rw_apply( void *private, const char *filter, struct berval *val )
int rc;
thrctx = ldap_pvt_thread_pool_context();
op = (Operation *)&opbuf;
connection_fake_init2( &conn, op, thrctx, 0 );
connection_fake_init2( &conn, &opbuf, thrctx, 0 );
op = &opbuf.ob_op;
op->o_tag = LDAP_REQ_SEARCH;
op->o_req_dn = op->o_req_ndn = sl->base;

View File

@ -2579,11 +2579,11 @@ struct Operation {
LDAP_STAILQ_ENTRY(Operation) o_next; /* next operation in list */
};
#define OPERATION_BUFFER_SIZE ( sizeof(Operation) + sizeof(Opheader) + \
SLAP_MAX_CIDS*sizeof(void *) )
typedef LBER_ALIGNED_BUFFER(operation_buffer_u,OPERATION_BUFFER_SIZE)
OperationBuffer;
typedef struct OperationBuffer {
Operation ob_op;
Opheader ob_hdr;
void *ob_controls[SLAP_MAX_CIDS];
} OperationBuffer;
#define send_ldap_error( op, rs, err, text ) do { \
(rs)->sr_err = err; (rs)->sr_text = text; \

View File

@ -95,8 +95,8 @@ slapacl( int argc, char **argv )
argv = &argv[ optind ];
argc -= optind;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
connection_fake_init( &conn, &opbuf, &conn );
op = &opbuf.ob_op;
conn.c_listener = &listener;
conn.c_listener_url = listener_url;

View File

@ -70,8 +70,8 @@ slapadd( int argc, char **argv )
slap_tool_init( progname, SLAPADD, argc, argv );
memset( &opbuf, 0, sizeof(opbuf) );
op = (Operation *) &opbuf;
op->o_hdr = (Opheader *)(op+1);
op = &opbuf.ob_op;
op->o_hdr = &opbuf.ob_hdr;
if( !be->be_entry_open ||
!be->be_entry_close ||

View File

@ -88,8 +88,8 @@ slapauth( int argc, char **argv )
argv = &argv[ optind ];
argc -= optind;
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, &conn );
connection_fake_init( &conn, &opbuf, &conn );
op = &opbuf.ob_op;
conn.c_sasl_bind_mech = mech;

View File

@ -187,9 +187,9 @@ slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
LDAP_STAILQ_INIT( &conn->c_pending_ops );
op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
op->o_hdr = (Opheader *)(op + 1);
op->o_controls = (void **)(op->o_hdr + 1);
op = (Operation *) slapi_ch_calloc( 1, sizeof(OperationBuffer) );
op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
op->o_controls = ((OperationBuffer *) op)->ob_controls;
op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
op->o_callback->sc_response = slapi_int_response;

View File

@ -1123,8 +1123,8 @@ do_syncrepl(
return NULL;
}
op = (Operation *) &opbuf;
connection_fake_init( &conn, op, ctx );
connection_fake_init( &conn, &opbuf, ctx );
op = &opbuf.ob_op;
/* use global malloc for now */
op->o_tmpmemctx = NULL;