struct berval rdn;
int i;
Attribute *a;
+ slap_counters_t *sc;
static struct berval bv_ops = BER_BVC( "cn=operations" );
assert( mi != NULL );
ldap_pvt_mp_init( nInitiated );
ldap_pvt_mp_init( nCompleted );
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+ ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
for ( i = 0; i < SLAP_OP_LAST; i++ ) {
ldap_pvt_mp_add( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
ldap_pvt_mp_add( nCompleted, slap_counters.sc_ops_completed_[ i ] );
}
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+ ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
+ ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
+ }
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
+ ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
} else {
for ( i = 0; i < SLAP_OP_LAST; i++ ) {
if ( dn_match( &rdn, &monitor_op[ i ].nrdn ) )
{
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+ ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
ldap_pvt_mp_init_set( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
ldap_pvt_mp_init_set( nCompleted, slap_counters.sc_ops_completed_[ i ] );
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
+ ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
+ ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
break;
}
}
struct berval nrdn;
ldap_pvt_mp_t n;
Attribute *a;
+ slap_counters_t *sc;
int i;
assert( mi != NULL );
return SLAP_CB_CONTINUE;
}
- ldap_pvt_thread_mutex_lock(&slap_counters.sc_sent_mutex);
+ ldap_pvt_thread_mutex_lock(&slap_counters.sc_mutex);
switch ( i ) {
case MONITOR_SENT_ENTRIES:
ldap_pvt_mp_init_set( n, slap_counters.sc_entries );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ ldap_pvt_mp_add( n, sc->sc_entries );
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
break;
case MONITOR_SENT_REFERRALS:
ldap_pvt_mp_init_set( n, slap_counters.sc_refs );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ ldap_pvt_mp_add( n, sc->sc_refs );
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
break;
case MONITOR_SENT_PDU:
ldap_pvt_mp_init_set( n, slap_counters.sc_pdu );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ ldap_pvt_mp_add( n, sc->sc_pdu );
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
break;
case MONITOR_SENT_BYTES:
ldap_pvt_mp_init_set( n, slap_counters.sc_bytes );
+ for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
+ ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
+ ldap_pvt_mp_add( n, sc->sc_bytes );
+ ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
+ }
break;
default:
assert(0);
}
- ldap_pvt_thread_mutex_unlock(&slap_counters.sc_sent_mutex);
+ ldap_pvt_thread_mutex_unlock(&slap_counters.sc_mutex);
a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
assert( a != NULL );
static Connection* connection_get( ber_socket_t s );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-
typedef struct conn_readinfo {
Operation *op;
ldap_pvt_thread_start_t *func;
} conn_readinfo;
static int connection_input( Connection *c, conn_readinfo *cri );
-#else
-static int connection_input( Connection *c );
-#endif
static void connection_close( Connection *c );
static int connection_op_activate( Operation *op );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
static void connection_op_queue( Operation *op );
-#endif
static int connection_resched( Connection *conn );
static void connection_abandon( Connection *conn );
static void connection_destroy( Connection *c );
/* FIXME: returns 0 in case of failure */
#define INCR_OP_INITIATED(index) \
do { \
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
- ldap_pvt_mp_add_ulong(slap_counters.sc_ops_initiated_[(index)], 1); \
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+ ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_initiated_[(index)], 1); \
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
} while (0)
#define INCR_OP_COMPLETED(index) \
do { \
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
- ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed, 1); \
- ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed_[(index)], 1); \
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+ ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed, 1); \
+ ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed_[(index)], 1); \
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
} while (0)
#else /* !SLAPD_MONITOR */
#define INCR_OP_INITIATED(index) do { } while (0)
#define INCR_OP_COMPLETED(index) \
do { \
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
- ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed, 1); \
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); \
+ ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_completed, 1); \
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); \
} while (0)
#endif /* !SLAPD_MONITOR */
NULL
};
+/* Counters are per-thread, not per-connection.
+ */
+static void
+conn_counter_destroy( void *key, void *data )
+{
+ slap_counters_t **prev, *sc;
+
+ ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
+ for ( prev = &slap_counters.sc_next, sc = slap_counters.sc_next; sc;
+ prev = &sc->sc_next, sc = sc->sc_next ) {
+ if ( sc == data ) {
+ int i;
+
+ *prev = sc->sc_next;
+ /* Copy data to main counter */
+ ldap_pvt_mp_add( slap_counters.sc_bytes, sc->sc_bytes );
+ ldap_pvt_mp_add( slap_counters.sc_pdu, sc->sc_pdu );
+ ldap_pvt_mp_add( slap_counters.sc_entries, sc->sc_entries );
+ ldap_pvt_mp_add( slap_counters.sc_refs, sc->sc_refs );
+ ldap_pvt_mp_add( slap_counters.sc_ops_initiated, sc->sc_ops_initiated );
+ ldap_pvt_mp_add( slap_counters.sc_ops_completed, sc->sc_ops_completed );
+#ifdef SLAPD_MONITOR
+ for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+ ldap_pvt_mp_add( slap_counters.sc_ops_initiated_[ i ], sc->sc_ops_initiated_[ i ] );
+ ldap_pvt_mp_add( slap_counters.sc_ops_initiated_[ i ], sc->sc_ops_completed_[ i ] );
+ }
+#endif /* SLAPD_MONITOR */
+ slap_counters_destroy( sc );
+ ber_memfree_x( data, NULL );
+ break;
+ }
+ }
+ ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
+}
+
+static void
+conn_counter_init( Operation *op, void *ctx )
+{
+ slap_counters_t *sc;
+ void *vsc = NULL;
+
+ if ( ldap_pvt_thread_pool_getkey( ctx, conn_counter_init, &vsc, NULL ) || !vsc ) {
+ vsc = ch_malloc( sizeof( slap_counters_t ));
+ sc = vsc;
+ slap_counters_init( sc );
+ ldap_pvt_thread_pool_setkey( ctx, conn_counter_init, vsc,
+ conn_counter_destroy );
+
+ ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
+ sc->sc_next = slap_counters.sc_next;
+ slap_counters.sc_next = sc;
+ ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
+ }
+ op->o_counters = vsc;
+}
+
static void *
connection_operation( void *ctx, void *arg_v )
{
void *memctx_null = NULL;
ber_len_t memsiz;
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
+ conn_counter_init( op, ctx );
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
/* FIXME: returns 0 in case of failure */
- ldap_pvt_mp_add_ulong(slap_counters.sc_ops_initiated, 1);
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
+ ldap_pvt_mp_add_ulong(op->o_counters->sc_ops_initiated, 1);
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
op->o_threadctx = ctx;
op->o_tid = ldap_pvt_thread_pool_tid( ctx );
connection_return( c );
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
-
static int connection_read( ber_socket_t s, conn_readinfo *cri );
static void* connection_read_thread( void* ctx, void* argv )
return rc;
}
-#endif
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
static int
connection_read( ber_socket_t s, conn_readinfo *cri )
-#else
-int connection_read(ber_socket_t s)
-#endif
{
int rc = 0;
Connection *c;
}
if ( c->c_conn_state == SLAP_C_CLIENT ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
cri->func = c->c_clientfunc;
cri->arg = c->c_clientarg;
/* read should already be cleared */
-#else
- slapd_clr_read( s, 0 );
- ldap_pvt_thread_pool_submit( &connection_pool,
- c->c_clientfunc, c->c_clientarg );
-#endif
connection_return( c );
return 0;
}
/* if success and data is ready, fall thru to data input loop */
if( !ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
{
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
slapd_set_read( s, 1 );
-#endif
-
connection_return( c );
return 0;
}
if ( c->c_sasl_layers ) {
/* If previous layer is not removed yet, give up for now */
if ( !c->c_sasl_sockctx ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
slapd_set_read( s, 1 );
-#endif
-
connection_return( c );
return 0;
}
do {
/* How do we do this without getting into a busy loop ? */
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
rc = connection_input( c, cri );
-#else
- rc = connection_input( c );
-#endif
}
#ifdef DATA_READY_LOOP
while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ));
return 0;
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
slapd_set_write( s, 0 );
}
slapd_set_read( s, 1 );
-#else
- if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
- slapd_set_read( s, 1 );
- }
-
- if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
- slapd_set_write( s, 1 );
- }
-#endif
-
connection_return( c );
return 0;
}
static int
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
connection_input( Connection *conn , conn_readinfo *cri )
-#else
-connection_input( Connection *conn )
-#endif
{
Operation *op;
ber_tag_t tag;
connection_abandon( conn );
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
ctx = cri->ctx;
-#else
- ctx = NULL;
-#endif
op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++, ctx );
op->o_conn = conn;
} else {
conn->c_n_ops_executing++;
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
/*
* The first op will be processed in the same thread context,
* as long as there is only one op total.
}
connection_op_activate( op );
}
-#else
- connection_op_activate( op );
-#endif
}
#ifdef NO_THREADS
op->o_threadctx = ctx;
op->o_tid = ldap_pvt_thread_pool_tid( ctx );
+ op->o_counters = &slap_counters;
op->o_conn = conn;
op->o_connid = op->o_conn->c_connid;
connection_init_log_prefix( op );
# define SLAP_SOCK_CLR_READ(s) SLAP_EPOLL_SOCK_CLR((s), EPOLLIN)
# define SLAP_SOCK_CLR_WRITE(s) SLAP_EPOLL_SOCK_CLR((s), EPOLLOUT)
-# ifdef SLAP_LIGHTWEIGHT_DISPATCHER
# define SLAP_SOCK_SET_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] = 1 )
# define SLAP_SOCK_CLR_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] = 0 )
# define SLAP_SOCK_IS_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_EPOLL_SOCK_IX(s)] == 1 )
-# endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
# define SLAP_EPOLL_EVENT_CLR(i, mode) (revents[(i)].events &= ~(mode))
# define SLAP_SOCK_CLR_READ(s) SLAP_DEVPOLL_SOCK_CLR((s), POLLIN)
# define SLAP_SOCK_CLR_WRITE(s) SLAP_DEVPOLL_SOCK_CLR((s), POLLOUT)
-# ifdef SLAP_LIGHTWEIGHT_DISPATCHER
# define SLAP_SOCK_SET_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] = 1 )
# define SLAP_SOCK_CLR_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] = 0 )
# define SLAP_SOCK_IS_SUSPEND(s) \
( slap_daemon.sd_suspend[SLAP_DEVPOLL_SOCK_IX((s))] == 1 )
-# endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
# define SLAP_DEVPOLL_EVENT_CLR(i, mode) (revents[(i)].events &= ~(mode))
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
WAKE_LISTENER(1);
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
}
/*
l.sl_url.bv_val = NULL;
l.sl_mute = 0;
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
l.sl_busy = 0;
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
#ifndef HAVE_TLS
if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
s = accept( sl->sl_sd, (struct sockaddr *) &from, &len );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
/* Resume the listener FD to allow concurrent-processing of
* additional incoming connections.
*/
sl->sl_busy = 0;
WAKE_LISTENER(1);
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
if ( s == AC_SOCKET_INVALID ) {
int err = sock_errno();
return 0;
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
static void*
slap_listener_thread(
void* ctx,
}
return rc;
}
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
static void *
slapd_daemon_task(
return (void*)-1;
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
/* make the listening socket non-blocking */
if ( ber_pvt_socket_set_nonblock( slap_listeners[l]->sl_sd, 1 ) < 0 ) {
Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: "
slapd_shutdown = 2;
return (void*)-1;
}
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
slapd_add( slap_listeners[l]->sl_sd, 0, slap_listeners[l] );
}
if ( lr->sl_sd == AC_SOCKET_INVALID ) continue;
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
if ( lr->sl_mute || lr->sl_busy )
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
- if ( lr->sl_mute )
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
{
SLAP_SOCK_CLR_READ( lr->sl_sd );
} else {
continue;
}
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
if ( lr->sl_busy ) {
Debug( LDAP_DEBUG_CONNS,
"daemon: " SLAP_EVENT_FNAME ": "
lr->sl_sd, 0, 0 );
continue;
}
-#endif /* SLAP_LIGHTWEIGHT_DISPATCHER */
Debug( LDAP_DEBUG_CONNS,
"daemon: " SLAP_EVENT_FNAME ": "
SLAP_EVENT_CLR_WRITE( slap_listeners[l]->sl_sd );
ns--;
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
rc = slap_listener_activate( slap_listeners[l] );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
- rc = slap_listener( slap_listeners[l] );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
}
/* bypass the following tests if no descriptors left */
* active.
*/
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
connection_read_activate( rd );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
- connection_read( rd );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
}
#else /* !SLAP_EVENTS_ARE_INDEXED */
/* FIXME */
int rc = 1, fd;
if ( SLAP_EVENT_IS_LISTENER( i ) ) {
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
rc = slap_listener_activate( SLAP_EVENT_LISTENER( i ) );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
- rc = slap_listener( SLAP_EVENT_LISTENER( i ) );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
}
/* If we found a regular listener, rc is now zero, and we
fd, 0, 0 );
SLAP_EVENT_CLR_READ( i );
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
connection_read_activate( fd );
-#else /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
- /*
- * NOTE: it is possible that the connection was closed
- * and that the stream is now inactive.
- * connection_read() must valid the stream is still
- * active.
- */
- connection_read( fd );
-#endif /* ! SLAP_LIGHTWEIGHT_DISPATCHER */
} else {
Debug( LDAP_DEBUG_CONNS,
"daemon: hangup on %d\n", fd, 0, 0 );
int slap_tool_thread_max = 1;
ldap_pvt_thread_mutex_t gmtime_mutex;
-slap_counters_t slap_counters;
+slap_counters_t slap_counters, *slap_counters_list;
static const char* slap_name = NULL;
int slapMode = SLAP_UNDEFINED_MODE;
slap_init( int mode, const char *name )
{
int rc;
- int i;
assert( mode );
ldap_pvt_thread_pool_init( &connection_pool,
connection_pool_max, 0);
- ldap_pvt_thread_mutex_init( &slap_counters.sc_sent_mutex );
- ldap_pvt_thread_mutex_init( &slap_counters.sc_ops_mutex );
- ldap_pvt_mp_init( slap_counters.sc_bytes );
- ldap_pvt_mp_init( slap_counters.sc_pdu );
- ldap_pvt_mp_init( slap_counters.sc_entries );
- ldap_pvt_mp_init( slap_counters.sc_refs );
-
- ldap_pvt_mp_init( slap_counters.sc_ops_initiated );
- ldap_pvt_mp_init( slap_counters.sc_ops_completed );
+ slap_counters_init( &slap_counters );
ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
LDAP_STAILQ_INIT( &slapd_rq.task_list );
LDAP_STAILQ_INIT( &slapd_rq.run_list );
-#ifdef SLAPD_MONITOR
- for ( i = 0; i < SLAP_OP_LAST; i++ ) {
- ldap_pvt_mp_init( slap_counters.sc_ops_initiated_[ i ] );
- ldap_pvt_mp_init( slap_counters.sc_ops_completed_[ i ] );
- }
-#endif /* SLAPD_MONITOR */
-
ldap_pvt_thread_mutex_init( &gmtime_mutex );
slap_passwd_init();
int slap_destroy(void)
{
int rc;
- int i;
Debug( LDAP_DEBUG_TRACE,
"%s destroy: freeing system resources.\n",
switch ( slapMode & SLAP_MODE ) {
case SLAP_SERVER_MODE:
-
case SLAP_TOOL_MODE:
-
- ldap_pvt_thread_mutex_destroy( &slap_counters.sc_sent_mutex );
- ldap_pvt_thread_mutex_destroy( &slap_counters.sc_ops_mutex );
- ldap_pvt_mp_clear( slap_counters.sc_bytes );
- ldap_pvt_mp_clear( slap_counters.sc_pdu );
- ldap_pvt_mp_clear( slap_counters.sc_entries );
- ldap_pvt_mp_clear( slap_counters.sc_refs );
- ldap_pvt_mp_clear( slap_counters.sc_ops_initiated );
- ldap_pvt_mp_clear( slap_counters.sc_ops_completed );
-
-#ifdef SLAPD_MONITOR
- for ( i = 0; i < SLAP_OP_LAST; i++ ) {
- ldap_pvt_mp_clear( slap_counters.sc_ops_initiated_[ i ] );
- ldap_pvt_mp_clear( slap_counters.sc_ops_completed_[ i ] );
- }
-#endif /* SLAPD_MONITOR */
+ slap_counters_destroy( &slap_counters );
break;
default:
/* should destroy the above mutex */
return rc;
}
+
+void slap_counters_init( slap_counters_t *sc )
+{
+ int i;
+
+ ldap_pvt_thread_mutex_init( &sc->sc_mutex );
+ ldap_pvt_mp_init( sc->sc_bytes );
+ ldap_pvt_mp_init( sc->sc_pdu );
+ ldap_pvt_mp_init( sc->sc_entries );
+ ldap_pvt_mp_init( sc->sc_refs );
+
+ ldap_pvt_mp_init( sc->sc_ops_initiated );
+ ldap_pvt_mp_init( sc->sc_ops_completed );
+
+#ifdef SLAPD_MONITOR
+ for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+ ldap_pvt_mp_init( sc->sc_ops_initiated_[ i ] );
+ ldap_pvt_mp_init( sc->sc_ops_completed_[ i ] );
+ }
+#endif /* SLAPD_MONITOR */
+}
+
+void slap_counters_destroy( slap_counters_t *sc )
+{
+ int i;
+
+ ldap_pvt_thread_mutex_destroy( &sc->sc_mutex );
+ ldap_pvt_mp_clear( sc->sc_bytes );
+ ldap_pvt_mp_clear( sc->sc_pdu );
+ ldap_pvt_mp_clear( sc->sc_entries );
+ ldap_pvt_mp_clear( sc->sc_refs );
+
+ ldap_pvt_mp_clear( sc->sc_ops_initiated );
+ ldap_pvt_mp_clear( sc->sc_ops_completed );
+
+#ifdef SLAPD_MONITOR
+ for ( i = 0; i < SLAP_OP_LAST; i++ ) {
+ ldap_pvt_mp_clear( sc->sc_ops_initiated_[ i ] );
+ ldap_pvt_mp_clear( sc->sc_ops_completed_[ i ] );
+ }
+#endif /* SLAPD_MONITOR */
+}
+
LDAP_SLAPD_F (const char *) connection_state2str LDAP_P(( int state ))
LDAP_GCCATTR((const));
-#ifdef SLAP_LIGHTWEIGHT_DISPATCHER
LDAP_SLAPD_F (int) connection_read_activate LDAP_P((ber_socket_t s));
-#else
-LDAP_SLAPD_F (int) connection_read LDAP_P((ber_socket_t s));
-#endif
LDAP_SLAPD_F (int) connection_write LDAP_P((ber_socket_t s));
LDAP_SLAPD_F (unsigned long) connections_nextid(void);
LDAP_SLAPD_F (int) slap_startup LDAP_P(( Backend *be ));
LDAP_SLAPD_F (int) slap_shutdown LDAP_P(( Backend *be ));
LDAP_SLAPD_F (int) slap_destroy LDAP_P((void));
+LDAP_SLAPD_F (void) slap_counters_init LDAP_P((slap_counters_t *sc));
+LDAP_SLAPD_F (void) slap_counters_destroy LDAP_P((slap_counters_t *sc));
LDAP_SLAPD_V (char *) slap_known_controls[];
goto cleanup;
}
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
- ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
- ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
cleanup:;
/* Tell caller that we did this for real, as opposed to being
}
rs->sr_nentries++;
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
- ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
- ldap_pvt_mp_add_ulong( slap_counters.sc_entries, 1 );
- ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_entries, 1 );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
}
Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
if ( bytes < 0 ) {
rc = LDAP_UNAVAILABLE;
} else {
- ldap_pvt_thread_mutex_lock( &slap_counters.sc_sent_mutex );
- ldap_pvt_mp_add_ulong( slap_counters.sc_bytes, (unsigned long)bytes );
- ldap_pvt_mp_add_ulong( slap_counters.sc_refs, 1 );
- ldap_pvt_mp_add_ulong( slap_counters.sc_pdu, 1 );
- ldap_pvt_thread_mutex_unlock( &slap_counters.sc_sent_mutex );
+ ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 );
+ ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 );
+ ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
}
#ifdef LDAP_CONNECTIONLESS
}
int sc_valuesReturnFilter;
};
+/*
+ * Operation indices
+ */
+typedef enum {
+ SLAP_OP_BIND = 0,
+ SLAP_OP_UNBIND,
+ SLAP_OP_SEARCH,
+ SLAP_OP_COMPARE,
+ SLAP_OP_MODIFY,
+ SLAP_OP_MODRDN,
+ SLAP_OP_ADD,
+ SLAP_OP_DELETE,
+ SLAP_OP_ABANDON,
+ SLAP_OP_EXTENDED,
+ SLAP_OP_LAST
+} slap_op_t;
+
+typedef struct slap_counters_t {
+ struct slap_counters_t *sc_next;
+ ldap_pvt_thread_mutex_t sc_mutex;
+ ldap_pvt_mp_t sc_bytes;
+ ldap_pvt_mp_t sc_pdu;
+ ldap_pvt_mp_t sc_entries;
+ ldap_pvt_mp_t sc_refs;
+
+ ldap_pvt_mp_t sc_ops_completed;
+ ldap_pvt_mp_t sc_ops_initiated;
+#ifdef SLAPD_MONITOR
+ ldap_pvt_mp_t sc_ops_completed_[SLAP_OP_LAST];
+ ldap_pvt_mp_t sc_ops_initiated_[SLAP_OP_LAST];
+#endif /* SLAPD_MONITOR */
+} slap_counters_t;
+
/*
* represents an operation pending from an ldap client
*/
void *oh_tmpmemctx; /* slab malloc context */
BerMemoryFunctions *oh_tmpmfuncs;
+ slap_counters_t *oh_counters;
+
char oh_log_prefix[ /* sizeof("conn=18446744073709551615 op=18446744073709551615") */ SLAP_TEXT_BUFLEN ];
#ifdef LDAP_SLAPI
#define o_threadctx o_hdr->oh_threadctx
#define o_tmpmemctx o_hdr->oh_tmpmemctx
#define o_tmpmfuncs o_hdr->oh_tmpmfuncs
+#define o_counters o_hdr->oh_counters
#define o_tmpalloc o_tmpmfuncs->bmf_malloc
#define o_tmpcalloc o_tmpmfuncs->bmf_calloc
#define sl_addr sl_sa.sa_in_addr
};
-/*
- * Operation indices
- */
-typedef enum {
- SLAP_OP_BIND = 0,
- SLAP_OP_UNBIND,
- SLAP_OP_SEARCH,
- SLAP_OP_COMPARE,
- SLAP_OP_MODIFY,
- SLAP_OP_MODRDN,
- SLAP_OP_ADD,
- SLAP_OP_DELETE,
- SLAP_OP_ABANDON,
- SLAP_OP_EXTENDED,
- SLAP_OP_LAST
-} slap_op_t;
-
-typedef struct slap_counters_t {
- ldap_pvt_thread_mutex_t sc_sent_mutex;
- ldap_pvt_mp_t sc_bytes;
- ldap_pvt_mp_t sc_pdu;
- ldap_pvt_mp_t sc_entries;
- ldap_pvt_mp_t sc_refs;
-
- ldap_pvt_thread_mutex_t sc_ops_mutex;
- ldap_pvt_mp_t sc_ops_completed;
- ldap_pvt_mp_t sc_ops_initiated;
-#ifdef SLAPD_MONITOR
- ldap_pvt_mp_t sc_ops_completed_[SLAP_OP_LAST];
- ldap_pvt_mp_t sc_ops_initiated_[SLAP_OP_LAST];
-#endif /* SLAPD_MONITOR */
-} slap_counters_t;
-
/*
* Better know these all around slapd
*/