]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/config.c
Server timing as a private feature of the bdb2 backend.
[openldap] / servers / slapd / back-bdb2 / config.c
1 /* config.c - bdb2 backend configuration file routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/socket.h>
8 #include <ac/string.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12
13 static int
14 bdb2i_back_config_internal(
15     BackendInfo *bi,
16     char                *fname,
17     int                 lineno,
18     int                 argc,
19     char                **argv
20 )
21 {
22         struct ldbtype  *lty = (struct ldbtype *) bi->bi_private;
23
24         if ( lty == NULL ) {
25                 fprintf( stderr, "%s: line %d: ldbm backend type info is null!\n",
26                     fname, lineno );
27                 return( 1 );
28         }
29
30         /* directory where DB control files live */
31         if ( strcasecmp( argv[0], "home" ) == 0 ) {
32                 if ( argc < 2 ) {
33                         fprintf( stderr,
34                 "%s: line %d: missing dir in \"home <dir>\" line\n",
35                             fname, lineno );
36                         return( 1 );
37                 }
38                 lty->lty_dbhome = ch_strdup( argv[1] );
39
40         /* size of the DB memory pool */
41         } else if ( strcasecmp( argv[0], "mpoolsize" ) == 0 ) {
42                 if ( argc < 2 ) {
43                         fprintf( stderr,
44                         "%s: line %d: missing size in \"mpoolsize <size>\" line\n",
45                             fname, lineno );
46                         return( 1 );
47                 }
48                 lty->lty_mpsize = (size_t) atoi( argv[1] );
49                 /*  we should at least have the suggested 128k  */
50                 if ( lty->lty_mpsize < DEFAULT_DBCACHE_SIZE )
51                         lty->lty_mpsize = DEFAULT_DBCACHE_SIZE;
52
53         /* anything else */
54         } else {
55                 fprintf( stderr,
56 "%s: line %d: unknown directive \"%s\" in ldbm backend definition (ignored)\n",
57                     fname, lineno, argv[0] );
58         }
59
60         return 0;
61 }
62
63
64 int
65 bdb2_back_config(
66     BackendInfo *bi,
67     char        *fname,
68     int         lineno,
69     int         argc,
70     char        **argv
71 )
72 {
73         struct timeval  time1;
74         int             ret;
75
76         bdb2i_start_timing( bi, &time1 );
77
78         ret = bdb2i_back_config_internal( bi, fname, lineno, argc, argv );
79         bdb2i_stop_timing( bi, time1, "BE-CONFIG", NULL, NULL );
80
81         return( ret );
82 }
83
84
85 static int
86 bdb2i_back_db_config_internal(
87     BackendDB   *be,
88     char        *fname,
89     int         lineno,
90     int         argc,
91     char        **argv
92 )
93 {
94         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
95
96         if ( li == NULL ) {
97                 fprintf( stderr, "%s: line %d: ldbm database info is null!\n",
98                     fname, lineno );
99                 return( 1 );
100         }
101
102         /* directory where database files live */
103         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
104                 if ( argc < 2 ) {
105                         fprintf( stderr,
106                 "%s: line %d: missing dir in \"directory <dir>\" line\n",
107                             fname, lineno );
108                         return( 1 );
109                 }
110                 li->li_directory = ch_strdup( argv[1] );
111
112                 li->li_nextid_file =
113                         ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 );
114
115                 strcpy(li->li_nextid_file, li->li_directory);
116                 strcat(li->li_nextid_file, "/NEXTID");
117
118         /* mode with which to create new database files */
119         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
120                 if ( argc < 2 ) {
121                         fprintf( stderr,
122                         "%s: line %d: missing mode in \"mode <mode>\" line\n",
123                             fname, lineno );
124                         return( 1 );
125                 }
126                 li->li_mode = strtol( argv[1], NULL, 0 );
127
128         /* attribute to index */
129         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
130                 if ( argc < 2 ) {
131                         fprintf( stderr,
132 "%s: line %d: missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
133                             fname, lineno );
134                         return( 1 );
135                 } else if ( argc > 3 ) {
136                         fprintf( stderr,
137 "%s: line %d: extra junk after \"index <attr> [pres,eq,approx,sub]\" line (ignored)\n",
138                             fname, lineno );
139                 }
140                 bdb2i_attr_index_config( li, fname, lineno, argc - 1, &argv[1], 0 );
141
142         /* size of the cache in entries */
143         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
144                 if ( argc < 2 ) {
145                         fprintf( stderr,
146                 "%s: line %d: missing size in \"cachesize <size>\" line\n",
147                             fname, lineno );
148                         return( 1 );
149                 }
150                 li->li_cache.c_maxsize = atoi( argv[1] );
151
152         /* size of each dbcache in bytes */
153         } else if ( strcasecmp( argv[0], "dbcachesize" ) == 0 ) {
154                 if ( argc < 2 ) {
155                         fprintf( stderr,
156                 "%s: line %d: missing size in \"dbcachesize <size>\" line\n",
157                             fname, lineno );
158                         return( 1 );
159                 }
160                 li->li_dbcachesize = atoi( argv[1] );
161                 /*  we should at least have the suggested 128k  */
162                 if ( li->li_dbcachesize < DEFAULT_DBCACHE_SIZE )
163                         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
164
165         /* no write sync */
166         } else if ( strcasecmp( argv[0], "dbcachenowsync" ) == 0 ) {
167                 li->li_dbcachewsync = 0;
168
169         /* anything else */
170         } else {
171                 fprintf( stderr,
172 "%s: line %d: unknown directive \"%s\" in ldbm database definition (ignored)\n",
173                     fname, lineno, argv[0] );
174         }
175
176         return 0;
177 }
178
179
180 int
181 bdb2_back_db_config(
182     BackendDB   *be,
183     char        *fname,
184     int         lineno,
185     int         argc,
186     char        **argv
187 )
188 {
189         struct timeval  time1;
190         int             ret;
191
192         bdb2i_start_timing( be->be_private, &time1 );
193
194         ret = bdb2i_back_db_config_internal( be, fname, lineno, argc, argv );
195
196         bdb2i_stop_timing( be->be_private, time1, "DB-CONFIG", NULL, NULL );
197
198         return( ret );
199 }
200
201