]> git.sur5r.net Git - openldap/commitdiff
Give OperationBuffer normal struct members instead of using
authorHallvard Furuseth <hallvard@openldap.org>
Fri, 18 May 2007 23:54:26 +0000 (23:54 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Fri, 18 May 2007 23:54:26 +0000 (23:54 +0000)
LBER_ALIGNED_BUFFER(OPERATION_BUFFER_SIZE), as discussed in ITS#4078.
Add a corresponding SyncOperationBuffer in overlays/syncprov.c.

19 files changed:
servers/slapd/back-bdb/config.c
servers/slapd/back-monitor/init.c
servers/slapd/back-sql/init.c
servers/slapd/bconfig.c
servers/slapd/connection.c
servers/slapd/operation.c
servers/slapd/overlays/accesslog.c
servers/slapd/overlays/dds.c
servers/slapd/overlays/pcache.c
servers/slapd/overlays/refint.c
servers/slapd/overlays/syncprov.c
servers/slapd/proto-slap.h
servers/slapd/sasl.c
servers/slapd/slap.h
servers/slapd/slapacl.c
servers/slapd/slapadd.c
servers/slapd/slapauth.c
servers/slapd/slapi/slapi_ops.c
servers/slapd/syncrepl.c

index 77217110baccb34827f90b6dd77487bb54ee27ae..f6fd467671c502ec582622f6d58df8c1c997b250 100644 (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;
 
index 6a52708af70653ea9f8d0a6c6a081de52b0d1e96..40c526256c1b7eefa4554facc5a908040dc9bdc2 100644 (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;
 
index 59876d3d18d9d8400c7f02c1137e498371b7eccd..3c7a7fc34f1ca0cb636cecddb8fdbdf3ce4cb4c8 100644 (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;
 
index d157296d606de0e63a0f2eb28c3f21779ae77020..6e6bbdffc96872b8fbfb2344bf585efbd5c18771 100644 (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;
index b745cd3c35f7f85071301d18f643c9a6839b98e3..2fbfa4b315f68f2354f8671eaefc1cf59d38f666 100644 (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 );
index 978dd19af89526d0360dbffff24b012ac2912ff5..b5b2f3d1e661b180962917607614e7a74be17893 100644 (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;
index b23c421f1e9fd2630f69357140de7b0409f02fce..ef6a46d4a794a89d06172f594a7dc54205fdf196 100644 (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;
index b90fcd0e43fb1d45193b9d4671ff1ccfe7a2394c..5235a836214ea8b8d1aea0213cf981599937e748 100644 (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 ) );
index 56bf2a29b21bdf7d51abf6d18dca544022268a49..93fac07d835677b577a9e535fe8af7dda1889e94 100644 (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;
index 0a7c1aeb09d2decf3d8ca02dffb20f07ecd55d58..1d1b28723e439811b4feee7f53799d3cc531315d 100644 (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;
index bb1f753a5873be41d5bd937517662e5e2200a268..162635dfc29065a2784b152476915d7c5b4087e4 100644 (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;
index db194b0ce655e84df566ba587513660f7b1515ff..9a066cda38739c89f23896f204969775c0ba5526 100644 (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 *));
index e08400462fff20756c570216575938792c46574c..7b43c706d435fb7fb5f4957c7211de9d5199d931 100644 (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;
index 4a37dd4d02dd4fce12f7bf720a164bb1ce75e17a..16ab5ce27d7253027d145d36376b7673eeb23c5d 100644 (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; \
index f8573b5ed5ea7369cadada8abe35d4f924a9f006..99b5afa5d2ba35c4039a77b52a7865587ba04064 100644 (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;
index 72daa638c6b8e7fd212f1841ec7f15534755008b..a39ad0b9f4bacf6f2e58c4857dddb3e00f7612c2 100644 (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 ||
index 3a4c304ff940215166bdd4c3d5e7b21c4e5a8ffd..92799ac0c9d4c5ff06b99e3522744c93809d15fd 100644 (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;
 
index 27374322cb156e7d1250fb999a75f3897c5646dd..0d31168fbaa7a76317de94e8dd38c904d9385792 100644 (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;
index c1e16487dcbada8619bdceee53be332adc47aa38..e68d7dabd7b3882ce828ba3f452038d6114b5c39 100644 (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;