]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/monitor.c
Unify use of BDB lockers
[openldap] / servers / slapd / back-bdb / monitor.c
index 7607618f615ef4b3e40eb9695a41908ed296966f..9114fac70b8ade71f5b883173f4b6eb4ddca6251 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2006 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,6 +27,8 @@
 
 #include "../back-monitor/back-monitor.h"
 
+#include "config.h"
+
 static ObjectClass             *oc_olmBDBDatabase;
 
 static AttributeDescription    *ad_olmBDBEntryCache,
@@ -65,7 +67,7 @@ static struct {
                "DESC 'Number of items in Entry Cache' "
                "SUP monitorCounter "
                "NO-USER-MODIFICATION "
-               "USAGE directoryOperation )",
+               "USAGE dSAOperation )",
                &ad_olmBDBEntryCache },
 
        { "( olmBDBAttributes:2 "
@@ -73,7 +75,7 @@ static struct {
                "DESC 'Number of items in EntryInfo Cache' "
                "SUP monitorCounter "
                "NO-USER-MODIFICATION "
-               "USAGE directoryOperation )",
+               "USAGE dSAOperation )",
                &ad_olmBDBEntryInfo },
 
        { "( olmBDBAttributes:3 "
@@ -81,7 +83,7 @@ static struct {
                "DESC 'Number of items in IDL Cache' "
                "SUP monitorCounter "
                "NO-USER-MODIFICATION "
-               "USAGE directoryOperation )",
+               "USAGE dSAOperation )",
                &ad_olmBDBIDLCache },
 
        { "( olmBDBAttributes:4 "
@@ -90,7 +92,7 @@ static struct {
                        "where the database environment resides' "
                "SUP monitoredInfo "
                "NO-USER-MODIFICATION "
-               "USAGE directoryOperation )",
+               "USAGE dSAOperation )",
                &ad_olmDbDirectory },
 
        { NULL }
@@ -150,6 +152,7 @@ bdb_monitor_update(
        return SLAP_CB_CONTINUE;
 }
 
+#if 0  /* uncomment if required */
 static int
 bdb_monitor_modify(
        Operation       *op,
@@ -159,11 +162,12 @@ bdb_monitor_modify(
 {
        return SLAP_CB_CONTINUE;
 }
+#endif
 
 static int
 bdb_monitor_free(
        Entry           *e,
-       void            *priv )
+       void            **priv )
 {
        struct berval   values[ 2 ];
        Modification    mod = { 0 };
@@ -173,6 +177,9 @@ bdb_monitor_free(
 
        int             i, rc;
 
+       /* NOTE: if slap_shutdown != 0, priv might have already been freed */
+       *priv = NULL;
+
        /* Remove objectClass */
        mod.sm_op = LDAP_MOD_DELETE;
        mod.sm_desc = slap_schema.si_ad_objectClass;
@@ -196,35 +203,41 @@ bdb_monitor_free(
        return SLAP_CB_CONTINUE;
 }
 
+#define        bdb_monitor_initialize  BDB_SYMBOL(monitor_initialize)
+
 /*
  * call from within bdb_initialize()
  */
-int
+static int
 bdb_monitor_initialize( void )
 {
        int             i, code;
-       BackendInfo *bi;
+       ConfigArgs c;
+       char    *argv[ 3 ];
 
        static int      bdb_monitor_initialized = 0;
 
-       bi = backend_info("monitor");
-       if ( !bi )
+       if ( backend_info( "monitor" ) == NULL ) {
                return -1;
-
-       /* register schema here */
+       }
 
        if ( bdb_monitor_initialized++ ) {
                return 0;
        }
 
+       /* register schema here */
+
+       argv[ 0 ] = "back-bdb/back-hdb monitor";
+       c.argv = argv;
+       c.argc = 3;
+       c.fname = argv[0];
+
        for ( i = 0; s_oid[ i ].name; i++ ) {
-               char    *argv[ 3 ];
-       
-               argv[ 0 ] = "back-bdb/back-hdb monitor";
+               c.lineno = i;
                argv[ 1 ] = s_oid[ i ].name;
                argv[ 2 ] = s_oid[ i ].oid;
 
-               if ( parse_oidm( argv[ 0 ], i, 3, argv, 0, NULL ) != 0 ) {
+               if ( parse_oidm( &c, 0, NULL ) != 0 ) {
                        Debug( LDAP_DEBUG_ANY,
                                "bdb_monitor_initialize: unable to add "
                                "objectIdentifier \"%s=%s\"\n",
@@ -258,12 +271,17 @@ bdb_monitor_initialize( void )
  * call from within bdb_db_init()
  */
 int
-bdb_monitor_init( BackendDB *be )
+bdb_monitor_db_init( BackendDB *be )
 {
+       struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
+
        if ( bdb_monitor_initialize() == LDAP_SUCCESS ) {
+               /* monitoring in back-bdb is on by default */
                SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
        }
 
+       bdb->bi_monitor.bdm_scope = -1;
+
        return 0;
 }
 
@@ -271,7 +289,7 @@ bdb_monitor_init( BackendDB *be )
  * call from within bdb_db_open()
  */
 int
-bdb_monitor_open( BackendDB *be )
+bdb_monitor_db_open( BackendDB *be )
 {
        struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
        Attribute               *a, *next;
@@ -279,20 +297,19 @@ bdb_monitor_open( BackendDB *be )
        struct berval           suffix, *filter, *base;
        char                    *ptr;
        int                     rc = 0;
-       monitor_extra_t *mbe;
+       BackendInfo             *mi;
+       monitor_extra_t         *mbe;
 
        if ( !SLAP_DBMONITORING( be ) ) {
                return 0;
        }
 
-       {
-               BackendInfo *mi = backend_info( "monitor" );
-               if ( !mi || !mi->bi_extra ) {
-                       SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
-                       return 0;
-               }
-               mbe = mi->bi_extra;
+       mi = backend_info( "monitor" );
+       if ( !mi || !mi->bi_extra ) {
+               SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
+               return 0;
        }
+       mbe = mi->bi_extra;
 
        /* don't bother if monitor is not configured */
        if ( !mbe->is_configured() ) {
@@ -308,7 +325,9 @@ bdb_monitor_open( BackendDB *be )
                return 0;
        }
 
-       bdb->bi_monitor.bdm_scope = LDAP_SCOPE_SUBORDINATE;
+       if ( bdb->bi_monitor.bdm_scope == -1 ) {
+               bdb->bi_monitor.bdm_scope = LDAP_SCOPE_ONELEVEL;
+       }
        base = &bdb->bi_monitor.bdm_nbase;
        BER_BVSTR( base, "cn=databases,cn=monitor" );
        filter = &bdb->bi_monitor.bdm_filter;
@@ -321,17 +340,25 @@ bdb_monitor_open( BackendDB *be )
        } else {
                ldap_bv2escaped_filter_value( &be->be_nsuffix[ 0 ], &suffix );
        }
-       
-       filter->bv_len = STRLENOF( "(&(monitoredInfo=" )
-               + strlen( be->bd_info->bi_type )
-               + STRLENOF( ")(namingContexts:distinguishedNameMatch:=" )
-               + suffix.bv_len + STRLENOF( "))" );
-       ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
-       ptr = lutil_strcopy( ptr, "(&(monitoredInfo=" );
-       ptr = lutil_strcopy( ptr, be->bd_info->bi_type );
-       ptr = lutil_strcopy( ptr, ")(namingContexts:distinguishedNameMatch:=" );
-       ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
-       ptr = lutil_strcopy( ptr, "))" );
+
+       if ( BER_BVISEMPTY( &suffix ) ) {
+               /* frontend also has empty suffix, sigh! */
+               filter->bv_len = STRLENOF( "(&(namingContexts:distinguishedNameMatch:=" )
+                       + suffix.bv_len + STRLENOF( ")(!(cn=frontend)))" );
+               ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
+               ptr = lutil_strcopy( ptr, "(&(namingContexts:distinguishedNameMatch:=" );
+               ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
+               ptr = lutil_strcopy( ptr, ")(!(cn=frontend)))" );
+
+       } else {
+               /* just look for the naming context */
+               filter->bv_len = STRLENOF( "(namingContexts:distinguishedNameMatch:=" )
+                       + suffix.bv_len + STRLENOF( ")" );
+               ptr = filter->bv_val = ch_malloc( filter->bv_len + 1 );
+               ptr = lutil_strcopy( ptr, "(namingContexts:distinguishedNameMatch:=" );
+               ptr = lutil_strncopy( ptr, suffix.bv_val, suffix.bv_len );
+               ptr = lutil_strcopy( ptr, ")" );
+       }
        ptr[ 0 ] = '\0';
        assert( filter->bv_len == ptr - filter->bv_val );
        
@@ -422,12 +449,14 @@ bdb_monitor_open( BackendDB *be )
 
        cb = ch_calloc( sizeof( monitor_callback_t ), 1 );
        cb->mc_update = bdb_monitor_update;
+#if 0  /* uncomment if required */
        cb->mc_modify = bdb_monitor_modify;
+#endif
        cb->mc_free = bdb_monitor_free;
        cb->mc_private = (void *)bdb;
 
        rc = mbe->register_entry_attrs( NULL, a, cb,
-               base, LDAP_SCOPE_SUBORDINATE, filter );
+               base, bdb->bi_monitor.bdm_scope, filter );
 
 cleanup:;
        if ( rc != 0 ) {
@@ -463,22 +492,22 @@ cleanup:;
  * call from within bdb_db_close()
  */
 int
-bdb_monitor_close( BackendDB *be )
+bdb_monitor_db_close( BackendDB *be )
 {
        struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
 
        if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) {
-               BackendInfo *mi = backend_info( "monitor" );
-               monitor_extra_t *mbe;
-
-               if ( !mi || !mi->bi_extra )
-                       return 0;
-               mbe = mi->bi_extra;
-               mbe->unregister_entry_callback( NULL,
-                       (monitor_callback_t *)bdb->bi_monitor.bdm_cb,
-                       &bdb->bi_monitor.bdm_nbase,
-                       bdb->bi_monitor.bdm_scope,
-                       &bdb->bi_monitor.bdm_filter );
+               BackendInfo             *mi = backend_info( "monitor" );
+               monitor_extra_t         *mbe;
+
+               if ( mi && &mi->bi_extra ) {
+                       mbe = mi->bi_extra;
+                       mbe->unregister_entry_callback( NULL,
+                               (monitor_callback_t *)bdb->bi_monitor.bdm_cb,
+                               &bdb->bi_monitor.bdm_nbase,
+                               bdb->bi_monitor.bdm_scope,
+                               &bdb->bi_monitor.bdm_filter );
+               }
 
                if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) {
                        ch_free( bdb->bi_monitor.bdm_filter.bv_val );
@@ -494,7 +523,7 @@ bdb_monitor_close( BackendDB *be )
  * call from within bdb_db_destroy()
  */
 int
-bdb_monitor_destroy( BackendDB *be )
+bdb_monitor_db_destroy( BackendDB *be )
 {
        return 0;
 }