1 /* readw.c - deal with read waiters subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 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>
29 #include "back-monitor.h"
38 struct monitor_rww_t {
42 { BER_BVC("cn=Read"), BER_BVNULL },
43 { BER_BVC("cn=Write"), BER_BVNULL },
44 { BER_BVNULL, BER_BVNULL }
48 monitor_subsys_rww_init(
61 mi = ( monitor_info_t * )be->be_private;
63 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_conn ) ) {
64 Debug( LDAP_DEBUG_ANY,
65 "monitor_subsys_rww_init: "
66 "unable to get entry \"%s\"\n",
67 ms->mss_ndn.bv_val, 0, 0 );
71 mp = ( monitor_entry_t * )e_conn->e_private;
72 mp->mp_children = NULL;
73 ep = &mp->mp_children;
75 for ( i = 0; i < MONITOR_RWW_LAST; i++ ) {
76 char buf[ BACKMONITOR_BUFSIZE ];
77 struct berval nrdn, bv;
80 snprintf( buf, sizeof( buf ),
83 "structuralObjectClass: %s\n"
87 "createTimestamp: %s\n"
88 "modifyTimestamp: %s\n",
89 monitor_rww[ i ].rdn.bv_val,
91 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
92 mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
93 &monitor_rww[ i ].rdn.bv_val[ STRLENOF( "cn=" ) ],
94 mi->mi_creatorsName.bv_val,
95 mi->mi_creatorsName.bv_val,
96 mi->mi_startTime.bv_val,
97 mi->mi_startTime.bv_val );
101 Debug( LDAP_DEBUG_ANY,
102 "monitor_subsys_rww_init: "
103 "unable to create entry \"cn=Read,%s\"\n",
104 ms->mss_ndn.bv_val, 0, 0 );
108 /* steal normalized RDN */
109 dnRdn( &e->e_nname, &nrdn );
110 ber_dupbv( &monitor_rww[ i ].nrdn, &nrdn );
112 BER_BVSTR( &bv, "0" );
113 attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, NULL );
115 mp = monitor_entrypriv_create();
119 e->e_private = ( void * )mp;
121 mp->mp_flags = ms->mss_flags \
122 | MONITOR_F_SUB | MONITOR_F_PERSISTENT;
124 if ( monitor_cache_add( mi, e ) ) {
125 Debug( LDAP_DEBUG_ANY,
126 "monitor_subsys_rww_init: "
127 "unable to add entry \"%s,%s\"\n",
128 monitor_rww[ i ].rdn.bv_val,
129 ms->mss_ndn.bv_val, 0 );
137 monitor_cache_release( mi, e_conn );
143 monitor_subsys_rww_update(
148 monitor_info_t *mi = (monitor_info_t *)op->o_bd->be_private;
151 long nconns, nwritewaiters, nreadwaiters;
157 char buf[] = "+9223372036854775807L";
161 assert( mi != NULL );
164 dnRdn( &e->e_nname, &nrdn );
166 for ( i = 0; !BER_BVISNULL( &monitor_rww[ i ].nrdn ); i++ ) {
167 if ( dn_match( &nrdn, &monitor_rww[ i ].nrdn ) ) {
172 if ( i == MONITOR_RWW_LAST ) {
176 nconns = nwritewaiters = nreadwaiters = 0;
177 for ( c = connection_first( &connindex );
179 c = connection_next( c, &connindex ), nconns++ )
181 if ( c->c_writewaiter ) {
186 if ( c->c_currentber != NULL ) {
193 case MONITOR_RWW_READ:
197 case MONITOR_RWW_WRITE:
205 snprintf( buf, sizeof( buf ), "%ld", num );
207 a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
210 if ( len > a->a_vals[ 0 ].bv_len ) {
211 a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
212 if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) {
213 BER_BVZERO( &a->a_vals[ 0 ] );
217 AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
218 a->a_vals[ 0 ].bv_len = len;
220 /* FIXME: touch modifyTimestamp? */