diff --git a/ldap/servers/slapd/backend_manager.c b/ldap/servers/slapd/backend_manager.c index 5fb0374..9b084dc 100644 --- a/ldap/servers/slapd/backend_manager.c +++ b/ldap/servers/slapd/backend_manager.c @@ -352,12 +352,12 @@ void be_unbindall(Connection *conn, Operation *op) { int i; - Slapi_PBlock pb; for ( i = 0; i < maxbackends; i++ ) { if ( backends[i] && (backends[i]->be_unbind != NULL) ) { + Slapi_PBlock pb; pblock_init_common( &pb, backends[i], conn, op ); if ( plugin_call_plugins( &pb, SLAPI_PLUGIN_PRE_UNBIND_FN ) == 0 ) diff --git a/ldap/servers/slapd/ch_malloc.c b/ldap/servers/slapd/ch_malloc.c index debac74..dad7ece 100644 --- a/ldap/servers/slapd/ch_malloc.c +++ b/ldap/servers/slapd/ch_malloc.c @@ -25,6 +25,7 @@ static int counters_created= 0; PR_DEFINE_COUNTER(slapi_ch_counter_malloc); +PR_DEFINE_COUNTER(slapi_ch_counter_memalign); PR_DEFINE_COUNTER(slapi_ch_counter_calloc); PR_DEFINE_COUNTER(slapi_ch_counter_realloc); PR_DEFINE_COUNTER(slapi_ch_counter_strdup); @@ -52,6 +53,7 @@ static void create_counters(void) { PR_CREATE_COUNTER(slapi_ch_counter_malloc,"slapi_ch","malloc",""); + PR_CREATE_COUNTER(slapi_ch_counter_memalign,"slapi_ch","memalign",""); PR_CREATE_COUNTER(slapi_ch_counter_calloc,"slapi_ch","calloc",""); PR_CREATE_COUNTER(slapi_ch_counter_realloc,"slapi_ch","realloc",""); PR_CREATE_COUNTER(slapi_ch_counter_strdup,"slapi_ch","strdup",""); @@ -76,7 +78,9 @@ create_counters(void) void oom_occurred(void) { int tmp_errno = errno; /* callers will need the error from malloc */ - if (oom_emergency_lock == NULL) return; + if (oom_emergency_lock == NULL) { + return; + } PR_Lock(oom_emergency_lock); if (oom_emergency_area) { @@ -131,6 +135,38 @@ slapi_ch_malloc( return( newmem ); } +/* See slapi-plugin.h */ +char * +slapi_ch_memalign(size_t size, size_t alignment) +{ + char *newmem; + + if (size <= 0) { + log_negative_alloc_msg( "memalign", "bytes", size ); + return 0; + } + + if ( posix_memalign((void **)&newmem, alignment, size) != 0 ) { + int oserr = errno; + + oom_occurred(); + slapi_log_error(SLAPI_LOG_ERR, SLAPD_MODULE, + "malloc of %lu bytes failed; OS error %d (%s)%s\n", + size, oserr, slapd_system_strerror( oserr ), oom_advice ); + exit( 1 ); + } + if(!counters_created) + { + create_counters(); + counters_created= 1; + } + PR_INCREMENT_COUNTER(slapi_ch_counter_memalign); + PR_INCREMENT_COUNTER(slapi_ch_counter_created); + PR_INCREMENT_COUNTER(slapi_ch_counter_exist); + + return( newmem ); +} + char * slapi_ch_realloc( char *block, diff --git a/ldap/servers/slapd/connection.c b/ldap/servers/slapd/connection.c index 568eef3..7a054c5 100644 --- a/ldap/servers/slapd/connection.c +++ b/ldap/servers/slapd/connection.c @@ -229,9 +229,6 @@ connection_cleanup(Connection *conn) /* free the connection socket buffer */ connection_free_private_buffer(conn); - if (enable_listeners && !g_get_shutdown()) { - ns_enable_listeners(); - } #ifdef ENABLE_NUNC_STANS /* even if !config_get_enable_nunc_stans, it is ok to set to 0 here */ conn->c_ns_close_jobs = 0; diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c index 9f8a183..b949bba 100644 --- a/ldap/servers/slapd/daemon.c +++ b/ldap/servers/slapd/daemon.c @@ -902,50 +902,6 @@ convert_pbe_des_to_aes(void) } #ifdef ENABLE_NUNC_STANS -static ns_job_type_t ns_listen_job_flags = NS_JOB_ACCEPT|NS_JOB_PERSIST|NS_JOB_PRESERVE_FD; -static PRStack *ns_disabled_listeners; /* holds the disabled listeners, if any */ -static PRInt32 num_disabled_listeners; -#endif - -#ifdef ENABLE_NUNC_STANS -static void -ns_disable_listener(listener_info *listener) -{ - /* tell the event framework not to listen for new connections on this listener */ - ns_job_modify(listener->ns_job, NS_JOB_DISABLE_ONLY|NS_JOB_PRESERVE_FD); - /* add the listener to our list of disabled listeners */ - PR_StackPush(ns_disabled_listeners, (PRStackElem *)listener); - PR_AtomicIncrement(&num_disabled_listeners); - LDAPDebug2Args(LDAP_DEBUG_ERR, "ns_disable_listener - " - "disabling listener for fd [%d]: [%d] now disabled\n", - PR_FileDesc2NativeHandle(listener->listenfd), - num_disabled_listeners); -} -#endif - -void -ns_enable_listeners() -{ -#ifdef ENABLE_NUNC_STANS - if (!enable_nunc_stans) { - return; - } - int num_enabled = 0; - listener_info *listener; - while ((listener = (listener_info *)PR_StackPop(ns_disabled_listeners))) { - /* there was a disabled listener - re-enable it to listen for new connections */ - ns_job_modify(listener->ns_job, ns_listen_job_flags); - PR_AtomicDecrement(&num_disabled_listeners); - num_enabled++; - } - if (num_enabled) { - LDAPDebug1Arg(LDAP_DEBUG_ERR, "ns_enable_listeners - " - "enabled [%d] listeners\n", num_enabled); - } -#endif -} - -#ifdef ENABLE_NUNC_STANS /* * Nunc stans logging function. */ @@ -972,6 +928,12 @@ nunc_stans_malloc(size_t size) } static void* +nunc_stans_memalign(size_t size, size_t alignment) +{ + return (void*)slapi_ch_memalign(size, alignment); +} + +static void* nunc_stans_calloc(size_t count, size_t size) { return (void*)slapi_ch_calloc((unsigned long)count, (unsigned long)size); @@ -1170,11 +1132,6 @@ void slapd_daemon( daemon_ports_t *ports ) #endif /* ENABLE_LDAPI */ listener_idxs = (listener_info *)slapi_ch_calloc(listeners, sizeof(*listener_idxs)); -#ifdef ENABLE_NUNC_STANS - if (enable_nunc_stans) { - ns_disabled_listeners = PR_CreateStack("disabled_listeners"); - } -#endif /* * Convert old DES encoded passwords to AES */ @@ -1187,11 +1144,8 @@ void slapd_daemon( daemon_ports_t *ports ) /* Set the nunc-stans thread pool config */ ns_thrpool_config_init(&tp_config); - tp_config.initial_threads = maxthreads; tp_config.max_threads = maxthreads; tp_config.stacksize = 0; - tp_config.event_queue_size = config_get_maxdescriptors(); - tp_config.work_queue_size = config_get_maxdescriptors(); #ifdef LDAP_DEBUG tp_config.log_fct = nunc_stans_logging; #else @@ -1200,6 +1154,7 @@ void slapd_daemon( daemon_ports_t *ports ) tp_config.log_start_fct = NULL; tp_config.log_close_fct = NULL; tp_config.malloc_fct = nunc_stans_malloc; + tp_config.memalign_fct = nunc_stans_memalign; tp_config.calloc_fct = nunc_stans_calloc; tp_config.realloc_fct = nunc_stans_realloc; tp_config.free_fct = nunc_stans_free; @@ -1211,7 +1166,7 @@ void slapd_daemon( daemon_ports_t *ports ) setup_pr_read_pds(the_connection_table,n_tcps,s_tcps,i_unix,&num_poll); for (ii = 0; ii < listeners; ++ii) { listener_idxs[ii].ct = the_connection_table; /* to pass to handle_new_connection */ - ns_add_io_job(tp, listener_idxs[ii].listenfd, ns_listen_job_flags, + ns_add_io_job(tp, listener_idxs[ii].listenfd, NS_JOB_ACCEPT|NS_JOB_PERSIST|NS_JOB_PRESERVE_FD, ns_handle_new_connection, &listener_idxs[ii], &listener_idxs[ii].ns_job); } @@ -2632,10 +2587,8 @@ ns_handle_new_connection(struct ns_job_t *job) */ if ((li->ct->size - g_get_current_conn_count()) <= config_get_reservedescriptors()) { - /* too many open fds - shut off this listener - when an fd is - * closed, try to resume this listener - */ - ns_disable_listener(li); + /* too many open fds - Just return, and hope next time is better. */ + slapi_log_error(SLAPI_LOG_FATAL, "ns_handle_new_connection", "Insufficient Reserve FD: File Descriptor exhaustion has occured! Connections will be silently dropped!\n"); return; } @@ -2644,12 +2597,13 @@ ns_handle_new_connection(struct ns_job_t *job) PRErrorCode prerr = PR_GetError(); if (PR_PROC_DESC_TABLE_FULL_ERROR == prerr) { /* too many open fds - shut off this listener - when an fd is - * closed, try to resume this listener + * closed, try to resume this listener. + * + * WARNING: This generates a lot of false negatives. Why? */ - ns_disable_listener(li); + slapi_log_error(SLAPI_LOG_FATAL, "ns_handle_new_connection", "PR_PROC_DESC_TABLE_FULL_ERROR: File Descriptor exhaustion has occured! Connections will be silently dropped!\n"); } else { - LDAPDebug(LDAP_DEBUG_CONNS, "ns_handle_new_connection - Error accepting" - " new connection listenfd=%d [%d:%s]\n", + slapi_log_error(SLAPI_LOG_FATAL, "ns_handle_new_connection", "Error accepting new connection listenfd=%d [%d:%s]\n", PR_FileDesc2NativeHandle(li->listenfd), prerr, slapd_pr_strerror(prerr)); } diff --git a/ldap/servers/slapd/fe.h b/ldap/servers/slapd/fe.h index 4368cc6..3d9ac08 100644 --- a/ldap/servers/slapd/fe.h +++ b/ldap/servers/slapd/fe.h @@ -123,7 +123,6 @@ int daemon_register_reslimits( void ); PRFileDesc * get_ssl_listener_fd(void); int configure_pr_socket( PRFileDesc **pr_socket, int secure, int local ); void configure_ns_socket( int * ns ); -void ns_enable_listeners(void); /* * sasl_io.c diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c index 0cff834..44560c2 100644 --- a/ldap/servers/slapd/pblock.c +++ b/ldap/servers/slapd/pblock.c @@ -35,7 +35,7 @@ pblock_init_common( ) { PR_ASSERT( NULL != pb ); - memset( pb, '\0', sizeof(Slapi_PBlock) ); + /* memset( pb, '\0', sizeof(Slapi_PBlock) ); */ pb->pb_backend = be; pb->pb_conn = conn; pb->pb_op = op; diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h index c1a9acf..7b24104 100644 --- a/ldap/servers/slapd/slapi-plugin.h +++ b/ldap/servers/slapd/slapi-plugin.h @@ -5820,6 +5820,13 @@ int slapi_is_shutting_down(void); * checking routines for allocating and freeing memory */ char * slapi_ch_malloc( unsigned long size ); +/* + * memalign returns an alligned block of memory as a multiple of alignment. + * alignment must be a power of 2. This is not normally needed, but is required + * for memory that works with certain cpu operations. It's basically malloc + * with some extra guarantees. + */ +char * slapi_ch_memalign( size_t size, size_t alignment); char * slapi_ch_realloc( char *block, unsigned long size ); char * slapi_ch_calloc( unsigned long nelem, unsigned long size ); char * slapi_ch_strdup( const char *s );