From de903b65c9054da6b9651aae04f872955fe899ec Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 22 Dec 2001 19:14:10 +0000 Subject: [PATCH] added operations and sent stats to back-monitor; minor cleanup --- servers/slapd/back-monitor/Makefile.in | 2 + servers/slapd/back-monitor/back-monitor.h | 14 + servers/slapd/back-monitor/backend.c | 2 +- servers/slapd/back-monitor/conn.c | 219 +++++++--- servers/slapd/back-monitor/database.c | 4 +- servers/slapd/back-monitor/init.c | 16 + servers/slapd/back-monitor/operation.c | 251 ++++++++++++ .../slapd/back-monitor/proto-back-monitor.h | 12 + servers/slapd/back-monitor/rww.c | 2 +- servers/slapd/back-monitor/search.c | 40 +- servers/slapd/back-monitor/sent.c | 387 ++++++++++++++++++ servers/slapd/tools/mimic.c | 5 + 12 files changed, 890 insertions(+), 64 deletions(-) create mode 100644 servers/slapd/back-monitor/operation.c create mode 100644 servers/slapd/back-monitor/sent.c diff --git a/servers/slapd/back-monitor/Makefile.in b/servers/slapd/back-monitor/Makefile.in index 7650495db3..1cdce32ce8 100644 --- a/servers/slapd/back-monitor/Makefile.in +++ b/servers/slapd/back-monitor/Makefile.in @@ -4,11 +4,13 @@ SRCS = init.c search.c compare.c abandon.c modify.c bind.c \ operational.c \ cache.c entry.c \ backend.c database.c thread.c conn.c rww.c log.c \ + operation.c sent.c \ dummy.c OBJS = init.lo search.lo compare.lo abandon.lo modify.lo bind.lo \ operational.lo \ cache.lo entry.lo \ backend.lo database.lo thread.lo conn.lo rww.lo log.lo \ + operation.lo sent.lo \ dummy.lo LDAP_INCDIR= ../../../include diff --git a/servers/slapd/back-monitor/back-monitor.h b/servers/slapd/back-monitor/back-monitor.h index 7b5d71f5c4..17441a8b01 100644 --- a/servers/slapd/back-monitor/back-monitor.h +++ b/servers/slapd/back-monitor/back-monitor.h @@ -151,6 +151,20 @@ struct monitorinfo { #define SLAPD_MONITOR_LOG_DN \ SLAPD_MONITOR_LOG_RDN "," SLAPD_MONITOR_DN +#define SLAPD_MONITOR_OPS 10 +#define SLAPD_MONITOR_OPS_NAME "Operations" +#define SLAPD_MONITOR_OPS_RDN \ + "cn=" SLAPD_MONITOR_OPS_NAME +#define SLAPD_MONITOR_OPS_DN \ + SLAPD_MONITOR_OPS_RDN "," SLAPD_MONITOR_DN + +#define SLAPD_MONITOR_SENT 11 +#define SLAPD_MONITOR_SENT_NAME "Sent" +#define SLAPD_MONITOR_SENT_RDN \ + "cn=" SLAPD_MONITOR_SENT_NAME +#define SLAPD_MONITOR_SENT_DN \ + SLAPD_MONITOR_SENT_RDN "," SLAPD_MONITOR_DN + struct monitorsubsys { int mss_type; char *mss_name; diff --git a/servers/slapd/back-monitor/backend.c b/servers/slapd/back-monitor/backend.c index ca359096a8..a357957e31 100644 --- a/servers/slapd/back-monitor/backend.c +++ b/servers/slapd/back-monitor/backend.c @@ -156,7 +156,7 @@ monitor_subsys_backend_init( mp = ( struct monitorentrypriv * )e_backend->e_private; mp->mp_children = e_tmp; - monitor_cache_release( mi, e_backend); + monitor_cache_release( mi, e_backend ); return( 0 ); } diff --git a/servers/slapd/back-monitor/conn.c b/servers/slapd/back-monitor/conn.c index ff65b7503b..f5fad1a0f2 100644 --- a/servers/slapd/back-monitor/conn.c +++ b/servers/slapd/back-monitor/conn.c @@ -48,15 +48,17 @@ monitor_subsys_conn_init( { struct monitorinfo *mi; - Entry *e; - struct berval *bv[2], val; + Entry *e, *e_tmp, *e_conn; + struct monitorentrypriv *mp; + char buf[1024]; + struct berval val, *bv[2] = { &val, NULL }; assert( be != NULL ); mi = ( struct monitorinfo * )be->be_private; if ( monitor_cache_get( mi, - monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e ) ) { + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e_conn ) ) { #ifdef NEW_LOGGING LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, "monitor_subsys_conn_init: " @@ -72,10 +74,134 @@ monitor_subsys_conn_init( return( -1 ); } - bv[0] = &val; - bv[1] = NULL; + e_tmp = NULL; + + /* + * Total conns + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Total,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Total\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_conn_init: " + "unable to create entry 'cn=Total,%s'\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_conn_init: " + "unable to create entry 'cn=Total,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + mp->mp_flags &= ~MONITOR_F_VOLATILE_CH; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_conn_init: " + "unable to add entry 'cn=Total,%s'\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_conn_init: " + "unable to add entry 'cn=Total,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + /* + * Current conns + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Current,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Current\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_conn_init: " + "unable to create entry 'cn=Current,%s'\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_conn_init: " + "unable to create entry 'cn=Current,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_CONN]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_CONN].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + mp->mp_flags &= ~MONITOR_F_VOLATILE_CH; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_conn_init: " + "unable to add entry 'cn=Current,%s'\n", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_conn_init: " + "unable to add entry 'cn=Current,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + mp = ( struct monitorentrypriv * )e_conn->e_private; + mp->mp_children = e_tmp; - monitor_cache_release( mi, e ); + monitor_cache_release( mi, e_conn ); return( 0 ); } @@ -86,53 +212,41 @@ monitor_subsys_conn_update( Entry *e ) { - Connection *c; - int connindex; - int nconns, nwritewaiters, nreadwaiters; + long n = -1; - Attribute *a; - struct berval *bv[2], val, **b = NULL; - char buf[1024]; - - assert( mi != NULL ); - assert( e != NULL ); + assert( mi ); + assert( e ); - bv[0] = &val; - bv[1] = NULL; - - nconns = nwritewaiters = nreadwaiters = 0; - for ( c = connection_first( &connindex ); - c != NULL; - c = connection_next( c, &connindex ), nconns++ ) { - if ( c->c_writewaiter ) { - nwritewaiters++; - } - if ( c->c_currentber != NULL ) { - nreadwaiters++; + if ( strncasecmp( e->e_ndn, "CN=TOTAL", + sizeof("CN=TOTAL")-1 ) == 0 ) { + n = connections_nextid(); + + } else if ( strncasecmp( e->e_ndn, "CN=CURRENT", + sizeof("CN=CURRENT")-1 ) == 0 ) { + Connection *c; + int connindex; + + for ( n = 0, c = connection_first( &connindex ); + c != NULL; + n++, c = connection_next( c, &connindex ) ) { + /* No Op */ ; } + connection_done(c); } - connection_done(c); - -#if 0 - snprintf( buf, sizeof( buf ), "readwaiters=%d", nreadwaiters ); - - if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) { - for ( b = a->a_vals; b[0] != NULL; b++ ) { - if ( strncmp( b[0]->bv_val, "readwaiters=", - sizeof( "readwaiters=" ) - 1 ) == 0 ) { - free( b[0]->bv_val ); - b[0] = ber_bvstrdup( buf ); - break; - } + + if ( n != -1 ) { + Attribute *a; + char buf[16]; + + a = attr_find( e->e_attrs, monitor_ad_desc ); + if ( a == NULL ) { + return( -1 ); } + + snprintf( buf, sizeof( buf ), "%ld", n ); + ber_bvfree( a->a_vals[ 0 ] ); + a->a_vals[ 0 ] = ber_bvstrdup( buf ); } - - if ( b == NULL || b[0] == NULL ) { - val.bv_val = buf; - val.bv_len = strlen( buf ); - attr_merge( e, monitor_ad_desc, bv ); - } -#endif return( 0 ); } @@ -149,7 +263,7 @@ conn_create( char buf2[22]; char buf3[22]; - struct berval *bv[2], val; + struct berval val, *bv[2] = { &val, NULL }; Entry *e; @@ -232,9 +346,6 @@ conn_create( buf3 ); - bv[0] = &val; - bv[1] = NULL; - val.bv_val = buf; val.bv_len = strlen( buf ); attr_merge( e, monitor_ad_desc, bv ); @@ -276,7 +387,8 @@ monitor_subsys_conn_create( c != NULL; c = connection_next( c, &connindex )) { if ( conn_create( c, &e ) || e == NULL ) { - // error + connection_done(c); + return( -1 ); } mp = ( struct monitorentrypriv * )e->e_private; mp->mp_next = e_tmp; @@ -301,7 +413,8 @@ monitor_subsys_conn_create( c = connection_next( c, &connindex )) { if ( c->c_connid == connid ) { if ( conn_create( c, ep ) || *ep == NULL ) { - // error + connection_done(c); + return( -1 ); } } } diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index 3c3b5c4020..54ec297ac8 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -51,7 +51,7 @@ monitor_subsys_database_init( int i; struct monitorentrypriv *mp; AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts; - struct berval *bv[2], val; + struct berval val, *bv[2] = { &val, NULL }; assert( be != NULL ); assert( monitor_ad_desc != NULL ); @@ -76,8 +76,6 @@ monitor_subsys_database_init( return( -1 ); } - bv[0] = &val; - bv[1] = NULL; e_tmp = NULL; for ( i = nBackendDB; i--; ) { char buf[1024]; diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index db4713afb1..8758715e73 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -130,6 +130,22 @@ struct monitorsubsys monitor_subsys[] = { NULL, /* update */ NULL, /* create */ monitor_subsys_log_modify + }, { + SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME, + NULL, NULL, NULL, + MONITOR_F_NONE, + monitor_subsys_ops_init, + monitor_subsys_ops_update, + NULL, /* create */ + NULL, /* modify */ + }, { + SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME, + NULL, NULL, NULL, + MONITOR_F_NONE, + monitor_subsys_sent_init, + monitor_subsys_sent_update, + NULL, /* create */ + NULL, /* modify */ }, { -1, NULL } }; diff --git a/servers/slapd/back-monitor/operation.c b/servers/slapd/back-monitor/operation.c new file mode 100644 index 0000000000..6e617f19b2 --- /dev/null +++ b/servers/slapd/back-monitor/operation.c @@ -0,0 +1,251 @@ +/* operation.c - deal with operation subsystem */ +/* + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* + * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + * + * Copyright 2001, Pierangelo Masarati, All rights reserved. + * + * This work has beed deveolped for the OpenLDAP Foundation + * in the hope that it may be useful to the Open Source community, + * but WITHOUT ANY WARRANTY. + * + * Permission is granted to anyone to use this software for any purpose + * on any computer system, and to alter it and redistribute it, subject + * to the following restrictions: + * + * 1. The author and SysNet s.n.c. are not responsible for the consequences + * of use of this software, no matter how awful, even if they arise from + * flaws in it. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Since few users ever read sources, + * credits should appear in the documentation. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. Since few users + * ever read sources, credits should appear in the documentation. + * SysNet s.n.c. cannot be responsible for the consequences of the + * alterations. + * + * 4. This notice may not be removed or altered. + */ + +#include "portable.h" + +#include + +#include "slap.h" +#include "back-monitor.h" + +int +monitor_subsys_ops_init( + BackendDB *be +) +{ + struct monitorinfo *mi; + + Entry *e, *e_tmp, *e_op; + struct monitorentrypriv *mp; + char buf[1024]; + struct berval val, *bv[2] = { &val, NULL }; + + assert( be != NULL ); + + mi = ( struct monitorinfo * )be->be_private; + + if ( monitor_cache_get( mi, + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_ops_init: " + "unable to get entry '%s'\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_ops_init: " + "unable to get entry '%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = NULL; + + /* + * Initiated ops + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Initiated,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Initiated\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_ops_init: " + "unable to create entry 'cn=Initiated,%s'\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_ops_init: " + "unable to create entry 'cn=Initiated,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_ops_init: " + "unable to add entry 'cn=Initiated,%s'\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_ops_init: " + "unable to add entry 'cn=Initiated,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + /* + * Completed ops + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Completed,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Completed\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_ops_init: " + "unable to create entry 'cn=Completed,%s'\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_ops_init: " + "unable to create entry 'cn=Completed,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_ops_init: " + "unable to add entry 'cn=Completed,%s'\n", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_ops_init: " + "unable to add entry 'cn=Completed,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + mp = ( struct monitorentrypriv * )e_op->e_private; + mp->mp_children = e_tmp; + + monitor_cache_release( mi, e_op ); + + return( 0 ); +} + +int +monitor_subsys_ops_update( + struct monitorinfo *mi, + Entry *e +) +{ + long n = -1; + + assert( mi ); + assert( e ); + + if ( strncasecmp( e->e_ndn, "CN=INITIATED", + sizeof("CN=INITIATED")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_ops_mutex); + n = num_ops_initiated; + ldap_pvt_thread_mutex_unlock(&num_ops_mutex); + + } else if ( strncasecmp( e->e_ndn, "CN=COMPLETED", + sizeof("CN=COMPLETED")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_ops_mutex); + n = num_ops_completed; + ldap_pvt_thread_mutex_unlock(&num_ops_mutex); + } + + if ( n != -1 ) { + Attribute *a; + char buf[16]; + + a = attr_find( e->e_attrs, monitor_ad_desc ); + if ( a == NULL ) { + return( -1 ); + } + + snprintf( buf, sizeof( buf ), "%ld", n ); + ber_bvfree( a->a_vals[ 0 ] ); + a->a_vals[ 0 ] = ber_bvstrdup( buf ); + } + + return( 0 ); +} + diff --git a/servers/slapd/back-monitor/proto-back-monitor.h b/servers/slapd/back-monitor/proto-back-monitor.h index ca16fd5a59..e9c4e8fa90 100644 --- a/servers/slapd/back-monitor/proto-back-monitor.h +++ b/servers/slapd/back-monitor/proto-back-monitor.h @@ -86,5 +86,17 @@ int monitor_subsys_writew_update LDAP_P(( struct monitorinfo *mi, Entry *e )); int monitor_subsys_log_init LDAP_P(( BackendDB *be )); int monitor_subsys_log_modify LDAP_P(( struct monitorinfo *mi, Entry *e, Modifications *modlist )); +/* + * operations + */ +int monitor_subsys_ops_init LDAP_P(( BackendDB *be )); +int monitor_subsys_ops_update LDAP_P(( struct monitorinfo *mi, Entry *e )); + +/* + * sent + */ +int monitor_subsys_sent_init LDAP_P(( BackendDB *be )); +int monitor_subsys_sent_update LDAP_P(( struct monitorinfo *mi, Entry *e )); + LDAP_END_DECL #endif diff --git a/servers/slapd/back-monitor/rww.c b/servers/slapd/back-monitor/rww.c index e05c45288b..91ccc0bb0f 100644 --- a/servers/slapd/back-monitor/rww.c +++ b/servers/slapd/back-monitor/rww.c @@ -116,7 +116,7 @@ monitor_subsys_readw_update_internal( if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) { for ( b = a->a_vals; b[0] != NULL; b++ ) { if ( strncmp( b[0]->bv_val, str, strlen( str ) ) == 0 ) { - free( b[0]->bv_val ); + ber_bvfree( b[0] ); b[0] = ber_bvstrdup( buf ); break; } diff --git a/servers/slapd/back-monitor/search.c b/servers/slapd/back-monitor/search.c index 64f3b95e6d..000369d29b 100644 --- a/servers/slapd/back-monitor/search.c +++ b/servers/slapd/back-monitor/search.c @@ -59,7 +59,7 @@ monitor_send_children( ) { struct monitorinfo *mi = (struct monitorinfo *) be->be_private; - Entry *e, *e_tmp; + Entry *e, *e_tmp, *e_ch; struct monitorentrypriv *mp; int nentries; int rc; @@ -67,14 +67,42 @@ monitor_send_children( mp = ( struct monitorentrypriv * )e_parent->e_private; e = mp->mp_children; - if ( e == NULL && MONITOR_HAS_VOLATILE_CH( mp ) ) { - monitor_entry_create( mi, NULL, e_parent, &e ); - if ( e != NULL) { - monitor_cache_lock( e ); - } + if ( MONITOR_HAS_VOLATILE_CH( mp ) ) { + monitor_entry_create( mi, NULL, e_parent, &e_ch ); } monitor_cache_release( mi, e_parent ); + /* no volatile entries? */ + if ( e_ch == NULL ) { + /* no persistent entries? return */ + if ( e == NULL ) { + return( 0 ); + } + + /* volatile entries */ + } else { + /* if no persistent, return only volatile */ + if ( e == NULL ) { + e = e_ch; + monitor_cache_lock( e_ch ); + + /* else append persistent to volatile */ + } else { + e_tmp = e_ch; + do { + mp = ( struct monitorentrypriv * )e_tmp->e_private; + e_tmp = mp->mp_next; + + if ( e_tmp == NULL ) { + mp->mp_next = e; + break; + } + } while ( e_tmp ); + e = e_ch; + } + } + + /* return entries */ for ( nentries = *nentriesp; e != NULL; ) { mp = ( struct monitorentrypriv * )e->e_private; diff --git a/servers/slapd/back-monitor/sent.c b/servers/slapd/back-monitor/sent.c new file mode 100644 index 0000000000..72e84bba13 --- /dev/null +++ b/servers/slapd/back-monitor/sent.c @@ -0,0 +1,387 @@ +/* sent.c - deal with data sent subsystem */ +/* + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* + * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + * + * Copyright 2001, Pierangelo Masarati, All rights reserved. + * + * This work has beed deveolped for the OpenLDAP Foundation + * in the hope that it may be useful to the Open Source community, + * but WITHOUT ANY WARRANTY. + * + * Permission is granted to anyone to use this software for any purpose + * on any computer system, and to alter it and redistribute it, subject + * to the following restrictions: + * + * 1. The author and SysNet s.n.c. are not responsible for the consequences + * of use of this software, no matter how awful, even if they arise from + * flaws in it. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Since few users ever read sources, + * credits should appear in the documentation. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. Since few users + * ever read sources, credits should appear in the documentation. + * SysNet s.n.c. cannot be responsible for the consequences of the + * alterations. + * + * 4. This notice may not be removed or altered. + */ + +#include "portable.h" + +#include + +#include "slap.h" +#include "back-monitor.h" + +int +monitor_subsys_sent_init( + BackendDB *be +) +{ + struct monitorinfo *mi; + + Entry *e, *e_tmp, *e_sent; + struct monitorentrypriv *mp; + char buf[1024]; + struct berval val, *bv[2] = { &val, NULL }; + + assert( be != NULL ); + + mi = ( struct monitorinfo * )be->be_private; + + if ( monitor_cache_get( mi, + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, &e_sent ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to get entry '%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to get entry '%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = NULL; + + /* + * Entries + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Entries,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Entries\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Entries,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Entries,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Entries,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Entries,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + /* + * Referrals + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Referrals,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Referrals\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Referrals,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Referrals,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Referrals,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Referrals,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + /* + * PDU + */ + snprintf( buf, sizeof( buf ), + "dn: cn=PDU,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: PDU\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=PDU,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=PDU,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=PDU,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=PDU,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + /* + * Bytes + */ + snprintf( buf, sizeof( buf ), + "dn: cn=Bytes,%s\n" + "objectClass: top\n" + "objectClass: LDAPsubEntry\n" +#ifdef SLAPD_MONITORSUBENTRY + "objectClass: monitorSubEntry\n" +#else /* !SLAPD_MONITORSUBENTRY */ + "objectClass: extensibleObject\n" +#endif /* !SLAPD_MONITORSUBENTRY */ + "cn: Bytes\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_dn ); + + e = str2entry( buf ); + if ( e == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Bytes,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to create entry 'cn=Bytes,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + val.bv_val = "0"; + val.bv_len = 1; + attr_merge( e, monitor_ad_desc, bv ); + + mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 ); + e->e_private = ( void * )mp; + mp->mp_next = e_tmp; + mp->mp_children = NULL; + mp->mp_info = &monitor_subsys[SLAPD_MONITOR_SENT]; + mp->mp_flags = monitor_subsys[SLAPD_MONITOR_SENT].mss_flags \ + | MONITOR_F_SUB | MONITOR_F_PERSISTENT; + + if ( monitor_cache_add( mi, e ) ) { +#ifdef NEW_LOGGING + LDAP_LOG(( "operation", LDAP_LEVEL_CRIT, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Bytes,%s'\n", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn )); +#else + Debug( LDAP_DEBUG_ANY, + "monitor_subsys_sent_init: " + "unable to add entry 'cn=Bytes,%s'\n%s%s", + monitor_subsys[SLAPD_MONITOR_SENT].mss_ndn, + "", "" ); +#endif + return( -1 ); + } + + e_tmp = e; + + mp = ( struct monitorentrypriv * )e_sent->e_private; + mp->mp_children = e_tmp; + + monitor_cache_release( mi, e_sent ); + + return( 0 ); +} + +int +monitor_subsys_sent_update( + struct monitorinfo *mi, + Entry *e +) +{ + long n = -1; + + assert( mi ); + assert( e ); + + if ( strncasecmp( e->e_ndn, "CN=ENTRIES", + sizeof("CN=ENTRIES")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_sent_mutex); + n = num_entries_sent; + ldap_pvt_thread_mutex_unlock(&num_sent_mutex); + + } else if ( strncasecmp( e->e_ndn, "CN=REFERRALS", + sizeof("CN=REFERRALS")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_sent_mutex); + n = num_refs_sent; + ldap_pvt_thread_mutex_unlock(&num_sent_mutex); + + } else if ( strncasecmp( e->e_ndn, "CN=PDU", + sizeof("CN=PDU")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_sent_mutex); + n = num_pdu_sent; + ldap_pvt_thread_mutex_unlock(&num_sent_mutex); + + } else if ( strncasecmp( e->e_ndn, "CN=BYTES", + sizeof("CN=BYTES")-1 ) == 0 ) { + ldap_pvt_thread_mutex_lock(&num_sent_mutex); + n = num_bytes_sent; + ldap_pvt_thread_mutex_unlock(&num_sent_mutex); + } + + if ( n != -1 ) { + Attribute *a; + char buf[16]; + + a = attr_find( e->e_attrs, monitor_ad_desc ); + if ( a == NULL ) { + return( -1 ); + } + + snprintf( buf, sizeof( buf ), "%ld", n ); + ber_bvfree( a->a_vals[ 0 ] ); + a->a_vals[ 0 ] = ber_bvstrdup( buf ); + } + + return( 0 ); +} + diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index ef6bad5d1f..50e8325af4 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -170,6 +170,11 @@ Connection * connection_next( Connection *c, ber_socket_t *b ) return NULL; } +unsigned long connections_nextid(void) +{ + return 0; +} + void connection_done( Connection *c ) { assert(0); -- 2.39.5