From 4097d261bb5e5437c7069595821922d5da716821 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 14 Mar 2008 16:49:53 +0000 Subject: [PATCH] Use macros for prev commit --- servers/slapd/add.c | 20 ++++++--- servers/slapd/backend.c | 74 ++++++++++++++----------------- servers/slapd/operation.c | 13 ------ servers/slapd/overlays/syncprov.c | 9 ++-- servers/slapd/proto-slap.h | 1 - servers/slapd/slap.h | 13 +++++- servers/slapd/slapi/slapi_ops.c | 16 ++++--- 7 files changed, 76 insertions(+), 70 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index aed74d39a2..2561152d0b 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -48,6 +48,7 @@ do_add( Operation *op, SlapReply *rs ) size_t textlen = sizeof( textbuf ); int rc = 0; int freevals = 1; + OpExtraDB oex; Debug( LDAP_DEBUG_TRACE, "%s do_add\n", op->o_log_prefix, 0, 0 ); @@ -185,8 +186,13 @@ do_add( Operation *op, SlapReply *rs ) freevals = 0; + oex.oe.oe_key = (void *)do_add; + oex.oe_db = NULL; + LDAP_SLIST_INSERT_HEAD(&op->o_extra, &oex.oe, oe_next); + op->o_bd = frontendDB; rc = frontendDB->be_add( op, rs ); + LDAP_SLIST_REMOVE(&op->o_extra, &oex.oe, OpExtra, oe_next); #ifdef LDAP_X_TXN if ( rc == LDAP_X_TXN_SPECIFY_OKAY ) { @@ -195,17 +201,15 @@ do_add( Operation *op, SlapReply *rs ) } else #endif if ( rc == 0 ) { - if ( op->ora_e != NULL && op->o_private != NULL ) { + if ( op->ora_e != NULL && oex.oe_db != NULL ) { BackendDB *bd = op->o_bd; - op->o_bd = (BackendDB *)op->o_private; - op->o_private = NULL; + op->o_bd = oex.oe_db; be_entry_release_w( op, op->ora_e ); op->ora_e = NULL; op->o_bd = bd; - op->o_private = NULL; } } @@ -329,11 +333,17 @@ fe_op_add( Operation *op, SlapReply *rs ) rc = op->o_bd->be_add( op, rs ); if ( rc == LDAP_SUCCESS ) { + OpExtra *oex; /* NOTE: be_entry_release_w() is * called by do_add(), so that global * overlays on the way back can * at least read the entry */ - op->o_private = op->o_bd; + LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) { + if ( oex->oe_key == (void *)do_add ) { + ((OpExtraDB *)oex)->oe_db = op->o_bd; + break; + } + } } } else { diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 22db58fdaf..fb92cf6f7f 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -1335,11 +1335,6 @@ be_entry_get_rw( return LDAP_UNWILLING_TO_PERFORM; } -typedef struct fe_extra { - OpExtra fe_oe; - BackendDB *fe_be; -} fe_extra; - int fe_acl_group( Operation *op, @@ -1355,15 +1350,15 @@ fe_acl_group( int rc; GroupAssertion *g; Backend *be = op->o_bd; - fe_extra *fex; + OpExtra *oex; - for ( fex = (fe_extra *)op->o_extra; fex; fex = (fe_extra *)fex->fe_oe.oe_next ) { - if ( fex->fe_oe.oe_key == (void *)backend_group ) + LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) { + if ( oex->oe_key == (void *)backend_group ) break; } - if ( fex && fex->fe_be ) - op->o_bd = fex->fe_be; + if ( oex && ((OpExtraDB *)oex)->oe_db ) + op->o_bd = ((OpExtraDB *)oex)->oe_db; else op->o_bd = select_backend( gr_ndn, 0 ); @@ -1572,26 +1567,25 @@ backend_group( { int rc; BackendDB *be_orig; - fe_extra fex; + OpExtraDB oex; if ( op->o_abandon ) { return SLAPD_ABANDON; } if ( op->o_bd && SLAP_ISOVERLAY( op->o_bd )) - fex.fe_be = op->o_bd->bd_orig; + oex.oe_db = op->o_bd->bd_orig; else - fex.fe_be = op->o_bd; - fex.fe_oe.oe_key = (void *)backend_group; - fex.fe_oe.oe_next = op->o_extra; - op->o_extra = (OpExtra *)&fex; + oex.oe_db = op->o_bd; + oex.oe.oe_key = (void *)backend_group; + LDAP_SLIST_INSERT_HEAD(&op->o_extra, &oex.oe, oe_next); be_orig = op->o_bd; op->o_bd = frontendDB; rc = frontendDB->be_group( op, target, gr_ndn, op_ndn, group_oc, group_at ); op->o_bd = be_orig; - slap_op_popextra( op, (OpExtra *)&fex ); + LDAP_SLIST_REMOVE(&op->o_extra, &oex.oe, OpExtra, oe_next); return rc; } @@ -1611,15 +1605,15 @@ fe_acl_attribute( int freeattr = 0, i, j, rc = LDAP_SUCCESS; AccessControlState acl_state = ACL_STATE_INIT; Backend *be = op->o_bd; - fe_extra *fex; + OpExtra *oex; - for ( fex = (fe_extra *)op->o_extra; fex; fex = (fe_extra *)fex->fe_oe.oe_next ) { - if ( fex->fe_oe.oe_key == (void *)backend_attribute ) + LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) { + if ( oex->oe_key == (void *)backend_attribute ) break; } - if ( fex && fex->fe_be ) - op->o_bd = fex->fe_be; + if ( oex && ((OpExtraDB *)oex)->oe_db ) + op->o_bd = ((OpExtraDB *)oex)->oe_db; else op->o_bd = select_backend( edn, 0 ); @@ -1741,22 +1735,21 @@ backend_attribute( { int rc; BackendDB *be_orig; - fe_extra fex; + OpExtraDB oex; if ( op->o_bd && SLAP_ISOVERLAY( op->o_bd )) - fex.fe_be = op->o_bd->bd_orig; + oex.oe_db = op->o_bd->bd_orig; else - fex.fe_be = op->o_bd; - fex.fe_oe.oe_key = (void *)backend_attribute; - fex.fe_oe.oe_next = op->o_extra; - op->o_extra = (OpExtra *)&fex; + oex.oe_db = op->o_bd; + oex.oe.oe_key = (void *)backend_attribute; + LDAP_SLIST_INSERT_HEAD(&op->o_extra, &oex.oe, oe_next); be_orig = op->o_bd; op->o_bd = frontendDB; rc = frontendDB->be_attribute( op, target, edn, entry_at, vals, access ); op->o_bd = be_orig; - slap_op_popextra( op, (OpExtra *)&fex ); + LDAP_SLIST_REMOVE(&op->o_extra, &oex.oe, OpExtra, oe_next); return rc; } @@ -1881,10 +1874,10 @@ fe_aux_operational( Attribute **ap; int rc = LDAP_SUCCESS; BackendDB *be_orig = op->o_bd; - fe_extra *fex; + OpExtra *oex; - for ( fex = (fe_extra *)op->o_extra; fex; fex = (fe_extra *)fex->fe_oe.oe_next ) { - if ( fex->fe_oe.oe_key == (void *)backend_operational ) + LDAP_SLIST_FOREACH(oex, &op->o_extra, oe_next) { + if ( oex->oe_key == (void *)backend_operational ) break; } @@ -1913,8 +1906,8 @@ fe_aux_operational( } /* Let the overlays have a chance at this */ - if ( fex && fex->fe_be ) { - op->o_bd = fex->fe_be; + if ( oex && ((OpExtraDB *)oex)->oe_db ) { + op->o_bd = ((OpExtraDB *)oex)->oe_db; } else { op->o_bd = select_backend( &op->o_req_ndn, 0 ); } @@ -1933,15 +1926,14 @@ int backend_operational( Operation *op, SlapReply *rs ) { int rc; BackendDB *be_orig; - fe_extra fex; + OpExtraDB oex; if ( op->o_bd && SLAP_ISOVERLAY( op->o_bd )) - fex.fe_be = op->o_bd->bd_orig; + oex.oe_db = op->o_bd->bd_orig; else - fex.fe_be = op->o_bd; - fex.fe_oe.oe_key = (void *)backend_operational; - fex.fe_oe.oe_next = op->o_extra; - op->o_extra = (OpExtra *)&fex; + oex.oe_db = op->o_bd; + oex.oe.oe_key = (void *)backend_operational; + LDAP_SLIST_INSERT_HEAD(&op->o_extra, &oex.oe, oe_next); /* Moved this into the frontend so global overlays are called */ @@ -1949,7 +1941,7 @@ int backend_operational( Operation *op, SlapReply *rs ) op->o_bd = frontendDB; rc = frontendDB->be_operational( op, rs ); op->o_bd = be_orig; - slap_op_popextra( op, (OpExtra *)&fex ); + LDAP_SLIST_REMOVE(&op->o_extra, &oex.oe, OpExtra, oe_next); return rc; } diff --git a/servers/slapd/operation.c b/servers/slapd/operation.c index c159313ab3..b3ec0372bc 100644 --- a/servers/slapd/operation.c +++ b/servers/slapd/operation.c @@ -184,19 +184,6 @@ slap_op_alloc( return( op ); } -void -slap_op_popextra( Operation *op, OpExtra *oe ) -{ - OpExtra **prev; - - for ( prev = &op->o_extra; *prev; prev = &(*prev)->oe_next ) { - if ( *prev == oe ) { - *prev = oe->oe_next; - break; - } - } -} - slap_op_t slap_req2op( ber_tag_t tag ) { diff --git a/servers/slapd/overlays/syncprov.c b/servers/slapd/overlays/syncprov.c index 1b42b79537..f6110b3da1 100644 --- a/servers/slapd/overlays/syncprov.c +++ b/servers/slapd/overlays/syncprov.c @@ -840,7 +840,7 @@ static int syncprov_qplay( Operation *op, struct re_s *rtask ) { syncops *so = rtask->arg; - slap_overinst *on = so->s_op->o_private; + slap_overinst *on = LDAP_SLIST_FIRST(&so->s_op->o_extra)->oe_key; syncres *sr; Entry *e; opcookie opc; @@ -933,7 +933,7 @@ syncprov_qtask( void *ctx, void *arg ) be = *so->s_op->o_bd; be.be_flags |= SLAP_DBFLAG_OVERLAY; op->o_bd = &be; - op->o_private = NULL; + LDAP_SLIST_FIRST(&op->o_extra) = NULL; op->o_callback = NULL; rc = syncprov_qplay( op, rtask ); @@ -1854,6 +1854,7 @@ syncprov_search_cleanup( Operation *op, SlapReply *rs ) typedef struct SyncOperationBuffer { Operation sob_op; Opheader sob_hdr; + OpExtra sob_oe; AttributeName sob_extra; /* not always present */ /* Further data allocated here */ } SyncOperationBuffer; @@ -1882,6 +1883,7 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on ) sopbuf2 = ch_calloc( 1, size ); op2 = &sopbuf2->sob_op; op2->o_hdr = &sopbuf2->sob_hdr; + LDAP_SLIST_FIRST(&op2->o_extra) = &sopbuf2->sob_oe; /* Copy the fields we care about explicitly, leave the rest alone */ *op2->o_hdr = *op->o_hdr; @@ -1889,7 +1891,8 @@ syncprov_detach_op( Operation *op, syncops *so, slap_overinst *on ) op2->o_time = op->o_time; op2->o_bd = on->on_info->oi_origdb; op2->o_request = op->o_request; - op2->o_private = on; + LDAP_SLIST_FIRST(&op2->o_extra)->oe_key = on; + LDAP_SLIST_NEXT(LDAP_SLIST_FIRST(&op2->o_extra), oe_next) = NULL; ptr = (char *) sopbuf2 + offsetof( SyncOperationBuffer, sob_extra ); if ( i ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 7c146fb836..0be103a967 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1395,7 +1395,6 @@ LDAP_SLAPD_F (Operation *) slap_op_alloc LDAP_P(( ber_tag_t tag, ber_int_t id, void *ctx )); LDAP_SLAPD_F (slap_op_t) slap_req2op LDAP_P(( ber_tag_t tag )); -LDAP_SLAPD_F (void) slap_op_popextra LDAP_P(( Operation *op, OpExtra *oe )); /* * operational.c diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 22abb59a61..7aa16a3b44 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -2467,11 +2467,20 @@ typedef union OpRequest { req_pwdexop_s oq_pwdexop; } OpRequest; +/* This is only a header. Actual users should define their own + * structs with the oe_next / oe_key fields at the top and + * whatever else they need following. + */ typedef struct OpExtra { - struct OpExtra *oe_next; + LDAP_SLIST_ENTRY(OpExtra) oe_next; void *oe_key; } OpExtra; +typedef struct OpExtraDB { + OpExtra oe; + BackendDB *oe_db; +} OpExtraDB; + struct Operation { Opheader *o_hdr; @@ -2665,7 +2674,7 @@ struct Operation { /* DEPRECATE o_private - use o_extra instead */ void *o_private; /* anything the backend needs */ - OpExtra *o_extra; /* anything the backend needs */ + LDAP_SLIST_HEAD(o_e, OpExtra) o_extra; /* anything the backend needs */ LDAP_STAILQ_ENTRY(Operation) o_next; /* next operation in list */ }; diff --git a/servers/slapd/slapi/slapi_ops.c b/servers/slapd/slapi/slapi_ops.c index 9080f174e5..e7aab5d8d3 100644 --- a/servers/slapd/slapi/slapi_ops.c +++ b/servers/slapd/slapi/slapi_ops.c @@ -419,6 +419,8 @@ slapi_add_internal_pb( Slapi_PBlock *pb ) { SlapReply *rs; Slapi_Entry *entry_orig = NULL; + OpExtraDB oex; + int rc; if ( pb == NULL ) { return -1; @@ -478,16 +480,20 @@ slapi_add_internal_pb( Slapi_PBlock *pb ) goto cleanup; } - if ( slapi_int_func_internal_pb( pb, op_add ) == 0 ) { - if ( pb->pb_op->ora_e != NULL && pb->pb_op->o_private != NULL ) { + oex.oe.oe_key = (void *)do_add; + oex.oe_db = NULL; + LDAP_SLIST_INSERT_HEAD(&pb->pb_op->o_extra, &oex.oe, oe_next); + rc = slapi_int_func_internal_pb( pb, op_add ); + LDAP_SLIST_REMOVE(&pb->pb_op->o_extra, &oex.oe, OpExtra, oe_next); + + if ( !rc ) { + if ( pb->pb_op->ora_e != NULL && oex.oe_db != NULL ) { BackendDB *bd = pb->pb_op->o_bd; - pb->pb_op->o_bd = (BackendDB *)pb->pb_op->o_private; - pb->pb_op->o_private = NULL; + pb->pb_op->o_bd = oex.oe_db; be_entry_release_w( pb->pb_op, pb->pb_op->ora_e ); pb->pb_op->ora_e = NULL; pb->pb_op->o_bd = bd; - pb->pb_op->o_private = NULL; } } -- 2.39.5