1 /* thread.c - deal with thread subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2006 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
25 #include <ac/string.h>
28 #include "back-monitor.h"
33 monitor_subsys_thread_update(
39 * initializes log subentry
42 monitor_subsys_thread_init(
49 Entry *e, **ep, *e_thread;
50 static char buf[ BACKMONITOR_BUFSIZE ];
53 ms->mss_update = monitor_subsys_thread_update;
55 mi = ( monitor_info_t * )be->be_private;
57 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_thread ) ) {
58 Debug( LDAP_DEBUG_ANY,
59 "monitor_subsys_thread_init: unable to get entry \"%s\"\n",
65 mp = ( monitor_entry_t * )e_thread->e_private;
66 mp->mp_children = NULL;
67 ep = &mp->mp_children;
72 BER_BVSTR( &bv, "cn=Max" );
73 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
74 mi->mi_oc_monitoredObject, mi, NULL, NULL );
76 Debug( LDAP_DEBUG_ANY,
77 "monitor_subsys_thread_init: "
78 "unable to create entry \"cn=Max,%s\"\n",
79 ms->mss_ndn.bv_val, 0, 0 );
82 bv.bv_len = snprintf( buf, sizeof( buf ), "%d", connection_pool_max );
84 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
86 mp = monitor_entrypriv_create();
90 e->e_private = ( void * )mp;
92 mp->mp_flags = ms->mss_flags \
93 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
95 if ( monitor_cache_add( mi, e ) ) {
96 Debug( LDAP_DEBUG_ANY,
97 "monitor_subsys_thread_init: "
98 "unable to add entry \"cn=Max,%s\"\n",
99 ms->mss_ndn.bv_val, 0, 0 );
109 BER_BVSTR( &bv, "cn=Backload" );
110 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
111 mi->mi_oc_monitoredObject, mi, NULL, NULL );
113 Debug( LDAP_DEBUG_ANY,
114 "monitor_subsys_thread_init: "
115 "unable to create entry \"cn=Backload,%s\"\n",
116 ms->mss_ndn.bv_val, 0, 0 );
119 BER_BVSTR( &bv, "0" );
120 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
122 mp = monitor_entrypriv_create();
126 e->e_private = ( void * )mp;
128 mp->mp_flags = ms->mss_flags \
129 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
131 if ( monitor_cache_add( mi, e ) ) {
132 Debug( LDAP_DEBUG_ANY,
133 "monitor_subsys_thread_init: "
134 "unable to add entry \"cn=Backload,%s\"\n",
135 ms->mss_ndn.bv_val, 0, 0 );
145 BER_BVSTR( &bv, "cn=Runqueue" );
146 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
147 mi->mi_oc_monitoredObject, mi, NULL, NULL );
149 Debug( LDAP_DEBUG_ANY,
150 "monitor_subsys_thread_init: "
151 "unable to create entry \"cn=Runqueue,%s\"\n",
152 ms->mss_ndn.bv_val, 0, 0 );
155 BER_BVSTR( &bv, "0" );
156 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
158 mp = monitor_entrypriv_create();
162 e->e_private = ( void * )mp;
164 mp->mp_flags = ms->mss_flags \
165 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
167 if ( monitor_cache_add( mi, e ) ) {
168 Debug( LDAP_DEBUG_ANY,
169 "monitor_subsys_thread_init: "
170 "unable to add entry \"cn=Runqueue,%s\"\n",
171 ms->mss_ndn.bv_val, 0, 0 );
178 monitor_cache_release( mi, e_thread );
184 monitor_subsys_thread_update(
189 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
191 char buf[ BACKMONITOR_BUFSIZE ];
192 static struct berval backload_bv = BER_BVC( "cn=backload" );
193 static struct berval runqueue_bv = BER_BVC( "cn=runqueue" );
194 struct berval rdn, bv;
199 assert( mi != NULL );
201 dnRdn( &e->e_nname, &rdn );
202 if ( dn_match( &rdn, &backload_bv ) ) {
205 } else if ( dn_match( &rdn, &runqueue_bv ) ) {
209 return SLAP_CB_CONTINUE;
212 a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
214 return rs->sr_err = LDAP_OTHER;
219 snprintf( buf, sizeof( buf ), "%d",
220 ldap_pvt_thread_pool_backload( &connection_pool ) );
222 if ( len > a->a_vals[ 0 ].bv_len ) {
223 a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
225 a->a_vals[ 0 ].bv_len = len;
226 AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
230 for ( i = 0; !BER_BVISNULL( &a->a_vals[ i ] ); i++ ) {
231 ch_free( a->a_vals[i].bv_val );
232 BER_BVZERO( &a->a_vals[ i ] );
235 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
236 LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) {
237 bv.bv_len = snprintf( buf, sizeof( buf ), "%s(%s)",
238 re->tname, re->tspec );
239 value_add_one( &a->a_vals, &bv );
241 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
243 /* don't leave 'round attributes with no values */
244 if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) {
245 BER_BVSTR( &bv, "()" );
246 value_add_one( &a->a_vals, &bv );
251 /* FIXME: touch modifyTimestamp? */
253 return SLAP_CB_CONTINUE;