diff --git a/configure.ac b/configure.ac index 65372c7de2..ed766cf46b 100644 --- a/configure.ac +++ b/configure.ac @@ -2147,18 +2147,18 @@ fi dnl ---------------------------------------------------------------- dnl Libevent if test $ol_enable_balancer != no ; then - AC_CHECK_LIB(event_core, evconnlistener_set_error_cb, + AC_CHECK_LIB(event_extra, evdns_base_new, [have_libevent=yes - LEVENT_LIBS="$LEVENT_LIBS -levent_core"], - [AC_CHECK_LIB(event, evconnlistener_set_error_cb, + LEVENT_LIBS="$LEVENT_LIBS -levent_core -levent_extra"], + [AC_CHECK_LIB(event, evdns_base_new, [have_libevent=yes LEVENT_LIBS="$LEVENT_LIBS -levent"], [have_libevent=no])]) if test $have_libevent = yes ; then AC_DEFINE(HAVE_LIBEVENT, 1, [define if you have -levent]) - elif test $ol_enable_balancer = yes ; then - AC_MSG_ERROR([You need libevent 2.0 or later to build the load balancer]) + else + AC_MSG_ERROR([You need libevent 2.0 or later with DNS support to build the load balancer]) fi fi diff --git a/servers/lloadd/daemon.c b/servers/lloadd/daemon.c index 3017e34b68..9388ae8afe 100644 --- a/servers/lloadd/daemon.c +++ b/servers/lloadd/daemon.c @@ -36,6 +36,7 @@ #include #include +#include #include #include "slap.h" @@ -81,6 +82,8 @@ Listener **slap_listeners = NULL; static volatile sig_atomic_t listening = 1; /* 0 when slap_listeners closed */ static ldap_pvt_thread_t listener_tid, *daemon_tid; +struct evdns_base *dnsbase; + #ifndef SLAPD_LISTEN_BACKLOG #define SLAPD_LISTEN_BACKLOG 1024 #endif /* ! SLAPD_LISTEN_BACKLOG */ @@ -1221,17 +1224,9 @@ slapd_daemon_task( void *ptr ) { int rc; int tid = (ldap_pvt_thread_t *)ptr - daemon_tid; - struct event_base *base; + struct event_base *base = slap_daemon[tid].base; struct event *event; - base = event_base_new(); - if ( !base ) { - Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: " - "failed to acquire event base\n" ); - return (void *)-1; - } - slap_daemon[tid].base = base; - event = event_new( base, -1, EV_WRITE, daemon_wakeup_cb, ptr ); if ( !event ) { Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: " @@ -1258,9 +1253,20 @@ int slapd_daemon( struct event_base *daemon_base ) { int i, rc; + Backend *b; + struct event_base *base; assert( daemon_base != NULL ); + dnsbase = evdns_base_new( daemon_base, + EVDNS_BASE_INITIALIZE_NAMESERVERS | + EVDNS_BASE_DISABLE_WHEN_INACTIVE ); + if ( !dnsbase ) { + Debug( LDAP_DEBUG_ANY, "lloadd startup: " + "failed to set up for async name resolution\n" ); + return -1; + } + if ( slapd_daemon_threads > SLAPD_MAX_DAEMON_THREADS ) slapd_daemon_threads = SLAPD_MAX_DAEMON_THREADS; @@ -1272,6 +1278,14 @@ slapd_daemon( struct event_base *daemon_base ) } for ( i = 0; i < slapd_daemon_threads; i++ ) { + base = event_base_new(); + if ( !base ) { + Debug( LDAP_DEBUG_ANY, "lloadd startup: " + "failed to acquire event base for an I/O thread\n" ); + return -1; + } + slap_daemon[i].base = base; + ldap_pvt_thread_mutex_init( &slap_daemon[i].sd_mutex ); /* threads that handle client and upstream sockets */ rc = ldap_pvt_thread_create( @@ -1285,6 +1299,13 @@ slapd_daemon( struct event_base *daemon_base ) } } + LDAP_STAILQ_FOREACH ( b, &backend, b_next ) { + rc = backend_connect( b ); + if ( rc ) { + return rc; + } + } + lloadd_inited = 1; rc = event_base_dispatch( daemon_base ); Debug( LDAP_DEBUG_ANY, "lloadd shutdown: " @@ -1365,6 +1386,13 @@ slap_sig_shutdown( evutil_socket_t sig, short what, void *arg ) errno = save_errno; } +struct event_base * +slap_get_base( ber_socket_t s ) +{ + int tid = DAEMON_ID(s); + return slap_daemon[tid].base; +} + Listener ** slapd_get_listeners( void ) { diff --git a/servers/lloadd/proto-slap.h b/servers/lloadd/proto-slap.h index a0363719ff..92464f7e28 100644 --- a/servers/lloadd/proto-slap.h +++ b/servers/lloadd/proto-slap.h @@ -36,6 +36,12 @@ LDAP_BEGIN_DECL struct config_args_s; /* config.h */ struct config_reply_s; /* config.h */ +/* + * backend.c + */ + +LDAP_SLAPD_F (int) backend_connect( Backend *b ); + /* * ch_malloc.c */ @@ -65,6 +71,7 @@ LDAP_SLAPD_F (void) bindconf_free( slap_bindconf *bc ); */ LDAP_SLAPD_F (Connection *) connection_init( ber_socket_t s, const char *peername, int use_tls ); LDAP_SLAPD_F (Connection *) client_init( ber_socket_t s, Listener *url, const char *peername, struct event_base *base, int use_tls ); +LDAP_SLAPD_F (Connection *) upstream_init( ber_socket_t s, Backend *b ); LDAP_SLAPD_F (void) connection_destroy( Connection *c ); /* @@ -74,9 +81,11 @@ LDAP_SLAPD_F (int) slapd_daemon_init( const char *urls ); LDAP_SLAPD_F (int) slapd_daemon_destroy( void ); LDAP_SLAPD_F (int) slapd_daemon( struct event_base *daemon_base ); LDAP_SLAPD_F (Listener **) slapd_get_listeners( void ); +LDAP_SLAPD_F (struct event_base *) slap_get_base( ber_socket_t s ); LDAP_SLAPD_F (void) slap_sig_shutdown( evutil_socket_t sig, short what, void *arg ); +LDAP_SLAPD_V (struct evdns_base *) dnsbase; LDAP_SLAPD_V (volatile sig_atomic_t) slapd_shutdown; LDAP_SLAPD_V (int) lloadd_inited; LDAP_SLAPD_V (struct runqueue_s) slapd_rq;