]> git.sur5r.net Git - openldap/commitdiff
added operations and sent stats to back-monitor; minor cleanup
authorPierangelo Masarati <ando@openldap.org>
Sat, 22 Dec 2001 19:14:10 +0000 (19:14 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 22 Dec 2001 19:14:10 +0000 (19:14 +0000)
12 files changed:
servers/slapd/back-monitor/Makefile.in
servers/slapd/back-monitor/back-monitor.h
servers/slapd/back-monitor/backend.c
servers/slapd/back-monitor/conn.c
servers/slapd/back-monitor/database.c
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/operation.c [new file with mode: 0644]
servers/slapd/back-monitor/proto-back-monitor.h
servers/slapd/back-monitor/rww.c
servers/slapd/back-monitor/search.c
servers/slapd/back-monitor/sent.c [new file with mode: 0644]
servers/slapd/tools/mimic.c

index 7650495db395d991b9202e9f7eedf942359d196a..1cdce32ce8be10e794b625201b47ca1a8ba8fba4 100644 (file)
@@ -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       
index 7b5d71f5c4242c40ec8e99c138e6d79991ad6d49..17441a8b01b66e55a2e1dacbd5747063210d42ee 100644 (file)
@@ -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;
index ca359096a80970cf6a6da80aaedcb15a065b5ebc..a357957e318bda0fceba611369ddc2e1c2ad3159 100644 (file)
@@ -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 );
 }
index ff65b7503b5128961f5335dc99eaea7484c9a2bc..f5fad1a0f2a787f2a1f152c2dc4d7ce13092391f 100644 (file)
@@ -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 );
                                }
                        }
                }
index 3c3b5c402001ead0a662f6f0616354d2980615d6..54ec297ac8df1623ff40185deb7afc72e89ba32e 100644 (file)
@@ -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];
index db4713afb1a2cc6e47e0534dbea0920f86114f95..8758715e73798844a3083257474b96957020d61a 100644 (file)
@@ -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 (file)
index 0000000..6e617f1
--- /dev/null
@@ -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. <ando@sys-net.it>
+ * 
+ * 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 <stdio.h>
+
+#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 );
+}
+
index ca16fd5a59a3478ac3273339c90667680e22adb6..e9c4e8fa90fb470b5422bd7fd7c02904c70c3b2d 100644 (file)
@@ -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
index e05c45288b68c7bd000cebd975b5be070cfc7bd4..91ccc0bb0f6e647b3709bb0d6f22e77235fc6797 100644 (file)
@@ -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;
                        }
index 64f3b95e6d4f59beeb3fcb7a525851d85149ada9..000369d29bda2194d168318a6ae197860a7a5a2a 100644 (file)
@@ -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 (file)
index 0000000..72e84bb
--- /dev/null
@@ -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. <ando@sys-net.it>
+ * 
+ * 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 <stdio.h>
+
+#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 );
+}
+
index ef6bad5d1fd18b262ec64ebb8dc8d47dd487c3ea..50e8325af49117588e053029b76ae99451f0f91f 100644 (file)
@@ -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);