+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
+ assert( e->e_private );
+
+ if ( avl_insert( &cache->c_dntree, (caddr_t) e,
+ entry_dn_cmp, avl_dup_error ) != 0 )
+ {
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,
+ "cache_update_entry: (%s):%ld already in dn cache\n",
+ e->e_dn, e->e_id, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "====> cache_update_entry( %ld ): \"%s\": already in dn cache\n",
+ e->e_id, e->e_dn, 0 );
+#endif
+
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ return( 1 );
+ }
+
+ /* id tree */
+ if ( avl_insert( &cache->c_idtree, (caddr_t) e,
+ entry_id_cmp, avl_dup_error ) != 0 )
+ {
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, DETAIL1,
+ "cache_update_entry: (%s)%ld already in id cache\n",
+ e->e_dn, e->e_id, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "====> cache_update_entry( %ld ): \"%s\": already in id cache\n",
+ e->e_id, e->e_dn, 0 );
+#endif
+
+ /* delete from dn tree inserted above */
+ if ( avl_delete( &cache->c_dntree, (caddr_t) e,
+ entry_dn_cmp ) == NULL )
+ {
+#ifdef NEW_LOGGING
+ LDAP_LOG( CACHE, INFO,
+ "cache_update_entry: can't delete (%s)%ld from dn cache.\n",
+ e->e_dn, e->e_id, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
+ 0, 0, 0 );
+#endif
+ }
+
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ return( -1 );
+ }
+
+ /* put the entry into 'CREATING' state */
+ /* will be marked after when entry is returned */
+ LEI(e)->lei_state = CACHE_ENTRY_CREATING;
+
+ /* lru */
+ LRU_ADD( cache, e );
+ if ( ++cache->c_cursize > cache->c_maxsize ) {
+ /*
+ * find the lru entry not currently in use and delete it.
+ * in case a lot of entries are in use, only look at the
+ * first 10 on the tail of the list.
+ */
+ i = 0;
+ while ( cache->c_lrutail != NULL &&
+ LEI(cache->c_lrutail)->lei_refcnt != 0 &&
+ i < 10 )
+ {
+ /* move this in-use entry to the front of the q */
+ ee = cache->c_lrutail;
+ LRU_DELETE( cache, ee );
+ LRU_ADD( cache, ee );
+ i++;
+ }
+
+ /*
+ * found at least one to delete - try to get back under
+ * the max cache size.
+ */
+ while ( cache->c_lrutail != NULL &&
+ LEI(cache->c_lrutail)->lei_refcnt == 0 &&
+ cache->c_cursize > cache->c_maxsize )
+ {
+ e = cache->c_lrutail;
+
+ /* delete from cache and lru q */
+ /* XXX do we need rc ? */
+ rc = cache_delete_entry_internal( cache, e );
+ cache_entry_private_destroy( e );
+ entry_free( e );
+ }
+ }
+
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+ return( 0 );
+}
+
+ID
+cache_find_entry_ndn2id(
+ Backend *be,
+ Cache *cache,
+ struct berval *ndn