From: Hallvard Furuseth Date: Fri, 18 May 2007 23:54:26 +0000 (+0000) Subject: Give OperationBuffer normal struct members instead of using X-Git-Tag: OPENLDAP_REL_ENG_2_4_MP~456 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=93fbb87545fd670f93a758f1baf1a67f3c4803ea;p=openldap 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. --- diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 77217110ba..f6fd467671 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -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; diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 6a52708af7..40c526256c 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -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; diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 59876d3d18..3c7a7fc34f 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -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; diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index d157296d60..6e6bbdffc9 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -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; diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index b745cd3c35..2fbfa4b315 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -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 ); diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index 978dd19af8..b5b2f3d1e6 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -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; diff --git a/servers/slapd/overlays/accesslog.c b/servers/slapd/overlays/accesslog.c index b23c421f1e..ef6a46d4a7 100644 --- a/servers/slapd/overlays/accesslog.c +++ b/servers/slapd/overlays/accesslog.c @@ -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; diff --git a/servers/slapd/overlays/dds.c b/servers/slapd/overlays/dds.c index b90fcd0e43..5235a83621 100644 --- a/servers/slapd/overlays/dds.c +++ b/servers/slapd/overlays/dds.c @@ -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 ) ); diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 56bf2a29b2..93fac07d83 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -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; diff --git a/servers/slapd/overlays/refint.c b/servers/slapd/overlays/refint.c index 0a7c1aeb09..1d1b28723e 100644 --- a/servers/slapd/overlays/refint.c +++ b/servers/slapd/overlays/refint.c @@ -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; diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index bb1f753a58..162635dfc2 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -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; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index db194b0ce6..9a066cda38 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 *)); diff --git a/servers/slapd/sasl.c b/servers/slapd/sasl.c index e08400462f..7b43c706d4 100644 --- a/servers/slapd/sasl.c +++ b/servers/slapd/sasl.c @@ -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; diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 4a37dd4d02..16ab5ce27d 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -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; \ diff --git a/servers/slapd/slapacl.c b/servers/slapd/slapacl.c index f8573b5ed5..99b5afa5d2 100644 --- a/servers/slapd/slapacl.c +++ b/servers/slapd/slapacl.c @@ -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; diff --git a/servers/slapd/slapadd.c b/servers/slapd/slapadd.c index 72daa638c6..a39ad0b9f4 100644 --- a/servers/slapd/slapadd.c +++ b/servers/slapd/slapadd.c @@ -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 || diff --git a/servers/slapd/slapauth.c b/servers/slapd/slapauth.c index 3a4c304ff9..92799ac0c9 100644 --- a/servers/slapd/slapauth.c +++ b/servers/slapd/slapauth.c @@ -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; diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 27374322cb..0d31168fba 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -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; diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index c1e16487dc..e68d7dabd7 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -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;