]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/rww.c
pass Operation instead of private info
[openldap] / servers / slapd / back-monitor / rww.c
1 /* readw.c - deal with read waiters subsystem */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8  * 
9  * This work has beed deveolped for the OpenLDAP Foundation 
10  * in the hope that it may be useful to the Open Source community, 
11  * but WITHOUT ANY WARRANTY.
12  * 
13  * Permission is granted to anyone to use this software for any purpose
14  * on any computer system, and to alter it and redistribute it, subject
15  * to the following restrictions:
16  * 
17  * 1. The author and SysNet s.n.c. are not responsible for the consequences
18  *    of use of this software, no matter how awful, even if they arise from
19  *    flaws in it.
20  * 
21  * 2. The origin of this software must not be misrepresented, either by
22  *    explicit claim or by omission.  Since few users ever read sources,
23  *    credits should appear in the documentation.
24  * 
25  * 3. Altered versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.  Since few users
27  *    ever read sources, credits should appear in the documentation.
28  *    SysNet s.n.c. cannot be responsible for the consequences of the
29  *    alterations.
30  * 
31  * 4. This notice may not be removed or altered.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37
38 #include "slap.h"
39 #include "back-monitor.h"
40
41 static int monitor_subsys_readw_update_internal( Operation *op, Entry *e, int rw );
42
43 int 
44 monitor_subsys_readw_update( 
45         Operation               *op,
46         Entry                   *e
47 )
48 {
49         return monitor_subsys_readw_update_internal( op, e, 0 );
50 }
51
52 int 
53 monitor_subsys_writew_update( 
54         Operation               *op,
55         Entry                   *e
56 )
57 {
58         return monitor_subsys_readw_update_internal( op, e, 1 );
59 }
60
61 static int 
62 monitor_subsys_readw_update_internal( 
63         Operation               *op,
64         Entry                   *e,
65         int                     rw
66 )
67 {
68         struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
69         Connection              *c;
70         int                     connindex;
71         int                     nconns, nwritewaiters, nreadwaiters;
72         
73         Attribute               *a;
74         struct berval           *b = NULL;
75         char                    buf[1024];
76         
77         char                    *str = NULL;
78         int                     num = 0;
79
80         assert( mi != NULL );
81         assert( e != NULL );
82         
83         nconns = nwritewaiters = nreadwaiters = 0;
84         for ( c = connection_first( &connindex );
85                         c != NULL;
86                         c = connection_next( c, &connindex ), nconns++ ) {
87                 if ( c->c_writewaiter ) {
88                         nwritewaiters++;
89                 }
90                 if ( c->c_currentber != NULL ) {
91                         nreadwaiters++;
92                 }
93         }
94         connection_done(c);
95
96         switch ( rw ) {
97         case 0:
98                 str = "read waiters";
99                 num = nreadwaiters;
100                 break;
101         case 1:
102                 str = "write waiters";
103                 num = nwritewaiters;
104                 break;
105         }
106         snprintf( buf, sizeof( buf ), "%s=%d", str, num );
107
108         if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
109                 for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
110                         if ( strncmp( b[0].bv_val, str, strlen( str ) ) == 0 ) {
111                                 free( b[0].bv_val );
112                                 ber_str2bv( buf, 0, 1, b );
113                                 break;
114                         }
115                 }
116         }
117
118         if ( b == NULL || b[0].bv_val == NULL ) {
119                 struct berval bv;
120
121                 bv.bv_val = buf;
122                 bv.bv_len = strlen( buf );
123
124                 attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
125         }
126
127         return( 0 );
128 }
129