From f5c308bdb6fb1b3dc14095800d2b00ee845368d0 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 18 Aug 2006 10:26:03 +0000 Subject: [PATCH] more thread monitoring reworking; connection_pool_max may change via back-config --- servers/slapd/attr.c | 4 +- servers/slapd/back-monitor/thread.c | 97 ++++++++++++++++------------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index bb4b4ca606..fc9579283a 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -208,7 +208,9 @@ attr_merge( * of nvals and the value of (*a)->a_nvals must be consistent */ assert( ( nvals == NULL && (*a)->a_nvals == (*a)->a_vals ) - || ( nvals != NULL && (*a)->a_nvals != (*a)->a_vals ) ); + || ( nvals != NULL && ( + ( (*a)->a_vals == NULL && (*a)->a_nvals == NULL ) + || ( (*a)->a_nvals != (*a)->a_vals ) ) ) ); } rc = value_add( &(*a)->a_vals, vals ); diff --git a/servers/slapd/back-monitor/thread.c b/servers/slapd/back-monitor/thread.c index 47b39c82d0..3ca7207388 100644 --- a/servers/slapd/back-monitor/thread.c +++ b/servers/slapd/back-monitor/thread.c @@ -152,8 +152,6 @@ monitor_subsys_thread_init( ms->mss_ndn.bv_val, 0, 0 ); return( -1 ); } - BER_BVSTR( &bv, "0" ); - attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); mp = monitor_entrypriv_create(); if ( mp == NULL ) { @@ -188,8 +186,6 @@ monitor_subsys_thread_init( bv.bv_val, ms->mss_ndn.bv_val, 0 ); return( -1 ); } - BER_BVSTR( &bv, "0" ); - attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL ); mp = monitor_entrypriv_create(); if ( mp == NULL ) { @@ -224,23 +220,25 @@ monitor_subsys_thread_update( { monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; Attribute *a; + BerVarray vals = NULL; char buf[ BACKMONITOR_BUFSIZE ]; enum { MT_UNKNOWN, + MT_MAX, MT_BACKLOAD, MT_RUNQUEUE, MT_TASKLIST, - MT_MAX /* unused */ + + MT_LAST }; static slap_verbmasks mt[] = { + { BER_BVC( "cn=max" ), MT_MAX }, { BER_BVC( "cn=backload" ), MT_BACKLOAD }, { BER_BVC( "cn=runqueue" ), MT_RUNQUEUE }, { BER_BVC( "cn=tasklist" ), MT_TASKLIST }, - { BER_BVC( "cn=max" ), MT_UNKNOWN }, { BER_BVNULL, MT_UNKNOWN } }; struct berval rdn, bv; - ber_len_t len; int which, i; struct re_s *re; @@ -256,80 +254,91 @@ monitor_subsys_thread_update( } a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo ); - if ( a == NULL ) { - return rs->sr_err = LDAP_OTHER; - } switch ( mt[ which ].mask ) { + case MT_MAX: + if ( a == NULL ) { + return rs->sr_err = LDAP_OTHER; + } + bv.bv_val = buf; + bv.bv_len = snprintf( buf, sizeof( buf ), "%d", connection_pool_max ); + if ( bv.bv_len >= sizeof( buf ) ) { + /* FIXME? */ + break; + } + ber_bvreplace( &a->a_vals[ 0 ], &bv ); + break; + case MT_BACKLOAD: - snprintf( buf, sizeof( buf ), "%d", + if ( a == NULL ) { + return rs->sr_err = LDAP_OTHER; + } + bv.bv_val = buf; + bv.bv_len = snprintf( buf, sizeof( buf ), "%d", ldap_pvt_thread_pool_backload( &connection_pool ) ); - len = strlen( buf ); - if ( len > a->a_vals[ 0 ].bv_len ) { - a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 ); + if ( bv.bv_len >= sizeof( buf ) ) { + /* FIXME? */ + break; } - a->a_vals[ 0 ].bv_len = len; - AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 ); + ber_bvreplace( &a->a_vals[ 0 ], &bv ); break; case MT_RUNQUEUE: - for ( i = 0; !BER_BVISNULL( &a->a_vals[ i ] ); i++ ) { - ch_free( a->a_vals[ i ].bv_val ); - BER_BVZERO( &a->a_vals[ i ] ); - } - if ( a->a_nvals != a->a_vals ) { - ber_bvarray_free( a->a_nvals ); + if ( a != NULL ) { + if ( a->a_nvals != a->a_vals ) { + ber_bvarray_free( a->a_nvals ); + } + ber_bvarray_free( a->a_vals ); + a->a_vals = NULL; + a->a_nvals = NULL; } - a->a_nvals = NULL; + + i = 0; bv.bv_val = buf; ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); - i = 0; LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) { bv.bv_len = snprintf( buf, sizeof( buf ), "{%d}%s(%s)", i, re->tname, re->tspec ); if ( bv.bv_len < sizeof( buf ) ) { - value_add_one( &a->a_vals, &bv ); + value_add_one( &vals, &bv ); } i++; } ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - /* don't leave 'round attributes with no values */ - if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) { - BER_BVSTR( &bv, "{0}()" ); - value_add_one( &a->a_vals, &bv ); + if ( vals ) { + attr_merge_normalize( e, mi->mi_ad_monitoredInfo, vals, NULL ); + ber_bvarray_free( vals ); } - a->a_nvals = a->a_vals; break; case MT_TASKLIST: - for ( i = 0; !BER_BVISNULL( &a->a_vals[ i ] ); i++ ) { - ch_free( a->a_vals[ i ].bv_val ); - BER_BVZERO( &a->a_vals[ i ] ); - } - if ( a->a_nvals != a->a_vals ) { - ber_bvarray_free( a->a_nvals ); + if ( a != NULL ) { + if ( a->a_nvals != a->a_vals ) { + ber_bvarray_free( a->a_nvals ); + } + ber_bvarray_free( a->a_vals ); + a->a_vals = NULL; + a->a_nvals = NULL; } - a->a_nvals = NULL; + + i = 0; bv.bv_val = buf; ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); - i = 0; LDAP_STAILQ_FOREACH( re, &slapd_rq.task_list, tnext ) { bv.bv_len = snprintf( buf, sizeof( buf ), "{%d}%s(%s)", i, re->tname, re->tspec ); if ( bv.bv_len < sizeof( buf ) ) { - value_add_one( &a->a_vals, &bv ); + value_add_one( &vals, &bv ); } i++; } ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - /* don't leave 'round attributes with no values */ - if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) { - BER_BVSTR( &bv, "{0}()" ); - value_add_one( &a->a_vals, &bv ); + if ( vals ) { + attr_merge_normalize( e, mi->mi_ad_monitoredInfo, vals, NULL ); + ber_bvarray_free( vals ); } - a->a_nvals = a->a_vals; break; } -- 2.39.5