]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/operation.c
Revert ITS#3353 patch, it needs to be reworked.
[openldap] / servers / slapd / back-monitor / operation.c
1 /* operation.c - deal with operation subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2004 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-monitor.h"
29 #include "lber_pvt.h"
30
31 struct monitor_ops_t {
32         struct berval   rdn;
33         struct berval   nrdn;
34 } monitor_op[] = {
35         { BER_BVC( "cn=Bind" ),         BER_BVNULL },
36         { BER_BVC( "cn=Unbind" ),       BER_BVNULL },
37         { BER_BVC( "cn=Add" ),          BER_BVNULL },
38         { BER_BVC( "cn=Delete" ),       BER_BVNULL },
39         { BER_BVC( "cn=Modrdn" ),       BER_BVNULL },
40         { BER_BVC( "cn=Modify" ),       BER_BVNULL },
41         { BER_BVC( "cn=Compare" ),      BER_BVNULL },
42         { BER_BVC( "cn=Search" ),       BER_BVNULL },
43         { BER_BVC( "cn=Abandon" ),      BER_BVNULL },
44         { BER_BVC( "cn=Extended" ),     BER_BVNULL },
45         { BER_BVNULL,                   BER_BVNULL }
46 };
47
48 int
49 monitor_subsys_ops_init(
50         BackendDB               *be
51 )
52 {
53         struct monitorinfo      *mi;
54         
55         Entry                   *e_op, **ep;
56         struct monitorentrypriv *mp;
57         char                    buf[ BACKMONITOR_BUFSIZE ];
58         int                     i;
59         struct berval           bv_zero = BER_BVC("0");
60
61         assert( be != NULL );
62
63         mi = ( struct monitorinfo * )be->be_private;
64
65         if ( monitor_cache_get( mi,
66                         &monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn, &e_op ) )
67         {
68                 Debug( LDAP_DEBUG_ANY,
69                         "monitor_subsys_ops_init: "
70                         "unable to get entry \"%s\"\n",
71                         monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 
72                         0, 0 );
73                 return( -1 );
74         }
75
76         attr_merge_one( e_op, mi->mi_ad_monitorOpInitiated, &bv_zero, NULL );
77         attr_merge_one( e_op, mi->mi_ad_monitorOpCompleted, &bv_zero, NULL );
78
79         mp = ( struct monitorentrypriv * )e_op->e_private;
80         mp->mp_children = NULL;
81         ep = &mp->mp_children;
82
83         for ( i = 0; i < SLAP_OP_LAST; i++ ) {
84                 struct berval   rdn;
85                 Entry           *e;
86
87                 /*
88                  * Initiated ops
89                  */
90                 snprintf( buf, sizeof( buf ),
91                                 "dn: %s,%s\n"
92                                 "objectClass: %s\n"
93                                 "structuralObjectClass: %s\n"
94                                 "cn: %s\n"
95                                 "%s: 0\n"
96                                 "%s: 0\n"
97                                 "creatorsName: %s\n"
98                                 "modifiersName: %s\n"
99                                 "createTimestamp: %s\n"
100                                 "modifyTimestamp: %s\n",
101                                 monitor_op[ i ].rdn.bv_val,
102                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_dn.bv_val,
103                                 mi->mi_oc_monitorOperation->soc_cname.bv_val,
104                                 mi->mi_oc_monitorOperation->soc_cname.bv_val,
105                                 &monitor_op[ i ].rdn.bv_val[STRLENOF( "cn=" )],
106                                 mi->mi_ad_monitorOpInitiated->ad_cname.bv_val,
107                                 mi->mi_ad_monitorOpCompleted->ad_cname.bv_val,
108                                 mi->mi_creatorsName.bv_val,
109                                 mi->mi_creatorsName.bv_val,
110                                 mi->mi_startTime.bv_val,
111                                 mi->mi_startTime.bv_val );
112
113                 e = str2entry( buf );
114                 if ( e == NULL ) {
115                         Debug( LDAP_DEBUG_ANY,
116                                 "monitor_subsys_ops_init: "
117                                 "unable to create entry \"%s,%s\"\n",
118                                 monitor_op[ i ].rdn.bv_val,
119                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
120                         return( -1 );
121                 }
122         
123                 /* steal normalized RDN */
124                 dnRdn( &e->e_nname, &rdn );
125                 ber_dupbv( &monitor_op[i].nrdn, &rdn );
126         
127                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
128                 e->e_private = ( void * )mp;
129                 mp->mp_next = NULL;
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;
134
135                 if ( monitor_cache_add( mi, e ) ) {
136                         Debug( LDAP_DEBUG_ANY,
137                                 "monitor_subsys_ops_init: "
138                                 "unable to add entry \"%s,%s\"\n",
139                                 monitor_op[ i ].rdn.bv_val,
140                                 monitor_subsys[SLAPD_MONITOR_OPS].mss_ndn.bv_val, 0 );
141                         return( -1 );
142                 }
143
144                 *ep = e;
145                 ep = &mp->mp_next;
146         }
147
148         monitor_cache_release( mi, e_op );
149
150         return( 0 );
151 }
152
153 int
154 monitor_subsys_ops_update(
155         Operation               *op,
156         Entry                   *e
157 )
158 {
159         struct monitorinfo      *mi = 
160                 (struct monitorinfo *)op->o_bd->be_private;
161
162         ldap_pvt_mp_t           nInitiated,
163                                 nCompleted;
164         struct berval           rdn;
165         int                     i;
166         Attribute               *a;
167         static struct berval    bv_ops = BER_BVC( "cn=operations" );
168
169         assert( mi );
170         assert( e );
171
172         dnRdn( &e->e_nname, &rdn );
173
174         if ( dn_match( &rdn, &bv_ops ) ) {
175                 ldap_pvt_mp_init( nInitiated );
176                 ldap_pvt_mp_init( nCompleted );
177
178                 ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
179                 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
180                         ldap_pvt_mp_add( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
181                         ldap_pvt_mp_add( nCompleted, slap_counters.sc_ops_completed_[ i ] );
182                 }
183                 ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
184                 
185         } else {
186                 for ( i = 0; i < SLAP_OP_LAST; i++ ) {
187                         if ( dn_match( &rdn, &monitor_op[ i ].nrdn ) )
188                         {
189                                 ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex );
190                                 ldap_pvt_mp_init_set( nInitiated, slap_counters.sc_ops_initiated_[ i ] );
191                                 ldap_pvt_mp_init_set( nCompleted, slap_counters.sc_ops_completed_[ i ] );
192                                 ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
193                                 break;
194                         }
195                 }
196
197                 if ( i == SLAP_OP_LAST ) {
198                         /* not found ... */
199                         return( 0 );
200                 }
201         }
202
203         a = attr_find( e->e_attrs, mi->mi_ad_monitorOpInitiated );
204         assert ( a != NULL );
205
206         /* NOTE: no minus sign is allowed in the counters... */
207         UI2BV( &a->a_vals[ 0 ], nInitiated );
208         ldap_pvt_mp_clear( nInitiated );
209         
210         a = attr_find( e->e_attrs, mi->mi_ad_monitorOpCompleted );
211         assert ( a != NULL );
212
213         /* NOTE: no minus sign is allowed in the counters... */
214         UI2BV( &a->a_vals[ 0 ], nCompleted );
215         ldap_pvt_mp_clear( nCompleted );
216
217         return( 0 );
218 }
219