]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/monitor.c
Attribute/Modification value counters
[openldap] / servers / slapd / back-bdb / monitor.c
1 /* monitor.c - monitor bdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2007 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20 #include <ac/string.h>
21 #include <ac/unistd.h>
22 #include <ac/stdlib.h>
23 #include <ac/errno.h>
24 #include <sys/stat.h>
25 #include "lutil.h"
26 #include "back-bdb.h"
27
28 #include "../back-monitor/back-monitor.h"
29
30 #include "config.h"
31
32 static ObjectClass              *oc_olmBDBDatabase;
33
34 static AttributeDescription     *ad_olmBDBEntryCache,
35         *ad_olmBDBDNCache, *ad_olmBDBIDLCache,
36         *ad_olmDbDirectory;
37
38 #ifdef BDB_MONITOR_IDX
39 static int
40 bdb_monitor_idx_entry_add(
41         struct bdb_info *bdb,
42         Entry           *e );
43
44 static AttributeDescription     *ad_olmBDBNotIndexed;
45 #endif /* BDB_MONITOR_IDX */
46
47 /*
48  * NOTE: there's some confusion in monitor OID arc;
49  * by now, let's consider:
50  * 
51  * Subsystems monitor attributes        1.3.6.1.4.1.4203.666.1.55.0
52  * Databases monitor attributes         1.3.6.1.4.1.4203.666.1.55.0.1
53  * BDB database monitor attributes      1.3.6.1.4.1.4203.666.1.55.0.1.1
54  *
55  * Subsystems monitor objectclasses     1.3.6.1.4.1.4203.666.3.16.0
56  * Databases monitor objectclasses      1.3.6.1.4.1.4203.666.3.16.0.1
57  * BDB database monitor objectclasses   1.3.6.1.4.1.4203.666.3.16.0.1.1
58  */
59
60 static struct {
61         char                    *name;
62         char                    *oid;
63 }               s_oid[] = {
64         { "olmBDBAttributes",                   "olmDatabaseAttributes:1" },
65         { "olmBDBObjectClasses",                "olmDatabaseObjectClasses:1" },
66
67         { NULL }
68 };
69
70 static struct {
71         char                    *desc;
72         AttributeDescription    **ad;
73 }               s_at[] = {
74         { "( olmBDBAttributes:1 "
75                 "NAME ( 'olmBDBEntryCache' ) "
76                 "DESC 'Number of items in Entry Cache' "
77                 "SUP monitorCounter "
78                 "NO-USER-MODIFICATION "
79                 "USAGE dSAOperation )",
80                 &ad_olmBDBEntryCache },
81
82         { "( olmBDBAttributes:2 "
83                 "NAME ( 'olmBDBDNCache' ) "
84                 "DESC 'Number of items in DN Cache' "
85                 "SUP monitorCounter "
86                 "NO-USER-MODIFICATION "
87                 "USAGE dSAOperation )",
88                 &ad_olmBDBDNCache },
89
90         { "( olmBDBAttributes:3 "
91                 "NAME ( 'olmBDBIDLCache' ) "
92                 "DESC 'Number of items in IDL Cache' "
93                 "SUP monitorCounter "
94                 "NO-USER-MODIFICATION "
95                 "USAGE dSAOperation )",
96                 &ad_olmBDBIDLCache },
97
98         { "( olmBDBAttributes:4 "
99                 "NAME ( 'olmDbDirectory' ) "
100                 "DESC 'Path name of the directory "
101                         "where the database environment resides' "
102                 "SUP monitoredInfo "
103                 "NO-USER-MODIFICATION "
104                 "USAGE dSAOperation )",
105                 &ad_olmDbDirectory },
106
107 #ifdef BDB_MONITOR_IDX
108         { "( olmBDBAttributes:5 "
109                 "NAME ( 'olmBDBNotIndexed' ) "
110                 "DESC 'Missing indexes resulting from candidate selection' "
111                 "SUP monitoredInfo "
112                 "NO-USER-MODIFICATION "
113                 "USAGE dSAOperation )",
114                 &ad_olmBDBNotIndexed },
115 #endif /* BDB_MONITOR_IDX */
116
117         { NULL }
118 };
119
120 static struct {
121         char            *desc;
122         ObjectClass     **oc;
123 }               s_oc[] = {
124         /* augments an existing object, so it must be AUXILIARY
125          * FIXME: derive from some ABSTRACT "monitoredEntity"? */
126         { "( olmBDBObjectClasses:1 "
127                 "NAME ( 'olmBDBDatabase' ) "
128                 "SUP top AUXILIARY "
129                 "MAY ( "
130                         "olmBDBEntryCache "
131                         "$ olmBDBDNCache "
132                         "$ olmBDBIDLCache "
133                         "$ olmDbDirectory "
134 #ifdef BDB_MONITOR_IDX
135                         "$ olmBDBNotIndexed "
136 #endif /* BDB_MONITOR_IDX */
137                         ") )",
138                 &oc_olmBDBDatabase },
139
140         { NULL }
141 };
142
143 static int
144 bdb_monitor_update(
145         Operation       *op,
146         SlapReply       *rs,
147         Entry           *e,
148         void            *priv )
149 {
150         struct bdb_info         *bdb = (struct bdb_info *) priv;
151         Attribute               *a;
152
153         char                    buf[ BUFSIZ ];
154         struct berval           bv;
155
156         assert( ad_olmBDBEntryCache != NULL );
157
158         a = attr_find( e->e_attrs, ad_olmBDBEntryCache );
159         assert( a != NULL );
160         bv.bv_val = buf;
161         bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_cache.c_cursize );
162         ber_bvreplace( &a->a_vals[ 0 ], &bv );
163
164         a = attr_find( e->e_attrs, ad_olmBDBDNCache );
165         assert( a != NULL );
166         bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_cache.c_eiused );
167         ber_bvreplace( &a->a_vals[ 0 ], &bv );
168
169         a = attr_find( e->e_attrs, ad_olmBDBIDLCache );
170         assert( a != NULL );
171         bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_idl_cache_size );
172         ber_bvreplace( &a->a_vals[ 0 ], &bv );
173         
174 #ifdef BDB_MONITOR_IDX
175         bdb_monitor_idx_entry_add( bdb, e );
176 #endif /* BDB_MONITOR_IDX */
177
178         return SLAP_CB_CONTINUE;
179 }
180
181 #if 0   /* uncomment if required */
182 static int
183 bdb_monitor_modify(
184         Operation       *op,
185         SlapReply       *rs,
186         Entry           *e,
187         void            *priv )
188 {
189         return SLAP_CB_CONTINUE;
190 }
191 #endif
192
193 static int
194 bdb_monitor_free(
195         Entry           *e,
196         void            **priv )
197 {
198         struct berval   values[ 2 ];
199         Modification    mod = { 0 };
200
201         const char      *text;
202         char            textbuf[ SLAP_TEXT_BUFLEN ];
203
204         int             i, rc;
205
206         /* NOTE: if slap_shutdown != 0, priv might have already been freed */
207         *priv = NULL;
208
209         /* Remove objectClass */
210         mod.sm_op = LDAP_MOD_DELETE;
211         mod.sm_desc = slap_schema.si_ad_objectClass;
212         mod.sm_values = values;
213         values[ 0 ] = oc_olmBDBDatabase->soc_cname;
214         BER_BVZERO( &values[ 1 ] );
215
216         rc = modify_delete_values( e, &mod, 1, &text,
217                 textbuf, sizeof( textbuf ) );
218         /* don't care too much about return code... */
219
220         /* remove attrs */
221         for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
222                 mod.sm_desc = *s_at[ i ].ad;
223                 mod.sm_values = NULL;
224                 rc = modify_delete_values( e, &mod, 1, &text,
225                         textbuf, sizeof( textbuf ) );
226                 /* don't care too much about return code... */
227         }
228         
229         return SLAP_CB_CONTINUE;
230 }
231
232 #define bdb_monitor_initialize  BDB_SYMBOL(monitor_initialize)
233
234 /*
235  * call from within bdb_initialize()
236  */
237 static int
238 bdb_monitor_initialize( void )
239 {
240         int             i, code;
241         ConfigArgs c;
242         char    *argv[ 3 ];
243
244         static int      bdb_monitor_initialized = 0;
245
246         if ( backend_info( "monitor" ) == NULL ) {
247                 return -1;
248         }
249
250         if ( bdb_monitor_initialized++ ) {
251                 return 0;
252         }
253
254         /* register schema here */
255
256         argv[ 0 ] = "back-bdb/back-hdb monitor";
257         c.argv = argv;
258         c.argc = 3;
259         c.fname = argv[0];
260
261         for ( i = 0; s_oid[ i ].name; i++ ) {
262                 c.lineno = i;
263                 argv[ 1 ] = s_oid[ i ].name;
264                 argv[ 2 ] = s_oid[ i ].oid;
265
266                 if ( parse_oidm( &c, 0, NULL ) != 0 ) {
267                         Debug( LDAP_DEBUG_ANY,
268                                 "bdb_monitor_initialize: unable to add "
269                                 "objectIdentifier \"%s=%s\"\n",
270                                 s_oid[ i ].name, s_oid[ i ].oid, 0 );
271                         return 1;
272                 }
273         }
274
275         for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
276                 code = register_at( s_at[ i ].desc, s_at[ i ].ad, 1 );
277                 if ( code != LDAP_SUCCESS ) {
278                         Debug( LDAP_DEBUG_ANY,
279                                 "bdb_monitor_initialize: register_at failed\n",
280                                 0, 0, 0 );
281                 }
282                 (*s_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
283         }
284
285         for ( i = 0; s_oc[ i ].desc != NULL; i++ ) {
286                 code = register_oc( s_oc[ i ].desc, s_oc[ i ].oc, 1 );
287                 if ( code != LDAP_SUCCESS ) {
288                         Debug( LDAP_DEBUG_ANY,
289                                 "bdb_monitor_initialize: register_oc failed\n",
290                                 0, 0, 0 );
291                 }
292                 (*s_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
293         }
294
295         return 0;
296 }
297
298 /*
299  * call from within bdb_db_init()
300  */
301 int
302 bdb_monitor_db_init( BackendDB *be )
303 {
304         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
305
306         if ( SLAP_GLUE_SUBORDINATE( be ) ) {
307                 return 0;
308         }
309
310         if ( bdb_monitor_initialize() == LDAP_SUCCESS ) {
311                 /* monitoring in back-bdb is on by default */
312                 SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
313         }
314
315 #ifdef BDB_MONITOR_IDX
316         bdb->bi_idx = NULL;
317         ldap_pvt_thread_mutex_init( &bdb->bi_idx_mutex );
318 #endif /* BDB_MONITOR_IDX */
319
320         return 0;
321 }
322
323 /*
324  * call from within bdb_db_open()
325  */
326 int
327 bdb_monitor_db_open( BackendDB *be )
328 {
329         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
330         Attribute               *a, *next;
331         monitor_callback_t      *cb = NULL;
332         int                     rc = 0;
333         BackendInfo             *mi;
334         monitor_extra_t         *mbe;
335         struct berval dummy = BER_BVC("");
336
337         if ( !SLAP_DBMONITORING( be ) ) {
338                 return 0;
339         }
340
341         if ( SLAP_GLUE_SUBORDINATE( be ) ) {
342                 return 0;
343         }
344
345         mi = backend_info( "monitor" );
346         if ( !mi || !mi->bi_extra ) {
347                 SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
348                 return 0;
349         }
350         mbe = mi->bi_extra;
351
352         /* don't bother if monitor is not configured */
353         if ( !mbe->is_configured() ) {
354                 static int warning = 0;
355
356                 if ( warning++ == 0 ) {
357                         Debug( LDAP_DEBUG_ANY, "bdb_monitor_open: "
358                                 "monitoring disabled; "
359                                 "configure monitor database to enable\n",
360                                 0, 0, 0 );
361                 }
362
363                 return 0;
364         }
365
366         /* alloc as many as required (plus 1 for objectClass) */
367         a = attrs_alloc( 1 + 4 );
368         if ( a == NULL ) {
369                 rc = 1;
370                 goto cleanup;
371         }
372
373         a->a_desc = slap_schema.si_ad_objectClass;
374         attr_valadd( a, &oc_olmBDBDatabase->soc_cname, NULL, 1 );
375         next = a->a_next;
376
377         {
378                 struct berval   bv = BER_BVC( "0" );
379
380                 next->a_desc = ad_olmBDBEntryCache;
381                 attr_valadd( next, &bv, NULL, 1 );
382                 next = next->a_next;
383
384                 next->a_desc = ad_olmBDBDNCache;
385                 attr_valadd( next, &bv, NULL, 1 );
386                 next = next->a_next;
387
388                 next->a_desc = ad_olmBDBIDLCache;
389                 attr_valadd( next, &bv, NULL, 1 );
390                 next = next->a_next;
391         }
392
393         {
394                 struct berval   bv, nbv;
395                 ber_len_t       pathlen = 0, len = 0;
396                 char            path[ PATH_MAX ] = { '\0' };
397                 char            *fname = bdb->bi_dbenv_home,
398                                 *ptr;
399
400                 len = strlen( fname );
401                 if ( fname[ 0 ] != '/' ) {
402                         /* get full path name */
403                         getcwd( path, sizeof( path ) );
404                         pathlen = strlen( path );
405
406                         if ( fname[ 0 ] == '.' && fname[ 1 ] == '/' ) {
407                                 fname += 2;
408                                 len -= 2;
409                         }
410                 }
411
412                 bv.bv_len = pathlen + STRLENOF( "/" ) + len;
413                 ptr = bv.bv_val = ch_malloc( bv.bv_len + STRLENOF( "/" ) + 1 );
414                 if ( pathlen ) {
415                         ptr = lutil_strncopy( ptr, path, pathlen );
416                         ptr[ 0 ] = '/';
417                         ptr++;
418                 }
419                 ptr = lutil_strncopy( ptr, fname, len );
420                 if ( ptr[ -1 ] != '/' ) {
421                         ptr[ 0 ] = '/';
422                         ptr++;
423                 }
424                 ptr[ 0 ] = '\0';
425                 
426                 attr_normalize_one( ad_olmDbDirectory, &bv, &nbv, NULL );
427
428                 next->a_desc = ad_olmDbDirectory;
429                 next->a_vals = ch_calloc( sizeof( struct berval ), 2 );
430                 next->a_vals[ 0 ] = bv;
431                 next->a_numvals = 1;
432
433                 if ( BER_BVISNULL( &nbv ) ) {
434                         next->a_nvals = next->a_vals;
435
436                 } else {
437                         next->a_nvals = ch_calloc( sizeof( struct berval ), 2 );
438                         next->a_nvals[ 0 ] = nbv;
439                 }
440
441                 next = next->a_next;
442         }
443
444         cb = ch_calloc( sizeof( monitor_callback_t ), 1 );
445         cb->mc_update = bdb_monitor_update;
446 #if 0   /* uncomment if required */
447         cb->mc_modify = bdb_monitor_modify;
448 #endif
449         cb->mc_free = bdb_monitor_free;
450         cb->mc_private = (void *)bdb;
451
452         /* make sure the database is registered; then add monitor attributes */
453         rc = mbe->register_database( be, &bdb->bi_monitor.bdm_ndn );
454         if ( rc == 0 ) {
455                 rc = mbe->register_entry_attrs( &bdb->bi_monitor.bdm_ndn, a, cb,
456                         &dummy, 0, &dummy );
457         }
458
459 cleanup:;
460         if ( rc != 0 ) {
461                 if ( cb != NULL ) {
462                         ch_free( cb );
463                         cb = NULL;
464                 }
465
466                 if ( a != NULL ) {
467                         attrs_free( a );
468                         a = NULL;
469                 }
470         }
471
472         /* store for cleanup */
473         bdb->bi_monitor.bdm_cb = (void *)cb;
474
475         /* we don't need to keep track of the attributes, because
476          * bdb_monitor_free() takes care of everything */
477         if ( a != NULL ) {
478                 attrs_free( a );
479         }
480
481         return rc;
482 }
483
484 /*
485  * call from within bdb_db_close()
486  */
487 int
488 bdb_monitor_db_close( BackendDB *be )
489 {
490         struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
491
492         if ( SLAP_GLUE_SUBORDINATE( be ) ) {
493                 return 0;
494         }
495
496         if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_ndn ) ) {
497                 BackendInfo             *mi = backend_info( "monitor" );
498                 monitor_extra_t         *mbe;
499
500                 if ( mi && &mi->bi_extra ) {
501                         mbe = mi->bi_extra;
502                         mbe->unregister_entry_callback( &bdb->bi_monitor.bdm_ndn,
503                                 (monitor_callback_t *)bdb->bi_monitor.bdm_cb,
504                                 NULL, 0, NULL );
505                 }
506
507                 memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) );
508         }
509
510         return 0;
511 }
512
513 /*
514  * call from within bdb_db_destroy()
515  */
516 int
517 bdb_monitor_db_destroy( BackendDB *be )
518 {
519         if ( SLAP_GLUE_SUBORDINATE( be ) ) {
520                 return 0;
521         }
522
523 #ifdef BDB_MONITOR_IDX
524         {
525                 struct bdb_info         *bdb = (struct bdb_info *) be->be_private;
526
527                 /* TODO: free tree */
528                 ldap_pvt_thread_mutex_destroy( &bdb->bi_idx_mutex );
529                 avl_free( bdb->bi_idx, ch_free );
530         }
531 #endif /* BDB_MONITOR_IDX */
532
533         return 0;
534 }
535
536 #ifdef BDB_MONITOR_IDX
537
538 #define BDB_MONITOR_IDX_TYPES   (4)
539
540 typedef struct monitor_idx_t monitor_idx_t;
541
542 struct monitor_idx_t {
543         AttributeDescription    *idx_ad;
544         unsigned long           idx_count[BDB_MONITOR_IDX_TYPES];
545 };
546
547 static int
548 bdb_monitor_bitmask2key( slap_mask_t bitmask )
549 {
550         int     key;
551
552         for ( key = 0; key < 8*sizeof(slap_mask_t) && !( bitmask & 0x1U ); key++ ) {
553                 bitmask >>= 1;
554         }
555
556         return key;
557 }
558
559 static struct berval idxbv[] = {
560         BER_BVC( "present=" ),
561         BER_BVC( "equality=" ),
562         BER_BVC( "approx=" ),
563         BER_BVC( "substr=" ),
564         BER_BVNULL
565 };
566
567 static ber_len_t
568 bdb_monitor_idx2len( monitor_idx_t *idx )
569 {
570         int             i;
571         ber_len_t       len = 0;
572
573         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
574                 if ( idx->idx_count[ i ] != 0 ) {
575                         len += idxbv[i].bv_len;
576                 }
577         }
578
579         return len;
580 }
581
582 static int
583 monitor_idx_cmp( const void *p1, const void *p2 )
584 {
585         const monitor_idx_t     *idx1 = (const monitor_idx_t *)p1;
586         const monitor_idx_t     *idx2 = (const monitor_idx_t *)p2;
587
588         return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad );
589 }
590
591 static int
592 monitor_idx_dup( void *p1, void *p2 )
593 {
594         monitor_idx_t   *idx1 = (monitor_idx_t *)p1;
595         monitor_idx_t   *idx2 = (monitor_idx_t *)p2;
596
597         return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad ) == 0 ? -1 : 0;
598 }
599
600 int
601 bdb_monitor_idx_add(
602         struct bdb_info         *bdb,
603         AttributeDescription    *desc,
604         slap_mask_t             type )
605 {
606         monitor_idx_t           idx_dummy = { 0 },
607                                 *idx;
608         int                     rc = 0, key;
609
610         idx_dummy.idx_ad = desc;
611         key = bdb_monitor_bitmask2key( type ) - 1;
612         if ( key >= BDB_MONITOR_IDX_TYPES ) {
613                 /* invalid index type */
614                 return -1;
615         }
616
617         ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
618
619         idx = (monitor_idx_t *)avl_find( bdb->bi_idx,
620                 (caddr_t)&idx_dummy, monitor_idx_cmp );
621         if ( idx == NULL ) {
622                 idx = (monitor_idx_t *)ch_calloc( sizeof( monitor_idx_t ), 1 );
623                 idx->idx_ad = desc;
624                 idx->idx_count[ key ] = 1;
625
626                 switch ( avl_insert( &bdb->bi_idx, (caddr_t)idx, 
627                         monitor_idx_cmp, monitor_idx_dup ) )
628                 {
629                 case 0:
630                         break;
631
632                 default:
633                         ch_free( idx );
634                         rc = -1;
635                 }
636
637         } else {
638                 idx->idx_count[ key ]++;
639         }
640
641         ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
642
643         return rc;
644 }
645
646 static int
647 bdb_monitor_idx_apply( void *v_idx, void *v_valp )
648 {
649         monitor_idx_t   *idx = (monitor_idx_t *)v_idx;
650         BerVarray       *valp = (BerVarray *)v_valp;
651
652         struct berval   bv;
653         char            *ptr;
654         char            count_buf[ BDB_MONITOR_IDX_TYPES ][ SLAP_TEXT_BUFLEN ];
655         ber_len_t       count_len[ BDB_MONITOR_IDX_TYPES ],
656                         idx_len;
657         int             i, num = 0;
658
659         idx_len = bdb_monitor_idx2len( idx );
660
661         bv.bv_len = 0;
662         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
663                 if ( idx->idx_count[ i ] == 0 ) {
664                         continue;
665                 }
666
667                 count_len[ i ] = snprintf( count_buf[ i ],
668                         sizeof( count_buf[ i ] ), "%lu", idx->idx_count[ i ] );
669                 bv.bv_len += count_len[ i ];
670                 num++;
671         }
672
673         bv.bv_len += idx->idx_ad->ad_cname.bv_len
674                 + num
675                 + idx_len;
676         ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 );
677         ptr = lutil_strcopy( ptr, idx->idx_ad->ad_cname.bv_val );
678         for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
679                 if ( idx->idx_count[ i ] == 0 ) {
680                         continue;
681                 }
682
683                 ptr[ 0 ] = '#';
684                 ++ptr;
685                 ptr = lutil_strcopy( ptr, idxbv[ i ].bv_val );
686                 ptr = lutil_strcopy( ptr, count_buf[ i ] );
687         }
688
689         ber_bvarray_add( valp, &bv );
690
691         return 0;
692 }
693
694 static int
695 bdb_monitor_idx_entry_add(
696         struct bdb_info *bdb,
697         Entry           *e )
698 {
699         BerVarray       vals = NULL;
700         Attribute       *a;
701
702         a = attr_find( e->e_attrs, ad_olmBDBNotIndexed );
703
704         ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
705
706         avl_apply( bdb->bi_idx, bdb_monitor_idx_apply,
707                 &vals, -1, AVL_INORDER );
708
709         ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
710
711         if ( vals != NULL ) {
712                 if ( a != NULL ) {
713                         assert( a->a_nvals == a->a_vals );
714
715                         ber_bvarray_free( a->a_vals );
716
717                 } else {
718                         Attribute       **ap;
719
720                         for ( ap = &e->e_attrs; *ap != NULL; ap = &(*ap)->a_next )
721                                 ;
722                         *ap = attr_alloc( ad_olmBDBNotIndexed );
723                         a = *ap;
724                 }
725                 a->a_vals = vals;
726                 a->a_nvals = a->a_vals;
727         }
728
729         return 0;
730 }
731
732 #endif /* BDB_MONITOR_IDX */