From: Pierangelo Masarati Date: Sat, 15 Sep 2007 15:34:49 +0000 (+0000) Subject: apply Howard's cleanup of database monitoring registration X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~634 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=06e6e6c05398a41e434119f75c6510ed6e54d4f9;p=openldap apply Howard's cleanup of database monitoring registration --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 6776e3b68c..5ddb2f370a 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -183,9 +183,7 @@ struct bdb_db_info { typedef struct bdb_monitor_t { void *bdm_cb; - struct berval bdm_nbase; - int bdm_scope; - struct berval bdm_filter; + struct berval bdm_ndn; } bdb_monitor_t; /* From ldap_rq.h */ diff --git a/servers/slapd/back-bdb/monitor.c b/servers/slapd/back-bdb/monitor.c index c99204a657..f30469702c 100644 --- a/servers/slapd/back-bdb/monitor.c +++ b/servers/slapd/back-bdb/monitor.c @@ -317,8 +317,6 @@ bdb_monitor_db_init( BackendDB *be ) ldap_pvt_thread_mutex_init( &bdb->bi_idx_mutex ); #endif /* BDB_MONITOR_IDX */ - bdb->bi_monitor.bdm_scope = -1; - return 0; } @@ -331,11 +329,10 @@ bdb_monitor_db_open( BackendDB *be ) struct bdb_info *bdb = (struct bdb_info *) be->be_private; Attribute *a, *next; monitor_callback_t *cb = NULL; - struct berval suffix, *filter, *base; - char *ptr; int rc = 0; BackendInfo *mi; monitor_extra_t *mbe; + struct berval dummy = BER_BVC(""); if ( !SLAP_DBMONITORING( be ) ) { return 0; @@ -366,47 +363,6 @@ bdb_monitor_db_open( BackendDB *be ) return 0; } - 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; - BER_BVZERO( filter ); - - suffix.bv_len = ldap_bv2escaped_filter_value_len( &be->be_nsuffix[ 0 ] ); - if ( suffix.bv_len == be->be_nsuffix[ 0 ].bv_len ) { - suffix = be->be_nsuffix[ 0 ]; - - } else { - ldap_bv2escaped_filter_value( &be->be_nsuffix[ 0 ], &suffix ); - } - - 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 ); - - if ( suffix.bv_val != be->be_nsuffix[ 0 ].bv_val ) { - ch_free( suffix.bv_val ); - } - /* alloc as many as required (plus 1 for objectClass) */ a = attrs_alloc( 1 + 4 ); if ( a == NULL ) { @@ -497,10 +453,10 @@ bdb_monitor_db_open( BackendDB *be ) cb->mc_private = (void *)bdb; /* make sure the database is registered; then add monitor attributes */ - rc = mbe->register_database( be ); + rc = mbe->register_database( be, &bdb->bi_monitor.bdm_ndn ); if ( rc == 0 ) { - rc = mbe->register_entry_attrs( NULL, a, cb, - base, bdb->bi_monitor.bdm_scope, filter ); + rc = mbe->register_entry_attrs( &bdb->bi_monitor.bdm_ndn, a, cb, + &dummy, 0, &dummy ); } cleanup:; @@ -514,11 +470,6 @@ cleanup:; attrs_free( a ); a = NULL; } - - if ( !BER_BVISNULL( filter ) ) { - ch_free( filter->bv_val ); - BER_BVZERO( filter ); - } } /* store for cleanup */ @@ -545,21 +496,15 @@ bdb_monitor_db_close( BackendDB *be ) return 0; } - if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_filter ) ) { + if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_ndn ) ) { BackendInfo *mi = backend_info( "monitor" ); monitor_extra_t *mbe; if ( mi && &mi->bi_extra ) { mbe = mi->bi_extra; - mbe->unregister_entry_callback( NULL, + mbe->unregister_entry_callback( &bdb->bi_monitor.bdm_ndn, (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 ); + NULL, 0, NULL ); } memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) ); diff --git a/servers/slapd/back-monitor/back-monitor.h b/servers/slapd/back-monitor/back-monitor.h index 6e1ad91793..f69fa39ea1 100644 --- a/servers/slapd/back-monitor/back-monitor.h +++ b/servers/slapd/back-monitor/back-monitor.h @@ -288,7 +288,7 @@ typedef struct monitor_extra_t { int (*register_subsys)( monitor_subsys_t *ms ); int (*register_backend)( BackendInfo *bi ); - int (*register_database)( BackendDB *be ); + int (*register_database)( BackendDB *be, struct berval *ndn ); int (*register_overlay_info)( slap_overinst *on ); int (*register_overlay)( BackendDB *be ); int (*register_entry)( Entry *e, monitor_callback_t *cb, diff --git a/servers/slapd/back-monitor/database.c b/servers/slapd/back-monitor/database.c index f09001ed2b..f150b177bd 100644 --- a/servers/slapd/back-monitor/database.c +++ b/servers/slapd/back-monitor/database.c @@ -343,7 +343,8 @@ monitor_subsys_database_init_one( int monitor_back_register_database( - BackendDB *be ) + BackendDB *be, + struct berval *ndn ) { monitor_info_t *mi; Entry *e_database, **ep; @@ -358,7 +359,7 @@ monitor_back_register_database( assert( be_monitor != NULL ); if ( !monitor_subsys_is_opened() ) { - return monitor_back_register_database_limbo( be ); + return monitor_back_register_database_limbo( be, ndn ); } mi = ( monitor_info_t * )be_monitor->be_private; @@ -443,6 +444,9 @@ monitor_back_register_database( done:; monitor_cache_release( mi, e_database ); + if ( rc == 0 && ndn && ep && *ep ) { + *ndn = (*ep)->e_nname; + } return rc; } diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index 3df03cba3a..5e0128ec0c 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -291,7 +291,7 @@ typedef struct entry_limbo_t { slap_overinst *el_on; Entry *el_e; Attribute *el_a; - struct berval el_ndn; + struct berval *el_ndn; struct berval el_nbase; int el_scope; struct berval el_filter; @@ -337,7 +337,8 @@ monitor_back_register_backend_limbo( int monitor_back_register_database_limbo( - BackendDB *be ) + BackendDB *be, + struct berval *ndn ) { entry_limbo_t **elpp, el = { 0 }; monitor_info_t *mi; @@ -356,6 +357,7 @@ monitor_back_register_database_limbo( el.el_type = LIMBO_DATABASE; el.el_be = be; + el.el_ndn = ndn; for ( elpp = &mi->mi_entry_limbo; *elpp; @@ -1062,9 +1064,7 @@ done:; entry_limbo_t **elpp, el = { 0 }; el.el_type = LIMBO_ATTRS; - if ( !BER_BVISNULL( &ndn ) ) { - ber_dupbv( &el.el_ndn, &ndn ); - } + el.el_ndn = ndn_in; if ( !BER_BVISNULL( nbase ) ) { ber_dupbv( &el.el_nbase, nbase); } @@ -1102,9 +1102,6 @@ done:; if ( !BER_BVISNULL( &el.el_nbase ) ) { ch_free( &el.el_nbase.bv_val ); } - if ( !BER_BVISNULL( &el.el_ndn ) ) { - ch_free( el.el_ndn.bv_val ); - } return -1; } } @@ -2141,9 +2138,6 @@ monitor_back_destroy_limbo_entry( if ( el->el_a ) { attrs_free( el->el_a ); } - if ( !BER_BVISNULL( &el->el_ndn ) ) { - ber_memfree( el->el_ndn.bv_val ); - } if ( !BER_BVISNULL( &el->el_nbase ) ) { ber_memfree( el->el_nbase.bv_val ); } @@ -2401,7 +2395,7 @@ monitor_back_db_open( case LIMBO_ATTRS: rc = monitor_back_register_entry_attrs( - &el->el_ndn, + el->el_ndn, el->el_a, el->el_cb, &el->el_nbase, @@ -2411,7 +2405,7 @@ monitor_back_db_open( case LIMBO_CB: rc = monitor_back_register_entry_callback( - &el->el_ndn, + el->el_ndn, el->el_cb, &el->el_nbase, el->el_scope, @@ -2423,7 +2417,7 @@ monitor_back_db_open( break; case LIMBO_DATABASE: - rc = monitor_back_register_database( el->el_be ); + rc = monitor_back_register_database( el->el_be, el->el_ndn ); break; case LIMBO_OVERLAY_INFO: diff --git a/servers/slapd/back-monitor/proto-back-monitor.h b/servers/slapd/back-monitor/proto-back-monitor.h index f09522db1f..6b353563bf 100644 --- a/servers/slapd/back-monitor/proto-back-monitor.h +++ b/servers/slapd/back-monitor/proto-back-monitor.h @@ -145,7 +145,8 @@ monitor_back_register_backend LDAP_P(( BackendInfo *bi )); extern int monitor_back_register_database LDAP_P(( - BackendDB *be )); + BackendDB *be, + struct berval *ndn )); extern int monitor_back_register_overlay_info LDAP_P(( slap_overinst *on )); @@ -157,7 +158,8 @@ monitor_back_register_backend_limbo LDAP_P(( BackendInfo *bi )); extern int monitor_back_register_database_limbo LDAP_P(( - BackendDB *be )); + BackendDB *be, + struct berval *ndn )); extern int monitor_back_register_overlay_info_limbo LDAP_P(( slap_overinst *on ));