From: Howard Chu Date: Thu, 14 Aug 2014 03:49:05 +0000 (-0700) Subject: ITS#7920 fix for slapacl X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=27f3ef2cfdc172c065c112b4d1a37c8e93f149bc;p=openldap ITS#7920 fix for slapacl This needs to be streamlined in 2.5, current tool API is a mess. --- diff --git a/servers/slapd/back-mdb/id2entry.c b/servers/slapd/back-mdb/id2entry.c index cb4fb85aff..6cbeaf88fb 100644 --- a/servers/slapd/back-mdb/id2entry.c +++ b/servers/slapd/back-mdb/id2entry.c @@ -399,6 +399,8 @@ mdb_reader_flush( MDB_env *env ) } } +extern MDB_txn *mdb_tool_txn; + int mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **moip ) { @@ -455,18 +457,26 @@ mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **m } moi->moi_ref++; if ( !moi->moi_txn ) { - rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &moi->moi_txn ); - if (rc) { - Debug( LDAP_DEBUG_ANY, "mdb_opinfo_get: err %s(%d)\n", - mdb_strerror(rc), rc, 0 ); + if (( slapMode & SLAP_TOOL_MODE ) && mdb_tool_txn ) { + moi->moi_txn = mdb_tool_txn; + } else { + rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &moi->moi_txn ); + if (rc) { + Debug( LDAP_DEBUG_ANY, "mdb_opinfo_get: err %s(%d)\n", + mdb_strerror(rc), rc, 0 ); + } + return rc; } - return rc; } return 0; } /* OK, this is a reader */ if ( !moi->moi_txn ) { + if (( slapMode & SLAP_TOOL_MODE ) && mdb_tool_txn ) { + moi->moi_txn = mdb_tool_txn; + goto ok; + } if ( !ctx ) { /* Shouldn't happen unless we're single-threaded */ rc = mdb_txn_begin( mdb->mi_dbenv, NULL, MDB_RDONLY, &moi->moi_txn ); @@ -498,6 +508,7 @@ mdb_opinfo_get( Operation *op, struct mdb_info *mdb, int rdonly, mdb_op_info **m } moi->moi_flag |= MOI_READER; } +ok: if ( moi->moi_ref < 1 ) { moi->moi_ref = 0; } diff --git a/servers/slapd/back-mdb/tools.c b/servers/slapd/back-mdb/tools.c index 0839d56784..a84de6f4c8 100644 --- a/servers/slapd/back-mdb/tools.c +++ b/servers/slapd/back-mdb/tools.c @@ -50,7 +50,9 @@ typedef struct mdb_tool_idl_cache { #define MDB_TOOL_IDL_FLUSH(be, txn) #endif /* MDB_TOOL_IDL_CACHING */ -static MDB_txn *txn = NULL, *txi = NULL; +MDB_txn *mdb_tool_txn = NULL; + +static MDB_txn *txi = NULL; static MDB_cursor *cursor = NULL, *idcursor = NULL; static MDB_cursor *mcp = NULL, *mcd = NULL; static MDB_val key, data; @@ -196,16 +198,16 @@ int mdb_tool_entry_close( mdb_cursor_close( cursor ); cursor = NULL; } - if( txn ) { + if( mdb_tool_txn ) { int rc; - if (( rc = mdb_txn_commit( txn ))) { + if (( rc = mdb_txn_commit( mdb_tool_txn ))) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(mdb_tool_entry_close) ": database %s: " "txn_commit failed: %s (%d)\n", be->be_suffix[0].bv_val, mdb_strerror(rc), rc ); return -1; } - txn = NULL; + mdb_tool_txn = NULL; } if( nholes ) { @@ -249,13 +251,13 @@ ID mdb_tool_entry_next( mdb = (struct mdb_info *) be->be_private; assert( mdb != NULL ); - if ( !txn ) { - rc = mdb_txn_begin( mdb->mi_dbenv, NULL, MDB_RDONLY, &txn ); + if ( !mdb_tool_txn ) { + rc = mdb_txn_begin( mdb->mi_dbenv, NULL, MDB_RDONLY, &mdb_tool_txn ); if ( rc ) return NOID; - rc = mdb_cursor_open( txn, mdb->mi_id2entry, &cursor ); + rc = mdb_cursor_open( mdb_tool_txn, mdb->mi_id2entry, &cursor ); if ( rc ) { - mdb_txn_abort( txn ); + mdb_txn_abort( mdb_tool_txn ); return NOID; } } @@ -321,9 +323,9 @@ ID mdb_tool_dn2id_get( mdb = (struct mdb_info *) be->be_private; - if ( !txn ) { + if ( !mdb_tool_txn ) { rc = mdb_txn_begin( mdb->mi_dbenv, NULL, (slapMode & SLAP_TOOL_READONLY) != 0 ? - MDB_RDONLY : 0, &txn ); + MDB_RDONLY : 0, &mdb_tool_txn ); if ( rc ) return NOID; } @@ -333,7 +335,7 @@ ID mdb_tool_dn2id_get( op.o_tmpmemctx = NULL; op.o_tmpmfuncs = &ch_mfuncs; - rc = mdb_dn2id( &op, txn, NULL, dn, &id, NULL, NULL, NULL ); + rc = mdb_dn2id( &op, mdb_tool_txn, NULL, dn, &id, NULL, NULL, NULL ); if ( rc == MDB_NOTFOUND ) return NOID; @@ -378,7 +380,7 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep ) op.o_tmpmemctx = NULL; op.o_tmpmfuncs = &ch_mfuncs; if ( slapMode & SLAP_TOOL_READONLY ) { - rc = mdb_id2name( &op, txn, &idcursor, id, &dn, &ndn ); + rc = mdb_id2name( &op, mdb_tool_txn, &idcursor, id, &dn, &ndn ); if ( rc ) { rc = LDAP_OTHER; if ( e ) { @@ -396,7 +398,7 @@ mdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep ) } } } - rc = mdb_entry_decode( &op, txn, &data, &e ); + rc = mdb_entry_decode( &op, mdb_tool_txn, &data, &e ); e->e_id = id; if ( !BER_BVISNULL( &dn )) { e->e_name = dn; @@ -420,19 +422,19 @@ mdb_tool_entry_get( BackendDB *be, ID id ) Entry *e = NULL; int rc; - if ( !txn ) { + if ( !mdb_tool_txn ) { struct mdb_info *mdb = (struct mdb_info *) be->be_private; rc = mdb_txn_begin( mdb->mi_dbenv, NULL, - (slapMode & SLAP_TOOL_READONLY) ? MDB_RDONLY : 0, &txn ); + (slapMode & SLAP_TOOL_READONLY) ? MDB_RDONLY : 0, &mdb_tool_txn ); if ( rc ) return NULL; } if ( !cursor ) { struct mdb_info *mdb = (struct mdb_info *) be->be_private; - rc = mdb_cursor_open( txn, mdb->mi_id2entry, &cursor ); + rc = mdb_cursor_open( mdb_tool_txn, mdb->mi_id2entry, &cursor ); if ( rc ) { - mdb_txn_abort( txn ); - txn = NULL; + mdb_txn_abort( mdb_tool_txn ); + mdb_tool_txn = NULL; return NULL; } } @@ -648,8 +650,8 @@ ID mdb_tool_entry_put( mdb = (struct mdb_info *) be->be_private; - if ( !txn ) { - rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &txn ); + if ( !mdb_tool_txn ) { + rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &mdb_tool_txn ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "txn_begin failed: %s (%d)", @@ -659,7 +661,7 @@ ID mdb_tool_entry_put( text->bv_val, 0, 0 ); return NOID; } - rc = mdb_cursor_open( txn, mdb->mi_id2entry, &idcursor ); + rc = mdb_cursor_open( mdb_tool_txn, mdb->mi_id2entry, &idcursor ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "cursor_open failed: %s (%d)", @@ -673,7 +675,7 @@ ID mdb_tool_entry_put( ID dummy; mdb_next_id( be, idcursor, &dummy ); } - rc = mdb_cursor_open( txn, mdb->mi_dn2id, &mcp ); + rc = mdb_cursor_open( mdb_tool_txn, mdb->mi_dn2id, &mcp ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "cursor_open failed: %s (%d)", @@ -683,7 +685,7 @@ ID mdb_tool_entry_put( text->bv_val, 0, 0 ); return NOID; } - rc = mdb_cursor_open( txn, mdb->mi_dn2id, &mcd ); + rc = mdb_cursor_open( mdb_tool_txn, mdb->mi_dn2id, &mcd ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "cursor_open failed: %s (%d)", @@ -701,7 +703,7 @@ ID mdb_tool_entry_put( op.o_tmpmfuncs = &ch_mfuncs; /* add dn2id indices */ - rc = mdb_tool_next_id( &op, txn, e, text, 0 ); + rc = mdb_tool_next_id( &op, mdb_tool_txn, e, text, 0 ); if( rc != 0 ) { goto done; } @@ -709,7 +711,7 @@ ID mdb_tool_entry_put( if ( mdb_tool_threads > 1 ) { LDAP_SLIST_INSERT_HEAD( &op.o_extra, &mdb_tool_axinfo[0]->ai_oe, oe_next ); } - rc = mdb_tool_index_add( &op, txn, e ); + rc = mdb_tool_index_add( &op, mdb_tool_txn, e ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "index_entry_add failed: err=%d", rc ); @@ -721,7 +723,7 @@ ID mdb_tool_entry_put( /* id2entry index */ - rc = mdb_id2entry_add( &op, txn, idcursor, e ); + rc = mdb_id2entry_add( &op, mdb_tool_txn, idcursor, e ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "id2entry_add failed: err=%d", rc ); @@ -739,12 +741,12 @@ done: mdb_writes++; if ( mdb_writes >= mdb_writes_per_commit ) { unsigned i; - MDB_TOOL_IDL_FLUSH( be, txn ); - rc = mdb_txn_commit( txn ); + MDB_TOOL_IDL_FLUSH( be, mdb_tool_txn ); + rc = mdb_txn_commit( mdb_tool_txn ); for ( i=0; imi_nattrs; i++ ) mdb->mi_attrs[i]->ai_cursor = NULL; mdb_writes = 0; - txn = NULL; + mdb_tool_txn = NULL; idcursor = NULL; if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, @@ -759,8 +761,8 @@ done: } else { unsigned i; - mdb_txn_abort( txn ); - txn = NULL; + mdb_txn_abort( mdb_tool_txn ); + mdb_tool_txn = NULL; idcursor = NULL; for ( i=0; imi_nattrs; i++ ) mdb->mi_attrs[i]->ai_cursor = NULL; @@ -926,10 +928,10 @@ done: mdb_cursor_close( cursor ); txi = NULL; /* Must close the read txn to allow old pages to be reclaimed. */ - mdb_txn_abort( txn ); + mdb_txn_abort( mdb_tool_txn ); /* and then reopen it so that tool_entry_next still works. */ - mdb_txn_begin( mi->mi_dbenv, NULL, MDB_RDONLY, &txn ); - mdb_cursor_open( txn, mi->mi_id2entry, &cursor ); + mdb_txn_begin( mi->mi_dbenv, NULL, MDB_RDONLY, &mdb_tool_txn ); + mdb_cursor_open( mdb_tool_txn, mi->mi_id2entry, &cursor ); key.mv_data = &id; key.mv_size = sizeof(ID); mdb_cursor_get( cursor, &key, NULL, MDB_SET ); @@ -984,8 +986,8 @@ ID mdb_tool_entry_modify( mdb_cursor_close( cursor ); cursor = NULL; } - if ( !txn ) { - rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &txn ); + if ( !mdb_tool_txn ) { + rc = mdb_txn_begin( mdb->mi_dbenv, NULL, 0, &mdb_tool_txn ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "txn_begin failed: %s (%d)", @@ -1003,7 +1005,7 @@ ID mdb_tool_entry_modify( op.o_tmpmfuncs = &ch_mfuncs; /* id2entry index */ - rc = mdb_id2entry_update( &op, txn, NULL, e ); + rc = mdb_id2entry_update( &op, mdb_tool_txn, NULL, e ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "id2entry_update failed: err=%d", rc ); @@ -1015,7 +1017,7 @@ ID mdb_tool_entry_modify( done: if( rc == 0 ) { - rc = mdb_txn_commit( txn ); + rc = mdb_txn_commit( mdb_tool_txn ); if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, "txn_commit failed: %s (%d)", @@ -1027,7 +1029,7 @@ done: } } else { - mdb_txn_abort( txn ); + mdb_txn_abort( mdb_tool_txn ); snprintf( text->bv_val, text->bv_len, "txn_aborted! %s (%d)", mdb_strerror(rc), rc ); @@ -1036,7 +1038,7 @@ done: text->bv_val, 0, 0 ); e->e_id = NOID; } - txn = NULL; + mdb_tool_txn = NULL; idcursor = NULL; return e->e_id;