X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fconnection.c;h=d59d403e7a09126e192d283251cbe8cc7965e3e6;hb=d520cd607d452fe4809d86f37b299ee7665d0f12;hp=4ac1bde3c04a4023b66cd71873ac65b6095262ee;hpb=564d1a6affbe9ae4d9c20feb9a99936f4dcf0e3e;p=openldap diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 4ac1bde3c0..d59d403e7a 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -888,9 +888,31 @@ void connection_done( Connection *c ) } while (0) #else /* !SLAPD_MONITOR */ #define INCR_OP_INITIATED(index) -#define INCR_OP_COMPLETED(index) +#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 ); \ + } while (0) #endif /* !SLAPD_MONITOR */ +/* + * NOTE: keep in sync with enum in slapd.h + */ +static int (*opfun[])( Operation *op, SlapReply *rs ) = { + do_bind, + do_unbind, + do_add, + do_delete, + do_modrdn, + do_modify, + do_compare, + do_search, + do_abandon, + do_extended, + NULL +}; + static void * connection_operation( void *ctx, void *arg_v ) { @@ -898,9 +920,7 @@ connection_operation( void *ctx, void *arg_v ) Operation *op = arg_v; SlapReply rs = {REP_RESULT}; ber_tag_t tag = op->o_tag; -#ifdef SLAPD_MONITOR - ber_tag_t oldtag = tag; -#endif /* SLAPD_MONITOR */ + int opidx = -1; Connection *conn = op->o_conn; void *memctx = NULL; void *memctx_null = NULL; @@ -918,7 +938,7 @@ connection_operation( void *ctx, void *arg_v ) case LDAP_REQ_UNBIND: case LDAP_REQ_ADD: case LDAP_REQ_DELETE: - case LDAP_REQ_MODRDN: + case LDAP_REQ_MODDN: case LDAP_REQ_MODIFY: case LDAP_REQ_COMPARE: case LDAP_REQ_SEARCH: @@ -969,53 +989,43 @@ connection_operation( void *ctx, void *arg_v ) switch ( tag ) { case LDAP_REQ_BIND: - INCR_OP_INITIATED(SLAP_OP_BIND); - rc = do_bind( op, &rs ); + opidx = SLAP_OP_BIND; break; case LDAP_REQ_UNBIND: - INCR_OP_INITIATED(SLAP_OP_UNBIND); - rc = do_unbind( op, &rs ); + opidx = SLAP_OP_UNBIND; break; case LDAP_REQ_ADD: - INCR_OP_INITIATED(SLAP_OP_ADD); - rc = do_add( op, &rs ); + opidx = SLAP_OP_ADD; break; case LDAP_REQ_DELETE: - INCR_OP_INITIATED(SLAP_OP_DELETE); - rc = do_delete( op, &rs ); + opidx = SLAP_OP_DELETE; break; case LDAP_REQ_MODRDN: - INCR_OP_INITIATED(SLAP_OP_MODRDN); - rc = do_modrdn( op, &rs ); + opidx = SLAP_OP_MODRDN; break; case LDAP_REQ_MODIFY: - INCR_OP_INITIATED(SLAP_OP_MODIFY); - rc = do_modify( op, &rs ); + opidx = SLAP_OP_MODIFY; break; case LDAP_REQ_COMPARE: - INCR_OP_INITIATED(SLAP_OP_COMPARE); - rc = do_compare( op, &rs ); + opidx = SLAP_OP_COMPARE; break; case LDAP_REQ_SEARCH: - INCR_OP_INITIATED(SLAP_OP_SEARCH); - rc = do_search( op, &rs ); + opidx = SLAP_OP_SEARCH; break; case LDAP_REQ_ABANDON: - INCR_OP_INITIATED(SLAP_OP_ABANDON); - rc = do_abandon( op, &rs ); + opidx = SLAP_OP_ABANDON; break; case LDAP_REQ_EXTENDED: - INCR_OP_INITIATED(SLAP_OP_EXTENDED); - rc = do_extended( op, &rs ); + opidx = SLAP_OP_EXTENDED; break; default: @@ -1023,52 +1033,20 @@ connection_operation( void *ctx, void *arg_v ) assert( 0 ); } + assert( opidx > -1 ); + INCR_OP_INITIATED( opidx ); + rc = (*(opfun[opidx]))( op, &rs ); + operations_error: - if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR; + if ( rc == SLAPD_DISCONNECT ) { + tag = LBER_ERROR; -#ifdef SLAPD_MONITOR - switch (oldtag) { - case LDAP_REQ_BIND: - INCR_OP_COMPLETED(SLAP_OP_BIND); - break; - case LDAP_REQ_UNBIND: - INCR_OP_COMPLETED(SLAP_OP_UNBIND); - break; - case LDAP_REQ_ADD: - INCR_OP_COMPLETED(SLAP_OP_ADD); - break; - case LDAP_REQ_DELETE: - INCR_OP_COMPLETED(SLAP_OP_DELETE); - break; - case LDAP_REQ_MODDN: - INCR_OP_COMPLETED(SLAP_OP_MODRDN); - break; - case LDAP_REQ_MODIFY: - INCR_OP_COMPLETED(SLAP_OP_MODIFY); - break; - case LDAP_REQ_COMPARE: - INCR_OP_COMPLETED(SLAP_OP_COMPARE); - break; - case LDAP_REQ_SEARCH: - INCR_OP_COMPLETED(SLAP_OP_SEARCH); - break; - case LDAP_REQ_ABANDON: - INCR_OP_COMPLETED(SLAP_OP_ABANDON); - break; - case LDAP_REQ_EXTENDED: - INCR_OP_COMPLETED(SLAP_OP_EXTENDED); - break; - default: - /* this is reachable */ -#if 0 - /* not reachable */ - assert( 0 ) -#endif - ; + } else if ( opidx > -1 ) { + /* increment completed operations count + * only if operation was initiated + * and rc != SLAPD_DISCONNECT */ + INCR_OP_COMPLETED( opidx ); } -#endif /* SLAPD_MONITOR */ - - ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); if ( op->o_cancel == SLAP_CANCEL_REQ ) { op->o_cancel = LDAP_TOO_LATE; @@ -1083,27 +1061,11 @@ operations_error: ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null ); -#if 0 /* DELETE ME */ - if ( op->o_cancel != SLAP_CANCEL_ACK && - ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) - { - slap_sl_mem_detach( ctx, memctx ); - } else if ( op->o_sync_slog_size != -1 ) { - slap_sl_mem_detach( ctx, memctx ); - LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); - LDAP_STAILQ_NEXT(op, o_next) = NULL; - conn->c_n_ops_executing--; - conn->c_n_ops_completed++; - - } else -#endif - { - LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); - LDAP_STAILQ_NEXT(op, o_next) = NULL; - slap_op_free( op ); - conn->c_n_ops_executing--; - conn->c_n_ops_completed++; - } + LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next); + LDAP_STAILQ_NEXT(op, o_next) = NULL; + slap_op_free( op ); + conn->c_n_ops_executing--; + conn->c_n_ops_completed++; switch( tag ) { case LBER_ERROR: @@ -1448,7 +1410,7 @@ connection_input( } #endif if(tag == LDAP_REQ_BIND) { - /* immediately abandon all exiting operations upon BIND */ + /* immediately abandon all existing operations upon BIND */ connection_abandon( conn ); } @@ -1677,8 +1639,6 @@ int connection_write(ber_socket_t s) c = connection_get( s ); - slapd_clr_write( s, 0); - if( c == NULL ) { Debug( LDAP_DEBUG_ANY, "connection_write(%ld): no connection!\n", @@ -1688,6 +1648,8 @@ int connection_write(ber_socket_t s) return -1; } + slapd_clr_write( s, 0); + c->c_n_write++; Debug( LDAP_DEBUG_TRACE,