1 /* operation.c - deal with operation subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2009 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"
31 struct monitor_ops_t {
35 { BER_BVC( "cn=Bind" ), BER_BVNULL },
36 { BER_BVC( "cn=Unbind" ), BER_BVNULL },
37 { BER_BVC( "cn=Search" ), BER_BVNULL },
38 { BER_BVC( "cn=Compare" ), BER_BVNULL },
39 { BER_BVC( "cn=Modify" ), BER_BVNULL },
40 { BER_BVC( "cn=Modrdn" ), BER_BVNULL },
41 { BER_BVC( "cn=Add" ), BER_BVNULL },
42 { BER_BVC( "cn=Delete" ), BER_BVNULL },
43 { BER_BVC( "cn=Abandon" ), BER_BVNULL },
44 { BER_BVC( "cn=Extended" ), BER_BVNULL },
45 { BER_BVNULL, BER_BVNULL }
49 monitor_subsys_ops_destroy(
51 monitor_subsys_t *ms );
54 monitor_subsys_ops_update(
60 monitor_subsys_ops_init(
62 monitor_subsys_t *ms )
69 struct berval bv_zero = BER_BVC( "0" );
73 ms->mss_destroy = monitor_subsys_ops_destroy;
74 ms->mss_update = monitor_subsys_ops_update;
76 mi = ( monitor_info_t * )be->be_private;
78 if ( monitor_cache_get( mi,
79 &ms->mss_ndn, &e_op ) )
81 Debug( LDAP_DEBUG_ANY,
82 "monitor_subsys_ops_init: "
83 "unable to get entry \"%s\"\n",
89 attr_merge_one( e_op, mi->mi_ad_monitorOpInitiated, &bv_zero, &bv_zero );
90 attr_merge_one( e_op, mi->mi_ad_monitorOpCompleted, &bv_zero, &bv_zero );
92 mp = ( monitor_entry_t * )e_op->e_private;
93 mp->mp_children = NULL;
94 ep = &mp->mp_children;
96 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
104 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &monitor_op[i].rdn,
105 mi->mi_oc_monitorOperation, mi, NULL, NULL );
108 Debug( LDAP_DEBUG_ANY,
109 "monitor_subsys_ops_init: "
110 "unable to create entry \"%s,%s\"\n",
111 monitor_op[ i ].rdn.bv_val,
112 ms->mss_ndn.bv_val, 0 );
116 BER_BVSTR( &bv, "0" );
117 attr_merge_one( e, mi->mi_ad_monitorOpInitiated, &bv, NULL );
118 attr_merge_one( e, mi->mi_ad_monitorOpCompleted, &bv, NULL );
120 /* steal normalized RDN */
121 dnRdn( &e->e_nname, &rdn );
122 ber_dupbv( &monitor_op[ i ].nrdn, &rdn );
124 mp = monitor_entrypriv_create();
128 e->e_private = ( void * )mp;
130 mp->mp_flags = ms->mss_flags \
131 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
133 if ( monitor_cache_add( mi, e ) ) {
134 Debug( LDAP_DEBUG_ANY,
135 "monitor_subsys_ops_init: "
136 "unable to add entry \"%s,%s\"\n",
137 monitor_op[ i ].rdn.bv_val,
138 ms->mss_ndn.bv_val, 0 );
146 monitor_cache_release( mi, e_op );
152 monitor_subsys_ops_destroy(
154 monitor_subsys_t *ms )
158 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
159 if ( !BER_BVISNULL( &monitor_op[ i ].nrdn ) ) {
160 ch_free( monitor_op[ i ].nrdn.bv_val );
168 monitor_subsys_ops_update(
173 monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
175 ldap_pvt_mp_t nInitiated = LDAP_PVT_MP_INIT,
176 nCompleted = LDAP_PVT_MP_INIT;
181 static struct berval bv_ops = BER_BVC( "cn=operations" );
183 assert( mi != NULL );
186 dnRdn( &e->e_nname, &rdn );
188 if ( dn_match( &rdn, &bv_ops ) ) {
189 ldap_pvt_mp_init( nInitiated );
190 ldap_pvt_mp_init( nCompleted );
192 ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
193 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
194 ldap_pvt_mp_add( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
195 ldap_pvt_mp_add( nCompleted, slap_counters.sc_ops_completed_[ i ] );
197 for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
198 ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
199 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
200 ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
201 ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
203 ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
205 ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
208 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
209 if ( dn_match( &rdn, &monitor_op[ i ].nrdn ) )
211 ldap_pvt_thread_mutex_lock( &slap_counters.sc_mutex );
212 ldap_pvt_mp_init_set( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
213 ldap_pvt_mp_init_set( nCompleted, slap_counters.sc_ops_completed_[ i ] );
214 for ( sc = slap_counters.sc_next; sc; sc = sc->sc_next ) {
215 ldap_pvt_thread_mutex_lock( &sc->sc_mutex );
216 ldap_pvt_mp_add( nInitiated, sc->sc_ops_initiated_[ i ] );
217 ldap_pvt_mp_add( nCompleted, sc->sc_ops_completed_[ i ] );
218 ldap_pvt_thread_mutex_unlock( &sc->sc_mutex );
220 ldap_pvt_thread_mutex_unlock( &slap_counters.sc_mutex );
225 if ( i == SLAP_OP_LAST ) {
231 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
232 assert ( a != NULL );
234 /* NOTE: no minus sign is allowed in the counters... */
235 UI2BV( &a->a_vals[ 0 ], nInitiated );
236 ldap_pvt_mp_clear( nInitiated );
238 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
239 assert ( a != NULL );
241 /* NOTE: no minus sign is allowed in the counters... */
242 UI2BV( &a->a_vals[ 0 ], nCompleted );
243 ldap_pvt_mp_clear( nCompleted );
245 /* FIXME: touch modifyTimestamp? */
247 return SLAP_CB_CONTINUE;