From: Howard Chu Date: Fri, 9 Sep 2011 05:07:04 +0000 (-0700) Subject: Use tmpmem-based entries X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f72d65b77aa6cd4439ee0ad80b498f4ed707a278;p=openldap Use tmpmem-based entries --- diff --git a/servers/slapd/back-mdb/add.c b/servers/slapd/back-mdb/add.c index 7822b9fcf0..652bb1009b 100644 --- a/servers/slapd/back-mdb/add.c +++ b/servers/slapd/back-mdb/add.c @@ -146,7 +146,7 @@ txnReturn: switch( rs->sr_err ) { case 0: rs->sr_err = LDAP_ALREADY_EXISTS; - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; goto return_results; case MDB_NOTFOUND: @@ -175,7 +175,7 @@ txnReturn: rs->sr_ref = NULL; } if ( p != (Entry *)&slap_entry_root ) - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_add) ": parent " @@ -191,7 +191,7 @@ txnReturn: if ( ! rs->sr_err ) { if ( p != (Entry *)&slap_entry_root ) - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; Debug( LDAP_DEBUG_TRACE, @@ -204,7 +204,7 @@ txnReturn: if ( p != (Entry *)&slap_entry_root ) { if ( is_entry_subentry( p ) ) { - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; /* parent is a subentry, don't allow add */ Debug( LDAP_DEBUG_TRACE, @@ -216,7 +216,7 @@ txnReturn: } if ( is_entry_alias( p ) ) { - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; /* parent is an alias, don't allow add */ Debug( LDAP_DEBUG_TRACE, @@ -235,7 +235,7 @@ txnReturn: rs->sr_ref = referral_rewrite( ref, &p->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); ber_bvarray_free( ref ); - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_add) ": parent is referral\n", @@ -277,7 +277,7 @@ txnReturn: } } - mdb_entry_return( p ); + mdb_entry_return( op, p ); } p = NULL; diff --git a/servers/slapd/back-mdb/bind.c b/servers/slapd/back-mdb/bind.c index fe34954632..b828406ca9 100644 --- a/servers/slapd/back-mdb/bind.c +++ b/servers/slapd/back-mdb/bind.c @@ -141,7 +141,7 @@ done: } /* free entry and reader lock */ if( e != NULL ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } if ( rs->sr_err ) { diff --git a/servers/slapd/back-mdb/compare.c b/servers/slapd/back-mdb/compare.c index 9bb05dc53c..c5c45d256b 100644 --- a/servers/slapd/back-mdb/compare.c +++ b/servers/slapd/back-mdb/compare.c @@ -77,7 +77,7 @@ mdb_compare( Operation *op, SlapReply *rs ) } rs->sr_err = LDAP_REFERRAL; } - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; } else { @@ -133,7 +133,7 @@ done: } /* free entry */ if ( e != NULL ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } return rs->sr_err; diff --git a/servers/slapd/back-mdb/delete.c b/servers/slapd/back-mdb/delete.c index 01c31f183f..a557fc05bc 100644 --- a/servers/slapd/back-mdb/delete.c +++ b/servers/slapd/back-mdb/delete.c @@ -151,7 +151,7 @@ txnReturn: &op->o_req_dn, LDAP_SCOPE_DEFAULT ); } if ( p ) { - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; } @@ -192,7 +192,7 @@ txnReturn: } else { rs->sr_ref = NULL; } - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; rs->sr_err = LDAP_REFERRAL; @@ -392,7 +392,7 @@ txnReturn: } parent_is_leaf = 1; } - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; } @@ -435,12 +435,12 @@ return_results: } if ( p != NULL ) { - mdb_entry_return( p ); + mdb_entry_return( op, p ); } /* free entry */ if( e != NULL ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } if( moi == &opinfo ) { diff --git a/servers/slapd/back-mdb/id2entry.c b/servers/slapd/back-mdb/id2entry.c index 24e934cf47..e6c389ee34 100644 --- a/servers/slapd/back-mdb/id2entry.c +++ b/servers/slapd/back-mdb/id2entry.c @@ -23,6 +23,7 @@ #include "back-mdb.h" static int mdb_entry_encode(Operation *op, MDB_txn *txn, Entry *e, MDB_val *data); +static Entry *mdb_entry_alloc( Operation *op, int nattrs, int nvals ); static int mdb_id2entry_put( Operation *op, @@ -101,12 +102,28 @@ int mdb_id2entry( /* Looking for root entry on an empty-dn suffix? */ if ( !id && BER_BVISEMPTY( &op->o_bd->be_nsuffix[0] )) { struct berval gluebv = BER_BVC("glue"); - Entry *r = entry_alloc(); + Entry *r = mdb_entry_alloc(op, 2, 4); + Attribute *a = r->e_attrs; + struct berval *bptr; r->e_id = 0; - attr_merge_one( r, slap_schema.si_ad_objectClass, &gluebv, NULL ); - attr_merge_one( r, slap_schema.si_ad_structuralObjectClass, &gluebv, NULL ); r->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END; + bptr = a->a_vals; + a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS; + a->a_desc = slap_schema.si_ad_objectClass; + a->a_nvals = a->a_vals; + a->a_numvals = 1; + *bptr++ = gluebv; + BER_BVZERO(bptr); + bptr++; + a = a->a_next; + a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS; + a->a_desc = slap_schema.si_ad_structuralObjectClass; + a->a_vals = bptr; + a->a_nvals = a->a_vals; + a->a_numvals = 1; + *bptr++ = gluebv; + BER_BVZERO(bptr); *e = r; return MDB_SUCCESS; } @@ -142,11 +159,52 @@ int mdb_id2entry_delete( return rc; } +static Attribute * mdb_attrs_alloc( + Operation *op, + int nattrs, + int nvals ) +{ + Attribute *a, *s; + + if (!nattrs || !nvals) return NULL; + + s = op->o_tmpalloc( nattrs * sizeof(Attribute) + + nvals * sizeof(struct berval), op->o_tmpmemctx ); + + for (a=s; nattrs>1; nattrs--) { + a->a_next = a+1; + a++; + } + a->a_next = NULL; + s->a_vals = (struct berval *)(a+1); + return s; +} + +static Entry * mdb_entry_alloc( + Operation *op, + int nattrs, + int nvals ) +{ + Entry *e = op->o_tmpalloc( sizeof(Entry), op->o_tmpmemctx ); + BER_BVZERO(&e->e_bv); + e->e_attrs = mdb_attrs_alloc( op, nattrs, nvals ); + e->e_private = e; + return e; +} + int mdb_entry_return( + Operation *op, Entry *e ) { - entry_free( e ); + if ( e->e_private ) { + op->o_tmpfree( e->e_nname.bv_val, op->o_tmpmemctx ); + op->o_tmpfree( e->e_name.bv_val, op->o_tmpmemctx ); + op->o_tmpfree( e->e_attrs, op->o_tmpmemctx ); + op->o_tmpfree( e, op->o_tmpmemctx ); + } else { + entry_free( e ); + } return 0; } @@ -162,7 +220,7 @@ int mdb_entry_release( /* slapMode : SLAP_SERVER_MODE, SLAP_TOOL_MODE, SLAP_TRUNCATE_MODE, SLAP_UNDEFINED_MODE */ - mdb_entry_return ( e ); + mdb_entry_return( op, e ); if ( slapMode == SLAP_SERVER_MODE ) { OpExtra *oex; LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) { @@ -256,7 +314,7 @@ return_results: if( rc != LDAP_SUCCESS ) { /* free entry */ if ( e ) - mdb_entry_return( e ); + mdb_entry_return( op, e ); if (moi->moi_ref == 1) { LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next ); @@ -582,14 +640,13 @@ int mdb_entry_decode(Operation *op, MDB_val *data, Entry **e) nattrs = mdb_entry_getlen(&ptr); nvals = mdb_entry_getlen(&ptr); - x = entry_alloc(); + x = mdb_entry_alloc(op, nattrs, nvals); x->e_ocflags = mdb_entry_getlen(&ptr); - x->e_attrs = attrs_alloc( nattrs ); - x->e_bv.bv_len = nvals * sizeof(struct berval); - x->e_bv.bv_val = op->o_tmpalloc(x->e_bv.bv_len, op->o_tmpmemctx); - bptr = (BerVarray) x->e_bv.bv_val; - + if (!nvals) { + goto done; + } a = x->e_attrs; + bptr = a->a_vals; while ((i = mdb_entry_getlen(&ptr))) { a->a_desc = mdb->mi_ads[i]; @@ -645,6 +702,7 @@ int mdb_entry_decode(Operation *op, MDB_val *data, Entry **e) if ( !nattrs ) break; } +done: Debug(LDAP_DEBUG_TRACE, "<= mdb_entry_decode\n", 0, 0, 0 ); diff --git a/servers/slapd/back-mdb/modify.c b/servers/slapd/back-mdb/modify.c index c577ea9173..91ece764b8 100644 --- a/servers/slapd/back-mdb/modify.c +++ b/servers/slapd/back-mdb/modify.c @@ -89,7 +89,7 @@ int mdb_modify_internal( return LDAP_INSUFFICIENT_ACCESS; } - /* save_attrs will be disposed of by mdb_cache_modify */ + /* save_attrs will be disposed of by caller */ save_attrs = e->e_attrs; e->e_attrs = attrs_dup( e->e_attrs ); @@ -514,7 +514,7 @@ txnReturn: } else { rs->sr_ref = NULL; } - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; } else { @@ -675,7 +675,7 @@ done: } if( e != NULL ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) { diff --git a/servers/slapd/back-mdb/modrdn.c b/servers/slapd/back-mdb/modrdn.c index b628c259b5..08d615e261 100644 --- a/servers/slapd/back-mdb/modrdn.c +++ b/servers/slapd/back-mdb/modrdn.c @@ -219,7 +219,7 @@ txnReturn: } else { rs->sr_ref = NULL; } - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; } else { @@ -534,7 +534,7 @@ txnReturn: } parent_is_leaf = 1; } - mdb_entry_return( p ); + mdb_entry_return( op, p ); p = NULL; } @@ -621,17 +621,17 @@ done: /* LDAP v3 Support */ if( np != NULL ) { /* free new parent */ - mdb_entry_return( np ); + mdb_entry_return( op, np ); } if( p != NULL ) { /* free parent */ - mdb_entry_return( p ); + mdb_entry_return( op, p ); } /* free entry */ if( e != NULL ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } if( moi == &opinfo ) { diff --git a/servers/slapd/back-mdb/proto-mdb.h b/servers/slapd/back-mdb/proto-mdb.h index 294aed9af0..b2fe351815 100644 --- a/servers/slapd/back-mdb/proto-mdb.h +++ b/servers/slapd/back-mdb/proto-mdb.h @@ -170,8 +170,7 @@ int mdb_id2entry( ID id, Entry **e); -void mdb_entry_free ( Entry *e ); -int mdb_entry_return( Entry *e ); +int mdb_entry_return( Operation *op, Entry *e ); BI_entry_release_rw mdb_entry_release; BI_entry_get_rw mdb_entry_get; diff --git a/servers/slapd/back-mdb/referral.c b/servers/slapd/back-mdb/referral.c index be74c48492..44148b804e 100644 --- a/servers/slapd/back-mdb/referral.c +++ b/servers/slapd/back-mdb/referral.c @@ -91,7 +91,7 @@ mdb_referrals( Operation *op, SlapReply *rs ) } } - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; } @@ -144,6 +144,6 @@ done: LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next ); } if ( e ) - mdb_entry_return( e ); + mdb_entry_return( op, e ); return rc; } diff --git a/servers/slapd/back-mdb/search.c b/servers/slapd/back-mdb/search.c index 94ade1433a..a457dd57ce 100644 --- a/servers/slapd/back-mdb/search.c +++ b/servers/slapd/back-mdb/search.c @@ -107,7 +107,7 @@ static Entry * deref_base ( /* Free the previous entry, continue to work with the * one we just retrieved. */ - mdb_entry_return( *matched ); + mdb_entry_return( op, *matched ); /* We found a regular entry. Return this to the caller. */ @@ -179,7 +179,7 @@ static int search_aliases( if (first) { first = 0; } else { - mdb_entry_return( e ); + mdb_entry_return( op, e ); } /* Dereference all of the aliases in the current scope. */ @@ -196,7 +196,7 @@ static int search_aliases( * turned into a range that spans IDs indiscriminately */ if (!is_entry_alias(a)) { - mdb_entry_return (a); + mdb_entry_return(op, a); continue; } @@ -211,13 +211,13 @@ static int search_aliases( if (mdb_idl_insert(scopes, a->e_id) == 0) { mdb_idl_insert(newsubs, a->e_id); } - mdb_entry_return( a ); + mdb_entry_return( op, a ); } else if (matched) { /* Alias could not be dereferenced, or it deref'd to * an ID we've already seen. Ignore it. */ - mdb_entry_return( matched ); + mdb_entry_return( op, matched ); rs->sr_text = NULL; } } @@ -348,7 +348,7 @@ dn2entry_retry: if ( e ) { build_new_dn( &op->o_req_ndn, &e->e_nname, &stub, op->o_tmpmemctx ); - mdb_entry_return (e); + mdb_entry_return(op, e); matched = NULL; goto dn2entry_retry; } @@ -383,7 +383,7 @@ dn2entry_retry: rs->sr_matched = matched_dn.bv_val; } - mdb_entry_return (matched); + mdb_entry_return(op, matched); matched = NULL; if ( erefs ) { @@ -422,7 +422,7 @@ dn2entry_retry: rs->sr_err = LDAP_INSUFFICIENT_ACCESS; } - mdb_entry_return(e); + mdb_entry_return( op,e); send_ldap_result( op, rs ); goto done; } @@ -437,7 +437,7 @@ dn2entry_retry: rs->sr_err = LDAP_REFERRAL; - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; if ( erefs ) { @@ -468,7 +468,7 @@ dn2entry_retry: ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE )) { rs->sr_err = LDAP_ASSERTION_FAILED; - mdb_entry_return(e); + mdb_entry_return( op,e); send_ldap_result( op, rs ); goto done; } @@ -766,7 +766,7 @@ loop_begin: send_search_reference( op, rs ); - mdb_entry_return( e ); + mdb_entry_return( op, e ); rs->sr_entry = NULL; e = NULL; @@ -784,7 +784,7 @@ loop_begin: /* check size limit */ if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) { if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) { - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; send_paged_response( op, rs, &lastid, tentries ); goto done; @@ -805,7 +805,7 @@ loop_begin: rs->sr_attrs = NULL; rs->sr_entry = NULL; if (e != base) - mdb_entry_return( e ); + mdb_entry_return( op, e ); e = NULL; switch ( rs->sr_err ) { @@ -837,7 +837,7 @@ loop_begin: loop_continue: if( e != NULL ) { if ( e != base ) - mdb_entry_return( e ); + mdb_entry_return( op, e ); RS_ASSERT( rs->sr_entry == NULL ); e = NULL; rs->sr_entry = NULL; @@ -869,7 +869,7 @@ done: rs->sr_v2ref = NULL; } if (base) - mdb_entry_return(base); + mdb_entry_return( op,base); return rs->sr_err; } diff --git a/servers/slapd/back-mdb/tools.c b/servers/slapd/back-mdb/tools.c index 75a2951f59..92130ab1a8 100644 --- a/servers/slapd/back-mdb/tools.c +++ b/servers/slapd/back-mdb/tools.c @@ -310,7 +310,7 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep ) rc = mdb_id2name( &op, txn, &idcursor, id, &dn, &ndn ); if ( rc ) { rc = LDAP_OTHER; - mdb_entry_return( e ); + mdb_entry_return( &op, e ); e = NULL; goto done; }