Entry * wt_tool_entry_get( BackendDB *be, ID id ) { Entry *e = NULL; static EntryHeader eh; int rc, eoff; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); rc = wt_entry_header( &item, &eh ); assert( rc == 0 ); eoff = eh.data - (char *)item.data; eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size; eh.bv.bv_val = ch_realloc( eh.bv.bv_val, eh.bv.bv_len ); memset(eh.bv.bv_val, 0xff, eh.bv.bv_len); eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval ); memcpy(eh.data, item.data, item.size); eh.data += eoff; rc = entry_decode( &eh, &e ); assert( rc == 0 ); if( rc == LDAP_SUCCESS ) { e->e_id = id; } return e; }
int wt_id2entry( BackendDB *be, WT_SESSION *session, ID id, Entry **ep ){ int rc; WT_CURSOR *cursor = NULL; WT_ITEM item; EntryHeader eh; int eoff; Entry *e = NULL; rc = session->open_cursor(session, WT_TABLE_ID2ENTRY"(entry)", NULL, NULL, &cursor); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry) ": open_cursor failed: %s (%d)\n", wiredtiger_strerror(rc), rc, 0 ); goto done; } cursor->set_key(cursor, id); rc = cursor->search(cursor); if ( rc ) { goto done; } cursor->get_value(cursor, &item); rc = wt_entry_header( &item, &eh ); eoff = eh.data - (char *)item.data; eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + item.size; eh.bv.bv_val = ch_malloc( eh.bv.bv_len ); memset(eh.bv.bv_val, 0xff, eh.bv.bv_len); eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval ); memcpy(eh.data, item.data, item.size); eh.data += eoff; rc = entry_decode( &eh, &e ); if ( rc ) { Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(wt_id2entry) ": entry decode error: %s (%d)\n", rc, 0, 0 ); goto done; } e->e_id = id; *ep = e; done: if(cursor){ cursor->close(cursor); } return rc; }
static int bdb_tool_entry_get_int( BackendDB *be, ID id, Entry **ep ) { Entry *e = NULL; char *dptr; int rc, eoff; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); if ( ( tool_filter || tool_base ) && id == previd && tool_next_entry != NULL ) { *ep = tool_next_entry; tool_next_entry = NULL; return LDAP_SUCCESS; } if ( id != previd ) { data.ulen = data.dlen = sizeof( ehbuf ); data.data = ehbuf; data.flags |= DB_DBT_PARTIAL; BDB_ID2DISK( id, &nid ); rc = cursor->c_get( cursor, &key, &data, DB_SET ); if ( rc ) { rc = LDAP_OTHER; goto done; } } /* Get the header */ dptr = eh.bv.bv_val; eh.bv.bv_val = ehbuf; eh.bv.bv_len = data.size; rc = entry_header( &eh ); eoff = eh.data - eh.bv.bv_val; eh.bv.bv_val = dptr; if ( rc ) { rc = LDAP_OTHER; goto done; } /* Get the size */ data.flags &= ~DB_DBT_PARTIAL; data.ulen = 0; rc = cursor->c_get( cursor, &key, &data, DB_CURRENT ); if ( rc != DB_BUFFER_SMALL ) { rc = LDAP_OTHER; goto done; } /* Allocate a block and retrieve the data */ eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size; eh.bv.bv_val = ch_realloc( eh.bv.bv_val, eh.bv.bv_len ); eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval ); data.data = eh.data; data.ulen = data.size; /* Skip past already parsed nattr/nvals */ eh.data += eoff; rc = cursor->c_get( cursor, &key, &data, DB_CURRENT ); if ( rc ) { rc = LDAP_OTHER; goto done; } #ifndef BDB_HIER /* TODO: handle BDB_HIER accordingly */ if ( tool_base != NULL ) { struct berval ndn; entry_decode_dn( &eh, NULL, &ndn ); if ( !dnIsSuffixScope( &ndn, tool_base, tool_scope ) ) { return LDAP_NO_SUCH_OBJECT; } } #endif #ifdef SLAP_ZONE_ALLOC /* FIXME: will add ctx later */ rc = entry_decode( &eh, &e, NULL ); #else rc = entry_decode( &eh, &e ); #endif if( rc == LDAP_SUCCESS ) { e->e_id = id; #ifdef BDB_HIER if ( slapMode & SLAP_TOOL_READONLY ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; EntryInfo *ei = NULL; Operation op = {0}; Opheader ohdr = {0}; op.o_hdr = &ohdr; op.o_bd = be; op.o_tmpmemctx = NULL; op.o_tmpmfuncs = &ch_mfuncs; rc = bdb_cache_find_parent( &op, bdb->bi_cache.c_txn, id, &ei ); if ( rc == LDAP_SUCCESS ) { bdb_cache_entryinfo_unlock( ei ); e->e_private = ei; ei->bei_e = e; bdb_fix_dn( e, 0 ); ei->bei_e = NULL; e->e_private = NULL; } } #endif } done: if ( e != NULL ) { *ep = e; } return rc; }
Entry* bdb_tool_entry_get( BackendDB *be, ID id ) { Entry *e = NULL; char *dptr; int rc, eoff; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); if ( id != previd ) { data.ulen = data.dlen = sizeof( ehbuf ); data.data = ehbuf; data.flags |= DB_DBT_PARTIAL; BDB_ID2DISK( id, &nid ); rc = cursor->c_get( cursor, &key, &data, DB_SET ); if ( rc ) goto done; } /* Get the header */ dptr = eh.bv.bv_val; eh.bv.bv_val = ehbuf; eh.bv.bv_len = data.size; rc = entry_header( &eh ); eoff = eh.data - eh.bv.bv_val; eh.bv.bv_val = dptr; if ( rc ) goto done; /* Get the size */ data.flags &= ~DB_DBT_PARTIAL; data.ulen = 0; rc = cursor->c_get( cursor, &key, &data, DB_CURRENT ); if ( rc != DB_BUFFER_SMALL ) goto done; /* Allocate a block and retrieve the data */ eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size; eh.bv.bv_val = ch_realloc( eh.bv.bv_val, eh.bv.bv_len ); eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval ); data.data = eh.data; data.ulen = data.size; /* Skip past already parsed nattr/nvals */ eh.data += eoff; rc = cursor->c_get( cursor, &key, &data, DB_CURRENT ); if ( rc ) goto done; #ifdef SLAP_ZONE_ALLOC /* FIXME: will add ctx later */ rc = entry_decode( &eh, &e, NULL ); #else rc = entry_decode( &eh, &e ); #endif if( rc == LDAP_SUCCESS ) { e->e_id = id; #ifdef BDB_HIER if ( slapMode & SLAP_TOOL_READONLY ) { EntryInfo *ei = NULL; Operation op = {0}; Opheader ohdr = {0}; op.o_hdr = &ohdr; op.o_bd = be; op.o_tmpmemctx = NULL; op.o_tmpmfuncs = &ch_mfuncs; rc = bdb_cache_find_parent( &op, CURSOR_GETLOCKER(cursor), id, &ei ); if ( rc == LDAP_SUCCESS ) { bdb_cache_entryinfo_unlock( ei ); e->e_private = ei; ei->bei_e = e; bdb_fix_dn( e, 0 ); ei->bei_e = NULL; e->e_private = NULL; } } #endif } done: return e; }
int bdb_id2entry_rw( BackendDB *be, DB_TXN *tid, ID id, Entry **e, int rw, u_int32_t locker, DB_LOCK *lock ) { struct bdb_info *bdb = (struct bdb_info *) be->be_private; DB *db = bdb->bi_id2entry->bdi_db; DBT key, data; struct berval bv; int rc = 0, ret = 0; *e = NULL; DBTzero( &key ); key.data = (char *) &id; key.size = sizeof(ID); DBTzero( &data ); data.flags = DB_DBT_MALLOC; if ((*e = bdb_cache_find_entry_id(bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock)) != NULL) { return 0; } /* fetch it */ rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags | ( rw ? DB_RMW : 0 )); if( rc != 0 ) { return rc; } DBT2bv( &data, &bv ); rc = entry_decode( &bv, e ); if( rc == 0 ) { (*e)->e_id = id; } else { /* only free on error. On success, the entry was * decoded in place. */ ch_free( data.data ); } if ( rc == 0 ) { #ifdef BDB_HIER bdb_fix_dn(be, id, *e); #endif ret = bdb_cache_add_entry_rw( bdb->bi_dbenv, &bdb->bi_cache, *e, rw, locker, lock); while ( ret == 1 || ret == -1 ) { Entry *ee; int add_loop_cnt = 0; if ( (*e)->e_private != NULL ) { free ((*e)->e_private); } (*e)->e_private = NULL; if ( (ee = bdb_cache_find_entry_id (bdb->bi_dbenv, &bdb->bi_cache, id, rw, locker, lock) ) != NULL) { bdb_entry_return ( *e ); *e = ee; return 0; } if ( ++add_loop_cnt == BDB_MAX_ADD_LOOP ) { bdb_entry_return ( *e ); *e = NULL; return LDAP_BUSY; } } if ( ret != 0 ) { if ( (*e)->e_private != NULL ) free ( (*e)->e_private ); bdb_entry_return( *e ); *e = NULL; } rc = ret; } if (rc == 0) { bdb_cache_entry_commit(*e); } return rc; }