1 /* operation.c - deal with operation subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2004 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"
42 BER_BVC( "Extended" ),
47 monitor_subsys_ops_init(
51 struct monitorinfo *mi;
53 Entry *e, *e_tmp, *e_op;
54 struct monitorentrypriv *mp;
55 char buf[ BACKMONITOR_BUFSIZE ];
57 struct berval bv_zero = BER_BVC("0");
61 mi = ( struct monitorinfo * )be->be_private;
63 if ( monitor_cache_get( mi,
64 &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) ) {
66 LDAP_LOG( OPERATION, CRIT,
67 "monitor_subsys_ops_init: "
68 "unable to get entry '%s'\n",
69 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0, 0 );
71 Debug( LDAP_DEBUG_ANY,
72 "monitor_subsys_ops_init: "
73 "unable to get entry '%s'\n%s%s",
74 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val,
80 attr_merge_one( e_op, mi->mi_ad_monitorOpInitiated, &bv_zero, NULL );
81 attr_merge_one( e_op, mi->mi_ad_monitorOpCompleted, &bv_zero, NULL );
85 for ( i = SLAP_OP_LAST; i-- > 0; ) {
90 snprintf( buf, sizeof( buf ),
93 "structuralObjectClass: %s\n"
97 "createTimestamp: %s\n"
98 "modifyTimestamp: %s\n",
100 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
101 mi->mi_oc_monitorOperation->soc_cname.bv_val,
102 mi->mi_oc_monitorOperation->soc_cname.bv_val,
104 mi->mi_ad_monitorOpInitiated->ad_cname.bv_val,
105 mi->mi_ad_monitorOpCompleted->ad_cname.bv_val,
106 mi->mi_startTime.bv_val,
107 mi->mi_startTime.bv_val );
109 e = str2entry( buf );
112 LDAP_LOG( OPERATION, CRIT,
113 "monitor_subsys_ops_init: "
114 "unable to create entry 'cn=%s,%s'\n",
116 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
118 Debug( LDAP_DEBUG_ANY,
119 "monitor_subsys_ops_init: "
120 "unable to create entry 'cn=%s,%s'\n",
122 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
127 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
128 e->e_private = ( void * )mp;
130 mp->mp_children = NULL;
131 mp->mp_info = &monitor_subsys[SLAPD_MONITOR_OPS];
132 mp->mp_flags = monitor_subsys[SLAPD_MONITOR_OPS].mss_flags \
133 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
135 if ( monitor_cache_add( mi, e ) ) {
137 LDAP_LOG( OPERATION, CRIT,
138 "monitor_subsys_ops_init: "
139 "unable to add entry 'cn=%s,%s'\n",
141 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
143 Debug( LDAP_DEBUG_ANY,
144 "monitor_subsys_ops_init: "
145 "unable to add entry 'cn=%s,%s'\n",
147 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
155 mp = ( struct monitorentrypriv * )e_op->e_private;
156 mp->mp_children = e_tmp;
158 monitor_cache_release( mi, e_op );
164 monitor_subsys_ops_update(
169 struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
170 long nInitiated = 0, nCompleted = 0;
174 char buf[] = "+9223372036854775807L";
179 rdnvalue = e->e_dn + ( sizeof( "cn=" ) - 1 );
181 if ( strncmp( rdnvalue, SLAPD_MONITOR_OPS_NAME,
182 sizeof( SLAPD_MONITOR_OPS_NAME ) - 1 ) == 0 )
184 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
185 nInitiated += num_ops_initiated_[ i ];
186 nCompleted += num_ops_completed_[ i ];
190 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
191 if ( strncmp( rdnvalue, bv_op[ i ].bv_val,
192 bv_op[ i ].bv_len ) == 0 )
194 nInitiated = num_ops_initiated_[ i ];
195 nCompleted = num_ops_completed_[ i ];
200 if ( i == SLAP_OP_LAST ) {
206 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
207 assert ( a != NULL );
208 snprintf( buf, sizeof( buf ), "%ld", nInitiated );
209 free( a->a_vals[ 0 ].bv_val );
210 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );
212 a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
213 assert ( a != NULL );
214 snprintf( buf, sizeof( buf ), "%ld", nCompleted );
215 free( a->a_vals[ 0 ].bv_val );
216 ber_str2bv( buf, 0, 1, &a->a_vals[ 0 ] );