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 );
156 mp = monitor_entrypriv_create();
160 e->e_private = ( void * )mp;
162 mp->mp_flags = ms->mss_flags \
163 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
165 if ( monitor_cache_add( mi, e ) ) {
166 Debug( LDAP_DEBUG_ANY,
167 "monitor_subsys_thread_init: "
168 "unable to add entry \"cn=Runqueue,%s\"\n",
169 ms->mss_ndn.bv_val, 0, 0 );
179 BER_BVSTR( &bv, "cn=Tasklist" );
180 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
181 mi->mi_oc_monitoredObject, mi, NULL, NULL );
183 Debug( LDAP_DEBUG_ANY,
184 "monitor_subsys_thread_init: "
185 "unable to create entry \"%s,%s\"\n",
186 bv.bv_val, ms->mss_ndn.bv_val, 0 );
190 mp = monitor_entrypriv_create();
194 e->e_private = ( void * )mp;
196 mp->mp_flags = ms->mss_flags \
197 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
199 if ( monitor_cache_add( mi, e ) ) {
200 Debug( LDAP_DEBUG_ANY,
201 "monitor_subsys_thread_init: "
202 "unable to add entry \"%s\"\n",
203 e->e_name.bv_val, 0, 0 );
210 monitor_cache_release( mi, e_thread );
216 monitor_subsys_thread_update(
221 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
223 BerVarray vals = NULL;
224 char buf[ BACKMONITOR_BUFSIZE ];
234 static slap_verbmasks mt[] = {
235 { BER_BVC( "cn=max" ), MT_MAX },
236 { BER_BVC( "cn=backload" ), MT_BACKLOAD },
237 { BER_BVC( "cn=runqueue" ), MT_RUNQUEUE },
238 { BER_BVC( "cn=tasklist" ), MT_TASKLIST },
239 { BER_BVNULL, MT_UNKNOWN }
241 struct berval rdn, bv;
245 assert( mi != NULL );
247 dnRdn( &e->e_nname, &rdn );
249 which = bverb_to_mask( &rdn, mt );
250 if ( BER_BVISNULL( &mt[ which ].word )
251 || mt[ which ].mask == MT_UNKNOWN )
253 return SLAP_CB_CONTINUE;
256 a = attr_find( e->e_attrs, mi->mi_ad_monitoredInfo );
258 switch ( mt[ which ].mask ) {
261 return rs->sr_err = LDAP_OTHER;
264 bv.bv_len = snprintf( buf, sizeof( buf ), "%d", connection_pool_max );
265 if ( bv.bv_len >= sizeof( buf ) ) {
269 ber_bvreplace( &a->a_vals[ 0 ], &bv );
274 return rs->sr_err = LDAP_OTHER;
277 bv.bv_len = snprintf( buf, sizeof( buf ), "%d",
278 ldap_pvt_thread_pool_backload( &connection_pool ) );
279 if ( bv.bv_len >= sizeof( buf ) ) {
283 ber_bvreplace( &a->a_vals[ 0 ], &bv );
288 if ( a->a_nvals != a->a_vals ) {
289 ber_bvarray_free( a->a_nvals );
291 ber_bvarray_free( a->a_vals );
298 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
299 LDAP_STAILQ_FOREACH( re, &slapd_rq.run_list, rnext ) {
300 bv.bv_len = snprintf( buf, sizeof( buf ), "{%d}%s(%s)",
301 i, re->tname, re->tspec );
302 if ( bv.bv_len < sizeof( buf ) ) {
303 value_add_one( &vals, &bv );
307 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
310 attr_merge_normalize( e, mi->mi_ad_monitoredInfo, vals, NULL );
311 ber_bvarray_free( vals );
317 if ( a->a_nvals != a->a_vals ) {
318 ber_bvarray_free( a->a_nvals );
320 ber_bvarray_free( a->a_vals );
327 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
328 LDAP_STAILQ_FOREACH( re, &slapd_rq.task_list, tnext ) {
329 bv.bv_len = snprintf( buf, sizeof( buf ), "{%d}%s(%s)",
330 i, re->tname, re->tspec );
331 if ( bv.bv_len < sizeof( buf ) ) {
332 value_add_one( &vals, &bv );
336 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
339 attr_merge_normalize( e, mi->mi_ad_monitoredInfo, vals, NULL );
340 ber_bvarray_free( vals );
345 /* FIXME: touch modifyTimestamp? */
347 return SLAP_CB_CONTINUE;